Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: some minor cleanup, of the mess i made with AutoMake-sh

File size: 4.4 KB
RevLine 
[4597]1/*
[3655]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:
[3766]12   main-programmer: Benjamin Grauer
[3655]13   co-programmer: ...
[3766]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
[4597]18   adding them to orxonox. This is really important, because we do not
[3767]19   want to offend anyone.
[3655]20*/
21
[5357]22#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
[3655]23
[3766]24#include "text_engine.h"
[5344]25#include "text.h"
26#include "font.h"
[3655]27
28using namespace std;
29
[3766]30#include <stdlib.h>
31#include <stdio.h>
32#include <string.h>
[3655]33
[3766]34#include "graphics_engine.h"
[3769]35#include "resource_manager.h"
[5077]36#include "class_list.h"
[3769]37
[3766]38#include "debug.h"
[3911]39#include "list.h"
[3766]40
[3768]41///////////////////
42/// TEXT-ENGINE ///
43///////////////////
[3766]44/**
[4836]45 *  standard constructor
[3655]46*/
[4597]47TextEngine::TextEngine ()
[3655]48{
[4320]49   this->setClassID(CL_TEXT_ENGINE, "TextEngine");
[4597]50   this->setName("TextEngine");
[3769]51   this->enableFonts();
[3655]52}
53
54/**
[4836]55 *  the singleton reference to this class
[3655]56*/
[3766]57TextEngine* TextEngine::singletonRef = NULL;
[3655]58
59/**
[4836]60 *  standard deconstructor
[3655]61
62*/
[4597]63TextEngine::~TextEngine ()
[3655]64{
[5288]65  // first remove all the remaining Texts (if any).
66  tList<BaseObject>* textList = ClassList::getList(CL_TEXT);
[5290]67  if (textList != NULL)
[5288]68  {
[5289]69    tIterator<BaseObject>* textIterator = textList->getIterator();
70    Text* text = dynamic_cast<Text*>(textIterator->firstElement());
71    while( text != NULL)
72    {
73      delete text;
74      text = dynamic_cast<Text*>(textIterator->nextElement());
75    }
76    delete textIterator;
[5288]77  }
[5347]78  // delete all remaining fonts (There should not be Anything to do here)
[5287]79  tList<BaseObject>* fontList = ClassList::getList(CL_FONT);
80  if (fontList != NULL)
81  {
82    tIterator<BaseObject>* fontIterator = fontList->getIterator();
83    Font* font = dynamic_cast<Font*>(fontIterator->firstElement());
84    while( font != NULL)
85    {
86      ResourceManager::getInstance()->unload(font, RP_GAME);
87      font = dynamic_cast<Font*>(fontIterator->nextElement());
88    }
89    delete fontIterator;
90  }
91
[3769]92  this->disableFonts();
[4597]93
[3766]94  TextEngine::singletonRef = NULL;
[3655]95}
[3766]96
97/**
[4836]98 *  function to enable TTF_Fonts
[3766]99*/
[4746]100void TextEngine::enableFonts()
[3766]101{
102  if (!TTF_WasInit())
103    {
104      if(TTF_Init()==-1)
[4597]105        PRINTF(1)("TTF_Init: %s\n", TTF_GetError());
[3766]106
107      TextEngine::checkVersion();
108    }
109  else
110    PRINTF(4)("Fonts already initialized\n");
111}
112
113/**
[4836]114 *  function to disable TTF_fonts
[3766]115*/
[4746]116void TextEngine::disableFonts()
[3766]117{
118  if (TTF_WasInit())
119    {
[5336]120      Font::removeDefaultFont();
[3766]121      TTF_Quit();
122    }
123  else
124    PRINTF(4)("Fonts were not initialized.\n");
125}
126
127/**
[4836]128 *  outputs some nice Debug information
[5347]129 *
130 * @todo there should also be something outputted about Font
131 */
[4746]132void TextEngine::debug() const
[3774]133{
[5287]134  tList<BaseObject>* textList = ClassList::getList(CL_TEXT);
135  if (textList != NULL)
136  {
137    PRINT(0)("+-------------------------------+\n");
138    PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n");
139    PRINT(0)("+-------------------------------+\n");
140    PRINT(0)("Reference: %p; Text Counts: %d\n", this, textList->getSize());
[4597]141
[5287]142    tIterator<BaseObject>* textIterator = textList->getIterator();
143    Text* text = dynamic_cast<Text*>(textIterator->firstElement());
144    while( text != NULL)
145      {
146        text->debug();
147        text = dynamic_cast<Text*>(textIterator->nextElement());
148      }
149    delete textIterator;
150    PRINT(0)("+---------------------------TE--+\n");
151  }
[3774]152}
153
154
155/**
[4836]156 *  checks if the compiled version and the local version of SDL_ttf match.
157 * @returns true if match, false otherwise
[3766]158*/
[4746]159bool TextEngine::checkVersion()
[3766]160{
161  SDL_version compile_version;
162  SDL_version link_version;
163  TTF_VERSION(&compile_version);
164  link_version = *TTF_Linked_Version();
165
166  if (compile_version.major == link_version.major &&
167      compile_version.minor == link_version.minor &&
168      compile_version.patch == link_version.patch)
169    {
170      return true;
171    }
172  else
173    {
[4597]174      PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n",
175                compile_version.major,
176                compile_version.minor,
177                compile_version.patch);
178
179      PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n",
180                link_version.major,
181                link_version.minor,
182                link_version.patch);
[3766]183      return false;
184    }
185}
Note: See TracBrowser for help on using the repository browser.