Mercurial > projects > mde
diff mde/resource/font.d @ 57:9e1f05fbbcef
Coloured and alpha-blended text is now supported.
TextWidgets get text colour from argument.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 14 Jun 2008 13:09:03 +0100 |
parents | f000d6cd0f74 |
children | 7cab2af4ba21 |
line wrap: on
line diff
--- a/mde/resource/font.d Sat Jun 14 12:04:25 2008 +0100 +++ b/mde/resource/font.d Sat Jun 14 13:09:03 2008 +0100 @@ -16,6 +16,7 @@ /// Sets up freetype (in a basic way). module mde.resource.font; +public import mde.types.basic; // Colour import mde.Options; import mde.resource.FontTexture; import mde.resource.exception; @@ -228,7 +229,10 @@ * * The text block is drawn with top-left corner at x,y. To put the text's baseline at a given * y coordinate would require some changes. Line height is currently variable, depending on the - * highest glyph in the line. + * highest glyph in the line (should probably be fixed: FIXME). + * + * Specify the text's colour with col; currently this is only Colour.WHITE or Colour.BLACK + * (FIXME). FIXME: add alpha support. * * As a CPU-side code optimisation, store a TextBlock (unique to str) and pass a reference as * the cache argument. This is the recommended method, although for one-time calls when you @@ -246,26 +250,37 @@ * than this cache only serves as a small optimisation. However, the only way to get the size * of a text block is to use a TextBlock cache and update it, either with this function or with * the updateBlock function. */ - void textBlock (int x, int y, char[] str, ref TextBlock cache) { + void textBlock (int x, int y, char[] str, ref TextBlock cache, Colour col) { try { - fontTex.drawTextCache (face, str, cache, x, y); + fontTex.drawCache (face, str, cache, x, y, col); } catch (Exception e) { logger.warn ("Exception while drawing text: "~e.msg); } } /** ditto */ - void textBlock (int x, int y, char[] str) { + void textBlock (int x, int y, char[] str, Colour col) { try { // Using the cache method for one-time use is slightly less than optimal, but doing so // isn't really recommended anyway (and maintaining two versions of fontTex.drawText // would be horrible). TextBlock cache; - fontTex.drawTextCache (face, str, cache, x, y); + fontTex.drawCache (face, str, cache, x, y, col); } catch (Exception e) { logger.warn ("Exception while drawing text: "~e.msg); } } + /** A variation of textBlock for transparency. + * + * Set the alpha by calling glColor*() first. See FontTexture.drawCacheA()'s documentation for + * details. */ + void textBlockA (int x, int y, char[] str, ref TextBlock cache, Colour col) { + try { + fontTex.drawCacheA (face, str, cache, x, y, col); + } catch (Exception e) { + logger.warn ("Exception while drawing text: "~e.msg); + } + } /** The font-specified vertical distance between the baseline of consecutive lines. */ int getLineSeparation () {