Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/text_engine/text_engine.cc @ 9467

Last change on this file since 9467 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

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
28
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/// TEXT-ENGINE ///
41///////////////////
42/**
43 *  standard constructor
44*/
45TextEngine::TextEngine ()
46{
47   this->setClassID(CL_TEXT_ENGINE, "TextEngine");
48   this->setName("TextEngine");
49   this->enableFonts();
50}
51
52/**
53 *  the singleton reference to this class
54*/
55TextEngine* TextEngine::singletonRef = NULL;
56
57/**
58 *  standard deconstructor
59
60*/
61TextEngine::~TextEngine ()
62{
63  // first remove all the remaining Texts (if any).
64  const std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT);
65  if (textList != NULL)
66  {
67    while(textList->size() > 0)
68      delete dynamic_cast<Text*>(textList->front());
69  }
70  // delete all remaining fonts (There should not be Anything to do here)
71  const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT);
72  if (fontList != NULL)
73  {
74    ///FIXME
75//    while (fontList->size() > 0)
76    {
77//      Font* font = dynamic_cast<Font*>(fontList->back());
78      //if (likely(font != Font::getDefaultFont()))
79      //        ResourceManager::getInstance()->unload(font, RP_GAME);
80    }
81  }
82  this->disableFonts();
83
84  TextEngine::singletonRef = NULL;
85}
86
87/**
88 *  function to enable TTF_Fonts
89*/
90void TextEngine::enableFonts()
91{
92  if (!TTF_WasInit())
93    {
94      if(TTF_Init()==-1)
95        PRINTF(1)("TTF_Init: %s\n", TTF_GetError());
96
97      TextEngine::checkVersion();
98    }
99  else
100    PRINTF(4)("Fonts already initialized\n");
101}
102
103/**
104 *  function to disable TTF_fonts
105 */
106void TextEngine::disableFonts()
107{
108  if (TTF_WasInit())
109    {
110//      Font::removeDefaultFont();
111      TTF_Quit();
112    }
113  else
114    PRINTF(4)("Fonts were not initialized.\n");
115}
116
117/**
118 *  outputs some nice Debug information
119 *
120 * @todo there should also be something outputted about Font
121 */
122void TextEngine::debug() const
123{
124  const std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT);
125  if (textList != NULL)
126  {
127    PRINT(0)("+-------------------------------+\n");
128    PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n");
129    PRINT(0)("+-------------------------------+\n");
130    PRINT(0)("Reference: %p; Text Counts: %d\n", this, textList->size());
131
132    std::list<BaseObject*>::const_iterator text;
133    for ( text = textList->begin(); text != textList->end(); text++)
134      dynamic_cast<Text*>(*text)->debug();
135    PRINT(0)("+---------------------------TE--+\n");
136  }
137}
138
139
140/**
141 *  checks if the compiled version and the local version of SDL_ttf match.
142 * @returns true if match, false otherwise
143*/
144bool TextEngine::checkVersion()
145{
146  SDL_version compile_version;
147  SDL_version link_version;
148  TTF_VERSION(&compile_version);
149  link_version = *TTF_Linked_Version();
150
151  if (compile_version.major == link_version.major &&
152      compile_version.minor == link_version.minor &&
153      compile_version.patch == link_version.patch)
154    {
155      return true;
156    }
157  else
158    {
159      PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n",
160                compile_version.major,
161                compile_version.minor,
162                compile_version.patch);
163
164      PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n",
165                link_version.major,
166                link_version.minor,
167                link_version.patch);
168      return false;
169    }
170}
Note: See TracBrowser for help on using the repository browser.