Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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/graphics/text_engine
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.