* BUG: Remove Font.Strikeout property as it's only available in SDL_tff>2.0.9


git-svn-id: svn://localhost/gambas/trunk@3226 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Laurent Carlier 2010-09-16 12:26:09 +00:00
parent c0f29f9f90
commit 5fd4006167
5 changed files with 47 additions and 24 deletions

View file

@ -145,7 +145,7 @@ BEGIN_PROPERTY(CFONT_italic)
FONT->SetFontItalic(VPROP(GB_BOOLEAN)); FONT->SetFontItalic(VPROP(GB_BOOLEAN));
END_PROPERTY END_PROPERTY
/*
BEGIN_PROPERTY(CFONT_strikeout) BEGIN_PROPERTY(CFONT_strikeout)
if (READ_PROPERTY) if (READ_PROPERTY)
@ -154,7 +154,7 @@ BEGIN_PROPERTY(CFONT_strikeout)
FONT->SetFontStrikeout(VPROP(GB_BOOLEAN)); FONT->SetFontStrikeout(VPROP(GB_BOOLEAN));
END_PROPERTY END_PROPERTY
*/
BEGIN_PROPERTY(CFONT_underline) BEGIN_PROPERTY(CFONT_underline)
if (READ_PROPERTY) if (READ_PROPERTY)
@ -212,7 +212,7 @@ GB_DESC CFont[] =
GB_PROPERTY("Size", "i", CFONT_size), GB_PROPERTY("Size", "i", CFONT_size),
GB_PROPERTY("Bold", "b", CFONT_bold), GB_PROPERTY("Bold", "b", CFONT_bold),
GB_PROPERTY("Italic", "b", CFONT_italic), GB_PROPERTY("Italic", "b", CFONT_italic),
GB_PROPERTY("StrikeOut", "b", CFONT_strikeout), // GB_PROPERTY("StrikeOut", "b", CFONT_strikeout),
GB_PROPERTY("Underline", "b", CFONT_underline), GB_PROPERTY("Underline", "b", CFONT_underline),
GB_PROPERTY_READ("Ascent", "i", CFONT_ascent), GB_PROPERTY_READ("Ascent", "i", CFONT_ascent),

View file

@ -73,14 +73,14 @@ void SDLcursor::Show(Window w)
if (shape == SDL::DefaultCursor) if (shape == SDL::DefaultCursor)
shape = SDL::ArrowCursor; shape = SDL::ArrowCursor;
SDLapp->LockX11(); SDLapp->LockX11();
if (shape != SDL::CustomCursor) if (shape != SDL::CustomCursor)
cursor = XcursorShapeLoadCursor(myDisplay, shape); cursor = XcursorShapeLoadCursor(myDisplay, shape);
else else
cursor = XcursorImageLoadCursor(myDisplay, hImgCursor); cursor = XcursorImageLoadCursor(myDisplay, hImgCursor);
XDefineCursor(myDisplay, w, cursor); XDefineCursor(myDisplay, w, cursor);
SDLapp->UnlockX11(); SDLapp->UnlockX11();
} }

View file

@ -25,9 +25,9 @@
#include <string> #include <string>
#define COMP_WARN "gb.sdl warning: ", #define COMP_WARN "gb.sdl warning: &1",
#define COMP_ERR "gb.sdl error: ", #define COMP_ERR "gb.sdl error: &1",
#define COMP_INFO "gb.sdl info: ", #define COMP_INFO "gb.sdl info: &1",
class SDLerror class SDLerror
{ {

View file

@ -30,9 +30,11 @@
#include <string> #include <string>
#include <ctype.h> #include <ctype.h>
/*
#ifndef TTF_STYLE_STRIKETHROUGH #ifndef TTF_STYLE_STRIKETHROUGH
#define TTF_STYLE_STRIKETHROUGH 0x08 #define TTF_STYLE_STRIKETHROUGH 0x08
#endif #endif
*/
typedef struct { typedef struct {
std::string name; std::string name;
@ -44,7 +46,7 @@ typedef struct {
static std::vector<fontdesc> fontDB; static std::vector<fontdesc> fontDB;
static StringList _FontList; static StringList _FontList;
#define DEFAULT_FONT_SIZE 20 #define DEFAULT_FONT_SIZE 25
#define DEFAULT_DPI 72 /* Default DPI size in SDL_TTF */ #define DEFAULT_DPI 72 /* Default DPI size in SDL_TTF */
inline bool cmp_db_nocase(const fontdesc x, const fontdesc y) inline bool cmp_db_nocase(const fontdesc x, const fontdesc y)
@ -142,12 +144,10 @@ SDLfont::SDLfont()
hfonttype = X_font; hfonttype = X_font;
hfontsize = DEFAULT_FONT_SIZE; hfontsize = DEFAULT_FONT_SIZE;
hfontindex = 0; hfontindex = 0;
hSDLfont = 0;
hfontname = fontDB[hfontindex].path; hfontname = fontDB[hfontindex].path;
hSDLfont = TTF_OpenFont(hfontname.c_str(), hfontsize); OpenFont(hfontname.c_str());
if (UNLIKELY(hSDLfont == NULL))
SDLerror::RaiseError(TTF_GetError());
} }
SDLfont::SDLfont(char *fontfile) SDLfont::SDLfont(char *fontfile)
@ -155,11 +155,9 @@ SDLfont::SDLfont(char *fontfile)
hfonttype = SDLTTF_font; hfonttype = SDLTTF_font;
hfontsize = DEFAULT_FONT_SIZE; hfontsize = DEFAULT_FONT_SIZE;
hfontname = fontfile; hfontname = fontfile;
hSDLfont = 0;
hSDLfont = TTF_OpenFont(fontfile, hfontsize); OpenFont(fontfile);
if (UNLIKELY(hSDLfont == NULL))
SDLerror::RaiseError(TTF_GetError());
} }
SDLfont::~SDLfont() SDLfont::~SDLfont()
@ -168,8 +166,34 @@ SDLfont::~SDLfont()
TTF_CloseFont(hSDLfont); TTF_CloseFont(hSDLfont);
} }
void SDLfont::OpenFont(const char* file)
{
if (hSDLfont)
TTF_CloseFont(hSDLfont);
hSDLfont = TTF_OpenFont(file, hfontsize);
if (UNLIKELY(hSDLfont == NULL))
SDLerror::RaiseError(TTF_GetError());
}
void SDLfont::SetFontName(char* name) void SDLfont::SetFontName(char* name)
{ {
std::string font = name;
int i=0;
while (i<int(fontDB.size())) {
if (!fontDB[i].name.compare(font)) {
hfonttype = X_font;
hfontsize = DEFAULT_FONT_SIZE;
hfontindex = i;
hfontname = fontDB[hfontindex].path;
OpenFont(hfontname.c_str());
return;
}
i++;
}
SDLerror::RaiseError("Font not found!");
} }
const char* SDLfont::GetFontName(void ) const char* SDLfont::GetFontName(void )
@ -185,12 +209,7 @@ void SDLfont::SetFontSize(int size)
int style = TTF_GetFontStyle(hSDLfont); int style = TTF_GetFontStyle(hSDLfont);
hfontsize = size; hfontsize = size;
TTF_CloseFont(hSDLfont); OpenFont(hfontname.c_str());
hSDLfont = TTF_OpenFont(hfontname.c_str(), hfontsize);
if (UNLIKELY(hSDLfont == NULL))
SDLerror::RaiseError(TTF_GetError());
TTF_SetFontStyle(hSDLfont, style); TTF_SetFontStyle(hSDLfont, style);
} }
@ -223,15 +242,17 @@ bool SDLfont::IsFontItalic(void )
void SDLfont::SetFontStrikeout(bool state) void SDLfont::SetFontStrikeout(bool state)
{ {
/*
if (state == (TTF_GetFontStyle(hSDLfont) & TTF_STYLE_STRIKETHROUGH)) if (state == (TTF_GetFontStyle(hSDLfont) & TTF_STYLE_STRIKETHROUGH))
return; return;
TTF_SetFontStyle(hSDLfont, (TTF_GetFontStyle(hSDLfont) ^ TTF_STYLE_STRIKETHROUGH)); TTF_SetFontStyle(hSDLfont, (TTF_GetFontStyle(hSDLfont) ^ TTF_STYLE_STRIKETHROUGH));
*/
} }
bool SDLfont::IsFontStrikeout(void ) bool SDLfont::IsFontStrikeout(void )
{ {
return (TTF_GetFontStyle(hSDLfont) & TTF_STYLE_STRIKETHROUGH); // return (TTF_GetFontStyle(hSDLfont) & TTF_STYLE_STRIKETHROUGH);
} }
void SDLfont::SetFontUnderline(bool state) void SDLfont::SetFontUnderline(bool state)

View file

@ -72,6 +72,8 @@ public:
SDLsurface* RenderText(const char* text); SDLsurface* RenderText(const char* text);
private: private:
void OpenFont(const char* file);
int hfonttype; int hfonttype;
int hfontsize; int hfontsize;
int hfontindex; int hfontindex;