Skip to content

Commit

Permalink
Fix the input zone drawing in input settings
Browse files Browse the repository at this point in the history
  • Loading branch information
john-peterson committed Jan 18, 2015
1 parent 9d9ffa5 commit 3f8e5cc
Showing 1 changed file with 83 additions and 30 deletions.
113 changes: 83 additions & 30 deletions Source/Core/DolphinWX/InputConfigDiagBitmaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,66 @@
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/Device.h"

struct ShapePosition
{
double max;
double diag;
double box;
double scale;

double dz;
double range;

wxCoord offset;
};

// regular octagon
void DrawOctagon(wxDC* dc, ShapePosition p)
{
const int vertices = 8;
double radius = p.max;

wxPoint point[vertices];

double angle = 2.0 * M_PI / vertices;

for (int i = 0; i < vertices; i++)
{
double a = (angle * i);
double x = radius * cos(a);
double y = radius * sin(a);
point[i].x = x;
point[i].y = y;
}

dc->DrawPolygon(vertices, point, p.offset, p.offset);
}

// irregular dodecagon
void DrawDodecagon(wxDC* dc, ShapePosition p)
{
const int vertices = 12;

wxPoint point[vertices];
point[0].x = p.dz; point[0].y = p.max;
point[1].x = p.diag; point[1].y = p.diag;
point[2].x = p.max; point[2].y = p.dz;

point[3].x = p.max; point[3].y = -p.dz;
point[4].x = p.diag; point[4].y = -p.diag;
point[5].x = p.dz; point[5].y = -p.max;

point[6].x = -p.dz; point[6].y = -p.max;
point[7].x = -p.diag; point[7].y = -p.diag;
point[8].x = -p.max; point[8].y = -p.dz;

point[9].x = -p.max; point[9].y = p.dz;
point[10].x = -p.diag; point[10].y = p.diag;
point[11].x = -p.dz; point[11].y = p.max;

dc->DrawPolygon(vertices, point, p.offset, p.offset);
}

static void DrawCenteredRectangle(wxDC &dc, int x, int y, int w, int h)
{
x -= w / 2;
Expand Down Expand Up @@ -89,7 +149,7 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
dc.DrawRectangle(0, 31 - z*31, 64, 2);
}

// octagon for visual aid for diagonal adjustment
// input zone
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
if (GROUP_TYPE_STICK == g->control_group->type)
Expand All @@ -100,42 +160,35 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
dc.SetBrush(LightGrayBrush);
dc.SetPen(LightGrayPen);

// polygon offset
ControlState max
, diagonal
, box = 64
, d_of = box / 256.0
, x_of = box / 2.0;
ShapePosition p;
p.box = 64;
p.offset = p.box / 2;
p.range = 256;
p.scale = p.box / p.range;
p.dz = 15 * p.scale;
bool octagon = false;

if (g->control_group->name == "Main Stick")
{
max = (87.0 / 127.0) * 100;
diagonal = (55.0 / 127.0) * 100;
p.max = 87 * p.scale;
p.diag = 55 * p.scale;
}
else if (g->control_group->name == "C-Stick")
{
max = (74.0 / 127.0) * 100;
diagonal = (46.0 / 127.0) * 100;
p.max = 74 * p.scale;
p.diag = 46 * p.scale;
}
else
{
max = (82.0 / 127.0) * 100;
diagonal = (58.0 / 127.0) * 100;
p.scale = 1;
p.max = 32;
octagon = true;
}

// polygon corners
wxPoint Points[8];
Points[0].x = (int)(0.0 * d_of + x_of); Points[0].y = (int)(max * d_of + x_of);
Points[1].x = (int)(diagonal * d_of + x_of); Points[1].y = (int)(diagonal * d_of + x_of);
Points[2].x = (int)(max * d_of + x_of); Points[2].y = (int)(0.0 * d_of + x_of);
Points[3].x = (int)(diagonal * d_of + x_of); Points[3].y = (int)(-diagonal * d_of + x_of);
Points[4].x = (int)(0.0 * d_of + x_of); Points[4].y = (int)(-max * d_of + x_of);
Points[5].x = (int)(-diagonal * d_of + x_of); Points[5].y = (int)(-diagonal * d_of + x_of);
Points[6].x = (int)(-max * d_of + x_of); Points[6].y = (int)(0.0 * d_of + x_of);
Points[7].x = (int)(-diagonal * d_of + x_of); Points[7].y = (int)(diagonal * d_of + x_of);

// draw polygon
dc.DrawPolygon(8, Points);
if (octagon)
DrawOctagon(&dc, p);
else
DrawDodecagon(&dc, p);
}
else
{
Expand Down Expand Up @@ -407,10 +460,6 @@ void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
dc.SetFont(small_font);
dc.SetTextForeground(0xC0C0C0);

// label for sticks and stuff
if (64 == bitmap.GetHeight())
dc.DrawText(StrToWxStr(g->control_group->name).Upper(), 4, 2);

DrawControlGroupBox(dc, g);

// box outline
Expand All @@ -419,6 +468,10 @@ void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());

// label for sticks and stuff
if (64 == bitmap.GetHeight())
dc.DrawText(StrToWxStr(g->control_group->name).Upper(), 4, 2);

dc.SelectObject(wxNullBitmap);
g->static_bitmap->SetBitmap(bitmap);
}
Expand Down

0 comments on commit 3f8e5cc

Please sign in to comment.