Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Apr 28, 2006, 10:27:28 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ShellFont can be changed in threads :)

Location:
trunk/src/lib
Files:
3 edited

Legend:

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

    r7355 r7426  
    6565void Text::setFont(const std::string& fontFile, unsigned int fontSize)
    6666{
    67   Font* tmpFont;
    68   Text* newText;
    69   Vector tmpVec;
    70 
    71   // unloading the Font if we alrady have one loaded.
    72   if (this->font != NULL && this->font != Font::getDefaultFont())
    73     ResourceManager::getInstance()->unload(this->font);
    74   this->font = NULL;
     67  Font* newFont;
     68  Font* oldFont = this->font;
    7569
    7670  // load a new Font
    7771  if (!fontFile.empty())
    7872  {
    79     tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize);
    80     if (tmpFont != NULL)
    81       this->font = tmpFont;
    82     else
     73    newFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize);
     74    if (newFont == NULL)
     75    {
     76      newFont = Font::getDefaultFont();
    8377      PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile.c_str());
    84   }
     78    }
     79  }
     80  else
     81    newFont = Font::getDefaultFont();
     82
     83  // unloading the Font if we alrady have one loaded.
     84  this->font = newFont;
     85  if (oldFont != NULL && oldFont != Font::getDefaultFont())
     86    ResourceManager::getInstance()->unload(oldFont);
    8587}
    8688
  • trunk/src/lib/shell/shell.cc

    r7422 r7426  
    8585    // Element2D and generals
    8686    this->setAbsCoor2D(3, -400);
    87     this->textSize = 20;
     87    this->textSize = 15;
    8888    this->lineSpacing = 0;
    8989    this->bActive = true;
     
    250250  void Shell::resetValues()
    251251  {
    252     this->shellInput.setFont(this->fontFile, this->textSize);
    253     this->shellInput.setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
    254     this->shellInput.setBlending(this->textColor[3]);
    255     this->shellInput.setRelCoor2D(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize));
    256     this->shellInput.setLayer(this->getLayer());
    257     if (shellInput.getParent2D() != this)
    258       this->shellInput.setParent2D(this);
     252    this->resetText(&this->shellInput, 0);
     253    this->shellInput.setRelCoor2D(15, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize));
    259254
    260255    unsigned int i = 0;
    261     for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text, ++i)
    262     {
    263       (*text)->setFont(this->fontFile, this->textSize);
    264       (*text)->setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
    265       (*text)->setBlending(this->textColor[3]);
     256    /* Here we create a Copy of the Buffer, so that we do not f**k up the List when some
     257     * output is routed from Some other Thread or by Changing any Values.
     258     */
     259    std::list<Text*> bufferTextCopy = this->bufferText;
     260    for (std::list<Text*>::iterator text = bufferTextCopy.begin(); text != bufferTextCopy.end(); ++text, ++i)
     261    {
     262      this->resetText(*text, i);
    266263      (*text)->setRelCoor2D( calculateLinePosition(i) );
    267       (*text)->setLayer(this->getLayer());
    268       if ((*text)->getParent2D() != this)
    269         (*text)->setParent2D(this);
    270264    }
    271265    this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1);
     266  }
     267
     268  void Shell::resetText(Text* text, unsigned int position)
     269  {
     270    text->setFont(this->fontFile, this->textSize);
     271    text->setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
     272    text->setBlending(this->textColor[3]);
     273    text->setLayer(this->getLayer());
     274    if (text->getParent2D() != this)
     275      text->setParent2D(this);
    272276  }
    273277
  • trunk/src/lib/shell/shell.h

    r7377 r7426  
    6262    void setBackgroundImage(const std::string& fileName);
    6363
    64     void resetValues();
    65 
    6664    // BUFFERS
    6765    void setBufferDisplaySize(unsigned int bufferDisplaySize);
     
    8179
    8280  private:
     81    void resetValues();
     82    void resetText(Text* text, unsigned int position);
    8383    // helpers //
    8484    Vector2D calculateLinePosition(unsigned int lineNumber);
Note: See TracChangeset for help on using the changeset viewer.