summaryrefslogtreecommitdiff
path: root/Source/Plugins/InputPluginCommon/Src/ConfigDiagBitmaps.cpp
blob: 7f97249c173d132fc1ec5ca43b5a56f3424f4d4c (plain)
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

#include "ConfigDiag.h"

void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
{

	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 ( (*g)->static_bitmap )
		{

			// don't want game thread updating input when we are using it here
			if ( false == m_plugin.interface_crit.TryEnter() )
				return;

			//if ( false == is_game_running )
			// just always update
				m_plugin.controller_interface.UpdateInput();

			switch ( (*g)->control_group->type )
			{
			case GROUP_TYPE_TILT :
			case GROUP_TYPE_STICK :
				{
					float x = 0, y = 0;
					float xx, yy;
					if ( GROUP_TYPE_STICK == (*g)->control_group->type )
						((ControllerEmu::AnalogStick*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
					else
						((ControllerEmu::Tilt*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );

					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;

					// setup
					wxBitmap bitmap(64, 64);
					wxMemoryDC dc;
					dc.SelectObject(bitmap);
					dc.Clear();

					// draw the shit

					// circle for visual aid for diagonal adjustment
					dc.SetPen(*wxLIGHT_GREY_PEN);
					dc.SetBrush(*wxTRANSPARENT_BRUSH);
					if ( GROUP_TYPE_STICK == (*g)->control_group->type )
						dc.DrawCircle( 32, 32, 32);
					else
						dc.DrawRectangle( 16, 16, 32, 32 );

					// 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 );
					}

					// box outline
					// Windows XP color
					dc.SetPen(wxPen(_T("#7f9db9")));
					dc.SetBrush(*wxTRANSPARENT_BRUSH);
					dc.DrawRectangle(0, 0, 64, 64);

					// done drawing
					dc.SelectObject(wxNullBitmap);

					// set the shit
					(*g)->static_bitmap->SetBitmap( bitmap );
				}
				break;
			case GROUP_TYPE_BUTTONS :
				{
					const unsigned int button_count = ((unsigned int)(*g)->control_group->controls.size());
					// setup
					wxBitmap bitmap(12*button_count+1, 12);
					wxMemoryDC dc;
					dc.SelectObject(bitmap);
					dc.Clear();

					// 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 )
					{
						// TODO: threshold stuff, actually redo this crap with the GetState func
						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);
					}

					delete bitmasks;

					// box outline
					// Windows XP color
					dc.SetPen(wxPen(_T("#7f9db9")));
					dc.SetBrush(*wxTRANSPARENT_BRUSH);
					dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());

					// done drawing
					dc.SelectObject(wxNullBitmap);

					// set the shit
					(*g)->static_bitmap->SetBitmap( bitmap );					
				}
				break;

			case GROUP_TYPE_MIXED_TRIGGERS :
				{
					const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size() / 2));
					// setup
					wxBitmap bitmap( 64+12+1, 12*trigger_count+1);
					wxMemoryDC dc;
					dc.SelectObject(bitmap);
					dc.Clear();

					// 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);
					}
					dc.SetBrush(*wxTRANSPARENT_BRUSH);
					dc.DrawRectangle(thresh*64, 0, 128, trigger_count*14);

					// box outline
					// Windows XP color
					dc.SetPen(wxPen(_T("#7f9db9")));
					dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());

					// done drawing
					dc.SelectObject(wxNullBitmap);

					// set the shit
					(*g)->static_bitmap->SetBitmap( bitmap );	
				}
				break;
			default :
				break;
			}

			m_plugin.interface_crit.Leave();
		}
	}

}