source: trunk/src/text.cpp @ 320

Last change on this file since 320 was 320, checked in by sam, 9 years ago

Display mashed monsterz statistics, up to 12 icons.

  • Property svn:keywords set to Id
File size: 1.4 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 <cstdio>
16#include <cstdlib> /* free() */
17#include <cstring> /* strdup() */
18
19#include "core.h"
20
21/*
22 * Text implementation class
23 */
24
25class TextData
26{
27    friend class Text;
28
29private:
30    int font;
31    char *text;
32    int3 pos;
33};
34
35/*
36 * Public Text class
37 */
38
39Text::Text(char const *text, char const *font)
40  : data(new TextData())
41{
42    data->font = Forge::Register(font);
43    data->text = text ? strdup(text) : NULL;
44    data->pos = int3(0, 0, 0);
45
46    drawgroup = DRAWGROUP_HUD;
47}
48
49void Text::SetText(char const *text)
50{
51    if (data->text)
52        free(data->text);
53    data->text = text ? strdup(text) : NULL;
54}
55
56void Text::SetPos(int3 pos)
57{
58    data->pos = pos;
59}
60
61void Text::TickDraw(float deltams)
62{
63    Entity::TickDraw(deltams);
64
65    if (data->text)
66    {
67        Font *font = Forge::GetFont(data->font);
68        font->Print(data->pos, data->text);
69    }
70}
71
72Text::~Text()
73{
74    if (data->text)
75        free(data->text);
76    Forge::Deregister(data->font);
77    delete data;
78}
79
Note: See TracBrowser for help on using the repository browser.