~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Source/Core/DolphinWX/Src/InputConfigDiagBitmaps.cpp

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Dolphin Emulator Project
 
2
// Licensed under GPLv2
 
3
// Refer to the license.txt file included.
 
4
 
 
5
#include "InputConfigDiag.h"
 
6
#include "WxUtils.h"
 
7
 
 
8
void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
 
9
{
 
10
        wxFont small_font(6, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
 
11
 
 
12
        g_controller_interface.UpdateInput();
 
13
 
 
14
        // don't want game thread updating input when we are using it here
 
15
        std::unique_lock<std::recursive_mutex> lk(g_controller_interface.update_lock, std::try_to_lock);
 
16
        if (!lk.owns_lock())
 
17
                return;
 
18
 
 
19
        GamepadPage* const current_page = (GamepadPage*)m_pad_notebook->GetPage(m_pad_notebook->GetSelection());
 
20
 
 
21
        std::vector< ControlGroupBox* >::iterator
 
22
                g = current_page->control_groups.begin(),
 
23
                ge = current_page->control_groups.end();
 
24
        for ( ; g != ge; ++g  )
 
25
        {
 
26
                // if this control group has a bitmap
 
27
                if ( (*g)->static_bitmap )
 
28
                {
 
29
                        wxMemoryDC dc;
 
30
                        wxBitmap bitmap((*g)->static_bitmap->GetBitmap());
 
31
                        dc.SelectObject(bitmap);
 
32
                        dc.Clear();
 
33
 
 
34
                        dc.SetFont(small_font);
 
35
                        dc.SetTextForeground(0xC0C0C0);
 
36
 
 
37
                        // label for sticks and stuff
 
38
                        if (64 == bitmap.GetHeight())
 
39
                                dc.DrawText(StrToWxStr((*g)->control_group->name).Upper(), 4, 2);
 
40
 
 
41
                        switch ( (*g)->control_group->type )
 
42
                        {
 
43
                        case GROUP_TYPE_TILT :
 
44
                        case GROUP_TYPE_STICK :
 
45
                        case GROUP_TYPE_CURSOR :
 
46
                                {
 
47
                                        // this is starting to be a mess combining all these in one case
 
48
 
 
49
                                        float x = 0, y = 0, z = 0;
 
50
                                        float xx, yy;
 
51
 
 
52
                                        switch ((*g)->control_group->type)
 
53
                                        {
 
54
                                        case GROUP_TYPE_STICK :
 
55
                                                ((ControllerEmu::AnalogStick*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
 
56
                                                break;
 
57
                                        case GROUP_TYPE_TILT :
 
58
                                                ((ControllerEmu::Tilt*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
 
59
                                                break;
 
60
                                        case GROUP_TYPE_CURSOR :
 
61
                                                ((ControllerEmu::Cursor*)(*g)->control_group)->GetState( &x, &y, &z );
 
62
                                                x *= (32-1.5); x+= 32;
 
63
                                                y *= (32-1.5); y+= 32;
 
64
                                                break;
 
65
                                        }
 
66
 
 
67
                                        xx = (*g)->control_group->controls[3]->control_ref->State();
 
68
                                        xx -= (*g)->control_group->controls[2]->control_ref->State();
 
69
                                        yy = (*g)->control_group->controls[1]->control_ref->State();
 
70
                                        yy -= (*g)->control_group->controls[0]->control_ref->State();
 
71
                                        xx *= 32 - 1; xx += 32;
 
72
                                        yy *= 32 - 1; yy += 32;
 
73
 
 
74
                                        // draw the shit
 
75
 
 
76
                                        // ir cursor forward movement
 
77
                                        if (GROUP_TYPE_CURSOR == (*g)->control_group->type)
 
78
                                        {
 
79
                                                if (z)
 
80
                                                {
 
81
                                                        dc.SetPen(*wxRED_PEN);
 
82
                                                        dc.SetBrush(*wxRED_BRUSH);
 
83
                                                }
 
84
                                                else
 
85
                                                {
 
86
                                                        dc.SetPen(*wxGREY_PEN);
 
87
                                                        dc.SetBrush(*wxGREY_BRUSH);
 
88
                                                }
 
89
                                                dc.DrawRectangle( 0, 31 - z*31, 64, 2);
 
90
                                        }
 
91
 
 
92
                                        // octagon for visual aid for diagonal adjustment
 
93
                                        dc.SetPen(*wxLIGHT_GREY_PEN);
 
94
                                        dc.SetBrush(*wxWHITE_BRUSH);
 
95
                                        if ( GROUP_TYPE_STICK == (*g)->control_group->type )
 
96
                                        {
 
97
                                                // outline and fill colors
 
98
                                                wxBrush LightGrayBrush(_T("#dddddd"));
 
99
                                                wxPen LightGrayPen(_T("#bfbfbf"));
 
100
                                                dc.SetBrush(LightGrayBrush);
 
101
                                                dc.SetPen(LightGrayPen);
 
102
 
 
103
                                                // polygon offset
 
104
                                                float max
 
105
                                                        , diagonal
 
106
                                                        , box = 64
 
107
                                                        , d_of = box / 256.0
 
108
                                                        , x_of = box / 2.0;
 
109
 
 
110
                                                if (strcmp((*g)->control_group->name, "Main Stick") == 0)
 
111
                                                {
 
112
                                                        max = (87.0f / 127.0f) * 100;
 
113
                                                        diagonal = (55.0f / 127.0f) * 100.0;
 
114
                                                }
 
115
                                                else if (strcmp((*g)->control_group->name,"C-Stick") == 0)
 
116
                                                {
 
117
                                                        max = (74.0f / 127.0f) * 100;
 
118
                                                        diagonal = (46.0f / 127.0f) * 100;
 
119
                                                }
 
120
                                                else
 
121
                                                {
 
122
                                                        max = (82.0f / 127.0f) * 100;
 
123
                                                        diagonal = (58.0f / 127.0f) * 100;
 
124
                                                }
 
125
 
 
126
                                                // polygon corners
 
127
                                                wxPoint Points[8];
 
128
                                                Points[0].x = (int)(0.0 * d_of + x_of); Points[0].y = (int)(max * d_of + x_of);
 
129
                                                Points[1].x = (int)(diagonal * d_of + x_of); Points[1].y = (int)(diagonal * d_of + x_of);
 
130
                                                Points[2].x = (int)(max * d_of + x_of); Points[2].y = (int)(0.0 * d_of + x_of);
 
131
                                                Points[3].x = (int)(diagonal * d_of + x_of); Points[3].y = (int)(-diagonal * d_of + x_of);
 
132
                                                Points[4].x = (int)(0.0 * d_of + x_of); Points[4].y = (int)(-max * d_of + x_of);
 
133
                                                Points[5].x = (int)(-diagonal * d_of + x_of); Points[5].y = (int)(-diagonal * d_of + x_of);
 
134
                                                Points[6].x = (int)(-max * d_of + x_of); Points[6].y = (int)(0.0 * d_of + x_of);
 
135
                                                Points[7].x = (int)(-diagonal * d_of + x_of); Points[7].y = (int)(diagonal * d_of + x_of);
 
136
 
 
137
                                                // draw polygon
 
138
                                                dc.DrawPolygon(8, Points);
 
139
                                        }
 
140
                                        else
 
141
                                        {
 
142
                                                dc.DrawRectangle( 16, 16, 32, 32 );
 
143
                                        }
 
144
 
 
145
                                        if ( GROUP_TYPE_CURSOR != (*g)->control_group->type )
 
146
                                        {
 
147
                                                // deadzone circle
 
148
                                                dc.SetBrush(*wxLIGHT_GREY_BRUSH);
 
149
                                                dc.DrawCircle( 32, 32, ((*g)->control_group)->settings[SETTING_DEADZONE]->value * 32 );
 
150
                                        }
 
151
 
 
152
                                        // raw dot
 
153
                                        dc.SetPen(*wxGREY_PEN);
 
154
                                        dc.SetBrush(*wxGREY_BRUSH);
 
155
                                        // i like the dot better than the cross i think
 
156
                                        dc.DrawRectangle( xx - 2, yy - 2, 4, 4 );
 
157
                                        //dc.DrawRectangle( xx-1, 64-yy-4, 2, 8 );
 
158
                                        //dc.DrawRectangle( xx-4, 64-yy-1, 8, 2 );
 
159
 
 
160
                                        // adjusted dot
 
161
                                        if (x!=32 || y!=32)
 
162
                                        {
 
163
                                                dc.SetPen(*wxRED_PEN);
 
164
                                                dc.SetBrush(*wxRED_BRUSH);
 
165
                                                dc.DrawRectangle( x-2, 64-y-2, 4, 4 );
 
166
                                                // i like the dot better than the cross i think
 
167
                                                //dc.DrawRectangle( x-1, 64-y-4, 2, 8 );
 
168
                                                //dc.DrawRectangle( x-4, 64-y-1, 8, 2 );
 
169
                                        }
 
170
 
 
171
                                }
 
172
                                break;
 
173
                        case GROUP_TYPE_FORCE :
 
174
                                {
 
175
                                        float raw_dot[3];
 
176
                                        float adj_dot[3];
 
177
                                        const float deadzone = 32 * ((*g)->control_group)->settings[0]->value;
 
178
 
 
179
                                        // adjusted
 
180
                                        ((ControllerEmu::Force*)(*g)->control_group)->GetState( adj_dot, 32.0, 32-1.5 );
 
181
 
 
182
                                        // raw
 
183
                                        for ( unsigned int i=0; i<3; ++i )
 
184
                                        {
 
185
                                                raw_dot[i] = (*g)->control_group->controls[i*2 + 1]->control_ref->State()
 
186
                                                        - (*g)->control_group->controls[i*2]->control_ref->State();
 
187
                                                raw_dot[i] *= 32 - 1; raw_dot[i] += 32;
 
188
                                        }
 
189
 
 
190
                                        // deadzone rect for forward/backward visual
 
191
                                        dc.SetBrush(*wxLIGHT_GREY_BRUSH);
 
192
                                        dc.SetPen(*wxLIGHT_GREY_PEN);
 
193
                                        dc.DrawRectangle( 0, 32 - deadzone, 64, deadzone * 2 );
 
194
 
 
195
                                        // raw forward/background line
 
196
                                        dc.SetPen(*wxGREY_PEN);
 
197
                                        dc.SetBrush(*wxGREY_BRUSH);
 
198
                                        dc.DrawRectangle( 0, raw_dot[2] - 1, 64, 2 );
 
199
 
 
200
                                        // adjusted forward/background line
 
201
                                        if ( adj_dot[2]!=32 )
 
202
                                        {
 
203
                                                dc.SetPen(*wxRED_PEN);
 
204
                                                dc.SetBrush(*wxRED_BRUSH);
 
205
                                                dc.DrawRectangle( 0, adj_dot[2] - 1, 64, 2 );
 
206
                                        }
 
207
 
 
208
                                        // a rectangle, for looks i guess
 
209
                                        dc.SetBrush(*wxWHITE_BRUSH);
 
210
                                        dc.SetPen(*wxLIGHT_GREY_PEN);
 
211
                                        dc.DrawRectangle( 16, 16, 32, 32 );
 
212
 
 
213
                                        // deadzone square
 
214
                                        dc.SetBrush(*wxLIGHT_GREY_BRUSH);
 
215
                                        dc.DrawRectangle( 32 - deadzone, 32 - deadzone, deadzone * 2, deadzone * 2 );
 
216
 
 
217
                                        // raw dot
 
218
                                        dc.SetPen(*wxGREY_PEN);
 
219
                                        dc.SetBrush(*wxGREY_BRUSH);
 
220
                                        dc.DrawRectangle( raw_dot[1] - 2, raw_dot[0] - 2, 4, 4 );
 
221
 
 
222
                                        // adjusted dot
 
223
                                        if ( adj_dot[1]!=32 || adj_dot[0]!=32 )
 
224
                                        {
 
225
                                                dc.SetPen(*wxRED_PEN);
 
226
                                                dc.SetBrush(*wxRED_BRUSH);
 
227
                                                dc.DrawRectangle( adj_dot[1]-2, adj_dot[0]-2, 4, 4 );
 
228
                                        }
 
229
 
 
230
                                }
 
231
                                break;
 
232
                        case GROUP_TYPE_BUTTONS :
 
233
                                {
 
234
                                        const unsigned int button_count = ((unsigned int)(*g)->control_group->controls.size());
 
235
 
 
236
                                        // draw the shit
 
237
                                        dc.SetPen(*wxGREY_PEN);
 
238
 
 
239
                                        unsigned int * const bitmasks = new unsigned int[ button_count ];
 
240
                                        for (unsigned int n = 0; n<button_count; ++n)
 
241
                                                bitmasks[n] = (1 << n);
 
242
 
 
243
                                        unsigned int buttons = 0;
 
244
                                        ((ControllerEmu::Buttons*)(*g)->control_group)->GetState( &buttons, bitmasks );
 
245
 
 
246
                                        for (unsigned int n = 0; n<button_count; ++n)
 
247
                                        {
 
248
                                                if ( buttons & bitmasks[n] )
 
249
                                                {
 
250
                                                        dc.SetBrush( *wxRED_BRUSH );
 
251
                                                }
 
252
                                                else
 
253
                                                {
 
254
                                                        unsigned char amt = 255 - (*g)->control_group->controls[n]->control_ref->State() * 128;
 
255
                                                        dc.SetBrush(wxBrush(wxColor(amt, amt, amt)));
 
256
                                                }
 
257
                                                dc.DrawRectangle(n * 12, 0, 14, 12);
 
258
 
 
259
                                                // text
 
260
                                                const char* const name = (*g)->control_group->controls[n]->name;
 
261
                                                // bit of hax so ZL, ZR show up as L, R
 
262
                                                dc.DrawText(StrToWxStr(std::string(1, (name[1] && name[1] < 'a') ? name[1] : name[0])), n*12 + 2, 1);
 
263
                                        }
 
264
 
 
265
                                        delete[] bitmasks;
 
266
                                        
 
267
                                }
 
268
                                break;
 
269
                        case GROUP_TYPE_TRIGGERS :
 
270
                                {
 
271
                                        const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size()));
 
272
 
 
273
                                        // draw the shit
 
274
                                        dc.SetPen(*wxGREY_PEN);
 
275
                                        ControlState deadzone =  (*g)->control_group->settings[0]->value;
 
276
 
 
277
                                        unsigned int* const trigs = new unsigned int[trigger_count];
 
278
                                        ((ControllerEmu::Triggers*)(*g)->control_group)->GetState( trigs, 64 );
 
279
 
 
280
                                        for ( unsigned int n = 0; n < trigger_count; ++n )
 
281
                                        {
 
282
                                                ControlState trig_r = (*g)->control_group->controls[n]->control_ref->State();
 
283
 
 
284
                                                // outline
 
285
                                                dc.SetPen(*wxGREY_PEN);
 
286
                                                dc.SetBrush(*wxWHITE_BRUSH);
 
287
                                                dc.DrawRectangle(0, n*12, 64, 14);
 
288
 
 
289
                                                // raw
 
290
                                                dc.SetBrush(*wxGREY_BRUSH);
 
291
                                                dc.DrawRectangle(0, n*12, trig_r*64, 14);
 
292
 
 
293
                                                // deadzone affected
 
294
                                                dc.SetBrush(*wxRED_BRUSH);
 
295
                                                dc.DrawRectangle(0, n*12, trigs[n], 14);
 
296
 
 
297
                                                // text
 
298
                                                dc.DrawText(StrToWxStr((*g)->control_group->controls[n]->name), 3, n*12 + 1);
 
299
                                        }
 
300
 
 
301
                                        delete[] trigs;
 
302
 
 
303
                                        // deadzone box
 
304
                                        dc.SetPen(*wxLIGHT_GREY_PEN);
 
305
                                        dc.SetBrush(*wxTRANSPARENT_BRUSH);
 
306
                                        dc.DrawRectangle(0, 0, deadzone*64, trigger_count*14);
 
307
 
 
308
                                }
 
309
                                break;
 
310
                        case GROUP_TYPE_MIXED_TRIGGERS :
 
311
                                {
 
312
                                        const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size() / 2));
 
313
 
 
314
                                        // draw the shit
 
315
                                        dc.SetPen(*wxGREY_PEN);
 
316
                                        ControlState thresh =  (*g)->control_group->settings[0]->value;
 
317
 
 
318
                                        for ( unsigned int n = 0; n < trigger_count; ++n )
 
319
                                        {
 
320
                                                dc.SetBrush(*wxRED_BRUSH);
 
321
                                                ControlState trig_d = (*g)->control_group->controls[n]->control_ref->State();
 
322
 
 
323
                                                ControlState trig_a = trig_d > thresh ? 1
 
324
                                                        : (*g)->control_group->controls[n+trigger_count]->control_ref->State();
 
325
 
 
326
                                                dc.DrawRectangle(0, n*12, 64+20, 14);
 
327
                                                if ( trig_d <= thresh )
 
328
                                                        dc.SetBrush(*wxWHITE_BRUSH);
 
329
                                                dc.DrawRectangle(trig_a*64, n*12, 64+20, 14);
 
330
                                                dc.DrawRectangle(64, n*12, 32, 14);
 
331
 
 
332
                                                // text
 
333
                                                dc.DrawText(StrToWxStr((*g)->control_group->controls[n+trigger_count]->name), 3, n*12 + 1);
 
334
                                                dc.DrawText(StrToWxStr(std::string(1, (*g)->control_group->controls[n]->name[0])), 64 + 3, n*12 + 1);
 
335
                                        }
 
336
 
 
337
                                        // threshold box
 
338
                                        dc.SetPen(*wxLIGHT_GREY_PEN);
 
339
                                        dc.SetBrush(*wxTRANSPARENT_BRUSH);
 
340
                                        dc.DrawRectangle(thresh*64, 0, 128, trigger_count*14);
 
341
 
 
342
                                }
 
343
                                break;
 
344
                        case GROUP_TYPE_SLIDER:
 
345
                                {
 
346
                                        const ControlState deadzone =  (*g)->control_group->settings[0]->value;
 
347
 
 
348
                                        ControlState state = (*g)->control_group->controls[1]->control_ref->State() - (*g)->control_group->controls[0]->control_ref->State();
 
349
                                        dc.SetPen(*wxGREY_PEN);
 
350
                                        dc.SetBrush(*wxGREY_BRUSH);
 
351
                                        dc.DrawRectangle(31 + state * 30, 0, 2, 14);
 
352
 
 
353
                                        ((ControllerEmu::Slider*)(*g)->control_group)->GetState(&state, 1);
 
354
                                        if (state)
 
355
                                        {
 
356
                                                dc.SetPen(*wxRED_PEN);
 
357
                                                dc.SetBrush(*wxRED_BRUSH);
 
358
                                                dc.DrawRectangle(31 + state * 30, 0, 2, 14);
 
359
                                        }
 
360
 
 
361
                                        // deadzone box
 
362
                                        dc.SetPen(*wxLIGHT_GREY_PEN);
 
363
                                        dc.SetBrush(*wxTRANSPARENT_BRUSH);
 
364
                                        dc.DrawRectangle(32 - deadzone * 32, 0, deadzone * 64, 14);
 
365
                                }
 
366
                                break;
 
367
                        default :
 
368
                                break;
 
369
                        }
 
370
 
 
371
                        // box outline
 
372
                        // Windows XP color
 
373
                        dc.SetPen(wxPen(_T("#7f9db9")));
 
374
                        dc.SetBrush(*wxTRANSPARENT_BRUSH);
 
375
                        dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
 
376
 
 
377
                        dc.SelectObject(wxNullBitmap);
 
378
                        (*g)->static_bitmap->SetBitmap(bitmap);
 
379
                }
 
380
        }
 
381
}