source: trunk/src/font.cpp @ 1310

Last change on this file since 1310 was 1310, checked in by sam, 8 years ago

core: tick methods now use seconds, like any sane system.

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstring>
16#include <cstdio>
17
18#include "core.h"
19
20using namespace std;
21
22namespace lol
23{
24
25/*
26 * Font implementation class
27 */
28
29class FontData
30{
31    friend class Font;
32
33private:
34    char *name;
35    TileSet *tileset;
36    ivec2 size;
37};
38
39/*
40 * Public Font class
41 */
42
43Font::Font(char const *path)
44  : data(new FontData())
45{
46    data->name = (char *)malloc(7 + strlen(path) + 1);
47    sprintf(data->name, "<font> %s", path);
48
49    data->tileset = Tiler::Register(path, ivec2(0), ivec2(16));
50    data->size = data->tileset->GetSize(0);
51
52    m_drawgroup = DRAWGROUP_BEFORE;
53}
54
55Font::~Font()
56{
57    Tiler::Deregister(data->tileset);
58    free(data->name);
59    delete data;
60}
61
62void Font::TickDraw(float seconds)
63{
64    Entity::TickDraw(seconds);
65}
66
67char const *Font::GetName()
68{
69    return data->name;
70}
71
72void Font::Print(vec3 pos, char const *str, vec2 scale)
73{
74    Scene *scene = Scene::GetDefault();
75
76    while (*str)
77    {
78        uint32_t ch = (uint8_t)*str++;
79
80        if (ch != ' ')
81            scene->AddTile(data->tileset, ch & 255, pos, 0, scale);
82
83        pos.x += data->size.x * scale.x;
84    }
85}
86
87ivec2 Font::GetSize() const
88{
89    return data->size;
90}
91
92} /* namespace lol */
93
Note: See TracBrowser for help on using the repository browser.