- Funcions de pintat de text
This commit is contained in:
BIN
data/font.gif
Normal file
BIN
data/font.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 419 B |
@@ -16,13 +16,16 @@ namespace draw
|
|||||||
|
|
||||||
surface *screen = nullptr; // La superficie screen, que representa la pantalla. Se crea i destrueix internament
|
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 *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
|
uint32_t palette[256]; // La paleta de colors
|
||||||
uint8_t color_indices[256]; // Indices dels colors per defecte
|
uint8_t color_indices[256]; // Indices dels colors per defecte
|
||||||
uint8_t sel_color = 0; // Color seleccionat per defecte
|
uint8_t sel_color = 0; // Color seleccionat per defecte
|
||||||
uint8_t transparent = 0; // El color transparent
|
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
|
// 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)
|
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;
|
destination = screen;
|
||||||
sel_color = transparent = 0;
|
sel_color = transparent = 0;
|
||||||
for (int i=0;i<256;++i) color_indices[i] = i;
|
for (int i=0;i<256;++i) color_indices[i] = i;
|
||||||
|
|
||||||
|
textsurf = loadSurface("font.gif");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finalització del sistema
|
// Finalització del sistema
|
||||||
void quit()
|
void quit()
|
||||||
{
|
{
|
||||||
|
if (textsurf) freeSurface(textsurf);
|
||||||
|
|
||||||
// Si la superficie "screen" existia, alliberem la seua memòria
|
// Si la superficie "screen" existia, alliberem la seua memòria
|
||||||
if (screen != nullptr)
|
if (screen != nullptr)
|
||||||
{
|
{
|
||||||
@@ -143,6 +150,16 @@ namespace draw
|
|||||||
source = surf == nullptr ? screen : surf;
|
source = surf == nullptr ? screen : surf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pushSource()
|
||||||
|
{
|
||||||
|
pushedSource = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
void popSource()
|
||||||
|
{
|
||||||
|
source = pushedSource;
|
||||||
|
}
|
||||||
|
|
||||||
// Estableix la paleta del sistema carregant-la d'un GIF
|
// Estableix la paleta del sistema carregant-la d'un GIF
|
||||||
void loadPalette(const std::string &filename)
|
void loadPalette(const std::string &filename)
|
||||||
{
|
{
|
||||||
@@ -255,6 +272,11 @@ namespace draw
|
|||||||
color_indices[c1] = c2;
|
color_indices[c1] = c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void restorecol(const Uint8 c)
|
||||||
|
{
|
||||||
|
color_indices[c] = c;
|
||||||
|
}
|
||||||
|
|
||||||
void color(const Uint8 col)
|
void color(const Uint8 col)
|
||||||
{
|
{
|
||||||
sel_color = col;
|
sel_color = col;
|
||||||
@@ -283,6 +305,33 @@ namespace draw
|
|||||||
vline(x+w-1,y,h);
|
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<len;++i)
|
||||||
|
{
|
||||||
|
char chr = text[i];
|
||||||
|
if (borde!=0)
|
||||||
|
{
|
||||||
|
swapcol(1, borde);
|
||||||
|
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);
|
||||||
|
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
|
// Refresca la pantalla
|
||||||
void render()
|
void render()
|
||||||
{
|
{
|
||||||
@@ -310,4 +359,5 @@ namespace draw
|
|||||||
// I ho presentem
|
// I ho presentem
|
||||||
SDL_RenderPresent(sdl_renderer);
|
SDL_RenderPresent(sdl_renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ namespace draw
|
|||||||
/// @param surf punter a la superficie a establir com a oritge
|
/// @param surf punter a la superficie a establir com a oritge
|
||||||
void setSource(surface *surf);
|
void setSource(surface *surf);
|
||||||
|
|
||||||
|
void pushSource();
|
||||||
|
void popSource();
|
||||||
|
|
||||||
/// @brief Estableix la paleta del sistema carregant-la d'un GIF
|
/// @brief Estableix la paleta del sistema carregant-la d'un GIF
|
||||||
/// @param filename nom de l'arxiu GIF d'on carregar la paleta
|
/// @param filename nom de l'arxiu GIF d'on carregar la paleta
|
||||||
void loadPalette(const std::string &filename);
|
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)
|
/// @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 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 swapcol(const uint8_t c1, const uint8_t c2);
|
||||||
void color(const Uint8 col);
|
void restorecol(const uint8_t c);
|
||||||
|
void color(const uint8_t col);
|
||||||
void hline(const int x, const int y, const int w);
|
void hline(const int x, const int y, const int w);
|
||||||
void vline(const int x, const int y, const int h);
|
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 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 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
|
/// @brief Refresca la pantalla
|
||||||
void render();
|
void render();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ void restart()
|
|||||||
|
|
||||||
void game::init()
|
void game::init()
|
||||||
{
|
{
|
||||||
draw::init("The Pool", 320, 240, 3);
|
draw::init("The Pool", 420, 240, 3);
|
||||||
surf = draw::loadSurface("test.gif");
|
surf = draw::loadSurface("test.gif");
|
||||||
draw::setSource(surf);
|
draw::setSource(surf);
|
||||||
draw::loadPalette("test.gif");
|
draw::loadPalette("test.gif");
|
||||||
@@ -87,6 +87,7 @@ bool game::loop()
|
|||||||
print(0,30,input::mouseBtn(1)?1:0);
|
print(0,30,input::mouseBtn(1)?1:0);
|
||||||
print(0,40,input::mouseBtn(2)?1:0);
|
print(0,40,input::mouseBtn(2)?1:0);
|
||||||
print(0,50,input::mouseBtn(3)?1:0);
|
print(0,50,input::mouseBtn(3)?1:0);
|
||||||
|
draw::print("HOLA!", 30, 10, 14, 8);
|
||||||
draw::render();
|
draw::render();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user