diff --git a/data/font.gif b/data/font.gif new file mode 100644 index 0000000..3ec6ff7 Binary files /dev/null and b/data/font.gif differ diff --git a/source/jdraw.cpp b/source/jdraw.cpp index 71390d0..9c8b667 100644 --- a/source/jdraw.cpp +++ b/source/jdraw.cpp @@ -16,13 +16,16 @@ namespace draw surface *screen = nullptr; // La superficie screen, que representa la pantalla. Se crea i destrueix internament surface *destination = nullptr; // Punter a la actual superficie de destí - surface *source = nullptr; // Punter a la actual superficie de oritge + surface *source = nullptr; // Punter a la actual superficie d'oritge + surface *pushedSource = nullptr; // Punter a la superficie d'oritge que s'ha pushat uint32_t palette[256]; // La paleta de colors uint8_t color_indices[256]; // Indices dels colors per defecte uint8_t sel_color = 0; // Color seleccionat per defecte uint8_t transparent = 0; // El color transparent + surface *textsurf = nullptr; // Surface on guardar el gif amb la font + // Inicialització de tot el que fa falta per a carregar gràfics i pintar en pantalla void init(const std::string &titol, const uint16_t width, const uint16_t height, const int zoom) { @@ -41,11 +44,15 @@ namespace draw destination = screen; sel_color = transparent = 0; for (int i=0;i<256;++i) color_indices[i] = i; + + textsurf = loadSurface("font.gif"); } // Finalització del sistema void quit() { + if (textsurf) freeSurface(textsurf); + // Si la superficie "screen" existia, alliberem la seua memòria if (screen != nullptr) { @@ -143,6 +150,16 @@ namespace draw source = surf == nullptr ? screen : surf; } + void pushSource() + { + pushedSource = source; + } + + void popSource() + { + source = pushedSource; + } + // Estableix la paleta del sistema carregant-la d'un GIF void loadPalette(const std::string &filename) { @@ -255,6 +272,11 @@ namespace draw color_indices[c1] = c2; } + void restorecol(const Uint8 c) + { + color_indices[c] = c; + } + void color(const Uint8 col) { sel_color = col; @@ -283,6 +305,33 @@ namespace draw vline(x+w-1,y,h); } + void print(const char* text, const int x, const int y, const Uint8 color, const Uint8 borde) + { + surface* tmp = source; + source = textsurf; + swapcol(1, color); + const int len = strlen(text); + for (int i=0;i>4)*6); + draw(x+i*4, y-1, 4, 6, (chr&15)*4, (chr>>4)*6); + draw(1+x+i*4, y-1, 4, 6, (chr&15)*4, (chr>>4)*6); + draw(-1+x+i*4, y, 4, 6, (chr&15)*4, (chr>>4)*6); + draw(1+x+i*4, y, 4, 6, (chr&15)*4, (chr>>4)*6); + draw(-1+x+i*4, y+1, 4, 6, (chr&15)*4, (chr>>4)*6); + draw(x+i*4, y+1, 4, 6, (chr&15)*4, (chr>>4)*6); + draw(1+x+i*4, y+1, 4, 6, (chr&15)*4, (chr>>4)*6); + swapcol(1, color); + } + draw(x+i*4, y, 4, 6, (chr&15)*4, (chr>>4)*6); + } + source = tmp; + } + // Refresca la pantalla void render() { @@ -310,4 +359,5 @@ namespace draw // I ho presentem SDL_RenderPresent(sdl_renderer); } + } diff --git a/source/jdraw.h b/source/jdraw.h index e1ce441..aa625dc 100644 --- a/source/jdraw.h +++ b/source/jdraw.h @@ -51,6 +51,9 @@ namespace draw /// @param surf punter a la superficie a establir com a oritge void setSource(surface *surf); + void pushSource(); + void popSource(); + /// @brief Estableix la paleta del sistema carregant-la d'un GIF /// @param filename nom de l'arxiu GIF d'on carregar la paleta void loadPalette(const std::string &filename); @@ -73,13 +76,16 @@ namespace draw /// @param flip si s'ha de fer flip en hortizontal o vertical (o ambdos) void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const int flip = DRAW_FLIP_NONE); - void swapcol(const Uint8 c1, const Uint8 c2); - void color(const Uint8 col); + void swapcol(const uint8_t c1, const uint8_t c2); + void restorecol(const uint8_t c); + void color(const uint8_t col); void hline(const int x, const int y, const int w); void vline(const int x, const int y, const int h); void fillrect(const int x, const int y, const int w, const int h); void rect(const int x, const int y, const int w, const int h); + void print(const char* text, const int x, const int y, const uint8_t color, const uint8_t borde); + /// @brief Refresca la pantalla void render(); } diff --git a/source/main.cpp b/source/main.cpp index c6237eb..d078dfc 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -35,7 +35,7 @@ void restart() void game::init() { - draw::init("The Pool", 320, 240, 3); + draw::init("The Pool", 420, 240, 3); surf = draw::loadSurface("test.gif"); draw::setSource(surf); draw::loadPalette("test.gif"); @@ -87,6 +87,7 @@ bool game::loop() print(0,30,input::mouseBtn(1)?1:0); print(0,40,input::mouseBtn(2)?1:0); print(0,50,input::mouseBtn(3)?1:0); + draw::print("HOLA!", 30, 10, 14, 8); draw::render(); return true;