These are chat archives for AvaloniaUI/Avalonia

22nd
Dec 2018
dfkeenan
@dfkeenan
Dec 22 2018 01:57
I have never heard of open collective before. Is it like patreon but for open source software projects or something?
Kermalis
@Kermalis
Dec 22 2018 05:08
Is there a way to replace a specific color in a bitmap with another color?
If not, is there a specific type of bitmap that has that functionality?
I can't find a way to get the address of the pixel data except for writeablebitmap, but I'm not using that
dfkeenan
@dfkeenan
Dec 22 2018 05:12
WriteableBitmap?
ahopper
@ahopper
Dec 22 2018 06:53
@Kermalis Bitmaps are typically implementation specific objects that may well be stored in gpu memory so there is not a generic way to get a pointer to the pixels. The WriteableBitmap is a special case that keeps its pixels (or a copy) in cpu memory to enable what you want.
alternatively you could make the 'specific color' transparent and change the background
Nikita Tsukanov
@kekekeks
Dec 22 2018 06:58
You can get a drawing context for a writablebitmap
We might want to expose that api from writablebitmap itself
Kermalis
@Kermalis
Dec 22 2018 07:23
How can I create a writeablebitmap from this current bitmap I have then?
Right now I'm "drawing" onto a RenderTargetBitmap
            // Draw the string
            var rtb = new RenderTargetBitmap(new PixelSize(eachLineWidth.Max(), stringHeight));
            using (IDrawingContextImpl ctx = rtb.CreateDrawingContext(null))
            {
                double x = 0, y = 0;
                foreach (char c in str)
                {
                    if (c == ' ')
                    {
                        x += 4;
                    }
                    else if (c == '\r')
                    {
                        continue;
                    }
                    else if (c == '\n')
                    {
                        y += charHeight + 1;
                        x = 0;
                    }
                    else
                    {
                        Bitmap bmp = LoadedBitmaps[GetCharKey(c)];
                        int charWidth = bmp.PixelSize.Width;
                        ctx.DrawImage(bmp.PlatformImpl, 1.0, new Rect(0, 0, charWidth, charHeight), new Rect(x, y, charWidth, charHeight));
                        x += charWidth;
                    }
                }
            }
            return rtb;
I'm using resources which are all .png files, they each represent a unicode character, so I'm pasting them into this bitmap basically to create a sort of font
Each png only uses two colors, and transparency, so depending on the situation I would like to replace the primary and secondary color with another, but I don't think it'd be easy with writeablebitmap as it currently stands
ahopper
@ahopper
Dec 22 2018 07:34
It looks like loading a WriteableBitmap from stream etc is missing, I can see that could be useful.
MonkAlex
@MonkAlex
Dec 22 2018 07:41
<ProgressBar Grid.Row="3" IsVisible="{Binding UpdatePercent !=0}" Value="{Binding UpdatePercent}" Minimum="0" Maximum="1"/>
How to do this IsVisible binding?
{Binding !UpdatePercent} might work.
MonkAlex
@MonkAlex
Dec 22 2018 07:50
!! work, yeah
ahopper
@ahopper
Dec 22 2018 09:30
@Kermalis you could probably load your pngs Into Bitmaps and then save to a MemoryStream and then copy into a WriteableBitmap, a bit messy and I'm not sure how you would control the pixel format.
ahopper
@ahopper
Dec 22 2018 09:36
or make a proper font from them.
Kermalis
@Kermalis
Dec 22 2018 10:25
I had a proper font before, it's a huge pain to manage and update constantly, and the sizing needs to be pixel perfect to fit my project, so the font was lacking majorly there.
Nikita Tsukanov
@kekekeks
Dec 22 2018 10:29
class WbFb : IFramebufferPlatformSurface
{
      WritableBitmap _bitmap;
      public ILockedFramebuffer Lock()=>_bitmap.Lock();
}
using (var rt = AvaloniaLocator.Current.GetService<IPlatformThreadingInterface>().CreateRenderTarget(new[]{new WbFb(writableBitmap}))
using(var ctx = rt.CreateDrawingContext())
      ctx.DrawBitmap(your image here)
This way you can copy bitmap contents to WriteableBitmap
Kermalis
@Kermalis
Dec 22 2018 10:32
seems complicated but if it works, thanks so much :)
image.png
braca
@braca
Dec 22 2018 10:36
<TabControl>
    <TabControl.DataTemplates>
      <DataTemplate DataType="vms:SampleViewModel">
        <StackPanel Orientation="Vertical" Spacing="8">
          <TextBlock Text="SampleViewModel.."/>
          <local:SampleView />
        </StackPanel>
      </DataTemplate>
    </TabControl.DataTemplates>
    <TabItem Header="Tab 1 - Content from DataTemplate"><vms:SampleViewModel /></TabItem>
    <TabItem Header="Tab 2" Content="Content for item 2"/>
    <TabItem Header="Tab 3 - View without DataTemplate"><local:SampleView /> </TabItem>
</TabControl>
I'm playing with tabcontrol DataTemplates, but for some reason my DataTemplate is not working as I was expecting..
When I select Tab 1, it shows me my DataTemplate but any UserControl (local:SampleView) inside the DataTemplate is not displayed, it only shows the TextBlock
If I select Tab 3, the UserControl (local:SampleView) is shown properly..
Am I doing something wrong?
ahopper
@ahopper
Dec 22 2018 10:37
@kekekeks cool, I misread your previous post, yes it would be nice on the WriteableBitmap
Nikita Tsukanov
@kekekeks
Dec 22 2018 10:43
@Kermalis IPlatformRenderInterface
Don't have the code nearby
Kermalis
@Kermalis
Dec 22 2018 10:43
I see it in bitmaptests, thanks :D
Kermalis
@Kermalis
Dec 22 2018 11:36
Thanks to you I was led in the right direction and my color changing works
Jonathan
@vanillajonathan
Dec 22 2018 15:38
Does WPF and UWP suck? Is React much more productive?
Jumar Macato
@jmacato
Dec 22 2018 17:45
@vanillajonathan it's futile to think which frameworks suck because each fills its own niches, granted there are shortcomings on each of them but imo we should judge them for the things they are supposed to be used.
regarding productivity, it depends on what you're willing to invest your workflow into.
one can be productive with WPF while sucking at React and vice-versa
FoggyFinder
@FoggyFinder
Dec 22 2018 19:08
Hi all. Is it possible to keep caret position at center for TextBox when input is empty (TextAlignment="Center")?
okay, I found #1776
Benedikt Schroeder
@Gillibald
Dec 22 2018 20:42
@FoggyFinder Is this only happening with the skia backend or also D2D?
Can we introduce a tag for text rendering related issues?