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