-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDWriteWindow.h
More file actions
34 lines (28 loc) · 950 Bytes
/
DWriteWindow.h
File metadata and controls
34 lines (28 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#include <string>
#include <wil/com.h>
#include "BaseWindow.hpp"
#include <d2d1.h>
#include <dwrite.h>
#include "ITextDisplay.h"
#include <winrt/base.h>
struct ID2D1HwndRenderTarget;
//Draw text using DirectWrite
class DWriteWindow : public BaseWindow<DWriteWindow, L"DWriteWindowClass">, public ITextDisplay
{
winrt::hstring m_text;
winrt::hstring m_fontFamily{ TEXT("Microsoft YaHei") };
int m_fontSize = 56;
wil::com_ptr<ID2D1HwndRenderTarget> m_renderTarget;
wil::com_ptr<IDWriteTextFormat> textFormat;
wil::com_ptr<ID2D1SolidColorBrush> m_textBrush;
void recreateFont();
public:
DWriteWindow(winrt::hstring const& text);
static void OnPaint(HWND hwnd);
static void OnSize(HWND hwnd, WPARAM wparam, UINT width, UINT height);
// Inherited via ITextDisplay
void SetText(winrt::hstring const& text) override;
void SetFontSize(int fontSize) override;
void SetFontFamily(winrt::hstring const& fontFamily) override;
};