Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8614 in orxonox.OLD for branches


Ignore:
Timestamp:
Jun 20, 2006, 11:51:17 AM (18 years ago)
Author:
bensch
Message:

gui: added table

Location:
branches/gui/src
Files:
2 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/gui/src/defs/class_id.h

    r8538 r8614  
    363363  CL_GLGUI_TEXTFIELD            =    0x00000b61,
    364364  CL_GLGUI_IMAGE                =    0x00000b70,
     365  CL_GLGUI_TABLE                =    0x00000b71,
    365366
    366367  CL_GLGUI_NOTIFIER             =    0x00000b80,
  • branches/gui/src/lib/gui/gl/Makefile.am

    r8599 r8614  
    2626                glgui_inputline.cc \
    2727                glgui_textfield.cc \
     28                glgui_table.cc \
    2829                glgui_image.cc \
    2930                glgui_window.cc \
     
    5253                glgui_inputline.h \
    5354                glgui_textfield.h \
     55                glgui_table.h \
    5456                glgui_image.h \
    5557                glgui_window.h \
  • branches/gui/src/lib/gui/gl/glgui_table.cc

    r8613 r8614  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
    1717
    18 #include "glgui_inputline.h"
     18#include "glgui_table.h"
    1919
    2020namespace OrxGui
     
    2323   * @brief standard constructor
    2424   */
    25   GLGuiInputLine::GLGuiInputLine ()
     25  GLGuiTable::GLGuiTable ()
    2626  {
    2727    this->init();
     
    3232   * @brief standard deconstructor
    3333   */
    34   GLGuiInputLine::~GLGuiInputLine()
     34  GLGuiTable::~GLGuiTable()
    3535  {}
    36 
    37   float GLGuiInputLine::repeatDelay = 0.3f;
    38   float GLGuiInputLine::repeatRate  = 0.01f;
    39 
    4036
    4137  /**
    4238   * @brief initializes the GUI-element
    4339   */
    44   void GLGuiInputLine::init()
     40  void GLGuiTable::init()
    4541  {
    46     this->setClassID(CL_GLGUI_INPUTLINE, "GLGuiInputLine");
     42    this->setClassID(CL_GLGUI_TABLE, "GLGuiTable");
    4743
    4844    this->setFocusable(true);
     45    this->setClickable(true);
    4946
    50     this->_clearOnEnter = false;
    51     this->_text.setParent2D(this);
    52     this->_text.setRelCoor2D(4,4);
    53     this->_text.setFont("fonts/final_frontier.ttf", 20);
    54     this->_text.setLineWidth(400);
    55     this->_text.setDotsPosition(LimitedWidthText::Begin);
    56     this->_text.setColor(foregroundColor());
    57     this->_text.setVisibility(false);
    5847    this->resize();
    59 
    60     this->delayNext = 0.0;
    61     this->pressedKey = SDLK_FIRST;
    62     this->pressedKeyName = SDLK_FIRST;
    63 
    6448  }
    6549
    6650
    67   /**
    68    * @brief sets the Text of the InputLine
    69    * @param text The new Text.
    70    */
    71   void GLGuiInputLine::setText(const std::string& text)
     51  void GLGuiTable::setRowCount(unsigned int rowCount)
    7252  {
    73     this->_text.setText(text);
    74     this->changedText();
     53    this->_headers.resize(rowCount);
     54    for (unsigned int i = 0; i < rowCount; i++)
     55      this->_entries[i].resize(rowCount);
     56
     57    if (!this->isVisible())
     58      this->hiding();
    7559  }
    7660
    77   /**
    78    * @brief appends text to the InputLine
    79    * @param appendText the Text to append
    80    */
    81   void GLGuiInputLine::append(const std::string& appendText)
     61  void GLGuiTable::setColumnCount(unsigned int columnCount)
    8262  {
    83     this->_text.append(appendText);
    84     this->changedText();
     63    this->_entries.resize(columnCount);
     64    if (!this->isVisible())
     65      this->hiding();
    8566  }
    8667
    8768
    88   /**
    89    * @brief appends a Character to the InputLine
    90    * @param character the Character to append.
    91    */
    92   void GLGuiInputLine::appendCharacter(char character)
    93   {
    94     this->_text.appendCharacter(character);
    95     this->changedText();
    96   }
    97 
    98 
    99   /**
    100    * @brief Removes Characters from the InputLine
    101    * @param chars The count of characters to remove
    102    */
    103   void GLGuiInputLine::removeCharacters(unsigned int chars)
    104   {
    105     this->_text.removeCharacters(chars);
    106     this->changedText();
    107   }
    108 
    109   void GLGuiInputLine::clear()
    110   {
    111     this->_text.clear();
    112     this->changedText();
    113   }
    114 
    115   /**
    116    * @brief If the Text has been changed this function is called.
    117    *
    118    * This Function also emits the Signal textChanged.
    119    */
    120   void GLGuiInputLine::changedText()
    121   {
    122     this->resize();
    123     this->setFrontColor(Color(1,1,1,1), true);
    124     emit(this->textChanged(this->_text.text()));
    125   }
    12669
    12770
     
    12972   * removes the focus from this Widget.
    13073   */
    131   void GLGuiInputLine::removedFocus()
     74  void GLGuiTable::removedFocus()
    13275  {
    13376    GLGuiWidget::removedFocus();
    134     this->pressedKey = 0;
    135     this->pressedKeyName = 0;
    13677  }
    13778
    138   /**
    139    * @brief handles the EnterPush-Event.
    140    *
    141    * Emmits th EnterPushed Signal with the current Line,
    142    * and if _clearOnEnter is pushed clears the Line.
    143    */
    144   void GLGuiInputLine::pushEnter()
    145   {
    146     emit(this->enterPushed(this->_text.text()));
    147     if (this->_clearOnEnter)
    148       this->clear();
    149   }
    15079
    15180
     
    15584   * @return true if the event was catched.
    15685   */
    157   bool GLGuiInputLine::processEvent(const Event& event)
     86  bool GLGuiTable::processEvent(const Event& event)
    15887  {
    159     if (event.bPressed)
    160     {
    161       if (event.type == SDLK_BACKSPACE)
    162       {
    163         this->delayNext = GLGuiInputLine::repeatDelay;
    164         this->pressedKey = SDLK_BACKSPACE;
    165         this->pressedKeyName = SDLK_BACKSPACE;
    166         this->removeCharacters(1);
    167         return true;
    168       }
    169       else if(event.type == SDLK_RETURN || event.type == SDLK_KP_ENTER)
    170       {
    171         this->pushEnter();
    172         return true;
    173       }
    174       // any other keyboard key
    175       else if (likely(event.type < 127))
    176       {
    177         this->delayNext = GLGuiInputLine::repeatDelay;
    178 
    179         this->appendCharacter(event.x);
    180         this->pressedKey = event.type;
    181         this->pressedKeyName = event.x;
    182         return true;
    183       }
    184     }
    185     else // if(!event.bPressed)
    186     {
    187       if (this->pressedKey == event.type)
    188       {
    189         this->pressedKeyName = 0;
    190         this->pressedKey = 0;
    191         this->delayNext = 0.0;
    192         return true;
    193       }
    194     }
    19588    return false;
    19689  }
     
    20093   * @brief Resizes the Widget to the new Size-constraints.
    20194   */
    202   void GLGuiInputLine::resize()
     95  void GLGuiTable::resize()
    20396  {
    204     this->_text.setRelCoor2D(borderLeft(), borderTop());
    205     this->setSize2D( this->_text.getSize2D() + Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));
    20697    GLGuiWidget::resize();
    207     /*    this->frontRect().setTopLeft(borderLeft(), borderTop());
    208         this->frontRect().setSize(this->getSize2D() - Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));*/
    20998  }
    21099
    211   void GLGuiInputLine::updateFrontColor()
     100  void GLGuiTable::updateFrontColor()
    212101  {
    213     this->_text.setColor(foregroundColor());
     102    for (unsigned int i = 0; i < this->rowCount(); ++i)
     103    {
     104      this->_headers[i].setColor(this->foregroundColor());
     105      for (unsigned int j = 0; j < this->columnCount(); ++j)
     106        this->_entries[i][j].setColor(this->foregroundColor());
     107    }
    214108  }
    215109
    216   void GLGuiInputLine::hiding()
     110  void GLGuiTable::hiding()
    217111  {
    218     this->_text.setVisibility(false);
     112    for (unsigned int i = 0; i < this->rowCount(); ++i)
     113    {
     114      this->_headers[i].setVisibility(false);
     115      for (unsigned int j = 0; j < this->columnCount(); ++j)
     116        this->_entries[i][j].setVisibility(false);
     117    }
    219118  }
    220119
    221   void GLGuiInputLine::showing()
     120  void GLGuiTable::showing()
    222121  {
    223     this->_text.setVisibility(true);
     122    for (unsigned int i = 0; i < this->rowCount(); ++i)
     123    {
     124      this->_headers[i].setVisibility(true);
     125      for (unsigned int j = 0; j < this->columnCount(); ++j)
     126        this->_entries[i][j].setVisibility(true);
     127    }
    224128  }
    225129
    226130  /**
    227    * @brief ticks the InputLine
     131   * @brief ticks the Table
    228132   * @param dt the time passed.
    229133   */
    230   void GLGuiInputLine::tick(float dt)
     134  void GLGuiTable::tick(float dt)
    231135  {
    232     GLGuiWidget::tick(dt);
    233     if (this->delayNext > 0.0)
    234       this->delayNext -= dt;
    235     else if (this->pressedKey != SDLK_FIRST )
    236     {
    237       this->delayNext = GLGuiInputLine::repeatRate;
    238       switch (this->pressedKey)
    239       {
    240         case SDLK_BACKSPACE:
    241           this->removeCharacters(1);
    242           break;
    243         default:
    244           {
    245             if (likely(this->pressedKey < 127))
    246               this->appendCharacter(this->pressedKeyName);
    247           }
    248       }
    249     }
    250 
    251 
    252136  }
    253137
    254138  /**
    255    * @brief draws the GLGuiInputLine
     139   * @brief draws the GLGuiTable
    256140   */
    257   void GLGuiInputLine::draw() const
     141  void GLGuiTable::draw() const
    258142  {
    259143    this->beginDraw();
  • branches/gui/src/lib/gui/gl/glgui_table.h

    r8613 r8614  
    11/*!
    2  * @file glgui_inputline.h
    3  * The gl_INPUTLINE widget of th openglGUI
     2 * @file glgui_table.h
     3 * The gl_TABLE widget of th openglGUI
    44 *
    55 */
    66
    7 #ifndef _GLGUI_INPUTLINE_H
    8 #define _GLGUI_INPUTLINE_H
     7#ifndef _GLGUI_TABLE_H
     8#define _GLGUI_TABLE_H
    99
    1010#include "glgui_widget.h"
     
    1616{
    1717
    18   //! This is InputLine part of the openglGUI class
     18  //! This is Table part of the openglGUI class
    1919  /**
    20    * The InputLine is a Widget, that displays a Line, that can be manipulated through
     20   * The Table is a Widget, that displays a Line, that can be manipulated through
    2121   * Writing Text on it.
    2222   *
    2323   * Whenever the Text is changed the textChanged signal is emitted.
    2424   */
    25   class GLGuiInputLine : public OrxGui::GLGuiWidget
     25  class GLGuiTable : public OrxGui::GLGuiWidget
    2626  {
    2727
    2828  public:
    29     GLGuiInputLine();
    30     virtual ~GLGuiInputLine();
     29    GLGuiTable();
     30    virtual ~GLGuiTable();
    3131
     32    unsigned int columnCount() const { return this->_headers.size(); };
     33    unsigned int rowCount() const { return this->_entries.size(); };
     34    //const std::vector<std::string>& headers() const { return this->_headers; };
     35    //const std::vector<std::vector<std::string> >& entries() const { return this->_entries; };
    3236
    33     /** @returns the text of the inputLine */
    34     const std::string& _getText() const { return this->_text.text(); };
     37    void setRowCount(unsigned int rowCount);
     38    void setColumnCount(unsigned int columnCount);
    3539
    36     void setText(const std::string& text);
    37     void append(const std::string& appendText);
    38     void appendCharacter(char character);
    39     void removeCharacters(unsigned int chars);
    40     void clear();
     40    void setHeader(unsigned int number, const std::string& headerName);
     41    void setHeader(const std::vector<std::string>& headerNames);
    4142
    42     void clearOnEnter(bool clear = true) { this->_clearOnEnter = clear; };
     43    void setEntry(unsigned int column, unsigned int rowNumber, const std::string& name);
    4344
    44     virtual void removedFocus();
     45    void setColumnWidth(unsigned int column, float size);
     46    void setRowSize(unsigned int row, unsigned int size);
    4547
    4648    virtual void tick(float dt);
    4749    virtual void draw() const;
    4850
    49     virtual bool processEvent(const Event& event);
    50 
    51     DeclareSignal1(textChanged, const std::string&);
    52     DeclareSignal1(enterPushed, const std::string&);
    5351
    5452  protected:
     53    virtual void removedFocus();
     54
    5555    virtual void updateFrontColor();
    5656    virtual void hiding();
     
    5858    virtual void resize();
    5959
     60    virtual bool processEvent(const Event& event);
     61
    6062
    6163  private:
    6264    void init();
    63     void pushEnter();
    64     void changedText();
     65
     66  private:
     67    typedef std::vector<LimitedWidthText> TableTextList;
     68    TableTextList                _headers;
     69    std::vector<TableTextList>   _entries;     //!< inner is by column, outer is by row.
    6570
    6671
    67   private:
    68     LimitedWidthText        _text;            //!< The Text to display inside of the InputLine.
    69     bool                    _clearOnEnter;    //!< Clear on Enter
    70 
    71     Uint16                  pressedKey;       //!< the pressed key that will be repeated.
    72     Uint16                  pressedKeyName;   //!< The Name of the Key, that was pressed.
    73 
    74     float                   delayNext;        //!< How much time must pass before next output.
    75 
    76     static float            repeatDelay;      //!< Repead Delay.
    77     static float            repeatRate;       //!< Repeat Rate.
    7872  };
    7973}
    8074
    81 #endif /* _GLGUI_INPUTLINE_H */
     75#endif /* _GLGUI_TABLE_H */
Note: See TracChangeset for help on using the changeset viewer.