InputConfigDiagBitmaps: Rewrite the stick visualization code

Change our DrawCoordinate helper method to take raw coordinate
positions, and draw the rectangle using that. This is a lot better
and more friendly than applying various crazy constants in the GetState
for the base/range.
This commit is contained in:
Jasper St. Pierre 2014-07-11 08:43:00 -04:00
parent 8abff435e6
commit 4d2a39090b
1 changed files with 21 additions and 18 deletions

View File

@ -36,11 +36,18 @@ static void DrawCenteredRectangle(wxDC &dc, int x, int y, int w, int h)
dc.DrawRectangle(x, y, w, h); dc.DrawRectangle(x, y, w, h);
} }
#define VIS_BITMAP_SIZE 64
#define VIS_NORMALIZE(a) ((a / 2.0) + 0.5)
#define VIS_COORD(a) ((VIS_NORMALIZE(a)) * VIS_BITMAP_SIZE)
#define COORD_VIS_SIZE 4 #define COORD_VIS_SIZE 4
static void DrawCoordinate(wxDC &dc, int x, int y) static void DrawCoordinate(wxDC &dc, double x, double y)
{ {
DrawCenteredRectangle(dc, x, y, COORD_VIS_SIZE, COORD_VIS_SIZE); int xc = VIS_COORD(x);
int yc = VIS_COORD(y);
DrawCenteredRectangle(dc, xc, yc, COORD_VIS_SIZE, COORD_VIS_SIZE);
} }
static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g) static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
@ -54,32 +61,20 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
// this is starting to be a mess combining all these in one case // this is starting to be a mess combining all these in one case
float x = 0, y = 0, z = 0; float x = 0, y = 0, z = 0;
float xx, yy;
switch (g->control_group->type) switch (g->control_group->type)
{ {
case GROUP_TYPE_STICK : case GROUP_TYPE_STICK :
((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y, 32.0, 32-1.5); ((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y, 0, 1);
break; break;
case GROUP_TYPE_TILT : case GROUP_TYPE_TILT :
((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y, 32.0, 32-1.5); ((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y, 0, 1);
break; break;
case GROUP_TYPE_CURSOR : case GROUP_TYPE_CURSOR :
((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z); ((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z);
x *= (32-1.5); x+= 32;
y *= (32-1.5); y+= 32;
break; 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 // ir cursor forward movement
if (GROUP_TYPE_CURSOR == g->control_group->type) if (GROUP_TYPE_CURSOR == g->control_group->type)
{ {
@ -157,18 +152,26 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
} }
// raw dot // raw dot
{
float xx, yy;
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();
dc.SetPen(*wxGREY_PEN); dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxGREY_BRUSH); dc.SetBrush(*wxGREY_BRUSH);
DrawCoordinate(dc, xx, yy); DrawCoordinate(dc, xx, yy);
}
// adjusted dot // adjusted dot
if (x!=32 || y!=32) if (x != 0 && y != 0)
{ {
dc.SetPen(*wxRED_PEN); dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxRED_BRUSH); dc.SetBrush(*wxRED_BRUSH);
// XXX: The adjusted values flip the Y axis to be in the format // XXX: The adjusted values flip the Y axis to be in the format
// the Wii expects. Should this be in WiimoteEmu.cpp instead? // the Wii expects. Should this be in WiimoteEmu.cpp instead?
DrawCoordinate(dc, x, 64 - y); DrawCoordinate(dc, x, -y);
} }
} }
break; break;