Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/resources/src/lib/graphics/text_engine/text_engine.cc @ 9783

Last change on this file since 9783 was 7193, checked in by bensch, 19 years ago

orxonox/trunk: new style for resources (prework/movement)

File size: 4.0 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14
15   for some fonts and licenses visit: =http://www.dafont.com/en/font.php=
16
17   !! IMPORTANT !! When using ttf fonts clear the license issues prior to
18   adding them to orxonox. This is really important, because we do not
19   want to offend anyone.
20*/
21
22#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
23
24#include "text_engine.h"
25#include "text.h"
26#include "font.h"
27
28using namespace std;
29
30#include <stdlib.h>
31#include <stdio.h>
32#include <string.h>
33
34#include "graphics_engine.h"
35#include "util/loading/resource_manager.h"
36#include "class_list.h"
37
38#include "debug.h"
39
40///////////////////
41/// TEXT-ENGINE ///
42///////////////////
43/**
44 *  standard constructor
45*/
46TextEngine::TextEngine ()
47{
48   this->setClassID(CL_TEXT_ENGINE, "TextEngine");
49   this->setName("TextEngine");
50   this->enableFonts();
51}
52
53/**
54 *  the singleton reference to this class
55*/
56TextEngine* TextEngine::singletonRef = NULL;
57
58/**
59 *  standard deconstructor
60
61*/
62TextEngine::~TextEngine ()
63{
64  // first remove all the remaining Texts (if any).
65  const std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT);
66  if (textList != NULL)
67  {
68    while(textList->size() > 0)
69      delete dynamic_cast<Text*>(textList->front());
70  }
71  // delete all remaining fonts (There should not be Anything to do here)
72  const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT);
73  if (fontList != NULL)
74  {
75    ///FIXME
76//    while (fontList->size() > 0)
77    {
78      Font* font = dynamic_cast<Font*>(fontList->back());
79      if (likely(font != Font::getDefaultFont()))
80        ResourceManager::getInstance()->unload(font, RP_GAME);
81    }
82  }
83  this->disableFonts();
84
85  TextEngine::singletonRef = NULL;
86}
87
88/**
89 *  function to enable TTF_Fonts
90*/
91void TextEngine::enableFonts()
92{
93  if (!TTF_WasInit())
94    {
95      if(TTF_Init()==-1)
96        PRINTF(1)("TTF_Init: %s\n", TTF_GetError());
97
98      TextEngine::checkVersion();
99    }
100  else
101    PRINTF(4)("Fonts already initialized\n");
102}
103
104/**
105 *  function to disable TTF_fonts
106*/
107void TextEngine::disableFonts()
108{
109  if (TTF_WasInit())
110    {
111      Font::removeDefaultFont();
112      TTF_Quit();
113    }
114  else
115    PRINTF(4)("Fonts were not initialized.\n");
116}
117
118/**
119 *  outputs some nice Debug information
120 *
121 * @todo there should also be something outputted about Font
122 */
123void TextEngine::debug() const
124{
125  const list<BaseObject*>* textList = ClassList::getList(CL_TEXT);
126  if (textList != NULL)
127  {
128    PRINT(0)("+-------------------------------+\n");
129    PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n");
130    PRINT(0)("+-------------------------------+\n");
131    PRINT(0)("Reference: %p; Text Counts: %d\n", this, textList->size());
132
133    list<BaseObject*>::const_iterator text;
134    for ( text = textList->begin(); text != textList->end(); text++)
135      dynamic_cast<Text*>(*text)->debug();
136    PRINT(0)("+---------------------------TE--+\n");
137  }
138}
139
140
141/**
142 *  checks if the compiled version and the local version of SDL_ttf match.
143 * @returns true if match, false otherwise
144*/
145bool TextEngine::checkVersion()
146{
147  SDL_version compile_version;
148  SDL_version link_version;
149  TTF_VERSION(&compile_version);
150  link_version = *TTF_Linked_Version();
151
152  if (compile_version.major == link_version.major &&
153      compile_version.minor == link_version.minor &&
154      compile_version.patch == link_version.patch)
155    {
156      return true;
157    }
158  else
159    {
160      PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n",
161                compile_version.major,
162                compile_version.minor,
163                compile_version.patch);
164
165      PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n",
166                link_version.major,
167                link_version.minor,
168                link_version.patch);
169      return false;
170    }
171}
Note: See TracBrowser for help on using the repository browser.