case FcResultNoMatch:
font->index = 0;
break;
- case FcResultMatch:
+ case FcResultMatch:
break;
default:
GlftDebug("error getting FC_INDEX from pattern\n");
font->max_advance_width = font->face->size->metrics.max_advance >> 6;
font->descent = -(font->face->size->metrics.descender >> 6);
font->ascent = font->face->size->metrics.ascender >> 6;
- if (font->minspace) font->height = font->ascent + font->descent;
- else font->height = font->face->size->metrics.height >> 6;
+ if (font->minspace)
+ font->height = font->ascent + font->descent;
+ else
+ font->height = font->face->size->metrics.height >> 6;
font->kerning = FT_HAS_KERNING(font->face);
{
return font->max_advance_width;
}
+
+int GlftFontAscent(struct GlftFont *font)
+{
+ return font->ascent;
+}
+
+int GlftFontDescent(struct GlftFont *font)
+{
+ return font->descent;
+}
int *w,
int *h);
+int GlftFontAscent(struct GlftFont *font);
+int GlftFontDescent(struct GlftFont *font);
int GlftFontHeight(struct GlftFont *font);
int GlftFontMaxCharWidth(struct GlftFont *font);
const char *c;
struct GlftGlyph *g, *p = NULL;
+ y += font->descent - 1; /* XXX why -1? it works tho, it seems.. */
+
glColor4f(color->r, color->g, color->b, color->a);
glPushMatrix();
glTranslatef(x, y, 0.0);
#include "render.h"
#include "instance.h"
+#include "surface.h"
#include "font.h"
#include <stdlib.h>
#include <string.h>
+#include <glib.h>
+
+#define ALPHAS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
+ "1234567890`-=\\!@#$%^&*()~_+|[]{};':\",./<>?"
+#define ELIPSES "..."
struct RrFont *RrFontOpen(struct RrInstance *inst, const char *fontstring)
{
struct RrFont *font;
+ int w, h;
font = malloc(sizeof(struct RrFont));
font->inst = inst;
font->font = GlftFontOpen(RrDisplay(inst), RrScreen(inst), fontstring);
+
+ GlftMeasureString(font->font, ELIPSES, strlen(ELIPSES), &w, &h);
+ font->elipses = w;
+ GlftMeasureString(font->font, ALPHAS, strlen(ALPHAS), &w, &h);
+ font->height = h;
+
return font;
}
int RrFontHeight(struct RrFont *font)
{
- return GlftFontHeight(font->font);
+ return font->height;
}
int RrFontMaxCharWidth(struct RrFont *font)
{
return GlftFontMaxCharWidth(font->font);
}
+
+void RrFontRenderString(struct RrSurface *sur, struct RrFont *font,
+ struct RrColor *color, enum RrLayout layout,
+ const char *string, int x, int y, int w, int h)
+{
+ struct GlftColor col;
+ int fh = RrFontHeight(font);
+ int l, m;
+ GString *text;
+ int shortened = 0;
+
+ switch (layout) {
+ case RR_TOP_LEFT:
+ case RR_TOP:
+ case RR_TOP_RIGHT:
+ y += h - fh;
+ break;
+ case RR_LEFT:
+ case RR_CENTER:
+ case RR_RIGHT:
+ y += (h - fh) / 2;
+ break;
+ case RR_BOTTOM_LEFT:
+ case RR_BOTTOM:
+ case RR_BOTTOM_RIGHT:
+ break;
+ }
+
+ text = g_string_new(string);
+ l = g_utf8_strlen(text->str, -1);
+ m = RrFontMeasureString(font, text->str);
+ if (font->elipses > w)
+ l = 0; /* nothing fits.. */
+ else {
+ while (l && m > w) {
+ shortened = 1;
+ /* remove a character from the middle */
+ text = g_string_erase(text, l-- / 2, 1);
+ /* if the elipses are too large, don't show them at all */
+ m = RrFontMeasureString(font, text->str) + font->elipses;
+ }
+ if (shortened) {
+ text = g_string_insert(text, (l + 1) / 2, ELIPSES);
+ l += 3;
+ }
+ }
+ if (!l) return;
+
+ switch (layout) {
+ case RR_TOP_LEFT:
+ case RR_LEFT:
+ case RR_BOTTOM_LEFT:
+ break;
+ case RR_TOP:
+ case RR_CENTER:
+ case RR_BOTTOM:
+ x += (w - m) / 2;
+ break;
+ case RR_TOP_RIGHT:
+ case RR_RIGHT:
+ case RR_BOTTOM_RIGHT:
+ x += w - m;
+ break;
+ }
+
+ col.r = color->r;
+ col.g = color->g;
+ col.b = color->b;
+ col.a = color->a;
+ GlftRenderString(font->font, text->str, strlen(text->str), &col, x, y);
+}
struct RrFont {
struct RrInstance *inst;
struct GlftFont *font;
+
+ int height;
+ int elipses;
};
+#define RrFontElipsesLength(f) ((f)->elipses)
+
+void RrFontRenderString(struct RrSurface *sur, struct RrFont *font,
+ struct RrColor *color, enum RrLayout layout,
+ const char *string, int x, int y, int w, int h);
+
#endif
struct RrSurface *p;
int ok, i;
int surx, sury;
+ int x, y, w, h, e;
GSList *it;
inst = RrSurfaceInstance(sur);
if (!RrSurfaceVisible(sur)) return;
- g_message("PAINTING SURFACE %p", sur);
-
ok = glXMakeCurrent(RrDisplay(inst), RrSurfaceWindow(sur),RrContext(inst));
assert(ok);
*/
glPushMatrix();
- glTranslatef(-RrSurfaceX(sur),
- -RrSurfaceY(sur), 0);
+ glTranslatef(-RrSurfaceX(sur), -RrSurfaceY(sur), 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
p = sur;
switch (RrSurfaceType(sur)) {
case RR_SURFACE_PLANAR:
RrPlanarPaint(sur, surx, sury);
+ e = RrPlanarEdgeWidth(sur);
+ x = RrSurfaceX(sur) + e;
+ y = RrSurfaceY(sur) + e;
+ w = RrSurfaceWidth(sur) - e * 2;
+ h = RrSurfaceHeight(sur) - e * 2;
break;
case RR_SURFACE_NONPLANAR:
assert(0);
break;
case RR_SURFACE_NONE:
+ x = RrSurfaceX(sur);
+ y = RrSurfaceY(sur);
+ w = RrSurfaceWidth(sur);
+ h = RrSurfaceHeight(sur);
break;
}
for (i = 0; i < sur->ntextures; ++i)
- RrTexturePaint(sur, &sur->texture[i]);
+ RrTexturePaint(sur, &sur->texture[i], x, y, w, h);
glPopMatrix();
RrPlanarBorderWidth(sur), &RrPlanarBorderColor(sur));
}
-void RrPlanarMinSize(struct RrSurface *sur, int *w, int *h)
+int RrPlanarEdgeWidth(struct RrSurface *sur)
{
- *w = *h = RrPlanarBorderWidth(sur);
+ int w;
+ w = RrPlanarBorderWidth(sur);
switch (RrPlanarBevelType(sur)) {
case RR_SUNKEN_OUTER:
- (*w)++;
- (*h)++;
+ w++;
break;
case RR_SUNKEN_INNER:
- (*w)+=2;
- (*h)+=2;
+ w += 2;
break;
case RR_RAISED_OUTER:
- (*w)++;
- (*h)++;
+ w += 2;
break;
case RR_RAISED_INNER:
- (*w)+=2;
- (*h)+=2;
+ w++;
break;
case RR_BEVEL_NONE:
break;
}
+ return w;
+}
+
+void RrPlanarMinSize(struct RrSurface *sur, int *w, int *h)
+{
+ *w = *h = 2 * RrPlanarEdgeWidth(sur);
}
void RrPlanarMinSize(struct RrSurface *sur, int *w, int *h);
+int RrPlanarEdgeWidth(struct RrSurface *sur);
+
#endif
RrTextureFreeContents(tex);
}
-void RrTexturePaint(struct RrSurface *sur, struct RrTexture *tex)
+void RrTexturePaint(struct RrSurface *sur, struct RrTexture *tex,
+ int x, int y, int w, int h)
{
- struct GlftColor col;
-
glEnable(GL_TEXTURE_2D);
switch (tex->type) {
case RR_TEXTURE_NONE:
break;
case RR_TEXTURE_TEXT:
- assert(tex->data.text.font);
- col.r = tex->data.text.color.r;
- col.g = tex->data.text.color.g;
- col.b = tex->data.text.color.b;
- col.a = tex->data.text.color.a;
-
- GlftRenderString(tex->data.text.font->font, tex->data.text.string,
- strlen(tex->data.text.string), &col,
- RrSurfaceX(sur) + 2, RrSurfaceY(sur) + 4);
+ RrFontRenderString(sur, tex->data.text.font, &tex->data.text.color,
+ tex->data.text.layout, tex->data.text.string,
+ x, y, w, h);
break;
}
glDisable(GL_TEXTURE_2D);
union RrTextureData data;
};
-void RrTexturePaint(struct RrSurface *sur, struct RrTexture *tex);
+void RrTexturePaint(struct RrSurface *sur, struct RrTexture *tex,
+ int x, int y, int w, int h);
#endif
#include "render.h"
#include "theme.h"
+#include "planar.h"
#include <stdlib.h>
struct RrTheme *RrThemeLoad(struct RrInstance *inst, const char *name)
free(theme);
}
}
+
+int RrThemeLabelHeight(struct RrTheme *t)
+{
+ int h;
+ h = RrFontHeight(t->title_font);
+ h += 2 * MAX(RrPlanarEdgeWidth(t->label),
+ RrPlanarEdgeWidth(t->label_f));
+ return h;
+}
struct RrSurface *app_icon;
};
-#define RrThemeLabelHeight(t) (RrFontHeight((t)->title_font))
+int RrThemeLabelHeight(struct RrTheme *t);
#define RrThemeTitleHeight(t) (RrThemeLabelHeight(t) + \
((t)->bevel + (t)->bwidth) * 2)
#define RrThemeButtonSize(t) (RrThemeLabelHeight(t) - (t)->bevel * 2)