Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5251 in orxonox.OLD


Ignore:
Timestamp:
Sep 25, 2005, 1:13:19 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: saver change between fonts in Shell

Location:
trunk/src/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r5215 r5251  
    3636/**
    3737 * standard constructor
    38  * @todo this constructor is not jet implemented - do it
    39 */
     38 * @param parent the Parent of this node (default NULL)
     39 */
    4040Element2D::Element2D (Element2D* parent)
    4141{
     
    4848/**
    4949 * standard deconstructor
    50 */
     50 */
    5151Element2D::~Element2D ()
    5252{
     
    5454  Render2D::getInstance()->unregisterElement2D(this);
    5555
    56   if (this->parent)
    57     this->parent->removeChild2D(this);
    58   else
    59   {
    60     tIterator<Element2D>* iterator = this->children->getIterator();
    61     Element2D* pn = iterator->firstElement();
    62     while( pn != NULL)
    63     {
    64       delete pn;
    65       pn = iterator->nextElement();
    66     }
    67     delete iterator;
    68     /* this deletes all children in the list */
    69   }
     56  this->remove2D();
     57//   else
     58//   {
     59//     tIterator<Element2D>* iterator = this->children->getIterator();
     60//     Element2D* pn = iterator->firstElement();
     61//     while( pn != NULL)
     62//     {
     63//       delete pn;
     64//       pn = iterator->nextElement();
     65//     }
     66//     delete iterator;
     67//     /* this deletes all children in the list */
     68//   }
    7069  delete this->children;
    7170
     
    9089  this->bindNode = NULL;
    9190
     91  // PNODE-stuff
     92  this->children = new tList<Element2D>;
    9293  this->setParentMode2D(E2D_PARENT_ALL);
    93   this->parent = NULL;
    94   this->children = new tList<Element2D>;
     94  if (NullElement2D::isInstanciated())
     95  {
     96    this->parent = NullElement2D::getInstance();
     97    NullElement2D::getInstance()->children->add(this);
     98    NullElement2D::getInstance()->debug(0);
     99  }
     100  else
     101    this->parent = NULL;
    95102  this->absDirection = 0.0;
    96103  this->relDirection = 0.0;
     
    442449  if( likely(child->parent != NULL))
    443450  {
    444     PRINTF(4)("Element2D::addChild() - reparenting node: removing it and adding it again\n");
    445451    child->parent->children->remove(child);
    446452  }
     
    505511void Element2D::setParent2D (Element2D* parent)
    506512{
    507   parent->addChild2D(this);
     513  if (parent != NULL)
     514    parent->addChild2D(this);
    508515}
    509516
     
    517524  if (parentNode != NULL)
    518525    parentNode->addChild2D(this);
    519 
    520526}
    521527
  • trunk/src/lib/graphics/render2D/element_2d.h

    r5215 r5251  
    218218  public:
    219219    /** @returns a Pointer to the only object of this Class */
    220     inline static NullElement2D* getInstance() { if (!singletonRef) singletonRef = new NullElement2D();  return singletonRef; };
     220    inline static NullElement2D* getInstance() { if (!NullElement2D::singletonRef) NullElement2D::singletonRef = new NullElement2D();  return NullElement2D::singletonRef; };
     221    inline static bool isInstanciated() { return (likely(NullElement2D::singletonRef != NULL))?true:false; };
    221222    virtual ~NullElement2D ();
    222223
  • trunk/src/lib/shell/shell.cc

    r5249 r5251  
    6464  this->lineSpacing = 0;
    6565  this->bActive = false;
     66  this->fontFile = NULL;
     67  this->setFont("fonts/dpquake_.ttf");
    6668
    6769  // BUFFER
     
    8890  delete[] this->bufferText;
    8991  delete this->bufferIterator;
    90 
     92  delete[] this->fontFile;
    9193  // delete the inputLine
    9294  delete this->shellInput;
     
    123125void Shell::deactivate()
    124126{
     127   this->setFont("fonts/dark_crystal.ttf");
     128   this->rebuildText();
     129
    125130  if (this->bActive == false)
    126131    PRINTF(3)("The shell is already inactive\n");
     
    140145
    141146  this->bufferOffset = 0;
     147}
     148
     149/**
     150 * sets the File to load the fonts from
     151 * @param fontFile the file to load the font from
     152 */
     153void Shell::setFont(const char* fontFile)
     154{
     155  if (this->fontFile != NULL)
     156    delete[] this->fontFile;
     157
     158  this->fontFile = new char[strlen(fontFile)+1];
     159  strcpy(this->fontFile, fontFile);
     160
    142161}
    143162
     
    154173  this->textSize = textSize;
    155174  this->lineSpacing = lineSpacing;
    156   this->shellInput->setFont("fonts/dpquake_.ttf", this->textSize);
     175  this->shellInput->setFont(this->fontFile, this->textSize);
    157176
    158177//  this->rebuildText();
     
    166185void Shell::rebuildText()
    167186{
    168   this->shellInput->setFont("fonts/dpquake_.ttf", this->textSize);
     187  this->shellInput->setFont(this->fontFile, this->textSize);
    169188  this->shellInput->setColor(1, 0, 0);
    170189  this->shellInput->setAlignment(TEXT_ALIGN_LEFT);
     
    181200void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize)
    182201{
     202  Text** bufferText = this->bufferText;
     203  this->bufferText = NULL;
     204  if (bufferText != NULL)
     205  {
     206    for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
     207      delete bufferText[i];
     208    delete[] bufferText;
     209  }
     210
     211  bufferText = new Text*[bufferDisplaySize];
     212  for (unsigned int i = 0; i < bufferDisplaySize; i++)
     213  {
     214    bufferText[i] = TextEngine::getInstance()->createText(this->fontFile, this->textSize, TEXT_RENDER_DYNAMIC);
     215    bufferText[i]->setColor(1, 0, 0);
     216    bufferText[i]->setAlignment(TEXT_ALIGN_LEFT);
     217    bufferText[i]->setRelCoor2D(calculateLinePosition(i));
     218    bufferText[i]->setText(NULL);
     219    bufferText[i]->setParent2D(this);
     220  }
     221  this->bufferDisplaySize = bufferDisplaySize;
     222
     223  this->bufferText = bufferText;
     224  this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1);
     225}
     226
     227/**
     228 * deletes all the Buffers
     229 */
     230void Shell::flush()
     231{
     232  // remove all chars from the BufferTexts.
    183233  if (this->bufferText != NULL)
    184   {
    185     for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    186       delete this->bufferText[i];
    187     delete[] this->bufferText;
    188   }
    189 
    190   this->bufferText = new Text*[bufferDisplaySize];
    191   for (unsigned int i = 0; i < bufferDisplaySize; i++)
    192   {
    193     this->bufferText[i] = TextEngine::getInstance()->createText("fonts/dpquake_.ttf", this->textSize, TEXT_RENDER_DYNAMIC);
    194     this->bufferText[i]->setColor(1, 0, 0);
    195     this->bufferText[i]->setAlignment(TEXT_ALIGN_LEFT);
    196     this->bufferText[i]->setRelCoor2D(calculateLinePosition(i));
    197     this->bufferText[i]->setText(NULL);
    198     this->bufferText[i]->setParent2D(this);
    199   }
    200   this->bufferDisplaySize = bufferDisplaySize;
    201 
    202   this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1);
    203 }
    204 
    205 /**
    206  * deletes all the Buffers
    207  */
    208 void Shell::flush()
    209 {
    210   // remove all chars from the BufferTexts.
    211   if (this->bufferText)
    212234    for (int i = 0; i < this->bufferDisplaySize; i++)
    213235    {
  • trunk/src/lib/shell/shell.h

    r5248 r5251  
    4848    inline bool isActive() const { return this->bActive; };
    4949
     50    void setFont(const char* fontFile);
    5051    void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1);
    5152    void rebuildText();
     
    8384    unsigned int             lineSpacing;            //!< The Spacing between lines.
    8485    unsigned int             textSize;               //!< The size of the text.
    85     char*                    textFont;               //!< The file containing the font.
     86    char*                    fontFile;               //!< The file containing the font.
    8687
    8788    // HANDLING TEXT INPUT
Note: See TracChangeset for help on using the changeset viewer.