Class: SDL::TTF
- Inherits:
-
Object
- Object
- 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:
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 |
# File 'ext/sdl/sdl.c', line 1066
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
1104 1105 1106 1107 |
# File 'ext/sdl/sdl.c', line 1104
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
1079 1080 1081 1082 1083 |
# File 'ext/sdl/sdl.c', line 1079 static VALUE Font_height(VALUE self) { DEFINE_SELF(TTFFont, font, self); return INT2FIX(TTF_FontHeight(font)); } |
#render(dst, text, c) ⇒ Object
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 |
# File 'ext/sdl/sdl.c', line 1085
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
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 |
# File 'ext/sdl/sdl.c', line 1109
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");
}
}
|