Class: SDL::TTF
- Inherits:
-
Data
- Object
- Data
- SDL::TTF
- Defined in:
- ext/sdl/sdl.c
Class Method Summary collapse
-
.open(path, size) ⇒ Object
// SDL::TTFFont methods:.
Instance Method Summary collapse
- #draw(dst, text, x, y, c) ⇒ Object
- #height ⇒ Object
- #render(dst, text, c) ⇒ Object
- #text_size(text) ⇒ Object
Class Method Details
.open(path, size) ⇒ Object
// SDL::TTFFont methods:
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 |
# File 'ext/sdl/sdl.c', line 1015
static VALUE Font_s_open(VALUE self, VALUE path, VALUE size) {
UNUSED(self);
ExportStringValue(path);
TTF_Font* font = TTF_OpenFont(RSTRING_PTR(path), NUM2UINT16(size));
if (!font)
FAILURE("Font.open");
return TypedData_Wrap_Struct(cTTFFont, &_TTFFont_type, font);
}
|
Instance Method Details
#draw(dst, text, x, y, c) ⇒ Object
1053 1054 1055 1056 |
# File 'ext/sdl/sdl.c', line 1053
static VALUE Font_draw(VALUE self, VALUE dst, VALUE text, VALUE x, VALUE y, VALUE c) {
VALUE img = Font_render(self, dst, text, c);
return Renderer_blit(dst, img, x, y, Qnil, Qnil, Qnil, Qnil);
}
|
#height ⇒ Object
1028 1029 1030 1031 1032 |
# File 'ext/sdl/sdl.c', line 1028 static VALUE Font_height(VALUE self) { DEFINE_SELF(TTFFont, font, self); return INT2FIX(TTF_FontHeight(font)); } |
#render(dst, text, c) ⇒ Object
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 |
# File 'ext/sdl/sdl.c', line 1034
static VALUE Font_render(VALUE self, VALUE dst, VALUE text, VALUE c) {
DEFINE_SELF(TTFFont, font, self);
DEFINE_SELF(PixelFormat, format, rb_ivar_get(dst, id_iv_format));
SDL_Surface *result;
SDL_Color fg;
SDL_GetRGBA(VALUE2COLOR(c), format,
&(fg.r), &(fg.g), &(fg.b), &(fg.a));
ExportStringValue(text);
result = TTF_RenderUTF8_Blended(font, StringValueCStr(text), fg);
if (!result)
TTF_FAILURE("Font.render");
return TypedData_Wrap_Struct(cSurface, &_Surface_type, result);
}
|
#text_size(text) ⇒ Object
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 |
# File 'ext/sdl/sdl.c', line 1058
static VALUE Font_text_size(VALUE self, VALUE text) {
DEFINE_SELF(TTFFont, font, self);
int w = 1, h = 2, result;
ExportStringValue(text);
result = TTF_SizeText(font, StringValueCStr(text), &w, &h);
if (!result) {
return rb_ary_new_from_args(2, INT2FIX(w), INT2FIX(h));
} else {
FAILURE("SDL::TTF#text_size");
}
}
|