- Els camps numèrics de l'editor ara també es poden modificar escribint

This commit is contained in:
2024-07-08 06:46:06 +02:00
parent 84618348e2
commit d4ce5ef973
3 changed files with 31 additions and 14 deletions

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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;
}