Skip to content

Commit

Permalink
Cleanup|Fonts|Resources|Client: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 13, 2013
1 parent 0d1e452 commit 0938c98
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 108 deletions.
5 changes: 2 additions & 3 deletions doomsday/client/include/resource/abstractfont.h
Expand Up @@ -64,7 +64,6 @@ class AbstractFont
DENG2_AS_IS_METHODS()

fontid_t primaryBind() const;

void setPrimaryBind(fontid_t bindId);

/// @return @ref fontFlags
Expand All @@ -77,8 +76,8 @@ class AbstractFont
virtual void glInit();
virtual void glDeinit();

virtual de::Rectanglei const &charPosCoords(uchar ch) = 0;
virtual de::Rectanglei const &charTexCoords(uchar ch) = 0;
virtual de::Rectanglei const &glyphPosCoords(uchar ch) = 0;
virtual de::Rectanglei const &glyphTexCoords(uchar ch) = 0;
};

#endif // CLIENT_RESOURCE_ABSTRACTFONT_H
20 changes: 6 additions & 14 deletions doomsday/client/include/resource/bitmapfont.h
Expand Up @@ -21,9 +21,9 @@
#define CLIENT_RESOURCE_BITMAPFONT_H

#include "abstractfont.h"
#include "Texture"
#include "gl/gl_main.h"
#include <de/Rectangle>
#include <de/String>
#include <de/Vector>

/**
Expand All @@ -33,21 +33,13 @@
*/
class BitmapFont : public AbstractFont
{
public:
// Data for a character.
struct bitmapfont_char_t
{
de::Rectanglei geometry;
de::Rectanglei coords;
};

public:
BitmapFont(fontid_t bindId);

static BitmapFont *fromFile(fontid_t bindId, char const *resourcePath);
static BitmapFont *fromFile(fontid_t bindId, de::String resourcePath);

void rebuildFromFile(char const *resourcePath);
void setFilePath(char const *filePath);
void rebuildFromFile(de::String resourcePath);
void setFilePath(de::String resourcePath);

/// @return GL-texture name.
GLuint textureGLName() const;
Expand All @@ -56,8 +48,8 @@ class BitmapFont : public AbstractFont
void glInit();
void glDeinit();

de::Rectanglei const &charPosCoords(uchar ch);
de::Rectanglei const &charTexCoords(uchar ch);
de::Rectanglei const &glyphPosCoords(uchar ch);
de::Rectanglei const &glyphTexCoords(uchar ch);

private:
DENG2_PRIVATE(d)
Expand Down
20 changes: 9 additions & 11 deletions doomsday/client/include/resource/compositebitmapfont.h
Expand Up @@ -24,6 +24,7 @@
#include "def_main.h"
#include "Texture"
#include <de/Rectangle>
#include <de/String>
#include <de/Vector>

/**
Expand All @@ -34,8 +35,7 @@
class CompositeBitmapFont : public AbstractFont
{
public:
// Data for a character.
struct bitmapcompositefont_char_t
struct Glyph
{
de::Rectanglei geometry;
patchid_t patch;
Expand All @@ -62,18 +62,16 @@ class CompositeBitmapFont : public AbstractFont
*/
void rebuildFromDef(ded_compositefont_t *def);

patchid_t charPatch(uchar ch);
void charSetPatch(uchar ch, char const *encodedPatchName);

de::Texture::Variant *charTexture(uchar ch);

uint charBorder(uchar ch);

void glInit();
void glDeinit();

de::Rectanglei const &charPosCoords(uchar ch);
de::Rectanglei const &charTexCoords(uchar ch);
de::Rectanglei const &glyphPosCoords(uchar ch);
de::Rectanglei const &glyphTexCoords(uchar ch);

patchid_t glyphPatch(uchar ch);
void glyphSetPatch(uchar ch, de::String encodedPatchName);
de::Texture::Variant *glyphTexture(uchar ch);
uint glyphTextureBorder(uchar ch);

private:
DENG2_PRIVATE(d)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/resource/resourcesystem.h
Expand Up @@ -77,7 +77,7 @@ class ResourceSystem : public de::System
de::Texture *defineTexture(de::String schemeName, de::Uri const &resourceUri,
de::Vector2i const &dimensions = de::Vector2i());

patchid_t declarePatch(char const *encodedName);
patchid_t declarePatch(de::String encodedName);

#ifdef __CLIENT__
/**
Expand Down
28 changes: 14 additions & 14 deletions doomsday/client/src/render/rend_font.cpp
Expand Up @@ -416,7 +416,7 @@ void FR_CharSize(Size2Raw *size, uchar ch)
errorIfNotInited("FR_CharSize");
if(size)
{
Vector2ui dimensions = App_Fonts().toFont(fr.fontNum)->charPosCoords(ch).size();
Vector2ui dimensions = App_Fonts().toFont(fr.fontNum)->glyphPosCoords(ch).size();
size->width = dimensions.x;
size->height = dimensions.y;
}
Expand All @@ -427,7 +427,7 @@ int FR_CharWidth(uchar ch)
{
errorIfNotInited("FR_CharWidth");
if(fr.fontNum != 0)
return App_Fonts().toFont(fr.fontNum)->charPosCoords(ch).width();
return App_Fonts().toFont(fr.fontNum)->glyphPosCoords(ch).width();
return 0;
}

Expand All @@ -436,7 +436,7 @@ int FR_CharHeight(uchar ch)
{
errorIfNotInited("FR_CharHeight");
if(fr.fontNum != 0)
return App_Fonts().toFont(fr.fontNum)->charPosCoords(ch).height();
return App_Fonts().toFont(fr.fontNum)->glyphPosCoords(ch).height();
return 0;
}

Expand All @@ -448,7 +448,7 @@ int FR_SingleLineHeight(char const *text)
int ascent = App_Fonts().toFont(fr.fontNum)->ascent();
if(ascent != 0)
return ascent;
return App_Fonts().toFont(fr.fontNum)->charPosCoords((uchar)text[0]).height();
return App_Fonts().toFont(fr.fontNum)->glyphPosCoords((uchar)text[0]).height();
}

int FR_GlyphTopToAscent(char const *text)
Expand Down Expand Up @@ -747,15 +747,15 @@ static void drawChar(uchar ch, float x, float y, AbstractFont *font,
{
if(alignFlags & ALIGN_RIGHT)
{
x -= font->charPosCoords(ch).width();
x -= font->glyphPosCoords(ch).width();
}
else if(!(alignFlags & ALIGN_LEFT))
{
x -= font->charPosCoords(ch).width() / 2;
x -= font->glyphPosCoords(ch).width() / 2;
}

int const ascent = font->ascent();
int const lineHeight = ascent? ascent : font->charPosCoords(ch).height();
int const lineHeight = ascent? ascent : font->glyphPosCoords(ch).height();
if(alignFlags & ALIGN_BOTTOM)
{
y -= topToAscent(font) + lineHeight;
Expand All @@ -768,7 +768,7 @@ static void drawChar(uchar ch, float x, float y, AbstractFont *font,
glMatrixMode(GL_MODELVIEW);
glTranslatef(x, y, 0);

Rectanglei geometry = font->charPosCoords(ch);
Rectanglei geometry = font->glyphPosCoords(ch);

if(BitmapFont *bmapFont = font->maybeAs<BitmapFont>())
{
Expand All @@ -779,8 +779,8 @@ static void drawChar(uchar ch, float x, float y, AbstractFont *font,
}
else if(CompositeBitmapFont *compFont = font->maybeAs<CompositeBitmapFont>())
{
GL_BindTexture(compFont->charTexture(ch));
if(uint border = compFont->charBorder(ch))
GL_BindTexture(compFont->glyphTexture(ch));
if(uint border = compFont->glyphTextureBorder(ch))
{
geometry = geometry.expanded(border);
}
Expand All @@ -797,10 +797,10 @@ static void drawChar(uchar ch, float x, float y, AbstractFont *font,
geometry.setHeight(geometry.height() + font->_margin.y * 2);
}

Vector2i coords[4] = { font->charTexCoords(ch).topLeft,
font->charTexCoords(ch).topRight(),
font->charTexCoords(ch).bottomRight,
font->charTexCoords(ch).bottomLeft() };
Vector2i coords[4] = { font->glyphTexCoords(ch).topLeft,
font->glyphTexCoords(ch).topRight(),
font->glyphTexCoords(ch).bottomRight,
font->glyphTexCoords(ch).bottomLeft() };

GL_DrawRectWithCoords(geometry, coords);

Expand Down

0 comments on commit 0938c98

Please sign in to comment.