-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDUIElement.cpp
More file actions
186 lines (150 loc) · 4.88 KB
/
DUIElement.cpp
File metadata and controls
186 lines (150 loc) · 4.88 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
/** $VER: DUIElement.cpp (2024.03.11) P. Stuer **/
#include "pch.h"
#include "DUIElement.h"
#include "Color.h"
#include "Log.h"
#pragma hdrstop
#pragma region ui_element_instance interface
/// <summary>
/// Initializes a new instance.
/// </summary>
DUIElement::DUIElement(ui_element_config::ptr data, ui_element_instance_callback::ptr callback) : m_callback(callback)
{
_UIThread._IsDUI = true;
GetColors();
set_configuration(data);
}
/// <summary>
/// Retrieves the name of the element.
/// </summary>
void DUIElement::g_get_name(pfc::string_base & name)
{
name = STR_COMPONENT_NAME;
}
/// <summary>
/// Retrieves the description of the element.
/// </summary>
const char * DUIElement::g_get_description()
{
return "Spectum analyzer visualization using DirectX";
}
/// <summary>
/// Retrieves the GUID of the element.
/// </summary>
GUID DUIElement::g_get_guid()
{
return uielement_t::GetGUID();
}
/// <summary>
/// Retrieves the subclass GUID of the element.
/// </summary>
GUID DUIElement::g_get_subclass()
{
return ui_element_subclass_playback_visualisation;
}
/// <summary>
/// Retrieves the default configuration of the element.
/// </summary>
ui_element_config::ptr DUIElement::g_get_default_configuration()
{
state_t DefaultConfiguration;
ui_element_config_builder Builder;
DefaultConfiguration.Write(&Builder.m_stream);
return Builder.finish(g_get_guid());
}
/// <summary>
/// Initializes the element's windows.
/// </summary>
void DUIElement::initialize_window(HWND p_parent)
{
const DWORD Style = 0;
const DWORD ExStyle = 0;
this->Create(p_parent, nullptr, nullptr, Style, ExStyle);
}
/// <summary>
/// Alters element's current configuration. Specified ui_element_config's GUID must be the same as this element's GUID.
/// </summary>
void DUIElement::set_configuration(ui_element_config::ptr data)
{
ui_element_config_parser Parser(data);
_UIThread.Read(&Parser.m_stream, Parser.get_remaining());
}
/// <summary>
/// Retrieves element's current configuration. Returned object's GUID must be set to your element's GUID so your element can be re-instantiated with stored settings.
/// </summary>
ui_element_config::ptr DUIElement::get_configuration()
{
ui_element_config_builder Builder;
_UIThread.Write(&Builder.m_stream);
return Builder.finish(g_get_guid());
}
/// <summary>
/// Used by the host to notify the element about various events.
/// See ui_element_notify_* GUIDs for possible p_what parameter; meaning of other parameters depends on p_what value.
/// Container classes should dispatch all notifications to their children.
/// </summary>
void DUIElement::notify(const GUID & what, t_size param1, const void * param2, t_size param2Size)
{
if (what == ui_element_notify_colors_changed)
{
OnColorsChanged();
}
else
if (what == ui_element_notify_font_changed)
{
// m_callback->query_font_ex(ui_font_default);
}
else
if (what == ui_element_notify_visibility_changed)
{
_IsVisible = (bool) param1;
}
}
static service_factory_single_t<ui_element_impl_visualisation<DUIElement>> _Factory;
#pragma endregion
/*
/// <summary>
/// Handles the WM_ERASEBKGND message.
/// </summary>
LRESULT DUIElement::OnEraseBackground(CDCHandle hDC)
{
if (!_IsInitializing)
return 0;
RECT cr;
GetClientRect(&cr);
HBRUSH hBrush = color_t::CreateBrush(_UIThread._StyleManager.UserInterfaceColors[1]);
::FillRect(hDC, &cr, hBrush);
::DeleteObject((HGDIOBJ) hBrush);
_IsInitializing = false;
return 1; // Prevent GDI from erasing the background. Required for transparency.
}
*/
/// <summary>
/// Handles a context menu selection.
/// </summary>
void DUIElement::OnContextMenu(CWindow wnd, CPoint position)
{
if (m_callback->is_edit_mode_enabled())
SetMsgHandled(FALSE);
else
uielement_t::OnContextMenu(wnd, position);
}
/// <summary>
/// Toggles full screen mode.
/// </summary>
void DUIElement::ToggleFullScreen() noexcept
{
static_api_ptr_t<ui_element_common_methods_v2>()->toggle_fullscreen(g_get_guid(), core_api::get_main_window());
}
/// <summary>
/// Gets the user interface colors.
/// </summary>
void DUIElement::GetColors() noexcept
{
_UIThread._StyleManager.UserInterfaceColors.clear();
_UIThread._StyleManager.UserInterfaceColors.push_back(color_t::ToD2D1_COLOR_F(m_callback->query_std_color(ui_color_text)));
_UIThread._StyleManager.UserInterfaceColors.push_back(color_t::ToD2D1_COLOR_F(m_callback->query_std_color(ui_color_background)));
_UIThread._StyleManager.UserInterfaceColors.push_back(color_t::ToD2D1_COLOR_F(m_callback->query_std_color(ui_color_highlight)));
_UIThread._StyleManager.UserInterfaceColors.push_back(color_t::ToD2D1_COLOR_F(m_callback->query_std_color(ui_color_selection)));
_UIThread._StyleManager.UserInterfaceColors.push_back(color_t::ToD2D1_COLOR_F(m_callback->query_std_color(ui_color_darkmode)));
}