mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-22 19:39:24 +01:00
Add SDL_ttf font support, correct some stuff
This commit is contained in:
parent
1eff870e62
commit
0379a21a55
6
Makefile
6
Makefile
@ -5,14 +5,14 @@ all: menu
|
||||
%.oo: %.cpp
|
||||
g++ -Wall -g -c `sdl-config --cflags` -o $@ $<
|
||||
|
||||
menu.oo: menu.cpp menu.hh utils.hh Makefile
|
||||
menu.oo: menu.cpp menu.hh utils.hh font.hh Makefile
|
||||
|
||||
utils.oo: utils.cpp utils.hh Makefile
|
||||
|
||||
main.oo: menu.hh utils.hh Makefile
|
||||
main.oo: menu.hh utils.hh sdl_ttf_font.hh Makefile
|
||||
|
||||
menu: $(OBJS)
|
||||
g++ `sdl-config --libs` -lSDL -lSDL_image -lSDL_ttf -o $@ $+
|
||||
|
||||
clean:
|
||||
rm -f *.oo menu
|
||||
rm -f *.oo menu *~
|
||||
|
2
main.cpp
2
main.cpp
@ -80,7 +80,7 @@ static void init(void)
|
||||
TTF_Init();
|
||||
|
||||
|
||||
fnt = read_and_alloc_font("font.ttf", 18);
|
||||
fnt = read_and_alloc_font("themes/default/font.ttf", 18);
|
||||
|
||||
g_background = IMG_Load("themes/default/background.png");
|
||||
|
||||
|
63
sdl_ttf_font.hh
Normal file
63
sdl_ttf_font.hh
Normal file
@ -0,0 +1,63 @@
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
|
||||
#include "font.hh"
|
||||
#include "utils.hh"
|
||||
|
||||
#ifndef __SDL_TTF_FONT_HH__
|
||||
#define __SDL_TTF_FONT_HH__
|
||||
|
||||
class Font_TTF : public Font
|
||||
{
|
||||
public:
|
||||
Font_TTF(TTF_Font *font,
|
||||
int r, int g, int b)
|
||||
{
|
||||
this->clr = (SDL_Color){r, g, b};
|
||||
this->font = font;
|
||||
}
|
||||
|
||||
~Font_TTF()
|
||||
{
|
||||
free(this->font);
|
||||
}
|
||||
|
||||
int getHeight(const char *str)
|
||||
{
|
||||
int tw, th;
|
||||
|
||||
TTF_SizeText(this->font, str, &tw, &th);
|
||||
|
||||
return th;
|
||||
}
|
||||
|
||||
int getWidth(const char *str)
|
||||
{
|
||||
int tw, th;
|
||||
|
||||
TTF_SizeText(this->font, str, &tw, &th);
|
||||
|
||||
return tw;
|
||||
}
|
||||
|
||||
void draw(SDL_Surface *where, const char *msg,
|
||||
int x, int y, int w, int h)
|
||||
{
|
||||
SDL_Surface *p;
|
||||
SDL_Rect dst;
|
||||
|
||||
p = TTF_RenderText_Blended(this->font, msg, this->clr);
|
||||
panic_if(!p, "%s\n", TTF_GetError());
|
||||
|
||||
dst = (SDL_Rect){x, y, w, h};
|
||||
|
||||
SDL_BlitSurface(p, NULL, where, &dst);
|
||||
SDL_FreeSurface(p);
|
||||
}
|
||||
|
||||
protected:
|
||||
TTF_Font *font;
|
||||
SDL_Color clr;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user