-
Notifications
You must be signed in to change notification settings - Fork 19
/
BaseWindowD2D.h
99 lines (85 loc) · 3.12 KB
/
BaseWindowD2D.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// sktoolslib - common files for SK tools
// Copyright (C) 2020 - Stefan Kueng
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#pragma once
#include "BaseWindow.h"
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <math.h>
#include <d2d1.h>
#include <d2d1effects.h>
#include <d2d1helper.h>
#include <dwrite.h>
#include <wincodec.h>
#include <dxgi1_3.h>
#include <d3d11_2.h>
#include <d2d1_2.h>
#include <d2d1_2helper.h>
#include <dcomp.h>
#include <wrl.h>
using namespace Microsoft::WRL;
struct ComException
{
HRESULT result;
ComException(HRESULT const value)
: result(value)
{
}
};
void HR(HRESULT const result);
/**
* \ingroup Utils
* A base window class with Direct2D support.
*/
class CWindowD2D : public CWindow
{
public:
virtual bool Create() override;
virtual bool Create(DWORD dwStyles, HWND hParent = nullptr, RECT* rect = nullptr) override;
virtual bool CreateEx(DWORD dwExStyles, DWORD dwStyles, HWND hParent = nullptr, RECT* rect = nullptr, LPCWSTR classname = nullptr, HMENU hMenu = nullptr) override;
protected:
//constructor
CWindowD2D(HINSTANCE hInst, CONST WNDCLASSEX* wcx = nullptr)
: CWindow(hInst, wcx)
, m_window_width(0)
, m_window_height(0)
{
}
virtual ~CWindowD2D()
{
}
virtual LRESULT CALLBACK WinMsgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) = 0;
virtual HRESULT OnRender(ID2D1DeviceContext* dc) = 0;
virtual HRESULT CreateDeviceResources() = 0;
virtual HRESULT DiscardDeviceResources() = 0;
protected:
ComPtr<ID3D11Device> m_direct3dDevice;
ComPtr<IDXGIDevice> m_dxgiDevice;
ComPtr<IDXGIFactory2> m_dxFactory;
ComPtr<IDWriteFactory> m_writeFactory;
ComPtr<IDXGISwapChain1> m_swapChain;
ComPtr<ID2D1Factory2> m_d2Factory;
ComPtr<ID2D1Device1> m_d2Device;
ComPtr<ID2D1DeviceContext> m_dc;
ComPtr<IDXGISurface2> m_surface;
ComPtr<IDCompositionDevice> m_compositionDevice;
ComPtr<IDCompositionTarget> m_compositionTarget;
ComPtr<IDCompositionVisual> m_compositionVisual;
ComPtr<ID2D1Bitmap1> m_d2dBitmap;
UINT m_window_width, m_window_height;
private:
LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) override;
void Resize(UINT width, UINT height);
};