GCPadNew: Added option to disable input when Dolphin window isn't active. Some other...
[dolphin.git] / Source / Plugins / Plugin_GCPadNew / Src / ConfigDiagBitmaps.cpp
blob476f2e4e752dab487a094047a66423627aec5ba5
2 #include "ConfigDiag.h"
4 void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
7 GamepadPage* const current_page = (GamepadPage*)m_pad_notebook->GetPage( m_pad_notebook->GetSelection() );
9 std::vector< ControlGroupBox* >::iterator g = current_page->control_groups.begin(),
10 ge = current_page->control_groups.end();
11 for ( ; g != ge; ++g )
14 if ( (*g)->static_bitmap )
17 // don't want game thread updating input when we are using it here
18 if ( false == m_plugin.interface_crit.TryEnter() )
19 return;
21 //if ( false == is_game_running )
22 // just always update
23 m_plugin.controller_interface.UpdateInput();
25 switch ( (*g)->control_group->type )
27 case GROUP_TYPE_STICK :
29 float x, y;
30 float xx, yy;
31 ((ControllerEmu::AnalogStick*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
33 xx = ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[3]->control_ref->State();
34 xx -= ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[2]->control_ref->State();
35 yy = ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[1]->control_ref->State();
36 yy -= ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[0]->control_ref->State();
37 xx *= 32 - 1; xx += 32;
38 yy *= 32 - 1; yy += 32;
40 // setup
41 wxBitmap bitmap(64, 64);
42 wxMemoryDC dc;
43 dc.SelectObject(bitmap);
44 dc.Clear();
46 // draw the shit
48 // circle for visual aid for diagonal adjustment
49 dc.SetPen(*wxLIGHT_GREY_PEN);
50 dc.SetBrush(*wxTRANSPARENT_BRUSH);
51 dc.DrawCircle( 32, 32, 32);
53 // deadzone circle
54 dc.SetBrush(*wxLIGHT_GREY_BRUSH);
55 dc.DrawCircle( 32, 32, ((ControllerEmu::AnalogStick*)(*g)->control_group)->settings[0]->value * 32 );
57 // raw dot
58 dc.SetPen(*wxGREY_PEN);
59 dc.SetBrush(*wxGREY_BRUSH);
60 // i like the dot better than the cross i think
61 dc.DrawRectangle( xx - 2, yy - 2, 4, 4 );
62 //dc.DrawRectangle( xx-1, 64-yy-4, 2, 8 );
63 //dc.DrawRectangle( xx-4, 64-yy-1, 8, 2 );
65 // adjusted dot
66 if ( x!=32 || y!=32 )
68 dc.SetPen(*wxRED_PEN);
69 dc.SetBrush(*wxRED_BRUSH);
70 dc.DrawRectangle( x-2, 64-y-2, 4, 4 );
71 // i like the dot better than the cross i think
72 //dc.DrawRectangle( x-1, 64-y-4, 2, 8 );
73 //dc.DrawRectangle( x-4, 64-y-1, 8, 2 );
76 // box outline
77 // Windows XP color
78 dc.SetPen(wxPen(_T("#7f9db9")));
79 dc.SetBrush(*wxTRANSPARENT_BRUSH);
80 dc.DrawRectangle(0, 0, 64, 64);
82 // done drawing
83 dc.SelectObject(wxNullBitmap);
85 // set the shit
86 (*g)->static_bitmap->SetBitmap( bitmap );
88 break;
89 case GROUP_TYPE_BUTTONS :
91 const unsigned int button_count = ((unsigned int)(*g)->control_group->controls.size());
92 // setup
93 wxBitmap bitmap(12*button_count+1, 12);
94 wxMemoryDC dc;
95 dc.SelectObject(bitmap);
96 dc.Clear();
98 // draw the shit
99 dc.SetPen(*wxGREY_PEN);
101 unsigned int * const bitmasks = new unsigned int[ button_count ];
102 for ( unsigned int n = 0; n<button_count; ++n )
103 bitmasks[n] = ( 1 << n );
105 unsigned int buttons = 0;
106 ((ControllerEmu::Buttons*)(*g)->control_group)->GetState( &buttons, bitmasks );
108 for ( unsigned int n = 0; n<button_count; ++n )
110 // TODO: threshold stuff, actually redo this crap with the GetState func
111 if ( buttons & bitmasks[n] )
112 dc.SetBrush( *wxRED_BRUSH );
113 else
115 unsigned char amt = 255 - (*g)->control_group->controls[n]->control_ref->State() * 128;
116 dc.SetBrush( wxBrush( wxColor( amt, amt, amt ) ) );
118 dc.DrawRectangle(n*12, 0, 14, 12);
121 delete bitmasks;
123 // box outline
124 // Windows XP color
125 dc.SetPen(wxPen(_T("#7f9db9")));
126 dc.SetBrush(*wxTRANSPARENT_BRUSH);
127 dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
129 // done drawing
130 dc.SelectObject(wxNullBitmap);
132 // set the shit
133 (*g)->static_bitmap->SetBitmap( bitmap );
135 break;
137 case GROUP_TYPE_MIXED_TRIGGERS :
139 const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size() / 2));
140 // setup
141 wxBitmap bitmap( 64+12+1, 12*trigger_count+1);
142 wxMemoryDC dc;
143 dc.SelectObject(bitmap);
144 dc.Clear();
146 // draw the shit
147 dc.SetPen(*wxGREY_PEN);
148 ControlState thresh = (*g)->control_group->settings[0]->value;
150 for ( unsigned int n = 0; n < trigger_count; ++n )
152 dc.SetBrush(*wxRED_BRUSH);
153 ControlState trig_d = (*g)->control_group->controls[n]->control_ref->State();
155 ControlState trig_a = trig_d > thresh ? 1
156 : (*g)->control_group->controls[n+trigger_count]->control_ref->State();
158 dc.DrawRectangle(0, n*12, 64+20, 14);
159 if ( trig_d <= thresh )
160 dc.SetBrush(*wxWHITE_BRUSH);
161 dc.DrawRectangle(trig_a*64, n*12, 64+20, 14);
162 dc.DrawRectangle(64, n*12, 32, 14);
164 dc.SetBrush(*wxTRANSPARENT_BRUSH);
165 dc.DrawRectangle(thresh*64, 0, 128, trigger_count*14);
167 // box outline
168 // Windows XP color
169 dc.SetPen(wxPen(_T("#7f9db9")));
170 dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
172 // done drawing
173 dc.SelectObject(wxNullBitmap);
175 // set the shit
176 (*g)->static_bitmap->SetBitmap( bitmap );
178 break;
179 default :
180 break;
183 m_plugin.interface_crit.Leave();