Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5372 in orxonox.OLD for trunk/src/lib/shell


Ignore:
Timestamp:
Oct 13, 2005, 12:40:04 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: nicer rendering of the Shell

Location:
trunk/src/lib/shell
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell.cc

    r5369 r5372  
    2525#include "list.h"
    2626#include "graphics_engine.h"
     27#include "material.h"
    2728#include "event_handler.h"
    2829#include "debug.h"
     
    6162  EventHandler::getInstance()->subscribe(this, ES_SHELL, SDLK_PAGEDOWN);
    6263
     64  // BUFFER
     65  this->bufferText = NULL;
     66  this->bufferDisplaySize = 10;
     67  this->bufferOffset = 0;
     68  this->bufferIterator = ShellBuffer::getInstance()->getBuffer()->getIterator();
     69
     70  // INPUT LINE
     71  this->shellInput = new ShellInput;
     72
     73  this->backgroundMaterial = new Material;
    6374  // Element2D and generals
    6475  this->setAbsCoor2D(3, -400);
     
    6980  strcpy(this->fontFile, SHELL_DEFAULT_FONT);
    7081
    71   // BUFFER
    72   this->bufferText = NULL;
    73   this->bufferDisplaySize = 10;
    74   this->bufferOffset = 0;
    75   this->bufferIterator = ShellBuffer::getInstance()->getBuffer()->getIterator();
    76 
    77   // INPUT LINE
    78   this->shellInput = new ShellInput;
    79   //this->commandList = new tList<ShellCommand>;
    8082
    8183  this->rebuildText();
     84  this->setTextColor(SHELL_DEFAULT_TEXT_COLOR);
     85  this->setBackgroundColor(SHELL_DEFAULT_BACKGROUND_COLOR);
    8286
    8387  // register the shell at the ShellBuffer
     
    100104  // delete the inputLine
    101105  delete this->shellInput;
     106  delete this->backgroundMaterial;
    102107}
    103108
     
    183188  this->textSize = textSize;
    184189  this->lineSpacing = lineSpacing;
    185   this->shellInput->setSize(this->textSize);
    186   this->shellInput->setRelCoor2D(5, (this->textSize + this->lineSpacing)*this->bufferDisplaySize + this->textSize);
     190  this->resetValues();
     191}
     192
     193/**
     194 * sets the color of the Font.
     195 * @param r: red
     196 * @param g: green
     197 * @param b: blue
     198 * @param a: alpha-value.
     199 */
     200void Shell::setTextColor(float r, float g, float b, float a)
     201{
     202  this->textColor[0] = r;
     203  this->textColor[1] = g;
     204  this->textColor[2] = b;
     205  this->textColor[3] = a;
     206
     207  this->resetValues();
     208}
     209
     210
     211/**
     212 * sets the color of the Backgrond.
     213 * @param r: red
     214 * @param g: green
     215 * @param b: blue
     216 * @param a: alpha-value.
     217 */
     218void Shell::setBackgroundColor(float r, float g, float b, float a)
     219{
     220  this->backgroundMaterial->setDiffuse(r, g, b);
     221  this->backgroundColor[0] = r;
     222  this->backgroundColor[1] = g;
     223  this->backgroundColor[2] = b;
     224  this->backgroundColor[3] = a;
     225  this->backgroundMaterial->setTransparency(a);
     226}
     227
     228/**
     229 * resets the Values of all visible shell's commandos to the Shell's stored values
     230 *
     231 * this functions synchronizes the stored Data with the visible one.
     232 */
     233void Shell::resetValues()
     234{
     235  if (this->shellInput != NULL)
     236  {
     237    this->shellInput->setSize(this->textSize);
     238    this->shellInput->setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
     239    this->shellInput->setBlending(this->textColor[3]);
     240    this->shellInput->setRelCoor2D(5, (this->textSize + this->lineSpacing)*this->bufferDisplaySize + this->textSize);
     241  }
    187242
    188243  if (this->bufferText != NULL)
     
    193248      {
    194249        this->bufferText[i]->setSize(this->textSize);
    195         this->bufferText[i]->setRelCoorSoft2D(calculateLinePosition(i));
     250        this->bufferText[i]->setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
     251        this->bufferText[i]->setBlending(this->textColor[3]);
     252        this->bufferText[i]->setRelCoor2D(calculateLinePosition(i));
    196253      }
    197254    }
     
    209266{
    210267  this->shellInput->setFont(this->fontFile, this->textSize);
    211   this->shellInput->setColor(1, 0, 0);
    212268  this->shellInput->setAlignment(TEXT_ALIGN_LEFT);
    213269  if (shellInput->getParent() != this)
    214270    this->shellInput->setParent2D(this);
    215   this->shellInput->setRelCoor2D(5, (this->textSize + this->lineSpacing)*this->bufferDisplaySize + this->textSize);
    216271
    217272  this->setBufferDisplaySize(this->bufferDisplaySize);
     
    239294  {
    240295    bufferText[i] = new Text(this->fontFile, this->textSize, TEXT_RENDER_DYNAMIC);
    241     bufferText[i]->setColor(1, 0, 0);
    242296    bufferText[i]->setAlignment(TEXT_ALIGN_LEFT);
    243     bufferText[i]->setRelCoor2D(calculateLinePosition(i));
    244297    bufferText[i]->setText(text);
    245298    bufferText[i]->setParent2D(this);
     
    391444  // setting the Blending effects
    392445
    393   glColor4f(0.0f, 0.0f, 0.8f, .4);
    394   glEnable(GL_BLEND);
    395   glDisable(GL_TEXTURE_2D);
    396   glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    397 
    398   glBindTexture(GL_TEXTURE_2D, 0);
     446  this->backgroundMaterial->select();
     447  glColor4f(*(this->backgroundColor),
     448            *(this->backgroundColor+1),
     449            *(this->backgroundColor+2),
     450            *(this->backgroundColor+3));
     451
     452
    399453  glBegin(GL_TRIANGLE_STRIP);
    400454
  • trunk/src/lib/shell/shell.h

    r5253 r5372  
    44 *
    55 * @todo Buffer Display in different Colors for different debug mode.
     6 * @todo choose color of the Font and the background.
    67 */
    78
     
    1415#include <stdarg.h>
    1516
    16 #define         SHELL_DEFAULT_FONT      "fonts/dpquake_.ttf"
     17#define         SHELL_DEFAULT_FONT              "fonts/dpquake_.ttf"
     18#define         SHELL_DEFAULT_TEXT_COLOR        1,0,0,1
     19#define         SHELL_DEFAULT_BACKGROUND_COLOR  0,0,.8,.8
    1720
    1821// FORWARD DECLARATION
    1922class Text;
    2023class ShellInput;
     24class Material;
    2125template<class T> class tIterator;
    2226
     
    5256    void setFont(const char* fontFile);
    5357    void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1);
     58    void setTextColor(float r, float g, float b, float a);
     59    void setBackgroundColor(float r, float g, float b, float a);
     60
     61    void resetValues();
    5462    void rebuildText();
    5563
     
    8694    unsigned int             lineSpacing;            //!< The Spacing between lines.
    8795    unsigned int             textSize;               //!< The size of the text.
     96    float                    textColor[4];           //!< The text's color [r,g,b,a].
    8897    char*                    fontFile;               //!< The file containing the font.
     98    Material*                backgroundMaterial;     //!< A material for the background.
     99    float                    backgroundColor[4];     //!< The color of the background [r,g,b,a].
    89100
    90101    // HANDLING TEXT INPUT
Note: See TracChangeset for help on using the changeset viewer.