These are chat archives for AvaloniaUI/Avalonia

25th
May 2018
Jumar Macato
@jmacato
May 25 2018 02:13
@jkoritzinsky when #1594 is ready, can Animations use Setter without circ. dependency issue?
Jeremy Koritzinsky
@jkoritzinsky
May 25 2018 02:13
Yep!
Jumar Macato
@jmacato
May 25 2018 02:14
that's great
Rayyan Tahir
@RayyanTahir
May 25 2018 09:38

@kekekeks I'm trying to implement Window Transparency for Win32. At first I tried using SetLayeredWindowAttributes with Crkey approach but that doesn't seem as the right way of doing this. After reading https://blogs.msdn.microsoft.com/dwayneneed/2008/09/08/transparent-windows-in-wpf/ it turns out that WPF uses UpdateLayeredWindow approach. So I went with that, but now the Window doesn't show at all... My code:

In WindowImpl.cs

public void SetAllowTransparency(bool value)
        {
            _allowtransparency = value;
            if (_allowtransparency && !_decorated)
            {
                SetWindowLong(_hwnd, (int)WindowLongParam.GWL_EXSTYLE, GetWindowLong(_hwnd, (int)WindowLongParam.GWL_EXSTYLE) | (int)WindowStyles.WS_EX_LAYERED);
                //SetLayeredWindowAttributes(_hwnd, new IntPtr(0x000000), new IntPtr(1), new IntPtr(0x00000001));

            }
        }

And:

case UnmanagedMethods.WindowsMessage.WM_PAINT:
                    UnmanagedMethods.PAINTSTRUCT ps;

                    if (UnmanagedMethods.BeginPaint(_hwnd, out ps) != IntPtr.Zero)
                    {

                        var f = Scaling;
                        var r = ps.rcPaint;

                        int iWidth = (int)ClientSize.Width;
                        int iHeight = (int)ClientSize.Height;
                        // Make mem DC + mem  bitmap
                        IntPtr hdcScreen = GetDC(IntPtr.Zero);
                        IntPtr hDC = CreateCompatibleDC(hdcScreen);
                        IntPtr hBmp = new System.Drawing.Bitmap(iWidth, iHeight).GetHbitmap(System.Drawing.Color.Black);
                        IntPtr hBmpOld = SelectObject(hDC, hBmp);


                        BLENDFUNCTION blend = new BLENDFUNCTION();
                        blend.BlendOp = (byte)BLENDFUNCTION.BlendOP.AC_SRC_OVER;
                        blend.BlendFlags = 0;
                        blend.SourceConstantAlpha = 255;
                        blend.AlphaFormat = (byte)BLENDFUNCTION.BlendOP.AC_SRC_ALPHA;
                        Point ptPos = new Point(r.left, r.top);
                        Size sizeWnd = new Size(iWidth, iHeight);
                        Point ptSrc = new Point(0, 0);
                        bool ress = UpdateLayeredWindow(_hwnd, hdcScreen, ref ptPos, ref sizeWnd, hDC, ref ptSrc, 0, ref blend, 2);

                        SelectObject(hDC, hBmpOld);
                        DeleteObject(hBmp);
                        DeleteDC(hDC);
                        ReleaseDC(IntPtr.Zero, hdcScreen);

                        Paint?.Invoke(new Rect(r.left / f, r.top / f, (r.right - r.left) / f, (r.bottom - r.top) / f));
                        UnmanagedMethods.EndPaint(_hwnd, ref ps);
                    }

                    return IntPtr.Zero;
danwalmsley
@danwalmsley
May 25 2018 10:38
@grokys hmm starting to get call from invalid thread exceptions, from deffered renderer
image.png
Steven Kirk
@grokys
May 25 2018 10:39
hmm ok, that looks like a bug. should be easily fixable
could you add an issue?
danwalmsley
@danwalmsley
May 25 2018 10:39
yeah, but I don't know how its been introduced
it seems it might be since the font pr
Steven Kirk
@grokys
May 25 2018 10:42
quite possibly yeah
Benedikt Schroeder
@Gillibald
May 25 2018 10:47
@RayyanTahir Nice blog post "Because the underlying HwndSource expands the client area to fill the entire window, the Window class also requires that the WindowStyle property be set to None" now I understand why they require Windowstyle.None
The font PR introduces no async stuff or any kind of threading. I just use a ConcurrentDictionary for caches.
Thats probably not needed because you access everything on ui thread
Benedikt Schroeder
@Gillibald
May 25 2018 10:53
@danwalmsley Do you use custom fonts right now?
Rayyan Tahir
@RayyanTahir
May 25 2018 11:00
@Gillibald I am trying to use custom fonts. But I'm only getting characters instead of icons. Can I share my ttf file for you to test?
Benedikt Schroeder
@Gillibald
May 25 2018 11:00
Sure
Rayyan Tahir
@RayyanTahir
May 25 2018 11:01
Benedikt Schroeder
@Gillibald
May 25 2018 11:02
@grokys I wonder if we still need FontFamilyConverter that was probably merged in before you merged your typeconverter PR
that's done automatically by the typeconverter PR
Benedikt Schroeder
@Gillibald
May 25 2018 11:06
I just ment the typeconverter could be still there haven't checked if you have removed it
Steven Kirk
@grokys
May 25 2018 11:07
ah! yes right you are
removed
Benedikt Schroeder
@Gillibald
May 25 2018 11:22
@RayyanTahir Have checked your font with Direct2D1 and Skia and everything works fine
Maybe there is something wrong with your FontFamily definition
Rayyan Tahir
@RayyanTahir
May 25 2018 11:23
Here's how I'm using it:
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="CustomFontRepro" Width="200" Height="200">
  <Window.Resources>
    <Style x:Key="Icons" Selector="TextBlock.Icons">
      <Setter Property="FontFamily" Value="resm:CustomFontRepro.Assets?assembly=CustomFontRepro#swap-custom-icon"/>
    </Style>
  </Window.Resources>
  <Grid>
    <TextBlock Text="f" Classes="Icons" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="50"/>
  </Grid>
</Window>
Benedikt Schroeder
@Gillibald
May 25 2018 11:25
Looks good to me. Make sure swap-custom-icon is set to Embedded Resource
Rayyan Tahir
@RayyanTahir
May 25 2018 11:25
It is set to EmbeddedResource, but still doesn't work :worried:
I'm on the latest nightly build-5231
Rayyan Tahir
@RayyanTahir
May 25 2018 11:31
@Gillibald I found the issue. If i set it as a style it won't work, but works If i set the FontFamily property of the control directly like this:
<TextBlock Text="a" FontFamily="resm:CustomFontRepro.Assets?assembly=CustomFontRepro#swap-custom-icon" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="50"/>
Here is the repro CustomFontRepro.zip
Benedikt Schroeder
@Gillibald
May 25 2018 11:33
I wonder why that would make a difference
Can you verify that the style gets applied?
danwalmsley
@danwalmsley
May 25 2018 11:35
@Gillibald yeah was using custom fonts
im not sure whats happening need to investigate
Rayyan Tahir
@RayyanTahir
May 25 2018 11:37
@Gillibald Its strange...the style isn't applying...
danwalmsley
@danwalmsley
May 25 2018 11:38
@Gillibald @RayyanTahir you need to specify the font file name in your resm: url
"resm:CustomFontRepro.Assets.swap-custom-icon.ttf?assembly=CustomFontRepro#swap-custom-icon"
Rayyan Tahir
@RayyanTahir
May 25 2018 11:40
@danwalmsley that isn't working either
danwalmsley
@danwalmsley
May 25 2018 11:42
make sure you don't set bold or anything
your ttf implements Regular font weight?
Rayyan Tahir
@RayyanTahir
May 25 2018 11:43
Yup it does
danwalmsley
@danwalmsley
May 25 2018 11:45
im struggling to get fonts to work again
weird it tested yesterday and all seemed fine
@RayyanTahir if you debug with JustMyCode disabled
do you get the same crash im getting
call from invalid thread?
Rayyan Tahir
@RayyanTahir
May 25 2018 11:48
Let me check
danwalmsley
@danwalmsley
May 25 2018 11:49
probably should check all exceptions too
Rayyan Tahir
@RayyanTahir
May 25 2018 11:49
I get a NullReferenceException inside a System.Reflection.TargetInvocationException
danwalmsley
@danwalmsley
May 25 2018 11:51
try a full clean and rebuild
it could be that the recent changes broke api compatibility
Rayyan Tahir
@RayyanTahir
May 25 2018 11:52
Tried that too. Crashing with same exceptions
danwalmsley
@danwalmsley
May 25 2018 11:59
@RayyanTahir do you have a repro project?
Rayyan Tahir
@RayyanTahir
May 25 2018 11:59
For the fonts issue?
danwalmsley
@danwalmsley
May 25 2018 11:59
the crashing
/ font issue
it works in control catalog
Rayyan Tahir
@RayyanTahir
May 25 2018 12:00
I'll create a repro for you
danwalmsley
@danwalmsley
May 25 2018 12:02
@Gillibald with the font names like
SourceSansPro-BoldItalic
does the bold italic part need to be exactly BoldItalic
or are the ttf file parsed
and then if you set Bold and Italic it uses the correct one regardless of naming?
Rayyan Tahir
@RayyanTahir
May 25 2018 12:03
@danwalmsley After disabling JustMyCode and restarting Visual Studio, the crash went away
danwalmsley
@danwalmsley
May 25 2018 12:06
ok
@grokys hmm that crash is only in direct2d backend
some how id switched without realising
need to find a repro though
or can you tell the issue from the stack trace?
also in SolidColorBrush why is the Color property an avalonia property? that means it can only be accessed on ui thread
danwalmsley
@danwalmsley
May 25 2018 12:22
@RayyanTahir are custom fonts now working for you? and which rendering backend are you using?
@Gillibald there is definitely a bug in assets loading for fonts
trying to track it down
danwalmsley
@danwalmsley
May 25 2018 12:30
@Gillibald ok false alarm
id forgotten to specify assembly
Benedikt Schroeder
@Gillibald
May 25 2018 14:11
@danwalmsley The font api doesnt care about filenames in terms of fontweight and fontstyle it just loads the files and recognizes what the files are supporting
If you want to load all font files at once you just have to define the location without filename like FontFamily="resm:EntryAssembly.Assets.Fonts#MyFont"
Then all files of that location are cashed and loaded and you can use all variants of your fonts
FontFamily="resm:EntryAssembly.Assets.MyFont.ttf#MyFont" just loads a single file
FontFamily="resm:EntryAssembly.Assets.MyFont*.ttf#MyFont" loads all files that match "EntryAssembly.Assets.MyFont"
Have to write some docs...
danwalmsley
@danwalmsley
May 25 2018 14:49
@grokys do you have any quick thoughts on #1614? Is this an issue or have I used the wrong tool for the job perhaps
Steven Kirk
@grokys
May 25 2018 14:50
sounds like a bug to me
we're probably not handling scaling correctly on visual brushes somewhere?
danwalmsley
@danwalmsley
May 25 2018 14:54
ok
do you know where I would need to look to try and investigate it
ahopper
@ahopper
May 25 2018 18:43
Am I right in using Bounds.Width to replace wpf ActualWidth in controls?
Jeremy Koritzinsky
@jkoritzinsky
May 25 2018 19:02
@ahopper Yep!
@grokys I found the bug that was causing the intermittent test failures over the last few days. Fix is in #1615.
Splitwirez
@Splitwirez
May 25 2018 19:03
Oh is THAT why I couldn't get ActualWidth to work...? ._____.
ahopper
@ahopper
May 25 2018 19:04
@jkoritzinsky cheers, just started to replace a lot of them and had a moment of doubt, looks like one for the from wpf page