Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5344 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Oct 10, 2005, 12:39:21 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: new Way to load and unload Text

Location:
trunk/src/lib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/graphics_engine.cc

    r5318 r5344  
    2727#include "ini_parser.h"
    2828#include "substring.h"
    29 
     29#include "text.h"
    3030
    3131using namespace std;
     
    564564if (this->geTextCFPS == NULL)
    565565{
    566   this->geTextCFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
     566  this->geTextCFPS = new Text("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
    567567  this->geTextCFPS->setName("curFPS");
    568568  this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
     
    571571if (this->geTextMaxFPS == NULL)
    572572{
    573       this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
     573      this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
    574574      this->geTextMaxFPS->setName("MaxFPS");
    575575      this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
     
    578578if (this->geTextMinFPS == NULL)
    579579{
    580       this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
     580      this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
    581581      this->geTextMinFPS->setName("MinFPS");
    582582      this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
  • trunk/src/lib/graphics/text_engine/font.h

    r5343 r5344  
    22 * @file font.h
    33 * brief Definition of the FONT-loading class
     4 *
     5 * !! IMPORTANT !! When using ttf fonts clear the license issues prior to
     6 * adding them to orxonox. This is really important, because we do not want
     7 * to offend anyone.
    48 */
    59
  • trunk/src/lib/graphics/text_engine/text.cc

    r5343 r5344  
    3838  if (fontFile != NULL)
    3939    this->setFont(fontFile, fontSize);
    40   this->setType(type);
    41 }
    42 
    43 /**
    44  *  creates a new Text Element
    45  * @param font the Font to render this text in
    46  * @param type The renderType to display this font in
    47  *
    48  * this constructor is private, because the user should initialize
    49  * a text with the TextEngine.
    50  */
    51 Text::Text(Font* font, TEXT_RENDER_TYPE type)
    52 {
    53   this->init();
    54 
    55   this->font = font;
    5640  this->setType(type);
    5741}
     
    8973
    9074/**
    91  * sets the Font of this Text to font
    92  * @param font the Font (normaly from the ResourceManager) to allocate to this Text
    93  */
    94 void Text::setFont(Font* font)
    95 {
    96   if (this->font != NULL)
    97     ResourceManager::getInstance()->unload(this->font);
    98   this->font = font;
    99 }
    100 
    101 /**
    10275 * sets the Font of this Text to font from fontFile
    10376 * @param fontFile the File to load the Font from.
     
    11184
    11285  tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, &fontSize);
    113   if (tmpFont == NULL)
     86  if (tmpFont != NULL)
     87  {
     88    if (this->font != NULL)
     89      ResourceManager::getInstance()->unload(this->font);
     90    this->font = tmpFont;
     91  }
     92
     93  else
    11494  {
    11595    PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile);
    116     this->setFont(NULL);
    117   }
    118   else
    119     this->setFont(tmpFont);
     96    if (this->font != NULL)
     97      ResourceManager::getInstance()->unload(this->font);
     98    this->font = NULL;
     99  }
    120100}
    121101
  • trunk/src/lib/graphics/text_engine/text.h

    r5343 r5344  
    2424// FORWARD DECLARATION
    2525class Font;
    26 
    2726
    2827/**
     
    5756class Text : public Element2D
    5857{
    59   friend class TextEngine;
    6058  public:
    6159    Text(const char* fontFile, unsigned int fontSize = TEXT_DEFAULT_SIZE, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);
     
    8684
    8785  private:
    88     Text(Font* font = NULL, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);
    89     void setFont(Font* font);
    90 
    9186
    9287  private:
  • trunk/src/lib/graphics/text_engine/text_engine.cc

    r5343 r5344  
    2323
    2424#include "text_engine.h"
     25#include "text.h"
     26#include "font.h"
    2527
    2628using namespace std;
     
    3436#include "class_list.h"
    3537
    36 #include "p_node.h"
    37 #include "vector.h"
    3838#include "debug.h"
    3939#include "list.h"
     
    126126
    127127/**
    128  *  creates a new Text with a certain font.
    129  * @see Font::Font
    130  * @see Text::Text
    131 */
    132 Text* TextEngine::createText(const char* fontFile, unsigned int fontSize, int textType)
    133 {
    134   Font* tmpFont;
    135   Text* newText;
    136   Vector tmpVec;
    137 
    138   tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, &fontSize);
    139   if (!tmpFont)
    140     {
    141       PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile);
    142       return NULL;
    143     }
    144   else
    145     return new Text(tmpFont, TEXT_RENDER_DYNAMIC);
    146 }
    147 
    148 /**
    149128 *  outputs some nice Debug information
    150129
  • trunk/src/lib/graphics/text_engine/text_engine.h

    r5343 r5344  
    1818
    1919#include "base_object.h"
    20 #include "font.h"
    21 #include "text.h"
    2220
    2321#include "vector.h"
     
    2624class PNode;
    2725class Font;
     26class Text;
    2827
    2928///////////////////
     
    3736  /** @returns a Pointer to the only object of this Class */
    3837  inline static TextEngine* getInstance() { if (!singletonRef) singletonRef = new TextEngine();  return singletonRef; };
    39 
    40   Text* createText(const char* fontFile,
    41                    unsigned int fontSize = TEXT_DEFAULT_SIZE,
    42                    int textType = TEXT_RENDER_DYNAMIC);
    4338
    4439  void debug() const;
  • trunk/src/lib/shell/shell.cc

    r5335 r5344  
    2222
    2323
    24 #include "text_engine.h"
     24#include "text.h"
    2525#include "list.h"
    2626#include "graphics_engine.h"
     
    225225  for (unsigned int i = 0; i < bufferDisplaySize; i++)
    226226  {
    227     bufferText[i] = TextEngine::getInstance()->createText(this->fontFile, this->textSize, TEXT_RENDER_DYNAMIC);
     227    bufferText[i] = new Text(this->fontFile, this->textSize, TEXT_RENDER_DYNAMIC);
    228228    bufferText[i]->setColor(1, 0, 0);
    229229    bufferText[i]->setAlignment(TEXT_ALIGN_LEFT);
  • trunk/src/lib/shell/shell_input.h

    r5254 r5344  
    1010#define _SHELL_INPUT_H
    1111
    12 #include "text_engine.h"
     12#include "text.h"
    1313#include "event_listener.h"
    1414
Note: See TracChangeset for help on using the changeset viewer.