From d4ce5ef9735ac86472f3d17bfb9c5aa8146d973a Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Mon, 8 Jul 2024 06:46:06 +0200 Subject: [PATCH] =?UTF-8?q?-=20Els=20camps=20num=C3=A8rics=20de=20l'editor?= =?UTF-8?q?=20ara=20tamb=C3=A9=20es=20poden=20modificar=20escribint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/jui.cpp | 30 ++++++++++++++++++++++++------ source/jui.h | 2 +- source/m_game.cpp | 13 ++++++------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/source/jui.cpp b/source/jui.cpp index ab16282..62b2f21 100644 --- a/source/jui.cpp +++ b/source/jui.cpp @@ -115,7 +115,9 @@ namespace ui return 0; } - const int spin(const char *label, const int x, const int y, const int w, const int h) + char temp[10]; + + const char *spin(const char *label, const int x, const int y, const int w, const int h) { const int mx = draw::getLocalX(input::mouseX()); const int my = draw::getLocalY(input::mouseY()); @@ -134,14 +136,30 @@ namespace ui { draw::color(PAPER); draw::rect(x+1, y+1, w-2, h-2); - if (input::keyDown(SDL_SCANCODE_LCTRL)) - return input::mouseWheel()*32; - else - return input::mouseWheel(); + const uint8_t key = input::getKeyPressed(); + if (key==SDL_SCANCODE_BACKSPACE) { + strcpy(temp, label); const int size = strlen(label); + temp[size-1] = '\0'; + return temp; + } else if (key==SDL_SCANCODE_0) { + strcpy(temp, label); const int size = strlen(label); + temp[size] = '0'; temp[size+1] = '\0'; + return temp; + } else if (key>=SDL_SCANCODE_1 && key<=SDL_SCANCODE_9) { + strcpy(temp, label); const int size = strlen(label); + temp[size] = key+19; temp[size+1] = '\0'; + return temp; + } + const int wheel = input::mouseWheel(); + if (wheel != 0) { + const int value = SDL_atoi(label)+wheel*(input::keyDown(SDL_SCANCODE_LCTRL)?32:1); + SDL_itoa(value, temp, 10); + return temp; + } //if (input::mouseClk(1)) return 1; //if (input::mouseClk(3)) return 3; } - return 0; + return nullptr; } diff --git a/source/jui.h b/source/jui.h index d756bf2..c1cc3ae 100644 --- a/source/jui.h +++ b/source/jui.h @@ -8,6 +8,6 @@ namespace ui const bool button(const char *label, const int x, const int y, const int w, const int h, const bool pressed=false); const int check(const char *label, const int x, const int y, const int w, const int h, const bool checked); const int combo(const char *label, const int x, const int y, const int w, const int h); - const int spin(const char *label, const int x, const int y, const int w, const int h); + const char *spin(const char *label, const int x, const int y, const int w, const int h); const int textbox(const char *label, const int x, const int y, const int w, const int h); } diff --git a/source/m_game.cpp b/source/m_game.cpp index 68decde..535bb6a 100644 --- a/source/m_game.cpp +++ b/source/m_game.cpp @@ -60,11 +60,11 @@ namespace modules const bool btn_small(const int x, const int y, int &var, int min, int max) { char buffer[100]; - int result=0; - result=ui::spin(SDL_itoa(var, buffer, 10), x, y, 17, 11); + const char *result=ui::spin(SDL_itoa(var, buffer, 10), x, y, 17, 11); if (result) { - var=SDL_max(min, SDL_min(max, var+result)); + const int value = SDL_atoi(result); + var=SDL_max(min, SDL_min(max, value)); return true; } return false; @@ -73,12 +73,11 @@ namespace modules const bool btn_small(const int x, const int y, int &var, int min, int max, int width) { char buffer[100]; - int result=0; - result=ui::spin(SDL_itoa(var, buffer, 10), x, y, width, 11); + const char *result=ui::spin(SDL_itoa(var, buffer, 10), x, y, width, 11); if (result) { - var=SDL_max(min, SDL_min(max, var+result)); - return true; + const int value = SDL_atoi(result); + var=SDL_max(min, SDL_min(max, value)); } return false; }