Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8760 in orxonox.OLD


Ignore:
Timestamp:
Jun 24, 2006, 2:14:37 AM (18 years ago)
Author:
bensch
Message:

orxonox/font: nicer implementation

Location:
branches/fontdata/src/lib/graphics/text_engine
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/fontdata/src/lib/graphics/text_engine/font.h

    r8758 r8760  
    2828
    2929  Font& operator=(const Font& font);
     30  /** @brief compare two fonts @param font the comparator, @returns true if they match */
    3031  bool operator==(const Font& font) const { return this->data == font.data; };
    3132
     
    4546  int getMaxAscent() const;
    4647  int getMaxDescent() const;
    47 
    48   /** @returns the default Font */
    49   //inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; };
    50 
    5148
    5249  void createAsciiImage(const std::string& fileName, unsigned int size) const;
  • branches/fontdata/src/lib/graphics/text_engine/text.cc

    r8759 r8760  
    2828 */
    2929Text::Text(const std::string& fontFile, unsigned int textSize)
    30   : _font(fontFile, FONT_DEFAULT_RENDER_SIZE)
     30    : _font(fontFile, FONT_DEFAULT_RENDER_SIZE)
    3131{
    3232  this->setClassID(CL_TEXT, "Text");
     
    3535  this->_size = textSize;
    3636  this->setSizeY2D(textSize);
    37   this->_color = TEXT_DEFAULT_COLOR;
     37  this->setColor(TEXT_DEFAULT_COLOR);
    3838
    3939  this->setAlignment(TEXT_DEFAULT_ALIGNMENT);
     
    4141
    4242Text::Text(const Text& text)
    43   : _font()
     43    : _font()
    4444{
    4545  this->setClassID(CL_TEXT, "Text");
     
    5454Text::~Text()
    5555{
    56 /*  if (this->_font != NULL && this->_font != Font::getDefaultFont())
    57     ResourceManager::getInstance()->unload(this->_font);*/
     56  /*  if (this->_font != NULL && this->_font != Font::getDefaultFont())
     57      ResourceManager::getInstance()->unload(this->_font);*/
    5858}
    5959
     
    6767  return (this->_text == text._text &&
    6868          this->_size == text._size &&
    69           this->_font == text._font &&
    70           this->_color == text._color);
     69          this->_font == text._font );
    7170}
    7271
     
    8988{
    9089  this->_size = text._size;
    91   this->_color = text._color;
    9290  this->setAlignment(text.getAlignment());
    9391
     
    171169{
    172170  Font* newFont = NULL;
    173 //  Font* oldFont = this->_font;
     171  //  Font* oldFont = this->_font;
    174172
    175173  // load a new Font
     
    179177    if (newFont == NULL)
    180178    {
    181 //      newFont = &Font::();
     179      //      newFont = &Font::();
    182180      PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile.c_str());
    183181    }
    184182  }
    185 //  if (newFont == NULL)
    186 //    newFont = Font::getDefaultFont();
    187   assert(newFont != NULL);
    188 
    189   // unloading the Font if we alrady have one loaded.
    190 
    191   this->_font = *newFont;
    192 //   if (oldFont != NULL && oldFont != Font::getDefaultFont())
    193 //     ResourceManager::getInstance()->unload(oldFont);
    194 
     183
     184  if (newFont == NULL)
     185    this->_font = Font();
     186  else
     187    this->_font = *newFont;
     188
     189  printf("Font Texture is\n" );
     190  _font.debug();
    195191  this->setupTextWidth();
    196192}
     
    223219    glTranslatef(-this->getSizeX2D()/2, 0, 0);
    224220
    225   // drawing this Text.
    226   // setting the Blending effects
    227   glColor4fv(&this->_color[0]);
    228 
    229221  this->font().select();
    230222  glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
     
    278270{
    279271  PRINT(0)("=== TEXT: %s (with Font:'%s')  displaying %s ===\n", this->getName(), this->_font.getName(), this->_text.c_str());
    280   PRINT(0)("Color: r=%0.2f g=%0.2f b=%0.2f a=%0.2f\n", this->_color.r(), this->_color.g(), this->_color.b(), this->_color.a());
    281 }
    282 
     272  //  PRINT(0)("Color: r=%0.2f g=%0.2f b=%0.2f a=%0.2f\n", this->_color.r(), this->_color.g(), this->_color.b(), this->_color.a());
     273}
     274
  • branches/fontdata/src/lib/graphics/text_engine/text.h

    r8754 r8760  
    4545    void setFont(const std::string& fontFile, unsigned int renderSize);
    4646    /** @param blending the blending intensity to set (between 0.0 and 1.0) */
    47     inline void setBlending(float blending) { this->_color.a() = blending; };
     47    inline void setBlending(float blending) { this->_font.setTransparency(blending); };
    4848    /** @param r red @param g green @param b blue @brief sets the Color of the Text to render (values in [0-1]) */
    49     void setColor(float r, float g, float b) { this->_color = Color(r, g, b, this->_color.a()); };
    50     void setColor(float r, float g, float b, float a) { this->_color = Color(r, g, b, a); };
    51     void setColor(const Color& color) { this->_color = color; };
     49    void setColor(float r, float g, float b) { this->_font.setDiffuseColor(Color(r, g, b, this->blending())); };
     50    void setColor(float r, float g, float b, float a) { this->_font.setDiffuseColor(Color(r, g, b, a)); };
     51    void setColor(const Color& color) { this->_font.setDiffuseColor(color); };
    5252    void setSize(float size);
    5353
     
    6060    inline const Font& font() const { return this->_font; };
    6161    /** @returns the Blending Value [0 invisible 1.0 full visible */
    62     inline float blending() const { return this->_color.a(); };
     62    inline float blending() const { return this->_font.diffuseColor().a(); };
    6363    /** @returns: a Vector(r,g,b) @brief: retrieve a Vector holding the Color of the Text */
    64     inline const Color& color() const { return this->_color; };
     64    inline const Color& color() const { return this->_font.diffuseColor(); };
    6565    /** @returns the Size of the Text */
    6666    inline float size() const { return this->_size; };
     
    7979
    8080    std::string       _text;           //!< The text to display
    81     Color             _color;          //!< The color of the font.
    8281    float             _size;           //!< The size of the Text.
    8382};
Note: See TracChangeset for help on using the changeset viewer.