source: trunk/src/font.cpp @ 686

Last change on this file since 686 was 686, checked in by sam, 10 years ago

Put everything in the "lol" namespace. Better late than never.

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 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 <string.h>
16#include <stdio.h>
17
18#include "core.h"
19
20namespace lol
21{
22
23/*
24 * Font implementation class
25 */
26
27class FontData
28{
29    friend class Font;
30
31private:
32    char *name;
33    int tiler;
34    vec2i size;
35};
36
37/*
38 * Public Font class
39 */
40
41Font::Font(char const *path)
42  : data(new FontData())
43{
44    data->name = (char *)malloc(7 + strlen(path) + 1);
45    sprintf(data->name, "<font> %s", path);
46
47    data->tiler = Tiler::Register(path, 0, 16, 1.0f);
48    data->size = Tiler::GetSize(data->tiler);
49
50    drawgroup = DRAWGROUP_BEFORE;
51}
52
53Font::~Font()
54{
55    Tiler::Deregister(data->tiler);
56    free(data->name);
57    delete data;
58}
59
60void Font::TickDraw(float deltams)
61{
62    Entity::TickDraw(deltams);
63}
64
65char const *Font::GetName()
66{
67    return data->name;
68}
69
70void Font::Print(vec3i pos, char const *str)
71{
72    Scene *scene = Scene::GetDefault();
73
74    while (*str)
75    {
76        uint32_t ch = (uint8_t)*str++;
77
78        if (ch != ' ')
79            scene->AddTile((data->tiler << 16) | (ch & 255),
80                           pos.x, pos.y, pos.z, 0);
81
82        pos.x += data->size.x;
83    }
84}
85
86vec2i Font::GetSize() const
87{
88    return data->size;
89}
90
91} /* namespace lol */
92
Note: See TracBrowser for help on using the repository browser.