* BUG: Don't create a default TTF font for each draw event!


git-svn-id: svn://localhost/gambas/trunk@6107 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2014-01-27 13:00:36 +00:00
parent b596527086
commit d1aeb73fde
2 changed files with 23 additions and 13 deletions

View File

@ -32,7 +32,7 @@
static CDRAW draw_stack[DRAW_STACK_MAX];
static CDRAW *draw_current = 0;
static GB_CLASS font_id = NULL;
static CFONT *_default_font = NULL;
#define THIS (draw_current)
#define GFX (THIS->graphic)
@ -42,6 +42,17 @@ static GB_CLASS font_id = NULL;
/**************************************************************************/
static CFONT *get_default_font()
{
if (!_default_font)
{
_default_font = (CFONT *)GB.New(GB.FindClass("Font"), NULL, NULL);
GB.Ref(_default_font);
}
return _default_font;
}
static bool check_graphic(void)
{
if (UNLIKELY(THIS == NULL))
@ -73,13 +84,10 @@ void DRAW_begin(void *device)
THIS->backcolor = 0x00000000;
THIS->forecolor = 0x00FFFFFF;
if (!font_id)
font_id = GB.FindClass("Font");
if (FONT)
GB.Unref(POINTER(&FONT));
FONT = (CFONT *)GB.New(font_id, NULL, NULL);
FONT = get_default_font();
GB.Ref(FONT);
if (GB.Is(device, CLASS_Window)) {
@ -120,6 +128,13 @@ void DRAW_begin(void *device)
THIS--;
}
BEGIN_METHOD_VOID(Draw_exit)
if (_default_font)
GB.Unref(POINTER(&_default_font));
END_METHOD
BEGIN_METHOD(CDRAW_begin, GB_OBJECT device)
void *device = VARG(device);
@ -310,6 +325,8 @@ GB_DESC CDraw[] =
{
GB_DECLARE("Draw", 0), GB_NOT_CREATABLE(),
GB_STATIC_METHOD("_exit", NULL, Draw_exit, NULL),
GB_STATIC_METHOD("Begin", NULL, CDRAW_begin, "(Device)o"),
GB_STATIC_METHOD("End", NULL, CDRAW_end, NULL),

View File

@ -139,17 +139,10 @@ static void my_main(int *argc, char **argv)
static int my_loop()
{
//GLint errcode = 0;
while(myApp->HaveWindows())
{
myApp->ManageEvents();
GB.Loop(1); // Busy loop of 1 ms !
/* errcode = glGetError();
if (errcode != GL_NO_ERROR)
std::cerr << "GB.SDL: an OpenGL error was detected : " << std::hex << errcode << std::endl; */
GB.Loop(10);
}
return 1;