2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:43:35 -06:00
|
|
|
// Refer to the license.txt file included.
|
2010-04-01 20:48:24 -06:00
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cmath>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <cstring>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <wx/bitmap.h>
|
|
|
|
#include <wx/brush.h>
|
|
|
|
#include <wx/colour.h>
|
|
|
|
#include <wx/dcmemory.h>
|
|
|
|
#include <wx/font.h>
|
2016-08-02 00:22:48 -06:00
|
|
|
#include <wx/graphics.h>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <wx/notebook.h>
|
|
|
|
#include <wx/pen.h>
|
2016-08-02 00:22:48 -06:00
|
|
|
#include <wx/settings.h>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <wx/statbmp.h>
|
|
|
|
|
2016-11-18 00:03:06 -07:00
|
|
|
#include "DolphinWX/Input/InputConfigDiag.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DolphinWX/WxUtils.h"
|
2010-04-01 20:48:24 -06:00
|
|
|
|
2017-02-08 20:15:43 -07:00
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Cursor.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Force.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Slider.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Triggers.h"
|
2017-01-29 20:32:04 -07:00
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
|
|
|
|
2013-07-14 16:38:57 -06:00
|
|
|
struct ShapePosition
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
double max;
|
|
|
|
double diag;
|
|
|
|
double box;
|
|
|
|
double scale;
|
2013-07-14 16:38:57 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
double dz;
|
|
|
|
double range;
|
2013-07-14 16:38:57 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
wxCoord offset;
|
2013-07-14 16:38:57 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
// regular octagon
|
2016-08-02 00:22:48 -06:00
|
|
|
static void DrawOctagon(wxGraphicsContext* gc, ShapePosition p)
|
2013-07-14 16:38:57 -06:00
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
static constexpr int vertices = 8;
|
2016-06-24 02:43:46 -06:00
|
|
|
double radius = p.max;
|
2013-07-14 16:38:57 -06:00
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
wxGraphicsPath path = gc->CreatePath();
|
2013-07-14 16:38:57 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
double angle = 2.0 * M_PI / vertices;
|
2013-07-14 16:38:57 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
for (int i = 0; i < vertices; i++)
|
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
double a = angle * i;
|
2016-06-24 02:43:46 -06:00
|
|
|
double x = radius * cos(a);
|
|
|
|
double y = radius * sin(a);
|
2016-08-02 00:22:48 -06:00
|
|
|
if (i == 0)
|
|
|
|
path.MoveToPoint(x, y);
|
|
|
|
else
|
|
|
|
path.AddLineToPoint(x, y);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2016-08-02 00:22:48 -06:00
|
|
|
path.CloseSubpath();
|
|
|
|
|
|
|
|
wxGraphicsMatrix matrix = gc->CreateMatrix();
|
|
|
|
matrix.Translate(p.offset, p.offset);
|
|
|
|
path.Transform(matrix);
|
2013-07-14 16:38:57 -06:00
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->DrawPath(path);
|
2013-07-14 16:38:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// irregular dodecagon
|
2016-08-02 00:22:48 -06:00
|
|
|
static void DrawDodecagon(wxGraphicsContext* gc, ShapePosition p)
|
2013-07-14 16:38:57 -06:00
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
wxGraphicsPath path = gc->CreatePath();
|
|
|
|
path.MoveToPoint(p.dz, p.max);
|
|
|
|
path.AddLineToPoint(p.diag, p.diag);
|
|
|
|
path.AddLineToPoint(p.max, p.dz);
|
|
|
|
path.AddLineToPoint(p.max, -p.dz);
|
|
|
|
path.AddLineToPoint(p.diag, -p.diag);
|
|
|
|
path.AddLineToPoint(p.dz, -p.max);
|
|
|
|
path.AddLineToPoint(-p.dz, -p.max);
|
|
|
|
path.AddLineToPoint(-p.diag, -p.diag);
|
|
|
|
path.AddLineToPoint(-p.max, -p.dz);
|
|
|
|
path.AddLineToPoint(-p.max, p.dz);
|
|
|
|
path.AddLineToPoint(-p.diag, p.diag);
|
|
|
|
path.AddLineToPoint(-p.dz, p.max);
|
|
|
|
path.CloseSubpath();
|
|
|
|
|
|
|
|
wxGraphicsMatrix matrix = gc->CreateMatrix();
|
|
|
|
matrix.Translate(p.offset, p.offset);
|
|
|
|
path.Transform(matrix);
|
|
|
|
|
|
|
|
gc->DrawPath(path);
|
2013-07-14 16:38:57 -06:00
|
|
|
}
|
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
static void DrawCenteredRectangle(wxGraphicsContext* gc, double x, double y, double w, double h)
|
2014-07-11 05:57:52 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
x -= w / 2;
|
|
|
|
y -= h / 2;
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->DrawRectangle(x, y, w, h);
|
2014-07-11 05:57:52 -06:00
|
|
|
}
|
|
|
|
|
2014-07-11 06:43:00 -06:00
|
|
|
#define VIS_BITMAP_SIZE 64
|
|
|
|
|
|
|
|
#define VIS_NORMALIZE(a) ((a / 2.0) + 0.5)
|
|
|
|
#define VIS_COORD(a) ((VIS_NORMALIZE(a)) * VIS_BITMAP_SIZE)
|
|
|
|
|
2014-07-11 05:57:52 -06:00
|
|
|
#define COORD_VIS_SIZE 4
|
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
static void DrawCoordinate(wxGraphicsContext* gc, ControlState x, ControlState y)
|
2014-07-11 05:57:52 -06:00
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
double xc = VIS_COORD(x);
|
|
|
|
double yc = VIS_COORD(y);
|
|
|
|
DrawCenteredRectangle(gc, xc, yc, COORD_VIS_SIZE, COORD_VIS_SIZE);
|
2014-07-11 05:57:52 -06:00
|
|
|
}
|
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
static void DrawButton(const std::vector<unsigned int>& bitmasks, unsigned int buttons,
|
|
|
|
unsigned int n, wxGraphicsContext* gc, ControlGroupBox* g, unsigned int row,
|
|
|
|
const wxGraphicsMatrix& null_matrix)
|
2015-01-16 17:16:15 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (buttons & bitmasks[(row * 8) + n])
|
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxRED_BRUSH);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned char amt = 255 - g->control_group->controls[(row * 8) + n]->control_ref->State() * 128;
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(wxBrush(wxColour(amt, amt, amt)));
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->DrawRectangle(n * 12, (row == 0) ? 0 : (row * 11), 14, 12);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// text
|
|
|
|
const std::string name = g->control_group->controls[(row * 8) + n]->name;
|
2016-08-02 00:22:48 -06:00
|
|
|
// Matrix transformation needs to be disabled so we don't draw scaled/zoomed text.
|
|
|
|
wxGraphicsMatrix old_matrix = gc->GetTransform();
|
|
|
|
gc->SetTransform(null_matrix);
|
2016-06-24 02:43:46 -06:00
|
|
|
// bit of hax so ZL, ZR show up as L, R
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->DrawText(wxUniChar((name[1] && name[1] < 'a') ? name[1] : name[0]), (n * 12 + 2) * g->m_scale,
|
|
|
|
(1 + (row == 0 ? 0 : row * 11)) * g->m_scale);
|
|
|
|
gc->SetTransform(old_matrix);
|
2015-01-16 17:16:15 -07:00
|
|
|
}
|
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
|
2014-07-11 05:34:34 -06:00
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
wxGraphicsMatrix null_matrix = gc->GetTransform();
|
|
|
|
wxGraphicsMatrix scale_matrix = null_matrix;
|
|
|
|
scale_matrix.Scale(g->m_scale, g->m_scale);
|
|
|
|
|
|
|
|
gc->SetTransform(scale_matrix);
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
switch (g->control_group->type)
|
|
|
|
{
|
2017-02-24 22:35:02 -07:00
|
|
|
case ControllerEmu::GroupType::Tilt:
|
|
|
|
case ControllerEmu::GroupType::Stick:
|
|
|
|
case ControllerEmu::GroupType::Cursor:
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
// this is starting to be a mess combining all these in one case
|
|
|
|
|
|
|
|
ControlState x = 0, y = 0, z = 0;
|
|
|
|
|
|
|
|
switch (g->control_group->type)
|
|
|
|
{
|
2017-02-24 22:35:02 -07:00
|
|
|
case ControllerEmu::GroupType::Stick:
|
2016-06-24 02:43:46 -06:00
|
|
|
((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y);
|
|
|
|
break;
|
2017-02-24 22:35:02 -07:00
|
|
|
case ControllerEmu::GroupType::Tilt:
|
2016-06-24 02:43:46 -06:00
|
|
|
((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y);
|
|
|
|
break;
|
2017-02-24 22:35:02 -07:00
|
|
|
case ControllerEmu::GroupType::Cursor:
|
2016-06-24 02:43:46 -06:00
|
|
|
((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z);
|
|
|
|
break;
|
2017-03-22 00:39:09 -06:00
|
|
|
case ControllerEmu::GroupType::Other:
|
|
|
|
case ControllerEmu::GroupType::MixedTriggers:
|
|
|
|
case ControllerEmu::GroupType::Buttons:
|
|
|
|
case ControllerEmu::GroupType::Force:
|
|
|
|
case ControllerEmu::GroupType::Extension:
|
|
|
|
case ControllerEmu::GroupType::Triggers:
|
|
|
|
case ControllerEmu::GroupType::Slider:
|
|
|
|
break;
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ir cursor forward movement
|
2017-02-24 22:35:02 -07:00
|
|
|
if (g->control_group->type == ControllerEmu::GroupType::Cursor)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(z ? *wxRED_BRUSH : *wxGREY_BRUSH);
|
|
|
|
wxGraphicsPath path = gc->CreatePath();
|
|
|
|
path.AddRectangle(0, 31 - z * 31, 64, 2);
|
|
|
|
gc->FillPath(path);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// input zone
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxLIGHT_GREY_PEN);
|
2017-02-24 22:35:02 -07:00
|
|
|
if (g->control_group->type == ControllerEmu::GroupType::Stick)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(wxColour(0xDDDDDD)); // Light Gray
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
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")
|
|
|
|
{
|
|
|
|
p.max = 87 * p.scale;
|
|
|
|
p.diag = 55 * p.scale;
|
|
|
|
}
|
|
|
|
else if (g->control_group->name == "C-Stick")
|
|
|
|
{
|
|
|
|
p.max = 74 * p.scale;
|
|
|
|
p.diag = 46 * p.scale;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p.scale = 1;
|
|
|
|
p.max = 32;
|
|
|
|
octagon = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (octagon)
|
2016-08-02 00:22:48 -06:00
|
|
|
DrawOctagon(gc, p);
|
2016-06-24 02:43:46 -06:00
|
|
|
else
|
2016-08-02 00:22:48 -06:00
|
|
|
DrawDodecagon(gc, p);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxWHITE_BRUSH);
|
|
|
|
gc->DrawRectangle(16, 16, 32, 32);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2017-02-24 22:35:02 -07:00
|
|
|
if (g->control_group->type != ControllerEmu::GroupType::Cursor)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-02-24 22:35:02 -07:00
|
|
|
const int deadzone_idx = g->control_group->type == ControllerEmu::GroupType::Stick ?
|
2017-02-08 20:15:43 -07:00
|
|
|
ControllerEmu::AnalogStick::SETTING_DEADZONE :
|
|
|
|
0;
|
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
wxGraphicsPath path = gc->CreatePath();
|
|
|
|
path.AddCircle(VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE / 2,
|
|
|
|
g->control_group->numeric_settings[deadzone_idx]->GetValue() *
|
|
|
|
VIS_BITMAP_SIZE / 2);
|
|
|
|
gc->SetBrush(*wxLIGHT_GREY_BRUSH);
|
|
|
|
gc->FillPath(path);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// raw dot
|
2016-07-14 09:45:59 -06:00
|
|
|
ControlState 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();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
gc->SetBrush(*wxGREY_BRUSH);
|
|
|
|
DrawCoordinate(gc, xx, yy);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// adjusted dot
|
|
|
|
if (x != 0 || y != 0)
|
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxRED_BRUSH);
|
2016-06-24 02:43:46 -06:00
|
|
|
// XXX: The adjusted values flip the Y axis to be in the format
|
|
|
|
// the Wii expects. Should this be in WiimoteEmu.cpp instead?
|
2016-08-02 00:22:48 -06:00
|
|
|
DrawCoordinate(gc, x, -y);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-08-02 00:22:48 -06:00
|
|
|
|
2017-02-24 22:35:02 -07:00
|
|
|
case ControllerEmu::GroupType::Force:
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
ControlState raw_dot[3];
|
|
|
|
ControlState adj_dot[3];
|
2016-07-11 11:35:32 -06:00
|
|
|
const ControlState deadzone = g->control_group->numeric_settings[0]->GetValue();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// adjusted
|
|
|
|
((ControllerEmu::Force*)g->control_group)->GetState(adj_dot);
|
|
|
|
|
|
|
|
// raw
|
|
|
|
for (unsigned int i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
raw_dot[i] = (g->control_group->controls[i * 2 + 1]->control_ref->State() -
|
|
|
|
g->control_group->controls[i * 2]->control_ref->State());
|
|
|
|
}
|
|
|
|
|
|
|
|
// deadzone rect for forward/backward visual
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
gc->SetBrush(*wxLIGHT_GREY_BRUSH);
|
2016-06-24 02:43:46 -06:00
|
|
|
int deadzone_height = deadzone * VIS_BITMAP_SIZE;
|
2016-08-02 00:22:48 -06:00
|
|
|
DrawCenteredRectangle(gc, 0, VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE, deadzone_height);
|
2014-07-11 06:37:48 -06:00
|
|
|
|
|
|
|
#define LINE_HEIGHT 2
|
2016-06-24 02:43:46 -06:00
|
|
|
int line_y;
|
|
|
|
|
|
|
|
// raw forward/background line
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxGREY_BRUSH);
|
2016-06-24 02:43:46 -06:00
|
|
|
line_y = VIS_COORD(raw_dot[2]);
|
2016-08-02 00:22:48 -06:00
|
|
|
DrawCenteredRectangle(gc, VIS_BITMAP_SIZE / 2, line_y, VIS_BITMAP_SIZE, LINE_HEIGHT);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// adjusted forward/background line
|
|
|
|
if (adj_dot[2] != 0.0)
|
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxRED_BRUSH);
|
2016-06-24 02:43:46 -06:00
|
|
|
line_y = VIS_COORD(adj_dot[2]);
|
2016-08-02 00:22:48 -06:00
|
|
|
DrawCenteredRectangle(gc, VIS_BITMAP_SIZE / 2, line_y, VIS_BITMAP_SIZE, LINE_HEIGHT);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2014-07-11 05:34:34 -06:00
|
|
|
|
2014-07-11 06:37:48 -06:00
|
|
|
#define DEADZONE_RECT_SIZE 32
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
// empty deadzone square
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxLIGHT_GREY_PEN);
|
|
|
|
gc->SetBrush(*wxWHITE_BRUSH);
|
|
|
|
DrawCenteredRectangle(gc, VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE / 2, DEADZONE_RECT_SIZE,
|
2016-06-24 02:43:46 -06:00
|
|
|
DEADZONE_RECT_SIZE);
|
|
|
|
|
|
|
|
// deadzone square
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
gc->SetBrush(*wxLIGHT_GREY_BRUSH);
|
2016-06-24 02:43:46 -06:00
|
|
|
int dz_size = (deadzone * DEADZONE_RECT_SIZE);
|
2016-08-02 00:22:48 -06:00
|
|
|
DrawCenteredRectangle(gc, VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE / 2, dz_size, dz_size);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// raw dot
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxGREY_BRUSH);
|
|
|
|
DrawCoordinate(gc, raw_dot[1], raw_dot[0]);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// adjusted dot
|
|
|
|
if (adj_dot[1] != 0 && adj_dot[0] != 0)
|
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxRED_BRUSH);
|
|
|
|
DrawCoordinate(gc, adj_dot[1], adj_dot[0]);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-08-02 00:22:48 -06:00
|
|
|
|
2017-02-24 22:35:02 -07:00
|
|
|
case ControllerEmu::GroupType::Buttons:
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
const unsigned int button_count = static_cast<unsigned int>(g->control_group->controls.size());
|
|
|
|
std::vector<unsigned int> bitmasks(button_count);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// draw the shit
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxGREY_PEN);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
for (unsigned int n = 0; n < button_count; ++n)
|
|
|
|
bitmasks[n] = (1 << n);
|
|
|
|
|
|
|
|
unsigned int buttons = 0;
|
2016-08-02 00:22:48 -06:00
|
|
|
((ControllerEmu::Buttons*)g->control_group)->GetState(&buttons, bitmasks.data());
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// Draw buttons in rows of 8
|
|
|
|
for (unsigned int row = 0; row < ceil((float)button_count / 8.0f); row++)
|
|
|
|
{
|
|
|
|
unsigned int buttons_to_draw = 8;
|
|
|
|
if ((button_count - row * 8) <= 8)
|
|
|
|
buttons_to_draw = button_count - row * 8;
|
|
|
|
|
|
|
|
for (unsigned int n = 0; n < buttons_to_draw; ++n)
|
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
DrawButton(bitmasks, buttons, n, gc, g, row, null_matrix);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-08-02 00:22:48 -06:00
|
|
|
|
2017-02-24 22:35:02 -07:00
|
|
|
case ControllerEmu::GroupType::Triggers:
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
const unsigned int trigger_count = static_cast<unsigned int>(g->control_group->controls.size());
|
|
|
|
std::vector<ControlState> trigs(trigger_count);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// draw the shit
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxGREY_PEN);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
ControlState deadzone = g->control_group->numeric_settings[0]->GetValue();
|
|
|
|
((ControllerEmu::Triggers*)g->control_group)->GetState(trigs.data());
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
for (unsigned int n = 0; n < trigger_count; ++n)
|
|
|
|
{
|
|
|
|
ControlState trig_r = g->control_group->controls[n]->control_ref->State();
|
|
|
|
|
|
|
|
// outline
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxWHITE_BRUSH);
|
|
|
|
gc->DrawRectangle(0, n * 12, 64, 14);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// raw
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxGREY_BRUSH);
|
|
|
|
gc->DrawRectangle(0, n * 12, trig_r * 64, 14);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// deadzone affected
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxRED_BRUSH);
|
|
|
|
gc->DrawRectangle(0, n * 12, trigs[n] * 64, 14);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// text
|
2016-08-02 00:22:48 -06:00
|
|
|
// We don't want the text to be scaled/zoomed
|
|
|
|
gc->SetTransform(null_matrix);
|
|
|
|
gc->DrawText(StrToWxStr(g->control_group->controls[n]->name), 3 * g->m_scale,
|
|
|
|
(n * 12 + 1) * g->m_scale);
|
|
|
|
gc->SetTransform(scale_matrix);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// deadzone box
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxLIGHT_GREY_PEN);
|
|
|
|
gc->SetBrush(*wxTRANSPARENT_BRUSH);
|
|
|
|
gc->DrawRectangle(0, 0, deadzone * 64, trigger_count * 14);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
break;
|
2016-08-02 00:22:48 -06:00
|
|
|
|
2017-02-24 22:35:02 -07:00
|
|
|
case ControllerEmu::GroupType::MixedTriggers:
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
const unsigned int trigger_count = ((unsigned int)(g->control_group->controls.size() / 2));
|
|
|
|
|
|
|
|
// draw the shit
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxGREY_PEN);
|
2016-07-11 11:35:32 -06:00
|
|
|
ControlState thresh = g->control_group->numeric_settings[0]->GetValue();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
for (unsigned int n = 0; n < trigger_count; ++n)
|
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxRED_BRUSH);
|
2016-07-14 09:45:59 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
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();
|
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->DrawRectangle(0, n * 12, 64 + 20, 14);
|
2016-06-24 02:43:46 -06:00
|
|
|
if (trig_d <= thresh)
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxWHITE_BRUSH);
|
|
|
|
gc->DrawRectangle(trig_a * 64, n * 12, 64 + 20, 14);
|
|
|
|
gc->DrawRectangle(64, n * 12, 32, 14);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// text
|
2016-08-02 00:22:48 -06:00
|
|
|
// We don't want the text to be scaled/zoomed
|
|
|
|
gc->SetTransform(null_matrix);
|
|
|
|
gc->DrawText(StrToWxStr(g->control_group->controls[n + trigger_count]->name), 3 * g->m_scale,
|
|
|
|
(n * 12 + 1) * g->m_scale);
|
|
|
|
gc->DrawText(StrToWxStr(std::string(1, g->control_group->controls[n]->name[0])),
|
|
|
|
(64 + 3) * g->m_scale, (n * 12 + 1) * g->m_scale);
|
|
|
|
gc->SetTransform(scale_matrix);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// threshold box
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxLIGHT_GREY_PEN);
|
|
|
|
gc->SetBrush(*wxTRANSPARENT_BRUSH);
|
|
|
|
gc->DrawRectangle(thresh * 64, 0, 128, trigger_count * 14);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
break;
|
2016-08-02 00:22:48 -06:00
|
|
|
|
2017-02-24 22:35:02 -07:00
|
|
|
case ControllerEmu::GroupType::Slider:
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-07-11 11:35:32 -06:00
|
|
|
const ControlState deadzone = g->control_group->numeric_settings[0]->GetValue();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
ControlState state = g->control_group->controls[1]->control_ref->State() -
|
|
|
|
g->control_group->controls[0]->control_ref->State();
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
gc->SetBrush(*wxGREY_BRUSH);
|
|
|
|
gc->DrawRectangle(31 + state * 30, 0, 2, 14);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
ControlState adj_state;
|
|
|
|
((ControllerEmu::Slider*)g->control_group)->GetState(&adj_state);
|
|
|
|
if (state)
|
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetBrush(*wxRED_BRUSH);
|
|
|
|
gc->DrawRectangle(31 + adj_state * 30, 0, 2, 14);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// deadzone box
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetPen(*wxLIGHT_GREY_PEN);
|
|
|
|
gc->SetBrush(*wxTRANSPARENT_BRUSH);
|
|
|
|
gc->DrawRectangle(32 - deadzone * 32, 0, deadzone * 64, 14);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
break;
|
2016-08-02 00:22:48 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-08-02 00:22:48 -06:00
|
|
|
gc->SetTransform(null_matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DrawBorder(wxGraphicsContext* gc, double scale)
|
|
|
|
{
|
|
|
|
double pen_width = std::round(scale); // Pen width = 1px * scale
|
|
|
|
|
|
|
|
// Use the window caption bar color as a safe accent color.
|
|
|
|
wxPen border_pen(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION),
|
|
|
|
static_cast<int>(pen_width));
|
|
|
|
border_pen.SetCap(wxCAP_PROJECTING);
|
|
|
|
|
|
|
|
double width, height;
|
|
|
|
gc->GetSize(&width, &height);
|
|
|
|
|
|
|
|
wxGraphicsPath path = gc->CreatePath();
|
|
|
|
path.AddRectangle(pen_width / 2, pen_width / 2, width - pen_width, height - pen_width);
|
|
|
|
gc->SetPen(border_pen);
|
|
|
|
gc->StrokePath(path);
|
2014-07-11 05:34:34 -06:00
|
|
|
}
|
|
|
|
|
2010-06-12 12:45:39 -06:00
|
|
|
void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
|
2010-04-01 20:48:24 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
wxFont small_font(6, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
|
2016-08-02 00:22:48 -06:00
|
|
|
const wxColour font_color{0xB8B8B8};
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
g_controller_interface.UpdateInput();
|
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
wxMemoryDC dc;
|
2017-02-08 20:15:43 -07:00
|
|
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
2016-11-18 00:03:06 -07:00
|
|
|
for (ControlGroupBox* g : control_groups)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
// Only if this control group has a bitmap
|
|
|
|
if (!g->static_bitmap)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxBitmap bitmap(g->static_bitmap->GetBitmap());
|
|
|
|
// NOTE: Selecting the bitmap inherits the bitmap's ScaleFactor onto the DC as well.
|
2016-10-09 16:31:39 -06:00
|
|
|
dc.SelectObjectAsSource(bitmap);
|
2016-08-02 00:22:48 -06:00
|
|
|
dc.SetBackground(*wxWHITE_BRUSH);
|
|
|
|
dc.Clear();
|
|
|
|
|
|
|
|
#ifdef __WXGTK20__
|
|
|
|
int dc_height = 0;
|
|
|
|
dc.SetFont(small_font);
|
|
|
|
dc.GetTextExtent(g->control_group->name, nullptr, &dc_height);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::unique_ptr<wxGraphicsContext> gc{wxGraphicsContext::Create(dc)};
|
|
|
|
gc->DisableOffset();
|
|
|
|
gc->SetFont(small_font, font_color);
|
|
|
|
|
|
|
|
#ifdef __WXGTK20__
|
|
|
|
double gc_height = 0;
|
|
|
|
gc->GetTextExtent(g->control_group->name, nullptr, &gc_height);
|
|
|
|
// On GTK2, wx creates a new empty Cairo/Pango context for the graphics context instead
|
|
|
|
// of reusing the wxMemoryDC one, this causes it to forget the screen DPI so fonts stop
|
|
|
|
// scaling, we need to scale it manually instead.
|
|
|
|
if (std::ceil(gc_height) < dc_height)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-08-02 00:22:48 -06:00
|
|
|
wxFont fixed_font(small_font);
|
|
|
|
fixed_font.SetPointSize(static_cast<int>(fixed_font.GetPointSize() * g->m_scale));
|
|
|
|
gc->SetFont(fixed_font, font_color);
|
|
|
|
}
|
|
|
|
#endif
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
DrawControlGroupBox(gc.get(), g);
|
|
|
|
DrawBorder(gc.get(), g->m_scale);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
// label for sticks and stuff
|
|
|
|
if (g->HasBitmapHeading())
|
|
|
|
gc->DrawText(StrToWxStr(g->control_group->name).Upper(), 4 * g->m_scale, 2 * g->m_scale);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:48 -06:00
|
|
|
gc.reset();
|
|
|
|
dc.SelectObject(wxNullBitmap);
|
|
|
|
g->static_bitmap->SetBitmap(bitmap);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2010-04-01 20:48:24 -06:00
|
|
|
}
|