forked from zao/foo_wave_seekbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSeekbarWindow.h
250 lines (212 loc) · 7.54 KB
/
SeekbarWindow.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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// Copyright Lars Viklund 2008 - 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include "frontend_sdk/VisualFrontend.h"
#include "resource.h"
#include "PersistentSettings.h"
#include "FrontendCallbackImpl.h"
#include "FrontendConfigImpl.h"
#include "Helpers.h"
#include "SeekCallback.h"
#include "Player.h"
#include "Cache.h"
namespace wave
{
struct frontend_data
{
frontend_data() : auto_get_serial(0), valid_buckets(0) {}
void clear()
{
callback.reset();
frontend.reset();
}
recursive_mutex mutex;
std::unique_ptr<frontend_callback_impl> callback;
std::unique_ptr<frontend_config_impl> conf;
ref_ptr<visual_frontend> frontend;
metadb_handle_ptr displayed_song;
uint32_t auto_get_serial;
unsigned valid_buckets;
get_response pending_response;
uint32_t pending_serial;
};
enum mouse_drag_state
{
MouseDragNone, MouseDragSeeking, MouseDragSelection
};
struct mouse_drag_data
{
double from, to;
mouse_drag_data() : from(0.0), to(0.0) {}
};
enum { REPAINT_TIMER_ID = 0x4242 };
struct seekbar_window : CWindowImpl<seekbar_window>, waveform_listener
{
seekbar_window();
~seekbar_window();
DECLARE_WND_CLASS_EX(L"seekbar_dui", CS_HREDRAW | CS_VREDRAW, 0)
BEGIN_MSG_MAP(seekbar_window)
MSG_WM_CREATE(on_wm_create);
MSG_WM_DESTROY(on_wm_destroy);
MSG_WM_ERASEBKGND(on_wm_erasebkgnd)
MSG_WM_LBUTTONDOWN(on_wm_lbuttondown)
MSG_WM_LBUTTONUP(on_wm_lbuttonup)
MSG_WM_RBUTTONUP(on_wm_rbuttonup)
MSG_WM_MOUSEMOVE(on_wm_mousemove)
MSG_WM_MOUSEWHEEL(on_wm_mousewheel)
MSG_WM_PAINT(on_wm_paint)
MSG_WM_SIZE(on_wm_size)
MSG_WM_TIMER(on_wm_timer)
END_MSG_MAP()
private:
seekbar_window(seekbar_window const&);
seekbar_window& operator = (seekbar_window const&);
private:
LRESULT on_wm_create(LPCREATESTRUCT cs);
void on_wm_destroy();
LRESULT on_wm_erasebkgnd(HDC dc);
void on_wm_lbuttondown(UINT wparam, CPoint point);
void on_wm_lbuttonup(UINT wparam, CPoint point);
void on_wm_rbuttonup(UINT wparam, CPoint point);
void on_wm_mousemove(UINT wparam, CPoint point);
LRESULT on_wm_mousewheel(UINT wparam, short z_delta, CPoint point);
void on_wm_paint(HDC dc);
void on_wm_size(UINT wparam, CSize size);
void on_wm_timer(UINT_PTR wparam);
virtual void on_waveform(ref_ptr<waveform>) override;
virtual void on_time(double t) override;
virtual void on_duration(double t) override;
virtual void on_location(playable_location const& loc) override;
virtual void on_play() override;
virtual void on_stop() override;
protected:
void set_cursor_position(float f);
void set_cursor_visibility(bool b);
double compute_position(CPoint point);
void set_seek_position(CPoint point);
void set_playback_time(double t);
persistent_settings settings;
static void load_settings(persistent_settings& s, std::vector<char> const& in);
static void save_settings(persistent_settings const& s, std::vector<char>& out);
void toggle_orientation(frontend_callback_impl& cb, persistent_settings& s);
virtual bool forward_rightclick() { return false; }
void load_frontend_modules();
ref_ptr<visual_frontend> create_frontend(config::frontend id);
ref_ptr<waveform> placeholder_waveform;
std::shared_ptr<frontend_data> fe;
bool initializing_graphics;
mouse_drag_state drag_state;
mouse_drag_data drag_data;
bool possible_next_enqueued;
color global_colors[config::color_count];
void try_get_data();
void flush_frontend();
CRect client_rect;
double present_scale;
DWORD present_interval;
UINT_PTR repaint_timer_id;
CPoint last_seek_point;
std::shared_ptr<seek_callback> tooltip;
std::vector<std::weak_ptr<seek_callback>> seek_callbacks;
std::vector<std::function<void ()>> deferred_init;
private:
void initialize_frontend();
void test_playback_order(t_size order);
void apply_settings();
public:
void on_playback_order_changed(t_size p_new_index);
protected:
void set_border_visibility(bool);
void set_color(config::color which, color what, bool override);
void set_color_override(config::color which, bool override);
void set_frontend(config::frontend kind);
void set_orientation(config::orientation);
void set_shade_played(bool);
void set_display_mode(config::display_mode);
void set_downmix_display(config::downmix);
void set_flip_display(bool);
void set_channel_enabled(int channel, bool);
void swap_channel_order(int ch1, int ch2);
// Config dialog
struct configuration_dialog : ATL::CDialogImpl<configuration_dialog>
{
enum { IDD = IDD_CONFIG };
configuration_dialog();
#define COLOR_CLICK_HANDLER(Name) COMMAND_HANDLER_EX(Name, STN_CLICKED, on_color_click)
#define COLOR_USE_HANDLER(Name) COMMAND_HANDLER_EX(Name, BN_CLICKED, on_use_color_click)
BEGIN_MSG_MAP_EX(configuration_dialog)
MSG_WM_INITDIALOG(on_wm_init_dialog)
MSG_WM_CLOSE(on_wm_close)
MSG_WM_CTLCOLORSTATIC(on_wm_ctl_color_static)
COMMAND_HANDLER_EX(IDC_FRONTEND, CBN_SELCHANGE, on_frontend_select)
COMMAND_HANDLER_EX(IDC_NOBORDER, BN_CLICKED, on_no_border_click)
COMMAND_HANDLER_EX(IDC_SHADEPLAYED, BN_CLICKED, on_shade_played_click)
COLOR_CLICK_HANDLER(IDC_COLOR_BACKGROUND)
COLOR_CLICK_HANDLER(IDC_COLOR_FOREGROUND)
COLOR_CLICK_HANDLER(IDC_COLOR_HIGHLIGHT)
COLOR_CLICK_HANDLER(IDC_COLOR_SELECTION)
COLOR_USE_HANDLER(IDC_USE_BACKGROUND)
COLOR_USE_HANDLER(IDC_USE_FOREGROUND)
COLOR_USE_HANDLER(IDC_USE_HIGHLIGHT)
COLOR_USE_HANDLER(IDC_USE_SELECTION)
COMMAND_HANDLER_EX(IDC_DISPLAYMODE, CBN_SELCHANGE, on_display_select)
COMMAND_HANDLER_EX(IDC_DOWNMIX, CBN_SELCHANGE, on_downmix_select)
COMMAND_HANDLER_EX(IDC_MIRRORDISPLAY, BN_CLICKED, on_flip_click)
NOTIFY_HANDLER_EX(IDC_CHANNELS, LVN_ITEMCHANGED, on_channel_changed)
NOTIFY_HANDLER_EX(IDC_CHANNELS, NM_CLICK, on_channel_click)
COMMAND_HANDLER_EX(IDC_CHANNEL_UP, BN_CLICKED, on_channel_up)
COMMAND_HANDLER_EX(IDC_CHANNEL_DOWN, BN_CLICKED, on_channel_down)
COMMAND_HANDLER_EX(IDC_CONFIGURE, BN_CLICKED, on_configure_click)
END_MSG_MAP()
#define HANDLER_EX_IMPL(Name) void Name(UINT, int, CWindow)
LRESULT on_wm_init_dialog(CWindow focus, LPARAM lparam);
void on_wm_close();
HBRUSH on_wm_ctl_color_static(CDCHandle dc, CWindow wnd);
HANDLER_EX_IMPL(on_frontend_select);
HANDLER_EX_IMPL(on_no_border_click);
HANDLER_EX_IMPL(on_shade_played_click);
HANDLER_EX_IMPL(on_color_click);
HANDLER_EX_IMPL(on_use_color_click);
HANDLER_EX_IMPL(on_display_select);
HANDLER_EX_IMPL(on_downmix_select);
HANDLER_EX_IMPL(on_flip_click);
LRESULT on_channel_changed(NMHDR* nm);
LRESULT on_channel_click(NMHDR* nm);
HANDLER_EX_IMPL(on_channel_up);
HANDLER_EX_IMPL(on_channel_down);
HANDLER_EX_IMPL(on_configure_click);
virtual void OnFinalMessage(HWND);
explicit configuration_dialog(seekbar_window& sw);
private:
seekbar_window& sw;
bool initializing;
CListViewCtrl channels;
struct buttons
{
CButton up, down;
} buttons;
struct color_info
{
CStatic box;
color color;
COLORREF color_ref;
UINT display_id;
UINT use_id;
};
void mk_color_info(config::color color, UINT display_id, UINT use_id);
color_info colors[config::color_count];
struct channel_info
{
std::wstring text;
int data;
};
void swap_channels(int i1, int i2);
channel_info get_item(int, CListBox&);
void add_item(channel_info const&, CListBox&);
void remove_item(int, CListBox&);
};
std::unique_ptr<configuration_dialog> config_dialog;
};
}