Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3.  
  4. using System;
  5. using Avalonia;
  6. using Avalonia.Controls;
  7. using Avalonia.Markup.Xaml;
  8. using RenderDemo.ViewModels;
  9. using ReactiveUI;
  10. using System.Runtime.InteropServices;
  11.  
  12. namespace RenderDemo
  13. {
  14.     public class MainWindow : Window
  15.     {
  16.         internal enum AccentState
  17.         {
  18.             ACCENT_DISABLED = 1,
  19.             ACCENT_ENABLE_GRADIENT = 0,
  20.             ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
  21.             ACCENT_ENABLE_BLURBEHIND = 3,
  22.             ACCENT_INVALID_STATE = 4
  23.         }
  24.  
  25.         [StructLayout(LayoutKind.Sequential)]
  26.         internal struct AccentPolicy
  27.         {
  28.             public AccentState AccentState;
  29.             public int AccentFlags;
  30.             public int GradientColor;
  31.             public int AnimationId;
  32.         }
  33.  
  34.         [StructLayout(LayoutKind.Sequential)]
  35.         internal struct WindowCompositionAttributeData
  36.         {
  37.             public WindowCompositionAttribute Attribute;
  38.             public IntPtr Data;
  39.             public int SizeOfData;
  40.         }
  41.  
  42.         internal enum WindowCompositionAttribute
  43.         {
  44.             // ...
  45.             WCA_ACCENT_POLICY = 19
  46.             // ...
  47.         }
  48.  
  49.         [DllImport("user32.dll")]
  50.         internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
  51.  
  52.         internal void EnableBlur()
  53.         {
  54.             var hndl = this.PlatformImpl.Handle.Handle;
  55.  
  56.             var accent = new AccentPolicy();
  57.             accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND;
  58.  
  59.             var accentStructSize = Marshal.SizeOf(accent);
  60.  
  61.             var accentPtr = Marshal.AllocHGlobal(accentStructSize);
  62.             Marshal.StructureToPtr(accent, accentPtr, false);
  63.  
  64.             var data = new WindowCompositionAttributeData();
  65.             data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY;
  66.             data.SizeOfData = accentStructSize;
  67.             data.Data = accentPtr;
  68.  
  69.  
  70.             SetWindowCompositionAttribute(hndl, ref data);
  71.  
  72.             Marshal.FreeHGlobal(accentPtr);
  73.         }
  74.  
  75.         public MainWindow()
  76.         {
  77.             this.InitializeComponent();
  78.             this.AttachDevTools();
  79.  
  80.             var vm = new MainWindowViewModel();
  81.             vm.WhenAnyValue(x => x.DrawDirtyRects).Subscribe(x => Renderer.DrawDirtyRects = x);
  82.             vm.WhenAnyValue(x => x.DrawFps).Subscribe(x => Renderer.DrawFps = x);
  83.             this.DataContext = vm;
  84.  
  85.             EnableBlur();
  86.         }
  87.  
  88.         private void InitializeComponent()
  89.         {
  90.             AvaloniaXamlLoader.Load(this);
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement