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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
// Copyright (C) 2010 Dolphin Project.
// 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, version 2.0.
// 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "InputConfigDiag.h"
void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
{
wxFont small_font(6, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
g_controller_interface.UpdateInput();
// don't want game thread updating input when we are using it here
std::unique_lock<std::recursive_mutex> lk(g_controller_interface.update_lock, std::try_to_lock);
if (!lk.owns_lock())
return;
GamepadPage* const current_page = (GamepadPage*)m_pad_notebook->GetPage(m_pad_notebook->GetSelection());
std::vector< ControlGroupBox* >::iterator
g = current_page->control_groups.begin(),
ge = current_page->control_groups.end();
for ( ; g != ge; ++g )
{
// if this control group has a bitmap
if ( (*g)->static_bitmap )
{
wxMemoryDC dc;
wxBitmap bitmap((*g)->static_bitmap->GetBitmap());
dc.SelectObject(bitmap);
dc.Clear();
dc.SetFont(small_font);
dc.SetTextForeground(0xC0C0C0);
// label for sticks and stuff
if (64 == bitmap.GetHeight())
dc.DrawText(wxString::FromAscii((*g)->control_group->name).Upper(), 4, 2);
switch ( (*g)->control_group->type )
{
case GROUP_TYPE_TILT :
case GROUP_TYPE_STICK :
case GROUP_TYPE_CURSOR :
{
// this is starting to be a mess combining all these in one case
float x = 0, y = 0, z = 0;
float xx, yy;
switch ((*g)->control_group->type)
{
case GROUP_TYPE_STICK :
((ControllerEmu::AnalogStick*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
break;
case GROUP_TYPE_TILT :
((ControllerEmu::Tilt*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
break;
case GROUP_TYPE_CURSOR :
((ControllerEmu::Cursor*)(*g)->control_group)->GetState( &x, &y, &z );
x *= (32-1.5); x+= 32;
y *= (32-1.5); y+= 32;
break;
}
xx = (*g)->control_group->controls[3]->control_ref->State();
xx -= (*g)->control_group->controls[2]->control_ref->State();
yy = (*g)->control_group->controls[1]->control_ref->State();
yy -= (*g)->control_group->controls[0]->control_ref->State();
xx *= 32 - 1; xx += 32;
yy *= 32 - 1; yy += 32;
// draw the shit
// ir cursor forward movement
if (GROUP_TYPE_CURSOR == (*g)->control_group->type)
{
if (z)
{
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxRED_BRUSH);
}
else
{
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxGREY_BRUSH);
}
dc.DrawRectangle( 0, 31 - z*31, 64, 2);
}
// circle for visual aid for diagonal adjustment
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
if ( GROUP_TYPE_STICK == (*g)->control_group->type )
{
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawCircle( 32, 32, 32);
}
else
dc.DrawRectangle( 16, 16, 32, 32 );
if ( GROUP_TYPE_CURSOR != (*g)->control_group->type )
{
// deadzone circle
dc.SetBrush(*wxLIGHT_GREY_BRUSH);
dc.DrawCircle( 32, 32, ((*g)->control_group)->settings[0]->value * 32 );
}
// raw dot
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxGREY_BRUSH);
// i like the dot better than the cross i think
dc.DrawRectangle( xx - 2, yy - 2, 4, 4 );
//dc.DrawRectangle( xx-1, 64-yy-4, 2, 8 );
//dc.DrawRectangle( xx-4, 64-yy-1, 8, 2 );
// adjusted dot
if (x!=32 || y!=32)
{
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle( x-2, 64-y-2, 4, 4 );
// i like the dot better than the cross i think
//dc.DrawRectangle( x-1, 64-y-4, 2, 8 );
//dc.DrawRectangle( x-4, 64-y-1, 8, 2 );
}
}
break;
case GROUP_TYPE_FORCE :
{
float raw_dot[3];
float adj_dot[3];
const float deadzone = 32 * ((*g)->control_group)->settings[0]->value;
// adjusted
((ControllerEmu::Force*)(*g)->control_group)->GetState( adj_dot, 32.0, 32-1.5 );
// raw
for ( unsigned int i=0; i<3; ++i )
{
raw_dot[i] = (*g)->control_group->controls[i*2 + 1]->control_ref->State()
- (*g)->control_group->controls[i*2]->control_ref->State();
raw_dot[i] *= 32 - 1; raw_dot[i] += 32;
}
// deadzone rect for forward/backward visual
dc.SetBrush(*wxLIGHT_GREY_BRUSH);
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.DrawRectangle( 0, 32 - deadzone, 64, deadzone * 2 );
// raw forward/background line
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxGREY_BRUSH);
dc.DrawRectangle( 0, raw_dot[2] - 1, 64, 2 );
// adjusted forward/background line
if ( adj_dot[2]!=32 )
{
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle( 0, adj_dot[2] - 1, 64, 2 );
}
// a rectangle, for looks i guess
dc.SetBrush(*wxWHITE_BRUSH);
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.DrawRectangle( 16, 16, 32, 32 );
// deadzone square
dc.SetBrush(*wxLIGHT_GREY_BRUSH);
dc.DrawRectangle( 32 - deadzone, 32 - deadzone, deadzone * 2, deadzone * 2 );
// raw dot
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxGREY_BRUSH);
dc.DrawRectangle( raw_dot[1] - 2, raw_dot[0] - 2, 4, 4 );
// adjusted dot
if ( adj_dot[1]!=32 || adj_dot[0]!=32 )
{
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle( adj_dot[1]-2, adj_dot[0]-2, 4, 4 );
}
}
break;
case GROUP_TYPE_BUTTONS :
{
const unsigned int button_count = ((unsigned int)(*g)->control_group->controls.size());
// draw the shit
dc.SetPen(*wxGREY_PEN);
unsigned int * const bitmasks = new unsigned int[ button_count ];
for (unsigned int n = 0; n<button_count; ++n)
bitmasks[n] = (1 << n);
unsigned int buttons = 0;
((ControllerEmu::Buttons*)(*g)->control_group)->GetState( &buttons, bitmasks );
for (unsigned int n = 0; n<button_count; ++n)
{
if ( buttons & bitmasks[n] )
dc.SetBrush( *wxRED_BRUSH );
else
{
unsigned char amt = 255 - (*g)->control_group->controls[n]->control_ref->State() * 128;
dc.SetBrush(wxBrush(wxColor(amt, amt, amt)));
}
dc.DrawRectangle(n * 12, 0, 14, 12);
// text
const char* const name = (*g)->control_group->controls[n]->name;
// bit of hax so ZL, ZR show up as L, R
dc.DrawText(wxString::FromAscii((name[1] && name[1] < 'a') ? name[1] : name[0]), n*12 + 2, 1);
}
delete[] bitmasks;
}
break;
case GROUP_TYPE_TRIGGERS :
{
const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size()));
// draw the shit
dc.SetPen(*wxGREY_PEN);
ControlState deadzone = (*g)->control_group->settings[0]->value;
unsigned int* const trigs = new unsigned int[trigger_count];
((ControllerEmu::Triggers*)(*g)->control_group)->GetState( trigs, 64 );
for ( unsigned int n = 0; n < trigger_count; ++n )
{
ControlState trig_r = (*g)->control_group->controls[n]->control_ref->State();
// outline
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle(0, n*12, 64, 14);
// raw
dc.SetBrush(*wxGREY_BRUSH);
dc.DrawRectangle(0, n*12, trig_r*64, 14);
// deadzone affected
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(0, n*12, trigs[n], 14);
// text
dc.DrawText(wxString::FromAscii((*g)->control_group->controls[n]->name), 3, n*12 + 1);
}
delete[] trigs;
// deadzone box
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(0, 0, deadzone*64, trigger_count*14);
}
break;
case GROUP_TYPE_MIXED_TRIGGERS :
{
const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size() / 2));
// draw the shit
dc.SetPen(*wxGREY_PEN);
ControlState thresh = (*g)->control_group->settings[0]->value;
for ( unsigned int n = 0; n < trigger_count; ++n )
{
dc.SetBrush(*wxRED_BRUSH);
ControlState trig_d = (*g)->control_group->controls[n]->control_ref->State();
ControlState trig_a = trig_d > thresh ? 1
: (*g)->control_group->controls[n+trigger_count]->control_ref->State();
dc.DrawRectangle(0, n*12, 64+20, 14);
if ( trig_d <= thresh )
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle(trig_a*64, n*12, 64+20, 14);
dc.DrawRectangle(64, n*12, 32, 14);
// text
dc.DrawText(wxString::FromAscii((*g)->control_group->controls[n+trigger_count]->name), 3, n*12 + 1);
dc.DrawText(wxString::FromAscii((*g)->control_group->controls[n]->name[0]), 64 + 3, n*12 + 1);
}
// threshold box
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(thresh*64, 0, 128, trigger_count*14);
}
break;
case GROUP_TYPE_SLIDER:
{
const ControlState deadzone = (*g)->control_group->settings[0]->value;
ControlState state = (*g)->control_group->controls[1]->control_ref->State() - (*g)->control_group->controls[0]->control_ref->State();
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxGREY_BRUSH);
dc.DrawRectangle(31 + state * 30, 0, 2, 14);
((ControllerEmu::Slider*)(*g)->control_group)->GetState(&state, 1);
if (state)
{
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(31 + state * 30, 0, 2, 14);
}
// deadzone box
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(32 - deadzone * 32, 0, deadzone * 64, 14);
}
break;
default :
break;
}
// box outline
// Windows XP color
dc.SetPen(wxPen(_T("#7f9db9")));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
dc.SelectObject(wxNullBitmap);
(*g)->static_bitmap->SetBitmap(bitmap);
}
}
}
|