Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

Location:
trunk/src/lib/graphics/text_engine
Files:
11 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/text_engine/font.cc

    r8989 r9869  
    2929#include "compiler.h"
    3030
     31ObjectListDefinition(Font);
    3132
    3233Font::Font()
     
    3435{
    3536  this->init();
    36 
    3737}
    3838
     
    118118  Material::operator=(font);
    119119  this->data = font.data;
     120  this->setTexture(this->data->textureData());
    120121
    121122  return *this;
     
    130131  this->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    131132
    132   this->setClassID(CL_FONT, "Font");
    133   if (Font::defaultFontData.get() == NULL)
     133  this->registerObject(this, Font::_objectList);
     134  if (Font::defaultFontData.isNull())
    134135  {
    135136    Font::initDefaultFont();
     
    138139}
    139140
    140 FontDataPointer Font::defaultFontData(NULL);
     141FontData::Pointer Font::defaultFontData(NULL);
    141142
    142143/**
     
    146147{
    147148  // temporarily create a Font.
    148   Font::defaultFontData = FontDataPointer(new FontData);
     149  Font::defaultFontData = FontData::Pointer(new FontData);
    149150  // apply the Data.
    150151  Font::defaultFontData = Font(font_xpm).data;
     
    159160bool Font::loadFontFromTTF(const std::string& fontFile, unsigned int renderSize)
    160161{
    161   this->data = FontDataPointer (new FontData());
     162  this->data = FontData::Pointer (new FontData());
    162163  bool retVal = this->data->loadFontFromTTF(fontFile, renderSize);
    163164  if (!retVal)
     
    174175bool Font::loadFontFromSDL_Surface(SDL_Surface* surface)
    175176{
    176   this->data = FontDataPointer (new FontData());
     177  this->data = FontData::Pointer (new FontData());
    177178  bool retVal = this->data->loadFontFromSDL_Surface(surface);
    178179  if (!retVal)
     
    196197
    197198
    198 void Font::setTexture(const TextureDataPointer& texDataPointer)
     199void Font::setTexture(const TextureData::Pointer& texDataPointer)
    199200{
    200201  this->setDiffuseMap(texDataPointer);
  • trunk/src/lib/graphics/text_engine/font.h

    r8766 r9869  
    1919class Font : public Material
    2020{
    21 
     21  ObjectListDeclaration(Font);
     22public:
     23  typedef FontData::Glyph Glyph;
    2224public:
    2325  Font();
     
    3941
    4042  /** @returns a Pointer to the Array of Glyphs */
    41   inline Glyph** getGlyphArray() const { return this->data->getGlyphArray(); };
     43  inline const Glyph* const * const getGlyphArray() const { return this->data->getGlyphArray(); };
    4244
    4345  inline int getMaxHeight() const { return data->getMaxHeight(); };
     
    5052  void debug() const;
    5153
     54  void acquireData(const FontData::Pointer& data) { this->data = data; };
     55  const FontData::Pointer& dataPointer() const { return data; };
    5256private:
    5357  void init();
    5458  static void initDefaultFont();
    5559
    56   void setTexture(const TextureDataPointer& texDataPointer);
     60  void setTexture(const TextureData::Pointer& texDataPointer);
    5761
    5862private:
    59   FontDataPointer           data;                //!< A Data-Pointer to a Font.
     63  FontData::Pointer         data;                //!< A Data-Pointer to a Font.
    6064
    61   static FontDataPointer    defaultFontData;     //!< a default font, that is used, if other fonts were unable to be loaded.
     65  static FontData::Pointer  defaultFontData;     //!< a default font, that is used, if other fonts were unable to be loaded.
    6266};
    6367
  • trunk/src/lib/graphics/text_engine/font_data.h

    r8768 r9869  
    2626#define FONT_DEFAULT_RENDER_SIZE     50            //!< At what Resolution to render fonts.
    2727
     28class FontData
     29{
     30
     31
     32public:
     33
    2834//! A struct for handling glyphs
    2935/**
    3036 * a Glyph is one letter of a certain font
    3137 */
    32 struct Glyph
    33 {
     38  struct Glyph
     39  {
    3440  // Glyph-specific (size and so on)
    35   Uint16   character;         //!< The character
    36   float    minX;              //!< The minimum distance from the origin in X
    37   float    maxX;              //!< The maximum distance from the origin in X
    38   float    minY;              //!< The minimum distance from the origin in Y
    39   float    maxY;              //!< The maximum distance from the origin in Y
    40   float    width;             //!< The width of the Glyph
    41   float    height;            //!< The height of the Glyph
    42   float    bearingX;          //!< How much is right of the Origin
    43   float    bearingY;          //!< How much is above the Origin
    44   float    advance;           //!< How big a Glyph would be in monospace-mode
     41    Uint16   character;         //!< The character
     42    float    minX;              //!< The minimum distance from the origin in X
     43    float    maxX;              //!< The maximum distance from the origin in X
     44    float    minY;              //!< The minimum distance from the origin in Y
     45    float    maxY;              //!< The maximum distance from the origin in Y
     46    float    width;             //!< The width of the Glyph
     47    float    height;            //!< The height of the Glyph
     48    float    bearingX;          //!< How much is right of the Origin
     49    float    bearingY;          //!< How much is above the Origin
     50    float    advance;           //!< How big a Glyph would be in monospace-mode
    4551
    46   GLfloat texCoord[4];        //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.
    47 };
     52    GLfloat texCoord[4];        //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.
     53  };
    4854
    49 
    50 class FontData
    51 {
     55  typedef CountPointer<FontData> Pointer;
    5256public:
    5357  FontData();
     
    6165
    6266  /** @returns a Pointer to the Array of Glyphs */
    63   inline Glyph** getGlyphArray() const { return this->glyphArray; };
     67  inline const Glyph* const * const getGlyphArray() const { return this->glyphArray; };
    6468
    6569  int getMaxHeight() const { return maxHeight; };
     
    6872
    6973  /** @returns the Texture-Data of this FontData */
    70   const TextureDataPointer& textureData() const { return texData; };
     74  const TextureData::Pointer& textureData() const { return texData; };
    7175
    7276  bool rebuild() { return texData->rebuild(); };
     
    9195  int           maxDescent;          //!< Max Desent of the Font.
    9296
    93   TextureDataPointer   texData;
     97  TextureData::Pointer   texData;
    9498};
    9599
    96 typedef CountPointer<FontData> FontDataPointer;
    97 
    98100#endif /* _FONT_DATA_H */
  • trunk/src/lib/graphics/text_engine/limited_width_text.cc

    r9406 r9869  
    1919#include "font.h"
    2020
     21ObjectListDefinition(LimitedWidthText);
    2122/**
    2223 * @brief creates a new Text Element
     
    2728    : Text(fontFile, textSize)
    2829{
    29   this->setClassID(CL_LIMITED_WIDTH_TEXT, "LimitedWidthText");
     30  this->registerObject(this, LimitedWidthText::_objectList);
    3031
    3132  this->_dotsPosition = End;
     
    7576  glRotatef(this->getAbsDir2D(), 0, 0, 1);
    7677
    77   Glyph* tmpGlyph;
     78  const Font::Glyph* tmpGlyph;
    7879  float posX = 0.0f;
    7980  glBegin(GL_QUADS);
  • trunk/src/lib/graphics/text_engine/limited_width_text.h

    r8980 r9869  
    1414class LimitedWidthText : public Text
    1515{
     16  ObjectListDeclaration(LimitedWidthText);
    1617  public:
    1718    typedef enum {
  • trunk/src/lib/graphics/text_engine/multi_line_text.cc

    r9406 r9869  
    1919#include "font.h"
    2020
     21ObjectListDefinition(MultiLineText);
     22
    2123/**
    2224 * @brief creates a new Text Element
     
    2729  : Text(fontFile, textSize)
    2830{
    29   this->setClassID(CL_MULTI_LINE_TEXT, "MultiLineText");
     31  this->registerObject(this, MultiLineText::_objectList);
    3032
    3133  this->lineSpacing = 1.0;
     
    7880  glRotatef(this->getAbsDir2D(), 0, 0, 1);
    7981
    80   Glyph* tmpGlyph;
     82  const Font::Glyph* tmpGlyph;
    8183  float posX = 0.0f;
    8284  float posY = 0.0f;
  • trunk/src/lib/graphics/text_engine/multi_line_text.h

    r7757 r9869  
    1414class MultiLineText : public Text
    1515{
     16  ObjectListDeclaration(MultiLineText);
    1617  public:
    1718    MultiLineText(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE, float lineWidth = 100.0);
  • trunk/src/lib/graphics/text_engine/text.cc

    r9406 r9869  
    1717
    1818#include "text.h"
     19#include "resource_font.h"
    1920#include "font.h"
    20 
    21 #include "util/loading/resource_manager.h"
    2221#include "debug.h"
     22
     23ObjectListDefinition(Text);
    2324
    2425/**
     
    2829 */
    2930Text::Text(const std::string& fontFile, unsigned int textSize)
    30     // : _font(fontFile, FONT_DEFAULT_RENDER_SIZE)
    31 {
    32   this->setClassID(CL_TEXT, "Text");
     31// : _font(fontFile, FONT_DEFAULT_RENDER_SIZE)
     32{
     33  this->registerObject(this, Text::_objectList);
    3334
    3435  // initialize this Text
    35   this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE);
     36  if (!fontFile.empty())
     37    this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE);
     38  else
     39    this->setFont("fonts/final_frontier.ttf", FONT_DEFAULT_RENDER_SIZE);
    3640  this->_size = textSize;
    3741  this->setSizeY2D(textSize);
     
    4448    : _font()
    4549{
    46   this->setClassID(CL_TEXT, "Text");
     50  this->registerObject(this, Text::_objectList);
    4751
    4852  *this = text;
     
    169173void Text::setFont(const std::string& fontFile, unsigned int fontSize)
    170174{
    171   Font* newFont = NULL;
    172   //  Font* oldFont = this->_font;
    173 
    174   // load a new Font
    175   if (!fontFile.empty())
    176   {
    177     newFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize);
    178     if (newFont == NULL)
    179     {
    180       //      newFont = &Font::();
    181       PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile.c_str());
    182     }
    183   }
    184 
    185   if (newFont == NULL)
    186     this->_font = Font();
    187   else
    188     this->_font = *newFont;
     175  this->_font = ResourceFont(fontFile, fontSize);
    189176
    190177  this->setupTextWidth();
     
    233220  glRotatef(this->getAbsDir2D(), 0, 0, 1);
    234221
    235   Glyph* tmpGlyph;
     222  const Font::Glyph* tmpGlyph;
    236223  float posX = 0.0f;
    237224  glBegin(GL_QUADS);
  • trunk/src/lib/graphics/text_engine/text.h

    r8764 r9869  
    2626class Text : public Element2D
    2727{
     28  ObjectListDeclaration(Text);
    2829  public:
    2930    Text(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE);
  • trunk/src/lib/graphics/text_engine/text_engine.cc

    r9406 r9869  
    3333
    3434#include "graphics_engine.h"
    35 #include "util/loading/resource_manager.h"
    36 #include "class_list.h"
    3735
    3836#include "debug.h"
     
    4038/// TEXT-ENGINE ///
    4139///////////////////
     40ObjectListDefinition(TextEngine);
    4241/**
    4342 *  standard constructor
     
    4544TextEngine::TextEngine ()
    4645{
    47    this->setClassID(CL_TEXT_ENGINE, "TextEngine");
    48    this->setName("TextEngine");
    49    this->enableFonts();
     46  this->registerObject(this, TextEngine::_objectList);
     47  this->setName("TextEngine");
     48  this->enableFonts();
    5049}
    5150
     
    6261{
    6362  // 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   }
     63  while (!Text::objectList().empty())
     64    delete Text::objectList().front();
    7065  // 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)
     66
     67  //const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT);
     68  //if (fontList != NULL)
    7369  {
    7470    ///FIXME
    75 //    while (fontList->size() > 0)
     71    //    while (fontList->size() > 0)
    7672    {
    77 //      Font* font = dynamic_cast<Font*>(fontList->back());
     73      //      Font* font = dynamic_cast<Font*>(fontList->back());
    7874      //if (likely(font != Font::getDefaultFont()))
    7975      //        ResourceManager::getInstance()->unload(font, RP_GAME);
     
    9187{
    9288  if (!TTF_WasInit())
    93     {
    94       if(TTF_Init()==-1)
    95         PRINTF(1)("TTF_Init: %s\n", TTF_GetError());
     89  {
     90    if(TTF_Init()==-1)
     91      PRINTF(1)("TTF_Init: %s\n", TTF_GetError());
    9692
    97       TextEngine::checkVersion();
    98     }
     93    TextEngine::checkVersion();
     94  }
    9995  else
    10096    PRINTF(4)("Fonts already initialized\n");
     
    107103{
    108104  if (TTF_WasInit())
    109     {
    110 //      Font::removeDefaultFont();
    111       TTF_Quit();
    112     }
     105  {
     106    //      Font::removeDefaultFont();
     107    TTF_Quit();
     108  }
    113109  else
    114110    PRINTF(4)("Fonts were not initialized.\n");
     
    122118void TextEngine::debug() const
    123119{
    124   const std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT);
    125   if (textList != NULL)
     120  PRINT(0)("+-------------------------------+\n");
     121  PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n");
     122  PRINT(0)("+-------------------------------+\n");
     123  PRINT(0)("Reference: %p; Text Counts: %d\n", this, Text::objectList().size());
     124
     125  for (ObjectList<Text>::const_iterator it = Text::objectList().begin();
     126       it != Text::objectList().end();
     127       ++it)
    126128  {
    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();
     129      (*it)->debug();
    135130    PRINT(0)("+---------------------------TE--+\n");
    136131  }
     
    152147      compile_version.minor == link_version.minor &&
    153148      compile_version.patch == link_version.patch)
    154     {
    155       return true;
    156     }
     149  {
     150    return true;
     151  }
    157152  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);
     153  {
     154    PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n",
     155              compile_version.major,
     156              compile_version.minor,
     157              compile_version.patch);
    163158
    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     }
     159    PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n",
     160              link_version.major,
     161              link_version.minor,
     162              link_version.patch);
     163    return false;
     164  }
    170165}
  • trunk/src/lib/graphics/text_engine/text_engine.h

    r5515 r9869  
    2424class TextEngine : public BaseObject
    2525{
    26  public:
     26  ObjectListDeclaration(TextEngine);
     27  public:
    2728  virtual ~TextEngine();
    2829  /** @returns a Pointer to the only object of this Class */
Note: See TracChangeset for help on using the changeset viewer.