- [NEW] draw::setZoom() i getZoom()
- [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)
This commit is contained in:
@@ -9,9 +9,12 @@ namespace draw
|
|||||||
SDL_Renderer *sdl_renderer {nullptr}; // El renderer de SDL
|
SDL_Renderer *sdl_renderer {nullptr}; // El renderer de SDL
|
||||||
SDL_Texture *sdl_texture {nullptr}; // La textura a la que ho renderitze tot
|
SDL_Texture *sdl_texture {nullptr}; // La textura a la que ho renderitze tot
|
||||||
SDL_Texture *sdl_source {nullptr};
|
SDL_Texture *sdl_source {nullptr};
|
||||||
|
float zoom = 1.0f;
|
||||||
|
|
||||||
void init(const char *titol, const uint16_t width, const uint16_t height)
|
void init(const char *titol, const uint16_t width, const uint16_t height)
|
||||||
{
|
{
|
||||||
|
zoom = file::getConfigValueFloat("zoom", 1.0f);
|
||||||
|
|
||||||
sdl_window = SDL_CreateWindow(titol, width, height, SDL_WINDOW_RESIZABLE);
|
sdl_window = SDL_CreateWindow(titol, width, height, SDL_WINDOW_RESIZABLE);
|
||||||
if (!sdl_window) {
|
if (!sdl_window) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize window!\n");
|
SDL_LogCritical(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize window!\n");
|
||||||
@@ -32,12 +35,14 @@ namespace draw
|
|||||||
printf("Using: %s\n", SDL_GetRendererName(sdl_renderer));
|
printf("Using: %s\n", SDL_GetRendererName(sdl_renderer));
|
||||||
|
|
||||||
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height);
|
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height);
|
||||||
|
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resizeSystemTexture(const uint16_t width, const uint16_t height)
|
void resizeSystemTexture(const uint16_t width, const uint16_t height)
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(sdl_texture);
|
SDL_DestroyTexture(sdl_texture);
|
||||||
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height);
|
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width*zoom, height*zoom);
|
||||||
|
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
|
||||||
}
|
}
|
||||||
|
|
||||||
void quit()
|
void quit()
|
||||||
@@ -49,6 +54,20 @@ namespace draw
|
|||||||
sdl_renderer = nullptr;
|
sdl_renderer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setZoom(const float value)
|
||||||
|
{
|
||||||
|
zoom = value;
|
||||||
|
file::setConfigValueFloat("zoom", zoom);
|
||||||
|
int w, h;
|
||||||
|
SDL_GetWindowSize(sdl_window, &w, &h);
|
||||||
|
resizeSystemTexture(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float getZoom()
|
||||||
|
{
|
||||||
|
return zoom;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Texture *createSurface(const uint16_t w, const uint16_t h)
|
SDL_Texture *createSurface(const uint16_t w, const uint16_t h)
|
||||||
{
|
{
|
||||||
SDL_Texture *surf = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, w, h);
|
SDL_Texture *surf = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, w, h);
|
||||||
@@ -121,10 +140,11 @@ namespace draw
|
|||||||
SDL_SetRenderClipRect(sdl_renderer, nullptr);
|
SDL_SetRenderClipRect(sdl_renderer, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Point getWindowSize()
|
SDL_FPoint getWindowSize()
|
||||||
{
|
{
|
||||||
SDL_Point p;
|
int w, h;
|
||||||
SDL_GetWindowSize(sdl_window, &p.x, &p.y);
|
SDL_GetWindowSize(sdl_window, &w, &h);
|
||||||
|
SDL_FPoint p {w*zoom, h*zoom};
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ namespace draw
|
|||||||
void resizeSystemTexture(const uint16_t width, const uint16_t height);
|
void resizeSystemTexture(const uint16_t width, const uint16_t height);
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
|
void setZoom(const float value);
|
||||||
|
const float getZoom();
|
||||||
|
|
||||||
SDL_Texture *createSurface(const uint16_t w, const uint16_t h);
|
SDL_Texture *createSurface(const uint16_t w, const uint16_t h);
|
||||||
SDL_Texture *loadSurface(const char* filename, const int transparent = -1);
|
SDL_Texture *loadSurface(const char* filename, const int transparent = -1);
|
||||||
void freeSurface(SDL_Texture *surf);
|
void freeSurface(SDL_Texture *surf);
|
||||||
@@ -19,7 +22,7 @@ namespace draw
|
|||||||
void setClip(const int x, const int y, const int w, const int h);
|
void setClip(const int x, const int y, const int w, const int h);
|
||||||
void resetClip();
|
void resetClip();
|
||||||
|
|
||||||
SDL_Point getWindowSize();
|
SDL_FPoint getWindowSize();
|
||||||
|
|
||||||
void setColor(const uint32_t col);
|
void setColor(const uint32_t col);
|
||||||
void cls(const uint32_t color);
|
void cls(const uint32_t color);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
#include "draw.h"
|
||||||
|
|
||||||
namespace input
|
namespace input
|
||||||
{
|
{
|
||||||
@@ -78,7 +79,7 @@ namespace input
|
|||||||
{
|
{
|
||||||
float x;
|
float x;
|
||||||
SDL_GetMouseState(&x, NULL);
|
SDL_GetMouseState(&x, NULL);
|
||||||
return x;
|
return x*draw::getZoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Torna la posició Y actual del ratolí
|
// Torna la posició Y actual del ratolí
|
||||||
@@ -86,7 +87,7 @@ namespace input
|
|||||||
{
|
{
|
||||||
float y;
|
float y;
|
||||||
SDL_GetMouseState(NULL, &y);
|
SDL_GetMouseState(NULL, &y);
|
||||||
return y;
|
return y*draw::getZoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determina si el botó del ratolí especificat està sent polsada ara mateix
|
// Determina si el botó del ratolí especificat està sent polsada ara mateix
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ bool loop()
|
|||||||
if (treeview::getSelected(0) > -1) {
|
if (treeview::getSelected(0) > -1) {
|
||||||
if (treeview::getSelected(2) == -1) {
|
if (treeview::getSelected(2) == -1) {
|
||||||
propertygrid::sectionProperty("ROOM:");
|
propertygrid::sectionProperty("ROOM:");
|
||||||
propertygrid::stringProperty("NAME", room["room"]["name"].get_value<std::string>());
|
if (propertygrid::stringProperty("NAME", room["room"]["name"].get_value<std::string>())) room["room"]["name"] = propertygrid::getStringPropertyResult();
|
||||||
propertygrid::stringProperty("BGCOLOR", room["room"]["bgColor"].get_value<std::string>());
|
propertygrid::stringProperty("BGCOLOR", room["room"]["bgColor"].get_value<std::string>());
|
||||||
propertygrid::stringProperty("BORDER", room["room"]["border"].get_value<std::string>());
|
propertygrid::stringProperty("BORDER", room["room"]["border"].get_value<std::string>());
|
||||||
propertygrid::stringProperty("TILESET", room["room"]["tileSetFile"].get_value<std::string>());
|
propertygrid::stringProperty("TILESET", room["room"]["tileSetFile"].get_value<std::string>());
|
||||||
@@ -170,5 +170,8 @@ bool loop()
|
|||||||
font::print("SELECTION", x, 5); x+= font::len("SELECTION")+12;
|
font::print("SELECTION", x, 5); x+= font::len("SELECTION")+12;
|
||||||
font::print("VIEW", x, 5); x+= font::len("VIEW")+12;*/
|
font::print("VIEW", x, 5); x+= font::len("VIEW")+12;*/
|
||||||
draw::render();
|
draw::render();
|
||||||
|
|
||||||
|
if (input::keyPressed(SDL_SCANCODE_F1)) draw::setZoom(draw::getZoom()-0.1f);
|
||||||
|
if (input::keyPressed(SDL_SCANCODE_F2)) draw::setZoom(draw::getZoom()+0.1f);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,14 @@ namespace propertygrid
|
|||||||
int y = 0;
|
int y = 0;
|
||||||
int element = 0;
|
int element = 0;
|
||||||
int max_elements = 0;
|
int max_elements = 0;
|
||||||
|
int editing_element = -1;
|
||||||
|
std::string editing_text = "";
|
||||||
|
int editing_finished = 0;
|
||||||
|
|
||||||
void start()
|
void start()
|
||||||
{
|
{
|
||||||
y = 48;
|
y = 48;
|
||||||
const SDL_Point win_size = draw::getWindowSize();
|
const SDL_FPoint win_size = draw::getWindowSize();
|
||||||
draw::setClip(win_size.x-propertygrid::width,y,propertygrid::width, win_size.y-y);
|
draw::setClip(win_size.x-propertygrid::width,y,propertygrid::width, win_size.y-y);
|
||||||
draw::setColor(0xff181818);
|
draw::setColor(0xff181818);
|
||||||
draw::fillrect(win_size.x-propertygrid::width,y,propertygrid::width, win_size.y-y);
|
draw::fillrect(win_size.x-propertygrid::width,y,propertygrid::width, win_size.y-y);
|
||||||
@@ -31,26 +34,69 @@ namespace propertygrid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string stringProperty(std::string label, std::string value)
|
void doEditText()
|
||||||
{
|
{
|
||||||
const SDL_Point win_size = draw::getWindowSize();
|
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;
|
const int x = win_size.x-propertygrid::width;
|
||||||
draw::setClip(x,y,propertygrid::width, 24);
|
draw::setClip(x,y,propertygrid::width, 24);
|
||||||
//draw::setColor(0xffffffff);
|
font::print(label.c_str(), x+8, y+9);
|
||||||
//draw::fillrect(x,y,propertygrid::width, 24);
|
|
||||||
|
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::setColor(0xff000000);
|
||||||
draw::line(x,y+23,win_size.x, y+23);
|
draw::line(x,y+23,win_size.x, y+23);
|
||||||
draw::line(x+propertygrid::width/3,y,x+propertygrid::width/3, y+23);
|
draw::line(x+propertygrid::width/3,y,x+propertygrid::width/3, y+23);
|
||||||
font::print(label.c_str(), x+8, y+9);
|
|
||||||
font::print(value.c_str(), x+8+propertygrid::width/3, y+9);
|
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++;
|
line++;
|
||||||
y+=24;
|
y+=24;
|
||||||
return "";
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getStringPropertyResult()
|
||||||
|
{
|
||||||
|
return editing_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sectionProperty(std::string label)
|
void sectionProperty(std::string label)
|
||||||
{
|
{
|
||||||
const SDL_Point win_size = draw::getWindowSize();
|
const SDL_FPoint win_size = draw::getWindowSize();
|
||||||
const int x = win_size.x-propertygrid::width;
|
const int x = win_size.x-propertygrid::width;
|
||||||
draw::setClip(x,y,propertygrid::width, 16);
|
draw::setClip(x,y,propertygrid::width, 16);
|
||||||
draw::setColor(0xff3c3c3c);
|
draw::setColor(0xff3c3c3c);
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
namespace propertygrid
|
namespace propertygrid
|
||||||
{
|
{
|
||||||
void start();
|
void start();
|
||||||
std::string stringProperty(std::string label, std::string value);
|
bool stringProperty(std::string label, std::string value);
|
||||||
|
std::string getStringPropertyResult();
|
||||||
void sectionProperty(std::string label);
|
void sectionProperty(std::string label);
|
||||||
void end();
|
void end();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user