- [NEW] Ara amb F1 i F2 se pot fer zoom del contingut de la finestra - [NEW] Ja es pot editar els camps de text (pero encara no es guarda a arxiu)
120 lines
3.9 KiB
C++
120 lines
3.9 KiB
C++
#include "propertygrid.h"
|
|
#include "japi/draw.h"
|
|
#include "japi/font.h"
|
|
#include "japi/input.h"
|
|
|
|
namespace propertygrid
|
|
{
|
|
int width = 200;
|
|
int scroll = 0;
|
|
int line = 0;
|
|
int y = 0;
|
|
int element = 0;
|
|
int max_elements = 0;
|
|
int editing_element = -1;
|
|
std::string editing_text = "";
|
|
int editing_finished = 0;
|
|
|
|
void start()
|
|
{
|
|
y = 48;
|
|
const SDL_FPoint win_size = draw::getWindowSize();
|
|
draw::setClip(win_size.x-propertygrid::width,y,propertygrid::width, win_size.y-y);
|
|
draw::setColor(0xff181818);
|
|
draw::fillrect(win_size.x-propertygrid::width,y,propertygrid::width, win_size.y-y);
|
|
//current[0] = current[1] = current[2] =
|
|
line = element = 0;
|
|
|
|
max_elements = (win_size.y-y) / 24;
|
|
int mx = input::mouseX();
|
|
int my = input::mouseY();
|
|
if (mx>=win_size.x-propertygrid::width && my>=y && mx<win_size.x && my<draw::getWindowSize().y) {
|
|
scroll -= input::mouseWheel();
|
|
if (scroll < 0) scroll = 0;
|
|
}
|
|
}
|
|
|
|
void doEditText()
|
|
{
|
|
uint8_t key = input::getKeyPressed();
|
|
if (key == SDL_SCANCODE_UNKNOWN) return;
|
|
printf("key: %i\n", key);
|
|
if (key==SDL_SCANCODE_BACKSPACE && !editing_text.empty()) editing_text.pop_back();
|
|
else if (key>=SDL_SCANCODE_1 && key<=SDL_SCANCODE_9) editing_text.push_back(char(key+19));
|
|
else if (key==SDL_SCANCODE_0 || key==SDL_SCANCODE_KP_0) editing_text.push_back('0');
|
|
else if (key>=SDL_SCANCODE_KP_1 && key<=SDL_SCANCODE_KP_9) editing_text.push_back(char(key-40));
|
|
else if (key>=SDL_SCANCODE_A && key<=SDL_SCANCODE_Z) editing_text.push_back(char(key+61));
|
|
else if (key==SDL_SCANCODE_RETURN || key==SDL_SCANCODE_KP_ENTER) editing_finished = 1;
|
|
else if (key==SDL_SCANCODE_ESCAPE) editing_finished = 2;
|
|
}
|
|
|
|
bool stringProperty(std::string label, std::string value)
|
|
{
|
|
bool result = false;
|
|
const SDL_FPoint win_size = draw::getWindowSize();
|
|
const int x = win_size.x-propertygrid::width;
|
|
draw::setClip(x,y,propertygrid::width, 24);
|
|
font::print(label.c_str(), x+8, y+9);
|
|
|
|
if (editing_element==line) {
|
|
draw::setColor(0xff2a2d2e);
|
|
draw::fillrect(x+propertygrid::width/3,y,2*(propertygrid::width/3), 24);
|
|
font::print(editing_text.c_str(), x+8+propertygrid::width/3, y+9);
|
|
doEditText();
|
|
if (editing_finished!=0) {
|
|
if (editing_finished==1) {
|
|
result = true;
|
|
}
|
|
editing_element = -1;
|
|
}
|
|
} else {
|
|
font::print(value.c_str(), x+8+propertygrid::width/3, y+9);
|
|
}
|
|
draw::setColor(0xff000000);
|
|
draw::line(x,y+23,win_size.x, y+23);
|
|
draw::line(x+propertygrid::width/3,y,x+propertygrid::width/3, y+23);
|
|
|
|
int mx = input::mouseX();
|
|
int my = input::mouseY();
|
|
if (editing_element!=line && mx>=x && my>=y && mx<x+propertygrid::width && my<y+24) {
|
|
if (input::mouseClk(input::mouse::button::left)) {
|
|
editing_element = line;
|
|
editing_text = value;
|
|
editing_finished = 0;
|
|
}
|
|
}
|
|
|
|
line++;
|
|
y+=24;
|
|
return result;
|
|
}
|
|
|
|
std::string getStringPropertyResult()
|
|
{
|
|
return editing_text;
|
|
}
|
|
|
|
void sectionProperty(std::string label)
|
|
{
|
|
const SDL_FPoint win_size = draw::getWindowSize();
|
|
const int x = win_size.x-propertygrid::width;
|
|
draw::setClip(x,y,propertygrid::width, 16);
|
|
draw::setColor(0xff3c3c3c);
|
|
draw::fillrect(x,y,propertygrid::width, 16);
|
|
draw::setColor(0xff000000);
|
|
draw::line(x,y+15,win_size.x, y+15);
|
|
font::print(label.c_str(), x+8, y+5, 0xffeeeeee);
|
|
line++;
|
|
y+=16;
|
|
}
|
|
|
|
void end()
|
|
{
|
|
draw::resetClip();
|
|
if (element>max_elements && line<max_elements) {
|
|
scroll -= max_elements-line;
|
|
}
|
|
}
|
|
|
|
}
|