-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatch.cpp
More file actions
91 lines (72 loc) · 2.08 KB
/
Patch.cpp
File metadata and controls
91 lines (72 loc) · 2.08 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "pch.h"
using namespace winrt;
using namespace Windows::UI::Xaml;
using namespace winrt::Windows::Foundation;
using namespace winrt::Microsoft::Graphics::Canvas;
using namespace winrt::Microsoft::Graphics::Canvas::Brushes;
using namespace winrt::Microsoft::Graphics::Canvas::UI::Xaml;
using namespace winrt::Windows::Graphics::DirectX;
Patch::Patch(
CanvasDevice device) :
m_swapchain(nullptr), m_brush(nullptr)
{
m_device = device.GetSharedDevice();
}
Patch::~Patch()
{
}
void Patch::RecreateIfNeeded(winrt::Windows::Foundation::Size size)
{
bool destroy = size.Height <= 0 || size.Width <= 0;
bool resize = size.Height != m_height || size.Width != m_width;
bool recreate = !m_swapchain;
if (destroy)
{
m_swapchain = nullptr;
m_brush = nullptr;
return;
}
else if (recreate)
{
m_swapchain = CanvasSwapChain(
m_device.GetSharedDevice(),
size.Width, size.Height,
CanvasControl().Dpi(),
DirectXPixelFormat::R16G16B16A16Float,
2,
CanvasAlphaMode::Ignore
);
m_height = size.Height;
m_width = size.Width;
}
else if (resize)
{
m_swapchain.ResizeBuffers(size.Width, size.Width, CanvasControl().Dpi());
m_height = size.Height;
m_width = size.Width;
}
if (!m_brush)
{
m_brush = CanvasSolidColorBrush::CreateHdr(m_device, { m_red, m_green, m_blue, 1.0f });
}
}
void Patch::Draw(winrt::Windows::Foundation::Size size)
{
RecreateIfNeeded(size);
if (!m_swapchain) return;
auto ds = m_swapchain.CreateDrawingSession(winrt::Windows::UI::Colors::AliceBlue());
ds.FillRectangle(0, 0, m_width, m_height, m_brush);
m_swapchain.Present();
}
winrt::Microsoft::Graphics::Canvas::CanvasSwapChain Patch::GetSwapChain()
{
return m_swapchain;
}
void Patch::SetColors(float red, float green, float blue)
{
m_red = red;
m_green = green;
m_blue = blue;
if (m_brush) m_brush.ColorHdr({ m_red, m_green, m_blue, 1.0f });
Draw(Size(m_width, m_height));
}