Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8717 in orxonox.OLD for trunk/src/lib/gui/gl


Ignore:
Timestamp:
Jun 22, 2006, 2:04:28 PM (19 years ago)
Author:
bensch
Message:

merged the gui back

Location:
trunk/src/lib/gui/gl
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/gui/gl/Makefile.am

    r8619 r8717  
    6060                specials/glgui_notifier.h
    6161
    62 
    63 
    64 
    65 
    6662EXTRA_DIST =
    67 
  • trunk/src/lib/gui/gl/glgui_box.cc

    r8619 r8717  
    125125      height += borderBottom(); /* *2 done further up */
    126126
    127       printf("%f %f\n", width, height);
    128127      this->setSize2D(width, height);
    129128    }
     
    145144      height += borderBottom(); /* *2 done further up */
    146145
    147       printf("%f %f\n", width, height);
    148146      this->setSize2D(width, height);
    149147    }
  • trunk/src/lib/gui/gl/glgui_button.cc

    r8619 r8717  
    5151  {
    5252    this->setClassID(CL_GLGUI_BUTTON, "GLGuiButton");
     53
     54    this->setSelectable(true);
    5355    this->setFocusable(true);
    5456    this->setClickable(true);
     
    7981    emit(clicked());
    8082  }
    81   void GLGuiButton::releasing(const Vector2D& pos)
     83  void GLGuiButton::releasing(const Vector2D& pos, bool focused)
    8284  {
    83     GLGuiWidget::releasing(pos);
     85    GLGuiWidget::releasing(pos, focused);
    8486    emit(released());
    8587  }
     
    9698
    9799
     100  bool GLGuiButton::processEvent(const Event& event)
     101  {
     102    if (event.type == SDLK_SPACE && !event.bPressed)
     103    {
     104      emit(released());
     105      return true;
     106    }
     107    return false;
     108  }
     109
     110
    98111  /**
    99112   * @brief draws the GLGuiButton
  • trunk/src/lib/gui/gl/glgui_button.h

    r8619 r8717  
    4040
    4141      virtual void draw() const;
     42      virtual bool processEvent(const Event& event);
    4243
    4344      DeclareSignal0(clicked);
    4445      DeclareSignal0(released);
     46
    4547
    4648    protected:
     
    4850
    4951      virtual void clicking(const Vector2D& pos);
    50       virtual void releasing(const Vector2D& pos);
     52      virtual void releasing(const Vector2D& pos, bool focused);
    5153      virtual void hiding();
    5254      virtual void showing();
  • trunk/src/lib/gui/gl/glgui_checkbutton.cc

    r8619 r8717  
    7878
    7979
    80   void GLGuiCheckButton::releasing(const Vector2D& pos)
     80  void GLGuiCheckButton::releasing(const Vector2D& pos, bool focused)
    8181  {
    82     GLGuiButton::releasing(pos);
    83     this->toggleActiveState();
     82    GLGuiButton::releasing(pos, focused);
     83    if (focused)
     84      this->toggleActiveState();
    8485  }
    8586
  • trunk/src/lib/gui/gl/glgui_checkbutton.h

    r8448 r8717  
    3838  protected:
    3939    virtual void resize();
    40     virtual void releasing(const Vector2D& pos);
     40    virtual void releasing(const Vector2D& pos, bool focused);
    4141
    4242  private:
  • trunk/src/lib/gui/gl/glgui_handler.cc

    r8711 r8717  
    2525#include <cassert>
    2626
     27#include "debug.h"
     28
    2729#include <cassert>
    2830
     
    99101  }
    100102
     103  void GLGuiHandler::selectNext()
     104  {
     105    // retrieve Objects.
     106    const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET);
     107
     108    if (objects)
     109    {
     110      std::list<BaseObject*>::const_iterator it ;
     111      std::list<BaseObject*>::const_iterator currentIt = objects->end();
     112
     113      if (GLGuiWidget::selected() != NULL)
     114      {
     115        it = std::find(objects->begin(), objects->end(), GLGuiWidget::selected());
     116        if (it != objects->end())
     117        {
     118          currentIt = it;
     119          it++;
     120        }
     121      }
     122      else
     123      {
     124        it = objects->begin();
     125      }
     126
     127      bool cycledOnce = false;
     128
     129      for (; it != currentIt; ++it)
     130      {
     131        if (it == objects->end() && !cycledOnce)
     132        {
     133          it = objects->begin();
     134          cycledOnce = true;
     135        }
     136
     137        if (dynamic_cast<GLGuiWidget*>(*it)->selectable())
     138        {
     139          dynamic_cast<GLGuiWidget*>(*it)->select();
     140          return;
     141        }
     142      }
     143
     144    }
     145    else
     146    {
     147      PRINTF(0)("NO GUI-ELEMENTS EXISTING\n");
     148    }
     149  }
     150
     151  void GLGuiHandler::selectPrevious()
     152  {
     153    // retrieve Objects.
     154    const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET);
     155
     156    if (objects)
     157    {
     158      std::list<BaseObject*>::const_iterator it ;
     159      std::list<BaseObject*>::const_iterator currentIt = objects->begin();
     160
     161      if (GLGuiWidget::selected() != NULL)
     162      {
     163        it = std::find(objects->begin(), objects->end(), GLGuiWidget::selected());
     164        if (it != objects->end())
     165        {
     166          currentIt = it;
     167          it--;
     168        }
     169      }
     170      else
     171      {
     172        it = objects->end();
     173      }
     174
     175      bool cycledOnce = false;
     176
     177      for (; it != currentIt; --it)
     178      {
     179        if (it == objects->end() && !cycledOnce)
     180        {
     181          --it ;
     182          cycledOnce = true;
     183        }
     184
     185        if (dynamic_cast<GLGuiWidget*>(*it)->selectable())
     186        {
     187          dynamic_cast<GLGuiWidget*>(*it)->select();
     188          return;
     189        }
     190      }
     191
     192    }
     193    else
     194    {
     195      PRINTF(0)("NO GUI-ELEMENTS EXISTING\n");
     196    }
     197  }
     198
     199
    101200
    102201  void GLGuiHandler::process(const Event &event)
     
    105204    {
    106205      case  EV_MOUSE_BUTTON_LEFT:
    107         if (GLGuiWidget::focused() != NULL)
    108         {
    109           if (event.bPressed)
     206        if (GLGuiWidget::mouseFocused() != NULL && event.bPressed)
     207        {
     208          // if clickable select the Widget.
     209          if (GLGuiWidget::mouseFocused()->clickable())
    110210          {
    111             if (GLGuiWidget::focused()->clickable())
    112             {
    113               Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
    114               GLGuiWidget::focused()->click(cursorPos - GLGuiWidget::focused()->getAbsCoor2D());
    115             }
     211            Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
     212            GLGuiWidget::mouseFocused()->select();
     213            GLGuiWidget::mouseFocused()->click(cursorPos - GLGuiWidget::mouseFocused()->getAbsCoor2D());
    116214          }
    117           else
     215        }
     216        else if (GLGuiWidget::selected() != NULL && !event.bPressed)
     217        {
     218          if (GLGuiWidget::selected()->clickable())
    118219          {
    119             if (GLGuiWidget::focused()->clickable())
    120             {
    121               Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
    122               GLGuiWidget::focused()->release(cursorPos - GLGuiWidget::focused()->getAbsCoor2D());
    123             }
     220            Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
     221            GLGuiWidget::selected()->release(cursorPos - GLGuiWidget::selected()->getAbsCoor2D());
    124222          }
    125223        }
     224
    126225        break;
    127226      case EV_LEAVE_STATE:
    128         if (GLGuiWidget::focused() != NULL)
    129           GLGuiWidget::focused()->breakFocus();
     227        if (GLGuiWidget::selected() != NULL)
     228          GLGuiWidget::selected()->unselect();
     229
     230        if (GLGuiWidget::mouseFocused() != NULL)
     231          GLGuiWidget::mouseFocused()->breakMouseFocus();
    130232        break;
    131233
     
    134236          this->_cursor->setMaxBorders(Vector2D(event.resize.w, event.resize.h));
    135237        break;
    136     }
    137 
    138 
    139 
    140     if (GLGuiWidget::focused())
    141     {
    142       GLGuiWidget::focused()->processEvent(event);
     238      case SDLK_TAB:
     239        if (event.bPressed)
     240          this->selectNext();
     241        break;
     242    }
     243
     244    if (GLGuiWidget::selected() != NULL)
     245    {
     246      GLGuiWidget::selected()->processEvent(event);
    143247    }
    144248
     
    160264      return Vector2D::nullVector();
    161265  }
     266
    162267  Vector2D GLGuiHandler::cursorPositionRel(const GLGuiWidget* const widget) const
    163268  {
     
    170275
    171276
    172   void GLGuiHandler::draw()
    173   {
    174     //    GLGuiMainWidget::getInstance()->draw2D(E2D_LAYER_TOP);
    175   }
    176 
    177 
    178   void GLGuiHandler::tick(float dt)
    179   {
    180 
    181     // CHECK THE COLLISIONS.
     277  void GLGuiHandler::checkFocus()
     278  {
     279   // CHECK THE COLLISIONS.
    182280    const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET);
    183281
     
    193291        {
    194292          // receiving Focus
    195           if (GLGuiWidget::focused() != widget)
     293          if (GLGuiWidget::mouseFocused() != widget)
    196294          {
    197             widget->giveFocus();
     295            widget->giveMouseFocus();
    198296          }
    199297          return ;
    200298        }
    201299      }
    202       if (GLGuiWidget::focused() != NULL)
    203         GLGuiWidget::focused()->breakFocus();
    204     }
     300      if (GLGuiWidget::mouseFocused() != NULL)
     301        GLGuiWidget::mouseFocused()->breakMouseFocus();
     302    }
     303  }
     304
     305  void GLGuiHandler::draw()
     306  {
     307    //    GLGuiMainWidget::getInstance()->draw2D(E2D_LAYER_TOP);
     308  }
     309
     310
     311  void GLGuiHandler::tick(float dt)
     312  {
     313    // do not change if we already clicked into a Widget.
     314    // if (GLGuiWidget::selected() != NULL && GLGuiWidget::selected()->pushed())
     315    //      return ;
     316
     317    this->checkFocus();
    205318  }
    206319}
  • trunk/src/lib/gui/gl/glgui_handler.h

    r8324 r8717  
    3434    Vector2D cursorPositionRel(const GLGuiWidget* const widget) const;
    3535
     36    void selectNext();
     37    void selectPrevious();
     38
    3639    void activate();
    3740    void deactivate();
    3841
     42    void checkFocus();
    3943
    4044    virtual void process(const Event &event);
  • trunk/src/lib/gui/gl/glgui_inputline.cc

    r8619 r8717  
    4747
    4848    this->setFocusable(true);
     49    this->setClickable(true);
     50    this->setSelectable(true);
    4951
    5052    this->_clearOnEnter = false;
  • trunk/src/lib/gui/gl/glgui_pushbutton.cc

    r8448 r8717  
    6363  void GLGuiPushButton::receivedFocus()
    6464  {
    65     printf("%s received focus\n", this->label().c_str());
    6665    GLGuiWidget::receivedFocus();
    6766  }
     
    6968  void GLGuiPushButton::removedFocus()
    7069  {
    71     printf("%s removed focus\n", this->label().c_str());
    7270    GLGuiWidget::removedFocus();
    7371
     
    7674  void GLGuiPushButton::clicking(const Vector2D& pos)
    7775  {
    78     printf("%s clicked\n", this->label().c_str());
    7976    GLGuiButton::clicking(pos);
    8077  }
    8178
    8279
    83   void GLGuiPushButton::releasing(const Vector2D& pos)
     80  void GLGuiPushButton::releasing(const Vector2D& pos, bool focused)
    8481  {
    85     printf("%s released\n", this->label().c_str());
    86     GLGuiButton::releasing(pos);
     82    if (focused)
     83      GLGuiButton::releasing(pos, focused);
    8784  }
    8885
  • trunk/src/lib/gui/gl/glgui_pushbutton.h

    r8145 r8717  
    3131    virtual void draw() const;
    3232    virtual void update();
     33
    3334  protected:
    3435    virtual void resize();
    3536    virtual void clicking(const Vector2D& pos);
    36     virtual void releasing(const Vector2D& pos);
     37    virtual void releasing(const Vector2D& pos, bool focused);
    3738    virtual void receivedFocus();
    3839    virtual void removedFocus();
  • trunk/src/lib/gui/gl/glgui_slider.cc

    r8619 r8717  
    4848    this->setClassID(CL_GLGUI_SLIDER, "GLGuiSlider");
    4949
    50     this->setClickable( );
    51     this->setFocusable( );
     50    this->setClickable(true);
     51    this->setFocusable(true);
     52    this->setSelectable(true);
    5253
    5354    this->_value = 0.0;
     
    193194  }
    194195
    195   void GLGuiSlider::releasing(const Vector2D& pos)
    196   {
    197     GLGuiWidget::releasing(pos);
     196  void GLGuiSlider::releasing(const Vector2D& pos, bool focused)
     197  {
     198    GLGuiWidget::releasing(pos, focused);
    198199    this->grabbed = false;
    199200  }
     
    202203  {
    203204    GLGuiWidget::removedFocus();
    204     this->grabbed = false;
    205205  }
    206206
  • trunk/src/lib/gui/gl/glgui_slider.h

    r8448 r8717  
    5959
    6060    virtual void clicking(const Vector2D& pos);
    61     virtual void releasing(const Vector2D& pos);
     61    virtual void releasing(const Vector2D& pos, bool focused);
    6262    virtual void removedFocus();
    6363
  • trunk/src/lib/gui/gl/glgui_table.cc

    r8619 r8717  
    1919#include "debug.h"
    2020
     21#include "glgui_handler.h"
     22
    2123namespace OrxGui
    2224{
     
    2527   */
    2628  GLGuiTable::GLGuiTable (unsigned int rows, unsigned int columns)
     29  : _selected(-1, -1), _focused(-1, -1)
    2730  {
    2831    this->init();
     32
    2933    this->setRowCount(rows);
    3034    this->setColumnCount(columns);
     
    4549    this->setClassID(CL_GLGUI_TABLE, "GLGuiTable");
    4650
     51    this->setBorderTop(10);
     52
    4753    this->setFocusable(true);
    4854    this->setClickable(true);
    4955
    50     this->resize();
    5156  }
    5257
     
    5661
    5762    unsigned int currentRowCount = this->rowCount();
     63
     64    this->_rowHeights.resize(rowCount, 20);
     65
    5866    this->_entries.resize(rowCount);
    5967    for (unsigned int i = currentRowCount; i < this->rowCount(); ++i)
     
    6573
    6674    assert(this->checkIntegrity());
    67     this->debug();
     75    this->repositionText(currentRowCount, 0);
     76
     77
     78    this->resize();
    6879
    6980    if (!this->isVisible())
     
    7586    unsigned int i;
    7687    unsigned int currentColumnCount = this->columnCount();
     88
     89    this->_columnWidths.resize(columnCount, 100);
    7790
    7891    // setup Headers.
     
    89102    }
    90103    assert(this->checkIntegrity());
    91     this->debug();
    92 
     104
     105    this->repositionText(0, currentColumnCount);
     106
     107    this->resize();
    93108    if (!this->isVisible())
    94109      this->hiding();
     
    111126  }
    112127
    113   void GLGuiTable::setEntry(unsigned int column, unsigned int row, const std::string& name)
     128  void GLGuiTable::setEntry(unsigned int row, unsigned int column, const std::string& name)
    114129  {
    115130    if (column >= this->columnCount() )
     
    125140    for (unsigned int i = 0; i < this->rowCount(); ++i)
    126141      this->_entries[i][column].setLineWidth(size);
    127 
    128   }
     142  }
     143
     144
    129145
    130146  /// TODO.
     
    144160
    145161
    146 
    147162  /**
    148163   * @brief Processes an Event.
     
    152167  bool GLGuiTable::processEvent(const Event& event)
    153168  {
     169    if (event.type == EV_MOUSE_MOTION)
     170    {
     171      this->pixelPositionToElement((OrxGui::GLGuiHandler::getInstance()->cursorPositionRel(this)), &this->_focused.row, &this->_focused.column);
     172      return true;
     173    }
     174
    154175    return false;
    155176  }
     
    161182  void GLGuiTable::resize()
    162183  {
     184    Vector2D size;
     185    unsigned int i;
     186    for(i = 0; i < this->columnCount(); ++i)
     187      size.x += this->_columnWidths[i];
     188
     189    for(i = 0; i < this->rowCount(); ++i)
     190      size.y += this->_rowHeights[i];
     191
     192    this->setSize2D(size);
     193    this->setSize2D( size + Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));
     194
    163195    GLGuiWidget::resize();
    164196  }
     
    172204        this->_entries[j][i].setColor(this->foregroundColor());
    173205    }
     206
    174207  }
    175208
     
    196229
    197230  /**
    198    * @brief ticks the Table
    199    * @param dt the time passed.
    200    */
    201   void GLGuiTable::tick(float dt)
    202 {}
    203 
    204   /**
    205231   * @brief draws the GLGuiTable
    206232   */
     
    210236    GLGuiWidget::draw();
    211237
    212     //     this->frontMaterial().select();
    213     //     GLGuiWidget::drawRect(this->frontRect());
     238    float columnPos = this->borderLeft();
     239    float rowPos = this->borderTop();
     240
     241    unsigned int i;
     242    glColor4fv(&this->foregroundColor()[0]);
     243    glLineWidth(1.5);
     244    glBegin(GL_LINES);
     245
     246    glVertex2f(columnPos, this->borderTop());
     247    glVertex2f(columnPos, this->getSizeY2D());
     248    for (i = 0; i < this->columnCount(); ++i)
     249    {
     250      columnPos +=this->_columnWidths[i];
     251      glVertex2f(columnPos, this->borderTop());
     252      glVertex2f(columnPos, this->getSizeY2D());
     253    }
     254
     255    glVertex2f(this->borderLeft(), rowPos);
     256    glVertex2f(this->getSizeX2D(), rowPos);
     257    for (i = 0; i < this->rowCount(); ++i)
     258    {
     259      rowPos +=this->_rowHeights[i];
     260      glVertex2f(this->borderLeft(), rowPos);
     261      glVertex2f(this->getSizeX2D(), rowPos);
     262    }
     263
     264
     265    glEnd();
     266
     267
    214268
    215269    this->endDraw();
    216270  }
    217271
     272
     273  void GLGuiTable::pixelPositionToElement(const Vector2D& pixelPosition, int* row, int* column)
     274  {
     275    *row = 0;
     276    *column = 0;
     277    float columnPos = this->borderLeft();
     278    float rowPos = this->borderTop();
     279
     280    for (*row = 0; *row < (int)this->rowCount(); (*row)++)
     281    {
     282      if (pixelPosition.y > rowPos  && pixelPosition.y  < (rowPos += _rowHeights[*row]))
     283        break;
     284    }
     285    for (*column = 0; *column < (int)this->columnCount(); (*column)++)
     286    {
     287      if (pixelPosition.x > columnPos && pixelPosition.x  < (columnPos += _columnWidths[*column]))
     288        break;
     289    }
     290
     291    PRINTF(3)("Mouse Over row:%d Column:%d\n", *row, *column);
     292  }
     293
     294
     295  void GLGuiTable::repositionText(unsigned int fromLeft, unsigned int fromTop)
     296  {
     297    float columnPos = this->borderLeft();
     298    float rowPos = this->borderTop();
     299    unsigned int i, j;
     300    for (i = 0; i< fromLeft; ++i)
     301      columnPos+=this->_columnWidths[i];
     302    for (i = 0; i < fromTop; ++i)
     303      rowPos += this->_rowHeights[i];
     304
     305    for (i = fromLeft; i < this->columnCount(); ++i)
     306    {
     307      this->_headers[i].setRelCoor2D(columnPos, rowPos);
     308
     309      // not required, but a good idea :)
     310      this->_headers[i].setLineWidth(_columnWidths[i]);
     311
     312      float rowPosI = rowPos;
     313      for (j = fromTop; j < this->rowCount(); ++j)
     314      {
     315        this->_entries[j][i].setRelCoor2D(columnPos, rowPosI);
     316        this->_entries[j][i].setLineWidth(_columnWidths[i]);
     317        rowPosI += _rowHeights[j];
     318      }
     319      columnPos+=this->_columnWidths[i];
     320    }
     321  }
    218322
    219323  /**
     
    224328  {
    225329    text->setSize(this->textSize());
    226     //text->setLineWidth( );
     330    text->setLineWidth( this->_columnWidths[column] );
    227331    text->setFont("fonts/final_frontier.ttf", (int)this->textSize());
     332    text->setColor(this->foregroundColor());
    228333
    229334    text->setColor(this->foregroundColor());
     
    257362    for (unsigned int i = 0; i < this->rowCount(); ++i)
    258363      if (this->_entries[i].size() != this->columnCount())
    259     {
    260       PRINTF(1)("COLUMN-COUNT OF ROW %d WRONG (is %d should be %d)\n", i, this->_entries[i].size(), this->columnCount());
    261       retVal = false;
    262     }
     364      {
     365        PRINTF(1)("COLUMN-COUNT OF ROW %d WRONG (is %d should be %d)\n", i, this->_entries[i].size(), this->columnCount());
     366        retVal = false;
     367      }
    263368    return retVal;
    264369  }
  • trunk/src/lib/gui/gl/glgui_table.h

    r8619 r8717  
    3939    void setHeader(const std::vector<std::string>& headerNames);
    4040
    41     void setEntry(unsigned int column, unsigned int row, const std::string& name);
     41    void setEntry(unsigned int row, unsigned int column, const std::string& name);
    4242
    4343    void setColumnWidth(unsigned int column, float size);
    4444    void setRowHeight(unsigned int row, unsigned int size);
    4545
    46     virtual void tick(float dt);
    4746    virtual void draw() const;
    4847
     
    6059    virtual bool processEvent(const Event& event);
    6160
    62 
    6361  private:
    6462    void init();
    6563
     64    void pixelPositionToElement(const Vector2D& pixelPosition, int* row, int* column);
     65    void repositionText(unsigned int fromLeft, unsigned int fromTop);
    6666    void applyTextSettings(unsigned int row, unsigned int column, LimitedWidthText* text);
    6767    bool checkIntegrity() const;
    6868
    6969  private:
     70    typedef struct Entry {
     71      Entry(int row, int column) :row(row), column(column) {};
     72      int  row;
     73      int  column;
     74    };
     75
    7076    typedef std::vector<LimitedWidthText> TableTextList;
    7177    TableTextList                _headers;
     78    std::vector<float>           _columnWidths;
     79    std::vector<float>           _rowHeights;
     80
    7281    std::vector<TableTextList>   _entries;     //!< inner is by column, outer is by row.
     82
     83    Entry                        _selected;
     84    Entry                        _focused;
    7385
    7486
  • trunk/src/lib/gui/gl/glgui_widget.cc

    r8619 r8717  
    7272  GLGuiWidget::~GLGuiWidget()
    7373  {
    74     if (this == GLGuiWidget::_focused)
    75       GLGuiWidget::_focused = NULL;
     74    if (this == GLGuiWidget::_mouseFocused)
     75      GLGuiWidget::_mouseFocused = NULL;
     76    if (this == GLGuiWidget::selected())
     77      this->unselect();
    7678  }
    7779
    7880  GLGuiWidget* GLGuiWidget::_selected = NULL;
    79   GLGuiWidget* GLGuiWidget::_focused = NULL;
     81  GLGuiWidget* GLGuiWidget::_mouseFocused = NULL;
    8082  GLGuiWidget* GLGuiWidget::_inputGrabber = NULL;
    8183
     
    9193    this->_focusable = false;
    9294    this->_clickable = false;
     95    this->_selectable = false;
    9396    this->_pushed = false;
    9497    this->_state = OrxGui::Normal;
     
    133136  }
    134137
     138
     139  void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously)
     140  {
     141    this->_currentStyle._foreground.setDiffuseColor(frontColor);
     142    this->animateBack();
     143  };
     144
     145
     146  bool GLGuiWidget::focusOverWidget(const Vector2D& position) const
     147  {
     148    return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x &&
     149        this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
     150  }
     151
     152  bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const
     153  {
     154    return this->focusOverWidget(cursor->getAbsCoor2D());
     155  }
     156
     157
     158
    135159  /** @brief gives focus to this widget */
    136   void GLGuiWidget::giveFocus()
    137   {
    138     if (GLGuiWidget::focused() != NULL)
    139       GLGuiWidget::focused()->breakFocus();
    140     GLGuiWidget::_focused = this;
     160  void GLGuiWidget::giveMouseFocus()
     161  {
     162    if (this->_state == OrxGui::Insensitive)
     163      return ;
     164
     165    if (GLGuiWidget::mouseFocused() != NULL)
     166      GLGuiWidget::mouseFocused()->breakMouseFocus();
     167    GLGuiWidget::_mouseFocused = this;
     168
     169    this->switchState(OrxGui::Focused);
     170
    141171    this->receivedFocus();
    142172  };
    143173
    144   void GLGuiWidget::breakFocus()
    145   {
    146     if (GLGuiWidget::_focused == this)
     174  void GLGuiWidget::breakMouseFocus()
     175  {
     176    if (GLGuiWidget::_mouseFocused == this)
    147177    {
    148       GLGuiWidget::_focused = NULL;
    149       this->_pushed = false;
     178      GLGuiWidget::_mouseFocused = NULL;
     179
     180      if (GLGuiWidget::_selected != this)
     181        this->switchState(OrxGui::Normal);
     182      else
     183        this->switchState(OrxGui::Selected);
     184
    150185      this->removedFocus();
    151186    }
    152187  };
    153188
    154 
    155   bool GLGuiWidget::focusOverWidget(const Vector2D& position) const
    156   {
    157     return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x &&
    158             this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
    159   }
    160 
    161   bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const
    162   {
    163     return this->focusOverWidget(cursor->getAbsCoor2D());
    164   }
    165 
    166 
    167 
    168   void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously)
    169   {
    170     this->_currentStyle._foreground.setDiffuseColor(frontColor);
    171     this->animateBack();
    172   };
     189  /**
     190   * @brief selects the Widget, unselecting the old one (if existing)
     191   */
     192  void GLGuiWidget::select()
     193  {
     194    if (GLGuiWidget::_selected != NULL)
     195      GLGuiWidget::selected()->unselect();
     196    GLGuiWidget::_selected = this;
     197
     198    this->switchState(OrxGui::Selected);
     199  }
     200
     201  /**
     202   * @brief unselects the current Widget.
     203   *
     204   * if the current Widget is not selected, nothing is done here.
     205   */
     206  void GLGuiWidget::unselect()
     207  {
     208    if (GLGuiWidget::_selected != this)
     209      return;
     210
     211    if (GLGuiWidget::_mouseFocused == this)
     212      this->switchState(OrxGui::Focused);
     213    else
     214      this->switchState(OrxGui::Normal);
     215
     216    GLGuiWidget::_selected = NULL;
     217  }
    173218
    174219
     
    193238    if (this->_pushed)
    194239    {
    195       this->releasing(pos);
     240      this->releasing(pos, GLGuiWidget::_mouseFocused == this);
    196241      this->_pushed = false;
    197242    }
     
    200245
    201246  void GLGuiWidget::clicking(const Vector2D& pos)
    202   {
    203     this->switchState(OrxGui::Selected);
    204   }
    205 
    206   void GLGuiWidget::releasing(const Vector2D& pos)
    207   {
    208     this->switchState(OrxGui::Normal);
    209   }
     247  {}
     248
     249  void GLGuiWidget::releasing(const Vector2D& pos, bool focused)
     250  {}
    210251
    211252  void GLGuiWidget::receivedFocus()
    212253  {
    213     this->switchState(OrxGui::Focused);
    214254  }
    215255
    216256  void GLGuiWidget::removedFocus()
    217257  {
    218     this->switchState(OrxGui::Normal);
    219 
    220   }
    221 
    222   void GLGuiWidget::destroyed()
    223   {}
    224   ;
     258
     259  }
     260
     261  void GLGuiWidget::selecting()
     262  {
     263  }
     264
     265  void GLGuiWidget::unselecting()
     266  {
     267  }
     268
     269
     270  void GLGuiWidget::destroying()
     271  {
     272  }
    225273
    226274
     
    706754    //this->_currentStyle = this->_style[state];
    707755    this->_state = state;
    708     PRINTF(3)("Switching to state %s\n", OrxGui::StateString[state].c_str());
     756    PRINTF(3)("%s::%s Switches to state %s\n", this->getClassName(), this->getName(), OrxGui::StateString[state].c_str());
    709757
    710758    this->animateBack();
     
    762810    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
    763811      if (stateName == OrxGui::StateString[i])
    764     {
    765       *state = (OrxGui::State)i;
    766       return true;
    767     }
     812      {
     813        *state = (OrxGui::State)i;
     814        return true;
     815      }
    768816    return false;
    769817  }
     
    772820   * @brief print out some nice debug output about the Widget.
    773821   */
    774   void GLGuiWidget::debug() const
     822  void GLGuiWidget::debug(unsigned int level) const
    775823  {
    776824    PRINT(0)("Debug of %s::%s - WidgetPart ", this->getClassName(), this->getName());
  • trunk/src/lib/gui/gl/glgui_widget.h

    r8619 r8717  
    4242
    4343    /// FOCUS
    44     /** @brief gives focus to this widget */
    45     void giveFocus();
    46     void breakFocus();
     44    /** @brief gives mouse - focus to this widget */
     45    void giveMouseFocus();
     46    void breakMouseFocus();
     47
    4748    /** @returns true if the widget is focusable */
    4849    bool focusable() const { return this->_focusable; };
    49     /** @param focusable sets if the Widget should be focusable */
    50     void setFocusable(bool focusable = true) { this->_focusable = focusable; };
    5150    /** @returns true if the position is inside of the Widget. @param position the position to check */
    5251    bool focusOverWidget(const Vector2D& position) const;
     
    5453    bool focusOverWidget(const OrxGui::GLGuiCursor* const cursor) const;
    5554
    56     /** @returns the currently focused Widget (NULL if none is selected) */
    57     static GLGuiWidget* focused() { return GLGuiWidget::_focused; };
    58 
     55    /** @returns the currently mouse - focused Widget (NULL if none is focused). */
     56    static GLGuiWidget* mouseFocused() { return GLGuiWidget::_mouseFocused; };
     57
     58    /// SELECT
     59    void select();
     60    void unselect();
     61    /** @returns true if the Widget is selectable */
     62    bool selectable() const { return this->_selectable; }
     63
     64    /** @returns the currently Selected Widget (NULL if none is selected). */
     65    static GLGuiWidget* selected() { return GLGuiWidget::_selected; };
    5966
    6067    /// CLICK
     68    bool pushed() { return _pushed; };
    6169    void click(const Vector2D& pos);
    6270    void release(const Vector2D& pos);
    6371    bool clickable() const { return this->_clickable; };
    64     void setClickable(bool clickable = true) { this->_clickable = clickable; };
    6572
    6673    static void connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor);
     
    8188    void animateBack();
    8289
    83     /// STYLE
     90    ///////////////////////////////////////////////////////////////////////////////////
     91    /// STYLE /////////////////////////////////////////////////////////////////////////
    8492    ////////////////////////////////
    8593    /// Retrieve Current Values. ///
     
    201209    void setAnimatedStateChanges(bool animated);
    202210    void switchState(OrxGui::State state);
    203 
     211    ///////////////////////////////////////////////////////////////////////////////////
    204212
    205213
     
    225233
    226234  protected:
     235    /** @param focusable sets if the Widget should be focusable */
     236    void setFocusable(bool focusable = true) { this->_focusable = focusable; };
     237    /** @param selectable true if the widget should be selectable */
     238    void setSelectable(bool selectable) { this->_selectable = selectable; }
     239    /** @param focusable true if the widget should be focusable */
     240    void setClickable(bool clickable = true) { this->_clickable = clickable; };
     241
     242
     243    /// RENDERING
     244    inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
     245    inline void endDraw() const { glPopMatrix(); };
     246
     247
    227248    /// LOOKS
    228249    virtual void resize();
     
    230251    virtual void hiding() {};
    231252    virtual void showing() {};
     253
    232254    virtual void updateFrontColor() {};
    233255
    234     inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
    235     inline void endDraw() const { glPopMatrix(); };
    236256
    237257    /// EVENTS
    238     // if something was clickt on the GUI-widget.
     258    // mouse clicking
    239259    virtual void clicking(const Vector2D& pos);
    240     virtual void releasing(const Vector2D& pos);
     260    virtual void releasing(const Vector2D& pos, bool focused);
     261    // mouse focusing
    241262    virtual void receivedFocus();
    242263    virtual void removedFocus();
    243 
    244     virtual void destroyed();
    245 
    246     virtual void debug() const;
     264    // selecting either with the mouse by clicking, or by the keybord traversing to it.
     265    virtual void selecting();
     266    virtual void unselecting();
     267    // destroying the Widget.
     268    virtual void destroying();
     269
     270
     271    virtual void debug(unsigned int level) const;
    247272
    248273  private:
     
    251276  private:
    252277    static GLGuiWidget*            _selected;         //!< The currently selected Widget.
    253     static GLGuiWidget*            _focused;          //!< The currently Focused Widget.
    254     static GLGuiWidget*            _inputGrabber;     //!< The Widget that grabs input.
     278    static GLGuiWidget*            _mouseFocused;     //!< The currently Focused Widget (mouse-focus).
     279    static GLGuiWidget*            _inputGrabber;     //!< The Widget that grabs input (keyboard-focus).
    255280
    256281
     
    265290    /// EVENTS
    266291    OrxGui::State                  _state;
     292    bool                           _pushed;
    267293
    268294    bool                           _focusable;        //!< If this widget can receive focus.
    269295    bool                           _clickable;        //!< if this widget can be clicked upon.
    270 
    271     bool                           _pushed;
     296    bool                           _selectable;       //!< If this widget can be selected.
     297
    272298
    273299
     
    276302    typedef struct
    277303    {
    278       float             _borderLeft;           //!< The Distance to the left Border of the widget, before any internal Element starts.
    279       float             _borderRight;          //!< The Distance to the right Border of the widget, before any internal Element starts.
    280       float             _borderTop;            //!< The Distance to the top Border of the widget, before any internal Element starts
    281       float             _borderBottom;         //!< The Distance to the bottom Border of the widget, before any internal Element starts
    282 
    283       float             _textSize;             //!< The TextSize of the Widget.
    284 
    285       Material          _background;           //!< The Background Material of the Widget.
    286 
    287       Material          _foreground;           //!< The foreground Material of the Widget.
     304      float                        _borderLeft;           //!< The Distance to the left Border of the widget, before any internal Element starts.
     305      float                        _borderRight;          //!< The Distance to the right Border of the widget, before any internal Element starts.
     306      float                        _borderTop;            //!< The Distance to the top Border of the widget, before any internal Element starts
     307      float                        _borderBottom;         //!< The Distance to the bottom Border of the widget, before any internal Element starts
     308
     309      float                        _textSize;             //!< The TextSize of the Widget.
     310
     311      Material                     _background;           //!< The Background Material of the Widget.
     312
     313      Material                     _foreground;           //!< The foreground Material of the Widget.
    288314    }
    289315    StatedStyle;
    290316
    291317
    292     StatedStyle         _style[GLGUI_STATE_COUNT]; //!< Styles configured for different States
    293 
    294     FeaturePosition     _featurePosition;      //!< The Position a Feature will be layed at (checkbox(box), slider(text),...)
    295     Font*               _font;                 //!< The Font used in the current Widget.
     318    StatedStyle                    _style[GLGUI_STATE_COUNT]; //!< Styles configured for different States
     319
     320    FeaturePosition                _featurePosition;      //!< The Position a Feature will be layed at (checkbox(box), slider(text),...)
     321    Font*                          _font;                 //!< The Font used in the current Widget.
    296322
    297323
    298324    /// ANIMATION STUFF:
    299     bool                _animatedStateChanges; //!< If the Transitions between States are Animated automatically.
    300 
    301     bool                _animating;            //!< If the Widget is animated at the moment (Texture might be an AnimatedTexture.)
    302     float               _animationCycle;
    303     float               _animationDuration;
    304     StatedStyle         _currentStyle;
     325    bool                           _animatedStateChanges; //!< If the Transitions between States are Animated automatically.
     326
     327    bool                           _animating;            //!< If the Widget is animated at the moment (Texture might be an AnimatedTexture.)
     328    float                          _animationCycle;
     329    float                          _animationDuration;
     330    StatedStyle                    _currentStyle;
    305331
    306332  };
Note: See TracChangeset for help on using the changeset viewer.