2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
Cfont.cpp
|
|
|
|
|
|
|
|
(c) 2007 Laurent Carlier <lordheavy@users.sourceforge.net>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-08-17 12:41:51 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2007-12-30 17:41:49 +01:00
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __CFONT_CPP
|
|
|
|
|
|
|
|
#include "Cfont.h"
|
2010-06-16 14:48:11 +02:00
|
|
|
#include "Cimage.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static StringList FontList;
|
|
|
|
|
|
|
|
static void init_font_list(void )
|
|
|
|
{
|
|
|
|
if (FontList.empty())
|
|
|
|
FontList = SDLfont::GetFontList();
|
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CFONTS_next)
|
|
|
|
|
|
|
|
std::string s;
|
|
|
|
|
|
|
|
uint *index = (uint *)GB.GetEnum();
|
|
|
|
|
|
|
|
if (*index == 0)
|
|
|
|
init_font_list();
|
|
|
|
|
|
|
|
if (*index >= FontList.size())
|
|
|
|
GB.StopEnum();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = FontList[*index];
|
|
|
|
GB.ReturnNewZeroString(s.c_str());
|
|
|
|
(*index)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CFONTS_count)
|
|
|
|
|
|
|
|
init_font_list();
|
|
|
|
GB.ReturnInteger(FontList.size());
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
2009-08-17 20:08:56 +02:00
|
|
|
BEGIN_METHOD(CFONT_load, GB_STRING path)
|
|
|
|
|
|
|
|
CFONT *font;
|
2010-06-05 16:56:17 +02:00
|
|
|
GB.New(POINTER(&font), CLASS_Font, NULL, NULL);
|
2009-08-17 20:08:56 +02:00
|
|
|
font->font = new SDLfont(GB.RealFileName(STRING(path), LENGTH(path)));
|
|
|
|
GB.ReturnObject(font);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2010-06-05 16:56:17 +02:00
|
|
|
BEGIN_METHOD(CFONT_width, GB_STRING text)
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
FONT->SizeText(STRING(text), &width, &height);
|
|
|
|
GB.ReturnInteger(width);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
BEGIN_METHOD(CFONT_height, GB_STRING text)
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
FONT->SizeText(STRING(text), &width, &height);
|
|
|
|
GB.ReturnInteger(height);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2010-06-16 14:48:11 +02:00
|
|
|
BEGIN_METHOD(CFONT_image, GB_STRING text)
|
|
|
|
|
|
|
|
CIMAGE *img;
|
|
|
|
|
|
|
|
SDLsurface *txt = FONT->RenderText(GB.ToZeroString(ARG(text)));
|
|
|
|
img = CIMAGE_create(txt);
|
|
|
|
|
|
|
|
GB.ReturnObject(img);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2010-06-05 16:56:17 +02:00
|
|
|
BEGIN_METHOD(CFONT_new, GB_STRING font)
|
|
|
|
|
|
|
|
THIS->font = new SDLfont();
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2009-08-17 20:08:56 +02:00
|
|
|
BEGIN_METHOD_VOID(CFONT_free)
|
|
|
|
|
|
|
|
if (FONT)
|
|
|
|
delete (FONT);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CFONT_name)
|
|
|
|
|
|
|
|
if (READ_PROPERTY)
|
|
|
|
GB.ReturnNewZeroString(FONT->GetFontName());
|
|
|
|
else
|
|
|
|
FONT->SetFontName(GB.ToZeroString(PROP(GB_STRING)));
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CFONT_size)
|
|
|
|
|
|
|
|
if (READ_PROPERTY)
|
|
|
|
GB.ReturnInteger(FONT->GetFontSize());
|
|
|
|
else
|
|
|
|
FONT->SetFontSize(VPROP(GB_INTEGER));
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CFONT_ascent)
|
|
|
|
|
|
|
|
GB.ReturnInteger(FONT->GetFontAscent());
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CFONT_descent)
|
|
|
|
|
|
|
|
GB.ReturnInteger(FONT->GetFontDescent());
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CFONT_fixed)
|
|
|
|
|
|
|
|
GB.ReturnBoolean(FONT->IsFontFixed());
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CFONT_scalable)
|
|
|
|
|
2010-06-05 16:56:17 +02:00
|
|
|
GB.ReturnBoolean(FONT->IsFontScalable());
|
2009-08-17 20:08:56 +02:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
GB_DESC CFonts[] =
|
|
|
|
{
|
|
|
|
GB_DECLARE("Fonts", 0),
|
|
|
|
GB_NOT_CREATABLE(),
|
|
|
|
|
|
|
|
GB_STATIC_METHOD("_next", "s", CFONTS_next, NULL),
|
|
|
|
GB_STATIC_PROPERTY_READ("Count", "i", CFONTS_count),
|
|
|
|
|
|
|
|
GB_END_DECLARE
|
|
|
|
};
|
|
|
|
|
|
|
|
GB_DESC CFont[] =
|
|
|
|
{
|
|
|
|
GB_DECLARE("Font", sizeof(CFONT)),
|
|
|
|
|
2009-08-17 20:08:56 +02:00
|
|
|
GB_STATIC_METHOD("Load", "Font", CFONT_load, "(Path)s"),
|
|
|
|
|
2010-06-05 16:56:17 +02:00
|
|
|
GB_METHOD("_new", NULL, CFONT_new, "[(Font)s]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
GB_METHOD("_free", NULL, CFONT_free, NULL),
|
|
|
|
|
|
|
|
GB_PROPERTY("Name", "s", CFONT_name),
|
2009-08-17 20:08:56 +02:00
|
|
|
GB_PROPERTY("Size", "i", CFONT_size),
|
|
|
|
|
|
|
|
GB_PROPERTY_READ("Ascent", "i", CFONT_ascent),
|
|
|
|
GB_PROPERTY_READ("Descent", "i", CFONT_descent),
|
|
|
|
GB_PROPERTY_READ("Fixed", "b", CFONT_fixed),
|
|
|
|
GB_PROPERTY_READ("Scalable", "b", CFONT_scalable),
|
|
|
|
|
2010-06-05 16:56:17 +02:00
|
|
|
GB_METHOD("Width", "i", CFONT_width, "(Text)s"),
|
|
|
|
GB_METHOD("Height", "i", CFONT_height, "(Text)s"),
|
2010-06-16 14:48:11 +02:00
|
|
|
GB_METHOD("Image", "Image", CFONT_image, "(Text)s"),
|
|
|
|
|
2009-08-17 20:08:56 +02:00
|
|
|
/*
|
|
|
|
GB_STATIC_METHOD("_init", NULL, CFONT_init, NULL),
|
|
|
|
GB_STATIC_METHOD("_exit", NULL, CFONT_exit, NULL),
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
GB_PROPERTY("Grade", "i", CFONT_grade),
|
|
|
|
GB_PROPERTY("Bold", "b", CFONT_bold),
|
|
|
|
GB_PROPERTY("Italic", "b", CFONT_italic),
|
|
|
|
GB_PROPERTY("Underline", "b", CFONT_underline),
|
|
|
|
GB_PROPERTY("StrikeOut", "b", CFONT_strikeout),
|
|
|
|
|
|
|
|
GB_METHOD("ToString", "s", CFONT_to_string, NULL),
|
|
|
|
GB_STATIC_METHOD("_get", "Font", CFONT_get, "(Font)s"),
|
|
|
|
|
|
|
|
GB_PROPERTY_READ("Styles", "String[]", CFONT_styles),
|
2009-08-17 20:08:56 +02:00
|
|
|
*/
|
2007-12-30 17:41:49 +01:00
|
|
|
GB_END_DECLARE
|
|
|
|
};
|
2009-08-17 20:08:56 +02:00
|
|
|
|