forked from stuerp/foo_vis_spectrum_analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCUIElement.cpp
More file actions
195 lines (137 loc) · 4.77 KB
/
CUIElement.cpp
File metadata and controls
195 lines (137 loc) · 4.77 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/** $VER: CUIElement.cpp (2024.03.13) P. Stuer **/
#include "framework.h"
#include "CUIElement.h"
#include "Color.h"
#include "ui_extension.h"
#pragma hdrstop
namespace uie
{
static cui::colours::client::factory<CUIColorClient> _CUIColorClientFactory;
/// <summary>
/// Initializes a new instance.
/// </summary>
CUIElement::CUIElement()
{
_IsVisible = true; // CUI does send notifications.
_MainState._IsDUI = false;
GetColors();
}
/// <summary>
/// Destroys this instance.
/// </summary>
CUIElement::~CUIElement()
{
}
/// <summary>
/// Creates or transfers the window.
/// </summary>
HWND CUIElement::create_or_transfer_window(HWND hParent, const window_host_ptr & newHost, const ui_helpers::window_position_t & position)
{
if (*this == nullptr)
{
_Host = newHost;
CRect r;
position.convert_to_rect(r);
Create(hParent, r, 0, WS_CHILD, 0);
_hParent = hParent;
}
else
{
ShowWindow(SW_HIDE);
SetParent(hParent);
_Host->relinquish_ownership(*this);
_Host = newHost;
SetWindowPos(NULL, position.x, position.y, (int) position.cx, (int) position.cy, SWP_NOZORDER);
}
CUIColorClient::Register(this);
return *this;
}
/// <summary>
/// Destroys the window.
/// </summary>
void CUIElement::destroy_window()
{
CUIColorClient::Unregister(this);
::DestroyWindow(*this);
_Host.release();
}
/// <summary>
/// Handles the WM_ERASEBKGND message.
/// </summary>
LRESULT CUIElement::OnEraseBackground(CDCHandle hDC)
{
if (!_IsStartingUp)
return 0;
RECT cr;
GetClientRect(&cr);
HBRUSH hBrush = Color::CreateBrush(_MainState._StyleManager._UserInterfaceColors[3]);
::FillRect(hDC, &cr, hBrush);
::DeleteObject((HGDIOBJ) hBrush);
_IsStartingUp = false;
return 1;
}
/// <summary>
/// Toggles full screen mode.
/// </summary>
void CUIElement::ToggleFullScreen() noexcept
{
_CriticalSection.Enter();
if (!_IsFullScreen)
{
HMONITOR hMonitor = ::MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
if (hMonitor != NULL)
{
MONITORINFOEXW mix = { { sizeof(mix) } };
if (::GetMonitorInfoW(hMonitor, &mix))
{
GetWindowRect(&_OldBounds);
CWindow(_hParent).ScreenToClient(&_OldBounds);
ShowWindow(SW_HIDE);
SetParent(::GetDesktopWindow());
LONG_PTR Style = ::GetWindowLongPtrW(m_hWnd, GWL_STYLE);
::SetWindowLongPtrW(m_hWnd, GWL_STYLE, (Style & (LONG_PTR) ~WS_CHILD) | (LONG_PTR) WS_POPUP);
SetWindowPos(HWND_TOP, &mix.rcWork, SWP_ASYNCWINDOWPOS | SWP_NOZORDER | SWP_SHOWWINDOW);
_Host->relinquish_ownership(nullptr);
UpdateState();
_IsFullScreen = true;
}
}
}
else
{
ShowWindow(SW_HIDE);
SetParent(_hParent);
LONG_PTR Style = ::GetWindowLongPtrW(m_hWnd, GWL_STYLE);
::SetWindowLongPtrW(m_hWnd, GWL_STYLE, (Style & (LONG_PTR) ~WS_POPUP) | (LONG_PTR) WS_CHILD);
SetWindowPos(NULL, &_OldBounds, SWP_ASYNCWINDOWPOS | SWP_NOZORDER | SWP_SHOWWINDOW);
_Host->relinquish_ownership(_hParent);
UpdateState();
_IsFullScreen = false;
}
_CriticalSection.Leave();
}
/// <summary>
/// Gets the user interface colors.
/// </summary>
void CUIElement::GetColors() noexcept
{
cui::colours::helper Helper(pfc::guid_null);
_MainState._StyleManager._UserInterfaceColors.clear();
_MainState._StyleManager._UserInterfaceColors.push_back(Color::ToD2D1_COLOR_F(Helper.get_colour(cui::colours::colour_text)));
_MainState._StyleManager._UserInterfaceColors.push_back(Color::ToD2D1_COLOR_F(Helper.get_colour(cui::colours::colour_selection_text)));
_MainState._StyleManager._UserInterfaceColors.push_back(Color::ToD2D1_COLOR_F(Helper.get_colour(cui::colours::colour_inactive_selection_text)));
_MainState._StyleManager._UserInterfaceColors.push_back(Color::ToD2D1_COLOR_F(Helper.get_colour(cui::colours::colour_background)));
_MainState._StyleManager._UserInterfaceColors.push_back(Color::ToD2D1_COLOR_F(Helper.get_colour(cui::colours::colour_selection_background)));
_MainState._StyleManager._UserInterfaceColors.push_back(Color::ToD2D1_COLOR_F(Helper.get_colour(cui::colours::colour_inactive_selection_background)));
_MainState._StyleManager._UserInterfaceColors.push_back(Color::ToD2D1_COLOR_F(Helper.get_colour(cui::colours::colour_active_item_frame)));
}
static uie::window_factory<CUIElement> _WindowFactory;
void CUIColorClient::on_colour_changed(uint32_t changed_items_mask) const
{
for (auto Iter : _Elements)
Iter->OnColorsChanged();
}
void CUIColorClient::on_bool_changed(uint32_t changed_items_mask) const
{
}
}