summaryrefslogtreecommitdiffstats
path: root/minuitwrp/graphics.c
diff options
context:
space:
mode:
Diffstat (limited to 'minuitwrp/graphics.c')
-rw-r--r--minuitwrp/graphics.c101
1 files changed, 42 insertions, 59 deletions
diff --git a/minuitwrp/graphics.c b/minuitwrp/graphics.c
index 79b1e9aa5..9926904ef 100644
--- a/minuitwrp/graphics.c
+++ b/minuitwrp/graphics.c
@@ -58,6 +58,7 @@
// #define PRINT_SCREENINFO 1 // Enables printing of screen info to log
typedef struct {
+ int type;
GGLSurface texture;
unsigned offset[97];
unsigned cheight;
@@ -392,6 +393,11 @@ int gr_measureEx(const char *s, void* font)
if (!fnt) fnt = gr_font;
+#ifndef TW_DISABLE_TTF
+ if(fnt->type == FONT_TYPE_TTF)
+ return gr_ttf_measureEx(s, font);
+#endif
+
while ((off = *s++))
{
off -= 32;
@@ -410,6 +416,11 @@ int gr_maxExW(const char *s, void* font, int max_width)
if (!fnt) fnt = gr_font;
+#ifndef TW_DISABLE_TTF
+ if(fnt->type == FONT_TYPE_TTF)
+ return gr_ttf_maxExW(s, font, max_width);
+#endif
+
while ((off = *s++))
{
off -= 32;
@@ -425,21 +436,6 @@ int gr_maxExW(const char *s, void* font, int max_width)
return total;
}
-unsigned character_width(const char *s, void* pFont)
-{
- GRFont *font = (GRFont*) pFont;
- unsigned off;
-
- /* Handle default font */
- if (!font) font = gr_font;
-
- off = *s - 32;
- if (off == 0)
- return 0;
-
- return font->offset[off+1] - font->offset[off];
-}
-
int gr_textEx(int x, int y, const char *s, void* pFont)
{
GGLContext *gl = gr_context;
@@ -450,6 +446,11 @@ int gr_textEx(int x, int y, const char *s, void* pFont)
/* Handle default font */
if (!font) font = gr_font;
+#ifndef TW_DISABLE_TTF
+ if(font->type == FONT_TYPE_TTF)
+ return gr_ttf_textExWH(gl, x, y, s, pFont, -1, -1);
+#endif
+
gl->bindTexture(gl, &font->texture);
gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
@@ -480,6 +481,11 @@ int gr_textExW(int x, int y, const char *s, void* pFont, int max_width)
/* Handle default font */
if (!font) font = gr_font;
+#ifndef TW_DISABLE_TTF
+ if(font->type == FONT_TYPE_TTF)
+ return gr_ttf_textExWH(gl, x, y, s, pFont, max_width, -1);
+#endif
+
gl->bindTexture(gl, &font->texture);
gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
@@ -518,6 +524,11 @@ int gr_textExWH(int x, int y, const char *s, void* pFont, int max_width, int max
/* Handle default font */
if (!font) font = gr_font;
+#ifndef TW_DISABLE_TTF
+ if(font->type == FONT_TYPE_TTF)
+ return gr_ttf_textExWH(gl, x, y, s, pFont, max_width, max_height);
+#endif
+
gl->bindTexture(gl, &font->texture);
gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
@@ -549,34 +560,6 @@ int gr_textExWH(int x, int y, const char *s, void* pFont, int max_width, int max
return x;
}
-int twgr_text(int x, int y, const char *s)
-{
- GGLContext *gl = gr_context;
- GRFont *font = gr_font;
- unsigned off;
- unsigned cwidth = 0;
-
- y -= font->ascent;
-
- gl->bindTexture(gl, &font->texture);
- gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
- gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
- gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
- gl->enable(gl, GGL_TEXTURE_2D);
-
- while((off = *s++)) {
- off -= 32;
- if (off < 96) {
- cwidth = font->offset[off+1] - font->offset[off];
- gl->texCoord2i(gl, (off * cwidth) - x, 0 - y);
- gl->recti(gl, x, y, x + cwidth, y + font->cheight);
- }
- x += cwidth;
- }
-
- return x;
-}
-
void gr_fill(int x, int y, int w, int h)
{
GGLContext *gl = gr_context;
@@ -682,33 +665,32 @@ void* gr_loadFont(const char* fontName)
ftex->stride = width;
ftex->data = (void*) bits;
ftex->format = GGL_PIXEL_FORMAT_A_8;
+ font->type = FONT_TYPE_TWRP;
font->cheight = height;
font->ascent = height - 2;
return (void*) font;
}
-int gr_getFontDetails(void* font, unsigned* cheight, unsigned* maxwidth)
+void gr_freeFont(void *font)
+{
+ GRFont *f = font;
+ free(f->texture.data);
+ free(f);
+}
+
+int gr_getMaxFontHeight(void *font)
{
GRFont *fnt = (GRFont*) font;
if (!fnt) fnt = gr_font;
if (!fnt) return -1;
- if (cheight) *cheight = fnt->cheight;
- if (maxwidth)
- {
- int pos;
- *maxwidth = 0;
- for (pos = 0; pos < 96; pos++)
- {
- unsigned int width = fnt->offset[pos+1] - fnt->offset[pos];
- if (width > *maxwidth)
- {
- *maxwidth = width;
- }
- }
- }
- return 0;
+#ifndef TW_DISABLE_TTF
+ if(fnt->type == FONT_TYPE_TTF)
+ return gr_ttf_getMaxFontHeight(font);
+#endif
+
+ return fnt->cheight;
}
static void gr_init_font(void)
@@ -746,6 +728,7 @@ static void gr_init_font(void)
ftex->stride = width;
ftex->data = (void*) bits;
ftex->format = GGL_PIXEL_FORMAT_A_8;
+ gr_font->type = FONT_TYPE_TWRP;
gr_font->cheight = height;
gr_font->ascent = height - 2;
return;