From ff4d52059e14f6a645b5ad1be844235d3bcb7dbc Mon Sep 17 00:00:00 2001 From: TMaul Date: Sat, 22 Dec 2012 19:55:44 +0000 Subject: [PATCH] Clean up OSK code Remove some magic numbers and a few other things --- Core/Dialog/PSPOskDialog.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Core/Dialog/PSPOskDialog.cpp b/Core/Dialog/PSPOskDialog.cpp index b7fa333741..c5e8cb6380 100644 --- a/Core/Dialog/PSPOskDialog.cpp +++ b/Core/Dialog/PSPOskDialog.cpp @@ -149,6 +149,7 @@ int selectedChar; #define NUMKEYROWS 4 #define KEYSPERROW 13 +#define NUMBEROFVALIDCHARS 44 const char oskKeys[NUMKEYROWS][KEYSPERROW] = { {'1','2','3','4','5','6','7','8','9','0','-','+','\0'}, @@ -160,9 +161,7 @@ const char oskKeys[NUMKEYROWS][KEYSPERROW] = PSPOskDialog::PSPOskDialog() : PSPDialog() { - selectedChar = 15; - currentInputChar = 0; - memset(inputChars, 0x00, sizeof(inputChars)); + } PSPOskDialog::~PSPOskDialog() { @@ -196,7 +195,12 @@ int PSPOskDialog::Init(u32 oskPtr) memset(&oskParams, 0, sizeof(oskParams)); memset(&oskData, 0, sizeof(oskData)); + // TODO: should this be init'd to oskIntext? + memset(inputChars, 0x00, sizeof(inputChars)); oskParamsAddr = oskPtr; + selectedChar = 0; + currentInputChar = 0; + if (Memory::IsValidAddress(oskPtr)) { Memory::ReadStruct(oskPtr, &oskParams); @@ -212,7 +216,6 @@ int PSPOskDialog::Init(u32 oskPtr) return -1; } - return 0; } @@ -244,7 +247,6 @@ void PSPOskDialog::RenderKeyboard() } } } - for (int row = 0; row < NUMKEYROWS; row++) { if (selectedRow == row) @@ -256,9 +258,6 @@ void PSPOskDialog::RenderKeyboard() PPGeDrawText(oskKeys[row], 20, 70 + (25 * row), NULL , 0.6f, 0xFFFFFFFF); } } - - - for (int selectedItemCounter = 0; selectedItemCounter < KEYSPERROW; selectedItemCounter++ ) { if (selectedItemCounter!=selectedExtra) @@ -299,7 +298,6 @@ void PSPOskDialog::Update() PPGeDrawText("Start", 305, 220, PPGE_ALIGN_LEFT, 0.5f, 0xFFFFFFFF); PPGeDrawText("Finish", 350, 220, PPGE_ALIGN_LEFT, 0.5f, 0xFFFFFFFF); - if (IsButtonPressed(CTRL_UP)) { selectedChar += 10; @@ -319,13 +317,13 @@ void PSPOskDialog::Update() if (selectedChar < 0) { - selectedChar = 44; + selectedChar = NUMBEROFVALIDCHARS; } - - if (selectedChar > 44) + if (selectedChar > NUMBEROFVALIDCHARS) { selectedChar = 0; } + // TODO : Dialogs should take control over input and not send them to the game while displaying if (IsButtonPressed(CTRL_CROSS)) {