I do not like if(..).

This commit is contained in:
StackZ
2020-06-19 05:13:20 +02:00
parent 2641e4922b
commit c6f0798196
10 changed files with 111 additions and 107 deletions
+31 -32
View File
@@ -78,8 +78,7 @@ Structs::ButtonPos Numbers [] = {
extern bool touching(touchPosition touch, Structs::ButtonPos button);
void Input::DrawNumpad()
{
void Input::DrawNumpad() {
for(uint i=0;i<(sizeof(NumpadStruct)/sizeof(NumpadStruct[0]));i++) {
Gui::Draw_Rect(NumpadStruct[i].x, NumpadStruct[i].y, 60, 50, Config::Color1);
char c[2] = {NumpadStruct[i].character[0]};
@@ -90,7 +89,7 @@ void Input::DrawNumpad()
void Input::drawKeyboard() {
for(uint i=0;i<(sizeof(keysQWERTY)/sizeof(keysQWERTY[0]));i++) {
C2D_DrawRectSolid(keysQWERTY[i].x, keysQWERTY[i].y+103, 0.5f, 20, 20, Config::Color1 & C2D_Color32(255, 255, 255, 200));
if(shift) {
if (shift) {
char c[2] = {caps ? (char)toupper(keysQWERTYShift[i].character[0]) : keysQWERTYShift[i].character[0]};
Gui::DrawString(keysQWERTYShift[i].x+(10-(Gui::GetStringWidth(0.50, c)/2)), keysQWERTYShift[i].y+103+(10-(Gui::GetStringHeight(0.50, c)/2)), 0.50, Config::TxtColor, c);
} else {
@@ -98,6 +97,7 @@ void Input::drawKeyboard() {
Gui::DrawString(keysQWERTY[i].x+(10-(Gui::GetStringWidth(0.50, c)/2)), keysQWERTY[i].y+103+(10-(Gui::GetStringHeight(0.50, c)/2)), 0.50, Config::TxtColor, c);
}
}
for(uint i=0;i<(sizeof(modifierKeys)/sizeof(modifierKeys[0]));i++) {
std::string enter = modifierKeys[2].character;
std::string arrowUp = modifierKeys[3].character;
@@ -116,8 +116,7 @@ void Input::drawKeyboard() {
std::string Input::Numpad(std::string Text) { return Input::Numpad(-1, Text); }
std::string Input::Numpad(uint maxLength, std::string Text)
{
std::string Input::Numpad(uint maxLength, std::string Text) {
int hDown;
touchPosition touch;
std::string string;
@@ -133,25 +132,25 @@ std::string Input::Numpad(uint maxLength, std::string Text)
GFX::DrawTop();
Gui::DrawString((400-Gui::GetStringWidth(0.55f, Text))/2, 2, 0.55f, Config::TxtColor, Text, 400);
Gui::DrawString(180, 217, 0.8, Config::TxtColor, (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 400);
if(cursorBlink < -20) cursorBlink = 20;
if (cursorBlink < -20) cursorBlink = 20;
Gui::ScreenDraw(Bottom);
Gui::Draw_Rect(0, 0, 320, 240, Config::Color3);
DrawNumpad();
scanKeys();
hDown = keysDown();
if(keyDownDelay > 0) {
if (keyDownDelay > 0) {
keyDownDelay--;
} else if(keyDownDelay == 0) {
keyDownDelay--;
}
} while(!hDown);
if(keyDownDelay > 0) {
if (keyDownDelay > 0) {
}
keyDownDelay = 10;
if(hDown & KEY_TOUCH) {
if (hDown & KEY_TOUCH) {
touchRead(&touch);
if(string.length() < maxLength) {
if (string.length() < maxLength) {
if (touching(touch, Numbers[0])) {
string += "1";
} else if (touching(touch, Numbers[1])) {
@@ -176,11 +175,11 @@ std::string Input::Numpad(uint maxLength, std::string Text)
}
}
if(hDown & KEY_B || touching(touch, Numbers[11])) {
if (hDown & KEY_B || touching(touch, Numbers[11])) {
string = string.substr(0, string.length()-1);
}
if(hDown & KEY_START || touching(touch, Numbers[10]) || enter) {
if (hDown & KEY_START || touching(touch, Numbers[10]) || enter) {
break;
}
}
@@ -191,9 +190,9 @@ std::string Input::Numpad(uint maxLength, std::string Text)
int Input::getUint(int max, std::string Text) {
std::string s = Input::Numpad(3, Text);
if(s == "" || (atoi(s.c_str()) == 0 && s[0] != '0')) return -1;
if (s == "" || (atoi(s.c_str()) == 0 && s[0] != '0')) return -1;
int i = atoi(s.c_str());
if(i>max) return 255;
if (i > max) return 255;
return i;
}
@@ -217,25 +216,25 @@ std::string Input::getString(uint maxLength, std::string Text, float inputTextSi
drawKeyboard();
C2D_DrawRectSolid(0, 81, 0.5f, 320, 20, Config::Color1 & C2D_Color32(200, 200, 200, 200));
Gui::DrawString(2, 82, inputTextSize, Config::TxtColor, (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 316);
if(cursorBlink < -20) cursorBlink = 20;
if (cursorBlink < -20) cursorBlink = 20;
scanKeys();
hDown = keysDown();
if(keyDownDelay > 0) {
if (keyDownDelay > 0) {
keyDownDelay--;
} else if(keyDownDelay == 0) {
} else if (keyDownDelay == 0) {
keyDownDelay--;
}
} while(!hDown);
if(keyDownDelay > 0) {
if (keyDownDelay > 0) {
}
keyDownDelay = 10;
if(hDown & KEY_TOUCH) {
if (hDown & KEY_TOUCH) {
touchRead(&touch);
if(string.length() < maxLength) {
if (string.length() < maxLength) {
// Check if a regular key was pressed
for(uint i=0;i<(sizeof(keysQWERTY)/sizeof(keysQWERTY[0]));i++) {
if((touch.px > keysQWERTY[i].x-2 && touch.px < keysQWERTY[i].x+18) && (touch.py > keysQWERTY[i].y+(103)-2 && touch.py < keysQWERTY[i].y+18+(103))) {
if ((touch.px > keysQWERTY[i].x-2 && touch.px < keysQWERTY[i].x+18) && (touch.py > keysQWERTY[i].y+(103)-2 && touch.py < keysQWERTY[i].y+18+(103))) {
char c = (shift ? keysQWERTYShift[i] : keysQWERTY[i]).character[0];
string += (shift || caps ? toupper(c) : c);
shift = 0;
@@ -245,23 +244,23 @@ std::string Input::getString(uint maxLength, std::string Text, float inputTextSi
}
// Check if a modifier key was pressed
for(uint i=0;i<(sizeof(modifierKeys)/sizeof(modifierKeys[0]));i++) {
if((touch.px > modifierKeys[i].x-2 && touch.px < modifierKeys[i].x+modifierKeys[i].w+2) && (touch.py > modifierKeys[i].y+(103)-2 && touch.py < modifierKeys[i].y+18+(103))) {
if(modifierKeys[i].character == "\uE071") {
if ((touch.px > modifierKeys[i].x-2 && touch.px < modifierKeys[i].x+modifierKeys[i].w+2) && (touch.py > modifierKeys[i].y+(103)-2 && touch.py < modifierKeys[i].y+18+(103))) {
if (modifierKeys[i].character == "\uE071") {
string = string.substr(0, string.length()-1);
} else if(modifierKeys[i].character == "\uE01D") {
} else if (modifierKeys[i].character == "\uE01D") {
caps = !caps;
} else if(modifierKeys[i].character == "\uE056") {
} else if (modifierKeys[i].character == "\uE056") {
enter = true;
} else if(modifierKeys[i].character == "\uE01B") {
if(shift) shift = 0;
} else if (modifierKeys[i].character == "\uE01B") {
if (shift) shift = 0;
else shift = 1;
if(shift) {
if (shift) {
keyDownDelay = -1;
} else {
keyDownDelay = 0;
}
} else if(modifierKeys[i].character == " ") {
if(string.length() < maxLength) {
} else if (modifierKeys[i].character == " ") {
if (string.length() < maxLength) {
shift = 0;
string += modifierKeys[5].character[0];
}
@@ -269,11 +268,11 @@ std::string Input::getString(uint maxLength, std::string Text, float inputTextSi
break;
}
}
} else if(hDown & KEY_B) {
} else if (hDown & KEY_B) {
string = string.substr(0, string.length()-1);
}
if(hDown & KEY_START || enter) {
if (hDown & KEY_START || enter) {
break;
}
}