Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
May 21, 2006, 11:07:48 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Resize of the Shell works quite nice

Location:
trunk/src/lib
Files:
4 edited

Legend:

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

    r7756 r7757  
    2626 * @param type The renderType to display this font in
    2727 */
    28 MultiLineText::MultiLineText(const std::string& fontFile, unsigned int textSize, unsigned int lineWidth)
     28MultiLineText::MultiLineText(const std::string& fontFile, unsigned int textSize, float lineWidth)
    2929  : Text(fontFile, textSize)
    3030{
    3131  this->setClassID(CL_MULTI_LINE_TEXT, "MultiLineText");
    3232
    33   this->lineSpacing = 1.0f;
     33  this->lineSpacing = 1.0;
    3434  this->lineCount = 0;
    3535  this->setLineWidth(lineWidth);
     
    9393  for (unsigned int i = 0; i < this->getText().size(); ++i)
    9494  {
    95     if (unlikely(!this->lineEnds.empty() && i == this->lineEnds[lineNumber]))
     95    if (unlikely(this->lineEnds.size() > lineNumber && i == this->lineEnds[lineNumber]))
    9696    {
    9797      // go to the next Line.
    9898      ++lineNumber;
    99       posX = 0.0f;
     99      posX = 10.0f;
    100100      posY += this->lineSpacing + this->getSize(); //this->getFont()->getMaxHeight();
    101101    }
     
    149149      width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance;
    150150  }
    151 
    152   this->lineCount = lineEnds.size()+1;
     151  this->lineCount = lineEnds.size() + 1;
    153152  this->setSizeY2D((this->lineEnds.size()+1) * (this->lineSpacing + this->getFont()->getMaxHeight()));
    154153}
     154
     155void MultiLineText::debug() const
     156{
     157 printf("Debug %s::%s: %d lines\n", this->getClassName(), this->getName(), this->getLineCount());
     158
     159 std::string tmpText = this->getText();
     160 std::vector<unsigned int> ends = this->lineEnds;
     161 ends.push_back(tmpText.size());
     162
     163 unsigned int prev = 0;
     164  for (unsigned int i = 0; i < ends.size(); i++)
     165  {
     166    printf("Line %d: %s\n", i, tmpText.substr(prev, ends[i] - prev).c_str());
     167    prev = ends[i];
     168  }
     169}
  • trunk/src/lib/graphics/text_engine/multi_line_text.h

    r7754 r7757  
    1515{
    1616  public:
    17     MultiLineText(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE, unsigned int lineWidth = 100.0);
     17    MultiLineText(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE, float lineWidth = 100.0);
    1818
    1919    // Setup:
     
    3030    virtual void draw() const;
    3131
     32    void debug() const;
     33
    3234  protected:
    3335    virtual void setupTextWidth();
  • trunk/src/lib/shell/shell.cc

    r7750 r7757  
    6767    EventHandler::getInstance()->subscribe(this, ES_SHELL, SDLK_PAGEUP);
    6868    EventHandler::getInstance()->subscribe(this, ES_SHELL, SDLK_PAGEDOWN);
     69    EventHandler::getInstance()->subscribe(this, ES_SHELL, EV_VIDEO_RESIZE);
    6970
    7071    // BUFFER
     
    7677
    7778    // Element2D and generals
     79    this->setSizeX2D(GraphicsEngine::getInstance()->getResolutionX());
    7880    this->setAbsCoor2D(3, -400);
    7981    this->textSize = 15;
     
    136138        (*text)->setText("");
    137139    }
    138     repositionText();
     140    this->updateResolution( GraphicsEngine::getInstance()->getResolutionX());
     141    this->repositionText();
    139142  }
    140143
     
    226229  {
    227230    this->backgroundMaterial.setDiffuseMap(fileName);
     231  }
     232
     233
     234  /**
     235   * @brief updates the Shell's Width
     236   * @param width the new Width.
     237   */
     238  void Shell::updateResolution(unsigned int width)
     239  {
     240    if (width == this->getSizeX2D())
     241      return;
     242    this->setSizeX2D(width);
     243    for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
     244    {
     245      (*textIt)->setLineWidth(width);
     246    }
    228247  }
    229248
     
    402421
    403422
    404       (*textIt)->setRelCoor2D(calculateLinePosition( (linePos++ > 0)? linePos : 0));
     423      (*textIt)->setRelCoor2D(calculateLinePosition( (linePos++ > 0) ? linePos : 0));
    405424      (*textIt)->setText((*it));
    406425    }
     
    446465        this->moveDisplayBuffer(-this->bufferDisplaySize+1);
    447466      }
     467      else if (event.type == EV_VIDEO_RESIZE)
     468      {
     469        this->updateResolution(event.resize.w);
     470        this->repositionText();
     471      }
    448472    }
    449473  }
     
    487511  Vector2D Shell::calculateLinePosition(unsigned int lineNumber)
    488512  {
    489     return Vector2D(5, (int)(this->textSize + this->lineSpacing)*(int)((int)this->bufferDisplaySize - (int)lineNumber - (int)2) + (int)this->textSize);
     513    return Vector2D(5.0f, (float)(this->textSize + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1));
    490514  }
    491515
  • trunk/src/lib/shell/shell.h

    r7753 r7757  
    8181    void testShell() const;
    8282  private:
     83    void updateResolution(unsigned int width);
    8384    void repositionText();
    8485    void applyTextSettings(Text* text);
Note: See TracChangeset for help on using the changeset viewer.