Repository navigation
Expand file tree
/
Copy pathD2Objects.h
More file actions
73 lines (58 loc) · 1.86 KB
/
Copy pathD2Objects.h
File metadata and controls
73 lines (58 loc) · 1.86 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include "pch.h"
#include "Resource.h"
class D2Objects
{
public:
enum Formats { Segoe10, Segoe12, Segoe14, Segoe18, nFormats };
static float FontSize(Formats f);
void CreateLifetimeResources(HWND hwnd); // To be called on initialization
void CreateGraphicsResources(HWND hwnd); // To be called as needed (i.e. after calling DiscardGraphicsResources())
void DiscardGraphicsResources(); // To be called as needed (i.e. on resizing the window)
ID2D1DeviceContext* dc() const { return deviceContext.Get(); }
ID2D1SolidColorBrush* brush() const { return solidBrush.Get(); }
IDXGISwapChain1* swapChain() const { return m_swapChain.Get(); }
IDWriteTextFormat* textFormat(Formats f) const { return pTextFormats[f].Get(); }
private:
HWND m_hwndParent = nullptr;
// Boilerplate
ComPtr<ID3D11Device> direct3dDevice;
ComPtr<IDXGIDevice> dxgiDevice;
ComPtr<IDXGIFactory2> dxFactory;
ComPtr<ID2D1Factory2> d2Factory;
ComPtr<ID2D1Device1> d2Device;
ComPtr<IDXGISurface2> surface;
ComPtr<ID2D1Bitmap1> bitmap;
ComPtr<IDCompositionDevice> dcompDevice;
ComPtr<IDCompositionTarget> target;
ComPtr<IDCompositionVisual> visual;
ComPtr<IDWriteFactory1> pDWriteFactory;
// User
ComPtr<IDXGISwapChain1> m_swapChain;
ComPtr<ID2D1DeviceContext> deviceContext;
ComPtr<ID2D1SolidColorBrush> solidBrush;
// Styles
ComPtr<ID2D1StrokeStyle> pDashedStyle;
ComPtr<ID2D1StrokeStyle1> pFixedTransformStyle;
ComPtr<ID2D1StrokeStyle1> pHairlineStyle;
ComPtr<IDWriteTextFormat> pTextFormats[nFormats];
// Helpers
void CreateDrawingResources();
};
inline float D2Objects::FontSize(D2Objects::Formats font)
{
switch (font)
{
case D2Objects::Segoe10:
return 10.0f;
case D2Objects::Segoe12:
return 12.0f;
case D2Objects::Segoe14:
return 14.0f;
case D2Objects::Segoe18:
return 18.0f;
default:
OutputDebugString(L"FontSize() font not recognized\n");
return 0.0f;
}
}