Skip to content

Commit

Permalink
Customizable touch control (rebased with label)
Browse files Browse the repository at this point in the history
  • Loading branch information
iota97 committed Jul 9, 2021
1 parent 1f16edd commit 06339d8
Show file tree
Hide file tree
Showing 25 changed files with 864 additions and 417 deletions.
25 changes: 25 additions & 0 deletions Common/Data/Format/IniFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ void Section::Set(const char* key, uint32_t newValue) {
Set(key, StringFromFormat("0x%08x", newValue).c_str());
}

void Section::Set(const char* key, uint64_t newValue) {
Set(key, StringFromFormat("0x%016lx", newValue).c_str());
}

void Section::Set(const char* key, float newValue) {
Set(key, StringFromFormat("%f", newValue).c_str());
}
Expand Down Expand Up @@ -311,6 +315,16 @@ bool Section::Get(const char* key, uint32_t* value, uint32_t defaultValue)
return false;
}

bool Section::Get(const char* key, uint64_t* value, uint64_t defaultValue)
{
std::string temp;
bool retval = Get(key, &temp, 0);
if (retval && TryParse(temp, value))
return true;
*value = defaultValue;
return false;
}

bool Section::Get(const char* key, bool* value, bool defaultValue)
{
std::string temp;
Expand Down Expand Up @@ -659,6 +673,17 @@ bool IniFile::Get(const char* sectionName, const char* key, uint32_t* value, uin
}
}

bool IniFile::Get(const char* sectionName, const char* key, uint64_t* value, uint64_t defaultValue)
{
Section *section = GetSection(sectionName);
if (!section) {
*value = defaultValue;
return false;
} else {
return section->Get(key, value, defaultValue);
}
}

bool IniFile::Get(const char* sectionName, const char* key, bool* value, bool defaultValue)
{
Section *section = GetSection(sectionName);
Expand Down
6 changes: 6 additions & 0 deletions Common/Data/Format/IniFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Section {
bool Get(const char* key, std::string* value, const char* defaultValue);

void Set(const char* key, uint32_t newValue);
void Set(const char* key, uint64_t newValue);
void Set(const char* key, float newValue);
void Set(const char* key, const float newValue, const float defaultValue);
void Set(const char* key, double newValue);
Expand All @@ -58,6 +59,7 @@ class Section {

bool Get(const char* key, int* value, int defaultValue = 0);
bool Get(const char* key, uint32_t* value, uint32_t defaultValue = 0);
bool Get(const char* key, uint64_t* value, uint64_t defaultValue = 0);
bool Get(const char* key, bool* value, bool defaultValue = false);
bool Get(const char* key, float* value, float defaultValue = false);
bool Get(const char* key, double* value, double defaultValue = false);
Expand Down Expand Up @@ -103,6 +105,9 @@ class IniFile {
void Set(const char* sectionName, const char* key, uint32_t newValue) {
GetOrCreateSection(sectionName)->Set(key, newValue);
}
void Set(const char* sectionName, const char* key, uint64_t newValue) {
GetOrCreateSection(sectionName)->Set(key, newValue);
}
void Set(const char* sectionName, const char* key, bool newValue) {
GetOrCreateSection(sectionName)->Set(key, newValue);
}
Expand All @@ -114,6 +119,7 @@ class IniFile {
bool Get(const char* sectionName, const char* key, std::string* value, const char* defaultValue = "");
bool Get(const char* sectionName, const char* key, int* value, int defaultValue = 0);
bool Get(const char* sectionName, const char* key, uint32_t* value, uint32_t defaultValue = 0);
bool Get(const char* sectionName, const char* key, uint64_t* value, uint64_t defaultValue = 0);
bool Get(const char* sectionName, const char* key, bool* value, bool defaultValue = false);
bool Get(const char* sectionName, const char* key, std::vector<std::string>& values);

Expand Down
20 changes: 20 additions & 0 deletions Common/Data/Text/Parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ bool TryParse(const std::string &str, uint32_t *const output) {
return true;
}

bool TryParse(const std::string &str, uint64_t *const output) {
char *endptr = NULL;

// Holy crap this is ugly.

// Reset errno to a value other than ERANGE
errno = 0;

uint64_t value = strtoul(str.c_str(), &endptr, 0);

if (!endptr || *endptr)
return false;

if (errno == ERANGE)
return false;

*output = value;
return true;
}

bool TryParse(const std::string &str, bool *const output) {
if ("1" == str || !strcasecmp("true", str.c_str()))
*output = true;
Expand Down
1 change: 1 addition & 0 deletions Common/Data/Text/Parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ bool ParseMacAddress(std::string str, uint8_t macAddr[6]);

bool TryParse(const std::string &str, bool *const output);
bool TryParse(const std::string &str, uint32_t *const output);
bool TryParse(const std::string &str, uint64_t *const output);

template <typename N>
static bool TryParse(const std::string &str, N *const output) {
Expand Down
93 changes: 71 additions & 22 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,46 +68,56 @@ struct ConfigSetting {
TYPE_BOOL,
TYPE_INT,
TYPE_UINT32,
TYPE_UINT64,
TYPE_FLOAT,
TYPE_STRING,
TYPE_TOUCH_POS,
TYPE_PATH,
TYPE_CUSTOM_BUTTON
};
union DefaultValue {
bool b;
int i;
uint32_t u;
uint64_t lu;
float f;
const char *s;
const char *p; // not sure how much point..
ConfigTouchPos touchPos;
ConfigCustomButton customButton;
};
union SettingPtr {
bool *b;
int *i;
uint32_t *u;
uint64_t *lu;
float *f;
std::string *s;
Path *p;
ConfigTouchPos *touchPos;
ConfigCustomButton *customButton;
};

typedef bool (*BoolDefaultCallback)();
typedef int (*IntDefaultCallback)();
typedef uint32_t (*Uint32DefaultCallback)();
typedef uint64_t (*Uint64DefaultCallback)();
typedef float (*FloatDefaultCallback)();
typedef const char *(*StringDefaultCallback)();
typedef ConfigTouchPos(*TouchPosDefaultCallback)();
typedef const char *(*PathDefaultCallback)();
typedef ConfigCustomButton (*CustomButtonDefaultCallback)();

union Callback {
BoolDefaultCallback b;
IntDefaultCallback i;
Uint32DefaultCallback u;
Uint64DefaultCallback lu;
FloatDefaultCallback f;
StringDefaultCallback s;
PathDefaultCallback p;
TouchPosDefaultCallback touchPos;
CustomButtonDefaultCallback customButton;
};

ConfigSetting(bool v)
Expand Down Expand Up @@ -144,6 +154,13 @@ struct ConfigSetting {
default_.u = def;
}

ConfigSetting(const char *ini, uint64_t *v, uint64_t def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_UINT64), report_(false), save_(save), perGame_(perGame) {
ptr_.lu = v;
cb_.lu = nullptr;
default_.lu = def;
}

ConfigSetting(const char *ini, float *v, float def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_FLOAT), report_(false), save_(save), perGame_(perGame) {
ptr_.f = v;
Expand Down Expand Up @@ -172,6 +189,13 @@ struct ConfigSetting {
default_.touchPos = def;
}

ConfigSetting(const char *iniKey, const char *iniImage, const char *iniShape, const char *iniToggle, ConfigCustomButton *v, ConfigCustomButton def, bool save = true, bool perGame = false)
: iniKey_(iniKey), ini2_(iniImage), ini3_(iniShape), ini4_(iniToggle), type_(TYPE_CUSTOM_BUTTON), report_(false), save_(save), perGame_(perGame) {
ptr_.customButton = v;
cb_.customButton = nullptr;
default_.customButton = def;
}

ConfigSetting(const char *ini, bool *v, BoolDefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_BOOL), report_(false), save_(save), perGame_(perGame) {
ptr_.b = v;
Expand Down Expand Up @@ -242,6 +266,11 @@ struct ConfigSetting {
default_.u = cb_.u();
}
return section->Get(iniKey_, ptr_.u, default_.u);
case TYPE_UINT64:
if (cb_.lu) {
default_.lu = cb_.lu();
}
return section->Get(iniKey_, ptr_.lu, default_.lu);
case TYPE_FLOAT:
if (cb_.f) {
default_.f = cb_.f();
Expand Down Expand Up @@ -277,6 +306,15 @@ struct ConfigSetting {
}
return result;
}
case TYPE_CUSTOM_BUTTON:
if (cb_.customButton) {
default_.customButton = cb_.customButton();
}
section->Get(iniKey_, &ptr_.customButton->key, default_.customButton.key);
section->Get(ini2_, &ptr_.customButton->image, default_.customButton.image);
section->Get(ini3_, &ptr_.customButton->shape, default_.customButton.shape);
section->Get(ini4_, &ptr_.customButton->toggle, default_.customButton.toggle);
return true;
default:
_dbg_assert_msg_(false, "Unexpected ini setting type");
return false;
Expand All @@ -298,6 +336,8 @@ struct ConfigSetting {
return section->Set(iniKey_, *ptr_.i);
case TYPE_UINT32:
return section->Set(iniKey_, *ptr_.u);
case TYPE_UINT64:
return section->Set(iniKey_, *ptr_.lu);
case TYPE_FLOAT:
return section->Set(iniKey_, *ptr_.f);
case TYPE_STRING:
Expand All @@ -312,6 +352,12 @@ struct ConfigSetting {
section->Set(ini4_, ptr_.touchPos->show);
}
return;
case TYPE_CUSTOM_BUTTON:
section->Set(iniKey_, ptr_.customButton->key);
section->Set(ini2_, ptr_.customButton->image);
section->Set(ini3_, ptr_.customButton->shape);
section->Set(ini4_, ptr_.customButton->toggle);
return;
default:
_dbg_assert_msg_(false, "Unexpected ini setting type");
return;
Expand All @@ -329,6 +375,8 @@ struct ConfigSetting {
return data.Add(prefix + iniKey_, *ptr_.i);
case TYPE_UINT32:
return data.Add(prefix + iniKey_, *ptr_.u);
case TYPE_UINT64:
return data.Add(prefix + iniKey_, *ptr_.lu);
case TYPE_FLOAT:
return data.Add(prefix + iniKey_, *ptr_.f);
case TYPE_STRING:
Expand All @@ -338,6 +386,9 @@ struct ConfigSetting {
case TYPE_TOUCH_POS:
// Doesn't report.
return;
case TYPE_CUSTOM_BUTTON:
// Doesn't report.
return;
default:
_dbg_assert_msg_(false, "Unexpected ini setting type");
return;
Expand Down Expand Up @@ -490,7 +541,6 @@ static ConfigSetting generalSettings[] = {
ConfigSetting("GridView1", &g_Config.bGridView1, true),
ConfigSetting("GridView2", &g_Config.bGridView2, true),
ConfigSetting("GridView3", &g_Config.bGridView3, false),
ConfigSetting("ComboMode", &g_Config.iComboMode, 0),
ConfigSetting("RightAnalogUp", &g_Config.iRightAnalogUp, 0, true, true),
ConfigSetting("RightAnalogDown", &g_Config.iRightAnalogDown, 0, true, true),
ConfigSetting("RightAnalogLeft", &g_Config.iRightAnalogLeft, 0, true, true),
Expand Down Expand Up @@ -887,17 +937,16 @@ static ConfigSetting controlSettings[] = {
ConfigSetting("ShowTouchSquare", &g_Config.bShowTouchSquare, true, true, true),
ConfigSetting("ShowTouchTriangle", &g_Config.bShowTouchTriangle, true, true, true),

ConfigSetting("ComboKey0Mapping", &g_Config.iCombokey0, 0, true, true),
ConfigSetting("ComboKey1Mapping", &g_Config.iCombokey1, 0, true, true),
ConfigSetting("ComboKey2Mapping", &g_Config.iCombokey2, 0, true, true),
ConfigSetting("ComboKey3Mapping", &g_Config.iCombokey3, 0, true, true),
ConfigSetting("ComboKey4Mapping", &g_Config.iCombokey4, 0, true, true),

ConfigSetting("ComboKey0Toggle", &g_Config.bComboToggle0, false, true, true),
ConfigSetting("ComboKey1Toggle", &g_Config.bComboToggle1, false, true, true),
ConfigSetting("ComboKey2Toggle", &g_Config.bComboToggle2, false, true, true),
ConfigSetting("ComboKey3Toggle", &g_Config.bComboToggle3, false, true, true),
ConfigSetting("ComboKey4Toggle", &g_Config.bComboToggle4, false, true, true),
ConfigSetting("Custom0Mapping", "Custom0Image", "Custom0Shape", "Custom0Toggle", &g_Config.CustomKey0, {0, 0, 0, false}, true, true),
ConfigSetting("Custom1Mapping", "Custom1Image", "Custom1Shape", "Custom1Toggle", &g_Config.CustomKey1, {0, 1, 0, false}, true, true),
ConfigSetting("Custom2Mapping", "Custom2Image", "Custom2Shape", "Custom2Toggle", &g_Config.CustomKey2, {0, 2, 0, false}, true, true),
ConfigSetting("Custom3Mapping", "Custom3Image", "Custom3Shape", "Custom3Toggle", &g_Config.CustomKey3, {0, 3, 0, false}, true, true),
ConfigSetting("Custom4Mapping", "Custom4Image", "Custom4Shape", "Custom4Toggle", &g_Config.CustomKey4, {0, 4, 0, false}, true, true),
ConfigSetting("Custom5Mapping", "Custom5Image", "Custom5Shape", "Custom5Toggle", &g_Config.CustomKey5, {0, 0, 1, false}, true, true),
ConfigSetting("Custom6Mapping", "Custom6Image", "Custom6Shape", "Custom6Toggle", &g_Config.CustomKey6, {0, 1, 1, false}, true, true),
ConfigSetting("Custom7Mapping", "Custom7Image", "Custom7Shape", "Custom7Toggle", &g_Config.CustomKey7, {0, 2, 1, false}, true, true),
ConfigSetting("Custom8Mapping", "Custom8Image", "Custom8Shape", "Custom8Toggle", &g_Config.CustomKey8, {0, 3, 1, false}, true, true),
ConfigSetting("Custom9Mapping", "Custom9Image", "Custom9Shape", "Custom9Toggle", &g_Config.CustomKey9, {0, 4, 1, false}, true, true),

#if defined(_WIN32)
// A win32 user seeing touch controls is likely using PPSSPP on a tablet. There it makes
Expand Down Expand Up @@ -956,11 +1005,11 @@ static ConfigSetting controlSettings[] = {
ConfigSetting("fcombo2X", "fcombo2Y", "comboKeyScale2", "ShowComboKey2", &g_Config.touchCombo2, defaultTouchPosHide, true, true),
ConfigSetting("fcombo3X", "fcombo3Y", "comboKeyScale3", "ShowComboKey3", &g_Config.touchCombo3, defaultTouchPosHide, true, true),
ConfigSetting("fcombo4X", "fcombo4Y", "comboKeyScale4", "ShowComboKey4", &g_Config.touchCombo4, defaultTouchPosHide, true, true),
ConfigSetting("Speed1KeyX", "Speed1KeyY", "Speed1KeyScale", "ShowSpeed1Key", &g_Config.touchSpeed1Key, defaultTouchPosHide, true, true),
ConfigSetting("Speed2KeyX", "Speed2KeyY", "Speed2KeyScale", "ShowSpeed2Key", &g_Config.touchSpeed2Key, defaultTouchPosHide, true, true),
ConfigSetting("RapidFireKeyX", "RapidFireKeyY", "RapidFireKeyScale", "ShowRapidFireKey", &g_Config.touchRapidFireKey, defaultTouchPosHide, true, true),
ConfigSetting("AnalogRotationCWKeyX", "AnalogRotationKeyCWY", "AnalogRotationKeyCWScale", "ShowAnalogRotationCWKey", &g_Config.touchAnalogRotationCWKey, defaultTouchPosHide, true, true),
ConfigSetting("AnalogRotationCCWKeyX", "AnalogRotationKeyCCWY", "AnalogRotationKeyCCWScale", "ShowAnalogRotationCCWKey", &g_Config.touchAnalogRotationCCWKey, defaultTouchPosHide, true, true),
ConfigSetting("fcombo5X", "fcombo5Y", "comboKeyScale5", "ShowComboKey5", &g_Config.touchCombo5, defaultTouchPosHide, true, true),
ConfigSetting("fcombo6X", "fcombo6Y", "comboKeyScale6", "ShowComboKey6", &g_Config.touchCombo6, defaultTouchPosHide, true, true),
ConfigSetting("fcombo7X", "fcombo7Y", "comboKeyScale7", "ShowComboKey7", &g_Config.touchCombo7, defaultTouchPosHide, true, true),
ConfigSetting("fcombo8X", "fcombo8Y", "comboKeyScale8", "ShowComboKey8", &g_Config.touchCombo8, defaultTouchPosHide, true, true),
ConfigSetting("fcombo9X", "fcombo9Y", "comboKeyScale9", "ShowComboKey9", &g_Config.touchCombo9, defaultTouchPosHide, true, true),

ConfigSetting("AnalogDeadzone", &g_Config.fAnalogDeadzone, 0.15f, true, true),
ConfigSetting("AnalogInverseDeadzone", &g_Config.fAnalogInverseDeadzone, 0.0f, true, true),
Expand Down Expand Up @@ -1788,11 +1837,11 @@ void Config::ResetControlLayout() {
reset(g_Config.touchCombo2);
reset(g_Config.touchCombo3);
reset(g_Config.touchCombo4);
reset(g_Config.touchSpeed1Key);
reset(g_Config.touchSpeed2Key);
reset(g_Config.touchRapidFireKey);
reset(g_Config.touchAnalogRotationCWKey);
reset(g_Config.touchAnalogRotationCCWKey);
reset(g_Config.touchCombo5);
reset(g_Config.touchCombo6);
reset(g_Config.touchCombo7);
reset(g_Config.touchCombo8);
reset(g_Config.touchCombo9);
}

void Config::GetReportingInfo(UrlEncoder &data) {
Expand Down
Loading

0 comments on commit 06339d8

Please sign in to comment.