/ src / modules / alwaysontop / AlwaysOnTop / FrameDrawer.h
FrameDrawer.h
 1  #pragma once
 2  
 3  #include <mutex>
 4  
 5  #include <d2d1.h>
 6  #include <winrt/base.h>
 7  #include <dwrite.h>
 8  
 9  class FrameDrawer
10  {
11  public:
12      static std::unique_ptr<FrameDrawer> Create(HWND window);
13  
14      FrameDrawer(HWND window);
15      FrameDrawer(FrameDrawer&& other) = default;
16  
17      bool Init();
18  
19      void Show();
20      void Hide();
21      void SetBorderRect(RECT windowRect, COLORREF rgb, float alpha, int thickness, float radius);
22  
23  private:
24      bool CreateRenderTargets(const RECT& clientRect);
25  
26      struct DrawableRect
27      {
28          std::optional<D2D1_RECT_F> rect;
29          std::optional<D2D1_ROUNDED_RECT> roundedRect;
30          D2D1_COLOR_F borderColor;
31          int thickness;
32      };
33  
34      static ID2D1Factory* GetD2DFactory();
35      static IDWriteFactory* GetWriteFactory();
36      static D2D1_COLOR_F ConvertColor(COLORREF color, float alpha);
37      static D2D1_ROUNDED_RECT ConvertRect(RECT rect, int thickness, float radius);
38      static D2D1_RECT_F ConvertRect(RECT rect, int thickness);
39      void Render();
40  
41      HWND m_window = nullptr;
42      size_t m_renderTargetSizeHash = {};
43      winrt::com_ptr<ID2D1HwndRenderTarget> m_renderTarget;
44      winrt::com_ptr<ID2D1SolidColorBrush> m_borderBrush;
45      DrawableRect m_sceneRect = {};
46  };