Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8035 in orxonox.OLD for trunk/src/lib/gui


Ignore:
Timestamp:
May 31, 2006, 4:20:51 PM (18 years ago)
Author:
bensch
Message:

gui: merged the gui back to the trunk

Location:
trunk/src/lib/gui/gl_gui
Files:
27 edited

Legend:

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

    r7919 r8035  
    2525                glgui_inputline.cc \
    2626                glgui_textfield.cc \
     27                glgui_image.cc \
    2728                glgui_window.cc \
    2829                glgui_cursor.cc
     
    4748                glgui_inputline.h \
    4849                glgui_textfield.h \
     50                glgui_image.h \
    4951                glgui_window.h \
    5052                glgui_cursor.h
  • trunk/src/lib/gui/gl_gui/glgui.h

    r7919 r8035  
    77#define _GLGUI_H
    88
     9#include "glgui_defs.h"
    910#include "glgui_handler.h"
    1011
     
    1718//#include "glgui_colorselector.h"
    1819#include "glgui_pushbutton.h"
     20#include "glgui_slider.h"
    1921#include "glgui_cursor.h"
    2022#include "glgui_inputline.h"
    2123#include "glgui_textfield.h"
     24#include "glgui_image.h"
    2225
    2326
  • trunk/src/lib/gui/gl_gui/glgui_bar.cc

    r7919 r8035  
    6060  void GLGuiBar::draw() const
    6161  {
    62     this->startDraw();
     62    this->beginDraw();
    6363
    6464    GLGuiWidget::draw();
  • trunk/src/lib/gui/gl_gui/glgui_box.cc

    r7779 r8035  
    2323   * standard constructor
    2424  */
    25   GLGuiBox::GLGuiBox (BoxType type)
     25  GLGuiBox::GLGuiBox (OrxGui::Orientation orientation)
    2626  {
    2727    this->init();
    2828
    29     this->setType (type);
     29    this->setOrientation(orientation);
    3030  }
    3131
     
    4747  void GLGuiBox::pack(GLGuiWidget* widget)
    4848  {
    49     if (widget == NULL)
    50       return;
     49    assert (widget != NULL);
    5150
    5251    this->children.push_back(widget);
     52    widget->setParentWidget(this);
     53
     54    this->resize();
    5355  }
    5456
     
    5658  void GLGuiBox::unpack(GLGuiWidget* widget)
    5759  {
    58     if (widget == NULL)
     60    assert(widget == NULL);
     61
     62    std::vector<GLGuiWidget*>::iterator delWidget = std::find(this->children.begin(), this->children.end(), widget);
     63    if (delWidget != this->children.end())
    5964    {
    60       this->children.clear();
     65      (*delWidget)->setParentWidget(NULL);
     66      this->children.erase(delWidget);
    6167    }
    62     else
    63     {
    64       this->children.remove(widget);
    65     }
     68    this->resize();
     69  }
     70
     71  void GLGuiBox::clear()
     72  {
     73    this->children.clear();
     74    this->resize();
    6675  }
    6776
    6877  void GLGuiBox::showAll()
    6978  {
    70     std::list<GLGuiWidget*>::iterator itC = this->children.begin();
     79    std::vector<GLGuiWidget*>::iterator itC = this->children.begin();
    7180    while (itC != this->children.end())
    7281    {
     
    7988
    8089    this->show();
    81 
    8290  }
    8391
    8492  void GLGuiBox::hideAll()
    8593  {
    86     std::list<GLGuiWidget*>::iterator itC = this->children.begin();
     94    std::vector<GLGuiWidget*>::iterator itC = this->children.begin();
    8795    while (itC != this->children.end())
    8896    {
     
    97105  }
    98106
     107  void GLGuiBox::resize()
     108  {
     109    if (orientation() == OrxGui::Vertical)
     110    {
     111      float height = this->borderSize();
     112      float width = 0.0f;
     113      std::vector<GLGuiWidget*>::iterator widget;
     114
     115      // find out how big the Widgets are.
     116      for (widget = this->children.begin(); widget != this->children.end(); ++widget)
     117      {
     118        (*widget)->setRelCoor2D(this->borderSize(), height);
     119        height += (*widget)->getSizeY2D();
     120        width = fmax(width, (*widget)->getSizeX2D());
     121      }
     122
     123      width += this->borderSize() * 2.0;
     124      height += this->borderSize(); /* *2 done further up */
     125
     126      printf("%f %f\n", width, height);
     127      this->setSize2D(width, height);
     128    }
     129    else
     130    {
     131      float height = this->borderSize();
     132      float width = this->borderSize();
     133      std::vector<GLGuiWidget*>::iterator widget;
     134
     135      // find out how big the Widgets are.
     136      for (widget = this->children.begin(); widget != this->children.end(); ++widget)
     137      {
     138        (*widget)->setRelCoor2D(width, this->borderSize());
     139        height = fmax(height, (*widget)->getSizeY2D());
     140        width += (*widget)->getSizeX2D();
     141      }
     142
     143      width += this->borderSize() ;
     144      height += this->borderSize(); /* *2 done further up */
     145
     146      printf("%f %f\n", width, height);
     147      this->setSize2D(width, height);
     148    }
     149    GLGuiWidget::resize();
     150
     151    // resize everything.
     152    //for (widget = this->children.begin(); widget != this->children.end(); ++widget)
     153    //{}
     154  }
    99155
    100156  /**
    101    * draws the GLGuiBox
     157   * @brief draws the GLGuiBox
    102158   */
    103159  void GLGuiBox::draw() const
    104160  {
     161    this->beginDraw();
     162    GLGuiWidget::draw();
     163    this->endDraw();
    105164  }
    106165}
  • trunk/src/lib/gui/gl_gui/glgui_box.h

    r7779 r8035  
    99
    1010#include "glgui_container.h"
    11 
     11#include "glgui_defs.h"
    1212
    1313namespace OrxGui
    1414{
    15   typedef enum
    16   {
    17     Box_H,
    18     Box_V,
    19   } BoxType;
    20 
    2115  //! This is BOX part of the openglGUI class
    2216  /**
     
    2721
    2822  public:
    29     GLGuiBox(BoxType type = Box_H);
     23    GLGuiBox(OrxGui::Orientation orientation = OrxGui::Vertical);
    3024    virtual ~GLGuiBox();
    3125
    32     void init();
    33     void setType(BoxType type) { this->type = type; };
     26    /** @returns the Orientation of the Box */
     27    OrxGui::Orientation orientation() const { return this->_orientation; };
     28    /** @param orientation the Orientation of the Box */
     29    void setOrientation(OrxGui::Orientation orientation) { this->_orientation = orientation; };
    3430
    3531    virtual void pack(GLGuiWidget* widget);
    3632    virtual void unpack(GLGuiWidget* widget);
     33    virtual void clear();
     34
    3735    virtual void showAll();
    3836    virtual void hideAll();
     
    4038    virtual void draw() const;
    4139
     40  protected:
     41    virtual void resize();
     42
    4243  private:
    43     BoxType                  type;
    44     std::list<GLGuiWidget*>  children;
     44    void init();
     45
     46    Orientation                _orientation;
     47    std::vector<GLGuiWidget*>  children;
    4548  };
    4649}
  • trunk/src/lib/gui/gl_gui/glgui_button.cc

    r7919 r8035  
    6767  }
    6868
     69
     70
     71  void GLGuiButton::clicking(const Vector2D& pos)
     72  {
     73    emit(clicked());
     74  }
     75  void GLGuiButton::releasing(const Vector2D& pos)
     76  {
     77    emit(released());
     78  }
     79
    6980  /**
    7081   * @brief draws the GLGuiButton
  • trunk/src/lib/gui/gl_gui/glgui_button.h

    r7919 r8035  
    3232  {
    3333
    34   public:
    35     GLGuiButton(const std::string& label);
    36     virtual ~GLGuiButton();
     34    public:
     35      GLGuiButton(const std::string& label);
     36      virtual ~GLGuiButton();
    3737
    38     const std::string& getLabel() const { return this->label.getText(); };
    39     void setLabel(const std::string& label);
     38      const std::string& getLabel() const { return this->label.getText(); };
     39      void setLabel(const std::string& label);
    4040
    41     virtual void resize() = 0;
     41      virtual void draw() const;
    4242
    43     virtual void draw() const;
     43      DeclareSignal0(released);
     44      DeclareSignal0(clicked);
     45
     46    protected:
     47      virtual void clicking(const Vector2D& pos);
     48      virtual void releasing(const Vector2D& pos);
    4449
    4550    private:
     
    4752
    4853
    49   protected:
    5054
    51     Text                 label;
     55    protected:
    5256
    53   private:
    54     ButtonState          state;
     57      Text                 label;
     58
     59    private:
     60      ButtonState          state;
    5561  };
    5662}
  • trunk/src/lib/gui/gl_gui/glgui_checkbutton.cc

    r7919 r8035  
    5252  }
    5353
     54  void GLGuiCheckButton::setActivity(bool bActive)
     55  {
     56    this->bActive = bActive;
     57    emit(this->toggled(this->bActive));
     58  }
    5459
    5560  void GLGuiCheckButton::toggleActiveState()
    5661  {
    57     this->bActive = !this->bActive;
     62    this->setActivity(!this->isActive());
    5863  }
    5964
     
    6267    this->label.setRelCoor2D(25, 5);
    6368    this->setSize2D(this->label.getSizeX2D() + 30, this->label.getSizeY2D() + 10);
     69    GLGuiWidget::resize();
     70    this->frontRect().setTopLeft(borderSize(), borderSize());
     71    this->frontRect().setSize(this->getSizeX2D() -2.0*borderSize(), this->getSizeY2D() -2.0*borderSize());
    6472  }
    6573
    6674
    67   void GLGuiCheckButton::released()
     75  void GLGuiCheckButton::releasing(const Vector2D& pos)
    6876  {
    69     printf("%s released\n", this->getLabel().c_str());
    70     GLGuiWidget::released();
     77    GLGuiButton::releasing(pos);
    7178    this->toggleActiveState();
    7279  }
     80
     81
    7382
    7483  /**
     
    7786  void GLGuiCheckButton::draw() const
    7887  {
    79     this->startDraw();
     88    this->beginDraw();
    8089    GLGuiButton::draw();
    8190
    8291    this->frontMaterial().select();
    83     glBegin(GL_QUADS);
    84 
    85     glTexCoord2i(0,0); glVertex2d(1, 1);
    86     glTexCoord2i(0,1); glVertex2d(1, this->getSizeY2D() - 1);
    87     glTexCoord2i(1,1); glVertex2d(this->getSizeX2D() - 1, this->getSizeY2D() -1);
    88     glTexCoord2i(1,0); glVertex2d(this->getSizeX2D() - 1, 1);
     92    this->drawRect(this->frontRect());
    8993
    9094    if (this->bActive)
    9195    {
     96      glBegin(GL_QUADS);
    9297      glColor3f( 1, 1 ,1);
    9398      glTexCoord2i(0,0); glVertex2d(8, 8);
     
    117122    else
    118123    {
     124      glBegin(GL_QUADS);
    119125      glColor3f(0, 0, 0);
    120126      glTexCoord2i(0,0); glVertex2d(8, 8);
     
    125131    }
    126132
    127 
    128133    this->endDraw();
    129     //   this->label->draw();
    130     //  printf("test");
    131134  }
    132135}
  • trunk/src/lib/gui/gl_gui/glgui_checkbutton.h

    r7919 r8035  
    2626    virtual ~GLGuiCheckButton();
    2727
    28     virtual void resize();
    29     virtual void released();
    3028
    3129    bool    isActive() { return this->bActive; };
     
    3533    virtual void draw() const;
    3634    virtual void update() {};
     35
     36    DeclareSignal1(toggled, bool);
     37
     38  protected:
     39    virtual void resize();
     40    virtual void releasing(const Vector2D& pos);
    3741
    3842  private:
  • trunk/src/lib/gui/gl_gui/glgui_container.h

    r7779 r8035  
    2525    virtual ~GLGuiContainer();
    2626
    27     void init();
    28 
    29 
    30     void setBorderWidth(float borderwidth);
    31 
    32 
     27    /** @brief packs a widget into this one. */
    3328    virtual void pack(GLGuiWidget* widget) = 0;
    3429    /** unpacks a Widget from this container. @param widget the GLGuiWidget to unpack, if NULL all subwidgets will be unpackt. */
    3530    virtual void unpack(GLGuiWidget* widget) = 0;
     31    /** @brief clears all Widgets out. */
     32    virtual void clear() = 0;
     33
    3634    virtual void hideAll() = 0;
    3735    virtual void showAll() = 0;
     
    4139
    4240  private:
    43 
     41    void init();
    4442  };
    4543}
  • trunk/src/lib/gui/gl_gui/glgui_cursor.cc

    r7919 r8035  
    5959    this->backMaterial().setDiffuse(1.0,0.0,0.0);
    6060    this->backMaterial().setDiffuseMap("cursor.png");
    61     this->setSize2D(10, 20);
     61    this->backMaterial().setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     62    this->setSize2D(20, 30);
    6263    this->setAbsCoor2D(100, 100);
    6364    this->setLayer(E2D_LAYER_ABOVE_ALL);
    6465    this->color = 0.0f;
    6566
     67    this->resize();
    6668  }
    6769
     
    7476    this->backMaterial().setDiffuse(color.x, color.y, color.z);
    7577
    76     if (this->movement != Vector2D())
     78    //if (this->movement != Vector2D())
    7779    {
    7880      newPos += movement;
     
    8890
    8991
    90       this->setAbsCoorSoft2D(newPos, 10);
    9192      movement = Vector2D();
    9293    }
     94    this->setAbsCoor2D(newPos);
    9395  }
    9496
     
    98100  void GLGuiCursor::draw() const
    99101  {
    100     this->startDraw();
     102    this->beginDraw();
    101103    GLGuiWidget::draw();
    102104    this->endDraw();
  • trunk/src/lib/gui/gl_gui/glgui_handler.cc

    r7919 r8035  
    107107          {
    108108            if (GLGuiWidget::focused()->clickable())
    109               GLGuiWidget::focused()->click();
     109            {
     110              Vector2D cursorPos = (this->cursor != NULL) ? this->cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
     111              GLGuiWidget::focused()->click(cursorPos - GLGuiWidget::focused()->getAbsCoor2D());
     112            }
    110113          }
    111114          else
    112115          {
    113116            if (GLGuiWidget::focused()->clickable())
    114               GLGuiWidget::focused()->release();
     117            {
     118              Vector2D cursorPos = (this->cursor != NULL) ? this->cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
     119              GLGuiWidget::focused()->release(cursorPos - GLGuiWidget::focused()->getAbsCoor2D());
     120            }
    115121          }
    116122        }
     
    137143
    138144  }
     145
     146
     147  Vector2D GLGuiHandler::cursorPositionOverFocusedWidget() const
     148  {
     149    return (this->cursor != NULL) ? this->cursor->getAbsCoor2D() : Vector2D(0,0);
     150  }
     151
     152  const Vector2D& GLGuiHandler::cursorPositionAbs() const
     153  {
     154    if (this->cursor)
     155      return this->cursor->getAbsCoor2D();
     156    else
     157      return Vector2D::nullVector();
     158  }
     159  Vector2D GLGuiHandler::cursorPositionRel(const GLGuiWidget* const widget) const
     160  {
     161    assert (widget != NULL);
     162    if (this->cursor)
     163      return  this->cursor->getAbsCoor2D() - widget->getAbsCoor2D();
     164    else
     165      return Vector2D::nullVector();
     166  }
     167
    139168
    140169  void GLGuiHandler::draw()
  • trunk/src/lib/gui/gl_gui/glgui_handler.h

    r7919 r8035  
    3030    GLGuiCursor* getCursor() const { return this->cursor; }
    3131
     32    Vector2D cursorPositionOverFocusedWidget() const;
     33    const Vector2D& cursorPositionAbs() const;
     34    Vector2D cursorPositionRel(const GLGuiWidget* const widget) const;
     35
    3236    void activate();
    3337    void deactivate();
  • trunk/src/lib/gui/gl_gui/glgui_image.cc

    r7779 r8035  
    4343  void GLGuiImage::init()
    4444  {
    45     this->setClassID(CL_GLGUI_, "GLGuiImage");
     45    this->setClassID(CL_GLGUI_IMAGE, "GLGuiImage");
    4646
     47    this->frontMaterial().setDiffuseMap(this->texture);
     48    this->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     49
     50    this->resize();
    4751  }
    4852
     53
     54  void GLGuiImage::loadImageFromTexture(const Texture& texture)
     55  {
     56    this->frontMaterial().setDiffuseMap(texture);
     57    this->frontMaterial().setDiffuse(1,1,1);
     58  }
     59
     60  void GLGuiImage::loadImageFromFile(const std::string& fileName)
     61  {
     62    this->texture.loadImage(fileName);
     63  }
     64
     65  void GLGuiImage::loadImageFromSDLSurface(SDL_Surface* surface)
     66  {
     67    //this->texture.loadSurface(surface);
     68  }
     69
     70  void GLGuiImage::loadImageFromDisplayList(GLuint texture)
     71  {
     72//    this->texture.setTexture(texture);
     73  }
     74
     75  void GLGuiImage::resize()
     76  {
     77    this->frontRect().setTopLeft(this->borderSize(), this->borderSize());
     78    this->frontRect().setSize(this->getSizeX2D() -2.0*this->borderSize(), this->getSizeY2D() - 2.0* this->borderSize() );
     79    GLGuiWidget::resize();
     80  }
     81
     82
    4983  /**
    50    * draws the GLGuiImage
     84   * @brief draws the GLGuiImage
    5185   */
    52   void GLGuiImage::draw()
     86  void GLGuiImage::draw() const
    5387  {
     88    this->beginDraw();
     89    GLGuiWidget::draw();
     90
     91    this->frontMaterial().select();
     92    this->drawRect(this->frontRect());
     93    this->endDraw();
    5494  }
    5595}
  • trunk/src/lib/gui/gl_gui/glgui_image.h

    r7779 r8035  
    88#define _GLGUI_IMAGE_H
    99
    10 #include "base_object.h"
     10#include "glgui_widget.h"
    1111
    1212// FORWARD DECLARATION
     
    2626    virtual ~GLGuiImage();
    2727
    28     void init();
    29     void loadImageFromFile(const char* fileName);
     28    void loadImageFromTexture(const Texture& texture);
     29
     30    void loadImageFromFile(const std::string& fileName);
    3031    void loadImageFromSDLSurface(SDL_Surface* surface);
    31     void loadImageFromDisplayList(GLuint displayList);
     32    void loadImageFromDisplayList(GLuint texture);
    3233
    33     virtual void draw();
     34    virtual void draw() const;
     35
     36    DeclareSignal0(imageChanged);
    3437
    3538  private:
     39    void init();
     40    virtual void resize();
    3641
     42  private:
     43    Texture       texture;
    3744  };
    3845}
  • trunk/src/lib/gui/gl_gui/glgui_inputline.cc

    r7919 r8035  
    2121{
    2222  /**
    23    * standard constructor
     23   * @brief standard constructor
    2424  */
    2525  GLGuiInputLine::GLGuiInputLine ()
    2626  {
    2727    this->init();
    28 
    29   }
    30 
    31 
    32   /**
    33    * standard deconstructor
    34   */
     28  }
     29
     30
     31  /**
     32   * @brief standard deconstructor
     33   */
    3534  GLGuiInputLine::~GLGuiInputLine()
    3635  {}
     
    4140
    4241  /**
    43    * initializes the GUI-element
     42   * @brief initializes the GUI-element
    4443   */
    4544  void GLGuiInputLine::init()
     
    5251    this->text.setRelCoor2D(4,4);
    5352    this->text.setFont("fonts/final_frontier.ttf", 20);
    54   }
    55 
     53    this->resize();
     54  }
     55
     56
     57  /**
     58   * @brief sets the Text of the InputLine
     59   * @param text The new Text.
     60   */
    5661  void GLGuiInputLine::setText(const std::string& text)
    5762  {
    5863    this->text.setText(text);
    5964    this->resize();
    60   }
    61 
     65
     66    emit(this->textChanged(this->getText()));
     67  }
     68
     69  /**
     70   * @brief appends text to the InputLine
     71   * @param appendText the Text to append
     72   */
    6273  void GLGuiInputLine::append(const std::string& appendText)
    6374  {
    6475    this->text.append(appendText);
    6576    this->resize();
    66   }
    67 
     77    emit(this->textChanged(this->text.getText()));
     78  }
     79
     80
     81  /**
     82   * @brief appends a Character to the InputLine
     83   * @param character the Character to append.
     84   */
    6885  void GLGuiInputLine::appendCharacter(char character)
    6986  {
    7087    this->text.appendCharacter(character);
    7188    this->resize();
    72   }
    73 
    74 
     89    emit(this->textChanged(this->text.getText()));
     90  }
     91
     92
     93  /**
     94   * @brief Removes Characters from the InputLine
     95   * @param chars The count of characters to remove
     96   */
    7597  void GLGuiInputLine::removeCharacters(unsigned int chars)
    7698  {
    7799    this->text.removeCharacters(chars);
    78100    this->resize();
    79   }
    80 
    81 
     101    emit(this->textChanged(this->text.getText()));
     102  }
     103
     104
     105  /**
     106   * removes the focus from this Widget.
     107   */
    82108  void GLGuiInputLine::removedFocus()
    83109  {
     
    88114
    89115
     116  /**
     117   * Processes an Event.
     118   * @param event The event to be processed
     119   * @return true if the event was catched.
     120   */
    90121  bool GLGuiInputLine::processEvent(const Event& event)
    91122  {
     
    126157
    127158
     159  /**
     160   * @brief Resizes the Widget to the new Size-constraints.
     161   */
    128162  void GLGuiInputLine::resize()
    129163  {
    130164    this->setSize2D( this->text.getSize2D() + Vector2D(8, 8));
    131   }
    132 
    133 
     165    GLGuiWidget::resize();
     166    this->frontRect().setTopLeft(borderSize(), borderSize());
     167    this->frontRect().setSize(this->getSize2D() - Vector2D(borderSize(), borderSize()));
     168  }
     169
     170
     171  /**
     172   * ticks the InputLine
     173   * @param dt the time passed.
     174   */
    134175  void GLGuiInputLine::tick(float dt)
    135176  {
     
    156197
    157198  /**
    158    * draws the GLGuiInputLine
     199   * @brief draws the GLGuiInputLine
    159200   */
    160201  void GLGuiInputLine::draw() const
    161202  {
    162     this->startDraw();
     203    this->beginDraw();
    163204    GLGuiWidget::draw();
    164205
    165206    this->frontMaterial().select();
    166     glBegin(GL_QUADS);
    167 
    168     glTexCoord2i(0,0); glVertex2d(3, 3);
    169     glTexCoord2i(0,1); glVertex2d(3, this->getSizeY2D() - 3);
    170     glTexCoord2i(1,1); glVertex2d(this->getSizeX2D() - 3, this->getSizeY2D() -3);
    171     glTexCoord2i(1,0); glVertex2d(this->getSizeX2D() - 3, 3);
    172 
    173     glEnd();
     207    GLGuiWidget::drawRect(this->frontRect());
     208
    174209    this->endDraw();
    175210  }
  • trunk/src/lib/gui/gl_gui/glgui_inputline.h

    r7919 r8035  
    1616{
    1717
    18   //! This is part of the openglGUI class
     18  //! This is InputLine part of the openglGUI class
    1919  /**
     20   * The InputLine is a Widget, that displays a Line, that can be manipulated through
     21   * Writing Text on it.
    2022   *
     23   * Whenever the Text is changed the textChanged signal is emitted.
    2124   */
    2225  class GLGuiInputLine : public OrxGui::GLGuiWidget
     
    2730    virtual ~GLGuiInputLine();
    2831
    29     void init();
     32
     33    /** @returns the text of the inputLine */
     34    const std::string& getText() const { return this->text.getText(); };
    3035
    3136    void setText(const std::string& text);
     
    3338    void appendCharacter(char character);
    3439    void removeCharacters(unsigned int chars);
    35     const std::string& getName() const { return this->text.getText(); };
    36 
    3740
    3841    virtual void removedFocus();
     
    4346    virtual bool processEvent(const Event& event);
    4447
    45     private:
    46       void resize();
     48    DeclareSignal1(textChanged, const std::string&);
    4749
     50  private:
     51    void init();
     52    void resize();
    4853
    4954  private:
     
    5560    float                   delayNext;        //!< How much time must pass before next output.
    5661
    57     static float            repeatDelay;
    58     static float            repeatRate;
    59 
    60 
     62    static float            repeatDelay;      //!< Repead Delay.
     63    static float            repeatRate;       //!< Repeat Rate.
    6164  };
    6265}
  • trunk/src/lib/gui/gl_gui/glgui_pushbutton.cc

    r7919 r8035  
    4747    this->label.setRelCoor2D(5, 5);
    4848    this->setSize2D(this->label.getSizeX2D() + 10, this->label.getSizeY2D() + 10);
     49
     50    GLGuiWidget::resize();
     51    this->frontRect().setTopLeft(1, 1);
     52    this->frontRect().setSize(this->getSizeX2D() -2, this->getSizeY2D() -2);
    4953  }
    5054
     
    7074  }
    7175
    72   void GLGuiPushButton::clicked()
     76  void GLGuiPushButton::clicking(const Vector2D& pos)
    7377  {
    7478    printf("%s clicked\n", this->getLabel().c_str());
    75     GLGuiWidget::clicked();
     79    GLGuiButton::clicking(pos);
    7680  }
    7781
    7882
    79   void GLGuiPushButton::released()
     83  void GLGuiPushButton::releasing(const Vector2D& pos)
    8084  {
    8185    printf("%s released\n", this->getLabel().c_str());
    82     GLGuiWidget::released();
     86    GLGuiButton::releasing(pos);
    8387  }
    8488
     
    9094  void GLGuiPushButton::draw() const
    9195  {
    92     this->startDraw();
     96    this->beginDraw();
    9397    GLGuiButton::draw();
    9498
    9599    this->frontMaterial().select();
    96     glBegin(GL_QUADS);
    97 
    98     glTexCoord2i(0,0); glVertex2d(1, 1);
    99     glTexCoord2i(0,1); glVertex2d(1, this->getSizeY2D() - 1);
    100     glTexCoord2i(1,1); glVertex2d(this->getSizeX2D() - 1, this->getSizeY2D() -1);
    101     glTexCoord2i(1,0); glVertex2d(this->getSizeX2D() - 1, 1);
    102 
    103     glEnd();
     100    this->drawRect(this->frontRect());
    104101    this->endDraw();
    105102    //   this->label->draw();
  • trunk/src/lib/gui/gl_gui/glgui_pushbutton.h

    r7919 r8035  
    2727
    2828
    29     virtual void resize();
    30 
    31     virtual void receivedFocus();
    32     virtual void removedFocus();
    33     virtual void clicked();
    34     virtual void released();
    3529
    3630
    3731    virtual void draw() const;
    3832    virtual void update();
     33  protected:
     34    virtual void resize();
     35    virtual void clicking(const Vector2D& pos);
     36    virtual void releasing(const Vector2D& pos);
     37    virtual void receivedFocus();
     38    virtual void removedFocus();
     39
     40
     41
    3942  private:
    4043    void init();
  • trunk/src/lib/gui/gl_gui/glgui_slider.cc

    r7919 r8035  
    1717
    1818#include "glgui_slider.h"
     19#include "event_def.h"
     20
     21#include "glgui_handler.h"
    1922
    2023namespace OrxGui
     
    2225
    2326  /**
    24    * standard constructor
    25   */
     27   * @brief standard constructor
     28   */
    2629  GLGuiSlider::GLGuiSlider ()
    2730  {
     
    3235
    3336  /**
    34    * standard deconstructor
    35   */
     37   * @brief standard deconstructor
     38   */
    3639  GLGuiSlider::~GLGuiSlider()
    37   {
    38   }
    39 
    40   /**
    41    * initializes the GUI-element
     40  {}
     41
     42  /**
     43   * @brief initializes the GUI-element
    4244   */
    4345  void GLGuiSlider::init()
    4446  {
     47
    4548    this->setClassID(CL_GLGUI_SLIDER, "GLGuiSlider");
    4649
    47   }
    48 
    49   /**
    50    * draws the GLGuiSlider
     50    this->setClickable( );
     51    this->setFocusable( );
     52
     53    this->_value = 0.0;
     54    this->_minValue = 0.0;
     55    this->_maxValue = 1.0;
     56    this->_step = 0.1;
     57    this->_sliderWidth = 5.0;
     58    this->grabbed = false;
     59
     60    this->setSize2D(100, 30);
     61    this->resize();
     62  }
     63
     64  /**
     65   * @param value the new Value.
     66   * @note will automatically be set between max() and min()
     67   */
     68  void GLGuiSlider::setValue(float value)
     69  {
     70    if (value < this->min())
     71      this->_value = min();
     72    else if (value > max())
     73      this->_value = max();
     74    else
     75      this->_value = value;
     76    emit(valueChanged(this->_value));
     77  }
     78
     79  /**
     80   * @param minimum the minumum of the range.
     81   *
     82   * @note will rearange value if necessary and will not be made bigger than max()
     83   */
     84  void GLGuiSlider::setMin(float minimum)
     85  {
     86    if (minimum <= max())
     87    {
     88      this->_minValue = minimum;
     89      emit(rangeChanged(this->_minValue, this->_maxValue));
     90    }
     91    if (this->value() < this->min())
     92      this->setValue(this->min());
     93  }
     94
     95
     96  /**
     97   * @param maximum the maximum of the range.
     98   *
     99   * @note will rearange value if necessary and will not be made smaller than min()
     100   */
     101  void GLGuiSlider::setMax(float maximum)
     102  {
     103    if (maximum >= min())
     104    {
     105      this->_maxValue = maximum;
     106      emit(rangeChanged(this->_minValue, this->_maxValue));
     107    }
     108    if (this->value() > this->max())
     109      this->setValue(this->max());
     110  }
     111
     112  /**
     113   * @param minimum the minimum
     114   * @param maximum the maximum
     115   *
     116   * @see setMax
     117   * @see setMin
     118   */
     119  void GLGuiSlider::setRange(float minimum, float maximum)
     120  {
     121    if (minimum < maximum)
     122    {
     123      this->_minValue = minimum;
     124      this->_maxValue = maximum;
     125      emit(rangeChanged(this->_minValue, this->_maxValue));
     126    }
     127    if (this->value() < this->min())
     128      this->setValue(this->min());
     129    else if (this->value() > this->max())
     130      this->setValue(this->max());
     131  }
     132
     133  /**
     134   * @brief sets the stepSize
     135   */
     136  void GLGuiSlider::setStep(float step)
     137  {
     138    this->_step = step;
     139  }
     140
     141  /**
     142   * @brief makes one step into the minus direction
     143   */
     144  void GLGuiSlider::stepMinus()
     145  {
     146    this->setValue(value() - step());
     147  }
     148
     149  /**
     150   * @brief makes one step into the minus direction
     151   */
     152  void GLGuiSlider::stepPlus()
     153  {
     154    this->setValue(value() + step());
     155  }
     156
     157  /**
     158   * @brief resizes the Slider, and through this Synchronizes the GUI-size.
     159   */
     160  void GLGuiSlider::resize()
     161  {
     162    GLGuiWidget::resize();
     163    this->frontRect().setTopLeft(5, this->getSizeY2D()/2.0 - 2.0);
     164    this->frontRect().setSize(this->getSizeX2D() - 10.0, 4.0);
     165  }
     166
     167  /**
     168   * @brief handle the clicked event.
     169   * @param pos the position the Click occured (from the topleft corner out)
     170   */
     171  void GLGuiSlider::clicking(const Vector2D& pos)
     172  {
     173    GLGuiWidget::clicking(pos);
     174
     175    float sliderPosition = this->sliderPosition();
     176    if (sliderPosition > pos.x + this->_sliderWidth)
     177      this->setValue(this->value() - this->step());
     178
     179    else if (sliderPosition < pos.x - this->_sliderWidth)
     180      this->setValue(this->value() + this->step());
     181    else
     182      this->grabbed = true;
     183  }
     184
     185  void GLGuiSlider::releasing(const Vector2D& pos)
     186  {
     187    GLGuiWidget::releasing(pos);
     188    this->grabbed = false;
     189  }
     190
     191  void GLGuiSlider::removedFocus()
     192  {
     193    GLGuiWidget::removedFocus();
     194    this->grabbed = false;
     195  }
     196
     197  /**
     198   * @returns the current SliderPosition calculated from the current value and the Silders' size.
     199   */
     200  float GLGuiSlider::sliderPosition() const
     201  {
     202    return (this->_value - this->_minValue)/( this->_maxValue - this->_minValue) *
     203           (this->getSizeX2D() - 2.0*(borderSize() + _sliderWidth)) +
     204           (borderSize() +_sliderWidth);
     205  }
     206
     207  /**
     208   * @param position the position relative from the left border.
     209   * @returns the Value at the given position.
     210   */
     211  float GLGuiSlider::sliderValue(float position) const
     212  {
     213    return (position - (borderSize()+_sliderWidth)) / (this->getSizeX2D() - 2.0*(borderSize() + _sliderWidth))
     214           *( this->_maxValue - this->_minValue) +
     215           this->_minValue ;
     216  }
     217
     218  void GLGuiSlider::tick(float dt)
     219  {
     220  }
     221
     222  /**
     223   * @brief draws the GLGuiSlider
    51224   */
    52225  void GLGuiSlider::draw() const
    53226  {
     227    this->beginDraw();
     228    GLGuiWidget::draw();
     229
     230    this->frontMaterial().select();
     231    this->drawRect(this->frontRect());
     232
     233    this->drawRect(Rect2D(this->sliderPosition()-_sliderWidth/2.0, borderSize(), _sliderWidth, this->getSizeY2D() - 2 * borderSize()));
     234
     235    this->endDraw();
     236  }
     237
     238
     239  bool GLGuiSlider::processEvent( const Event& event )
     240  {
     241    if (this->grabbed && event.type == EV_MOUSE_MOTION)
     242    {
     243      this->setValue(sliderValue(GLGuiHandler::getInstance()->cursorPositionRel(this).x));
     244      return true;
     245    }
     246    else if (event.bPressed)
     247    {
     248      if (event.type == SDLK_LEFT)
     249      {
     250        this->stepMinus();
     251        return true;
     252      }
     253      else if (event.type == SDLK_RIGHT)
     254      {
     255        this->stepPlus();
     256        return true;
     257      }
     258    }
     259    return false;
    54260  }
    55261}
  • trunk/src/lib/gui/gl_gui/glgui_slider.h

    r7919 r8035  
    1717  //! This is part of the openglGUI class
    1818  /**
    19    *
     19   * The Slider is a Widget, with a Range and a Value.
    2020   */
    2121  class GLGuiSlider : public GLGuiWidget
     
    2626    virtual ~GLGuiSlider();
    2727
     28    /** @returns the Value of the Slider. */
     29    float value() const { return this->_value; }
     30    /** @returns the minimum of the sliders range */
     31    float min() const { return this->_minValue; };
     32    /** @returns the maximum of the sliders range */
     33    float max() const { return this->_maxValue; };
     34    /** @returns the step size */
     35    float step() const { return this->_step; };
     36
     37    void setValue(float value);
     38
     39    void setMin(float minimum);
     40    void setMax(float maximum);
     41    void setRange(float minimum, float maximum);
     42
     43    void setStep(float step);
     44
     45    void stepPlus();
     46    void stepMinus();
     47
     48
     49    virtual void tick(float dt);
     50    virtual bool processEvent(const Event& event);
     51    virtual void draw() const;
     52
     53    DeclareSignal1(valueChanged, float);
     54    DeclareSignal2(rangeChanged, float, float);
     55
     56  protected:
     57    virtual void resize();
     58
     59    virtual void clicking(const Vector2D& pos);
     60    virtual void releasing(const Vector2D& pos);
     61    virtual void removedFocus();
     62
     63  private:
    2864    void init();
    29 
    30     virtual void draw() const;
     65    float sliderPosition() const;
     66    float sliderValue(float position) const;
    3167
    3268  private:
     
    3571    float            _maxValue;
    3672    float            _minValue;
     73    float            _step;
    3774
    3875    float            _value;
     76
     77    float            _sliderWidth;
     78
     79    bool             grabbed;
    3980
    4081  };
  • trunk/src/lib/gui/gl_gui/glgui_text.h

    r7779 r8035  
    2626    virtual ~GLGuiText();
    2727
     28    void setText();
     29
     30    virtual void draw();
     31
     32  private:
    2833    void init();
    2934
    30     virtual void draw();
    3135
    3236  private:
  • trunk/src/lib/gui/gl_gui/glgui_textfield.cc

    r7919 r8035  
    4343  {
    4444    this->setClassID(CL_GLGUI_TEXTFIELD, "GLGuiTextfield");
    45 
    46 
    4745  }
    4846
    4947  /**
    50    * draws the GLGuiTextfield
     48   * @brief draws the GLGuiTextfield
    5149   */
    5250  void GLGuiTextfield::draw() const
    5351  {
     52    this->beginDraw();
     53    GLGuiWidget::draw();
     54
     55    this->frontMaterial().select();
     56    this->drawRect(this->frontRect());
     57    this->endDraw();
    5458  }
    5559}
  • trunk/src/lib/gui/gl_gui/glgui_widget.cc

    r7919 r8035  
    2828
    2929  /**
    30    * standard constructor
     30   * @brief standard constructor
    3131  */
    32   GLGuiWidget::GLGuiWidget ( )
     32  GLGuiWidget::GLGuiWidget (GLGuiWidget* parent)
    3333  {
    3434    this->init();
    35   }
    36 
    37 
    38   /**
    39    * standard deconstructor
     35
     36    this->setParentWidget(parent);
     37  }
     38
     39
     40  /**
     41   * @brief standard deconstructor
    4042   */
    4143  GLGuiWidget::~GLGuiWidget()
     
    4547  }
    4648
     49  GLGuiWidget* GLGuiWidget::_selected = NULL;
    4750  GLGuiWidget* GLGuiWidget::_focused = NULL;
    4851  GLGuiWidget* GLGuiWidget::_inputGrabber = NULL;
     
    6366    this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE);
    6467
    65     this->backMat.setDiffuse(1.0, 1.0, 1.0);
    66     this->frontMat.setDiffuse(1.0, 0.0, 0.0);
    67 
    68     this->widgetSignals.resize(SignalCount, SignalConnector());
    69   }
    70 
     68    this->_backMat.setDiffuse(1.0, 1.0, 1.0);
     69    this->_frontMat.setDiffuse(1.0, 0.0, 0.0);
     70    this->_borderSize = 1.0;
     71  }
     72
     73
     74  void GLGuiWidget::setParentWidget(GLGuiWidget* parent)
     75  {
     76    this->_parent = parent;
     77
     78    if (parent != NULL)
     79      parent->addChild2D(this);
     80  }
    7181
    7282  /** @brief gives focus to this widget */
     
    93103  {
    94104    return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x &&
    95         this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
     105            this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
    96106  }
    97107
     
    101111  }
    102112
    103   void GLGuiWidget::click()
     113
     114  void GLGuiWidget::setBorderSize(float borderSize)
     115  {
     116    this->_borderSize = borderSize;
     117    this->resize();
     118  }
     119
     120
     121  void GLGuiWidget::resize()
     122  {
     123    this->backRect().setSize(this->getSize2D());
     124    if (this->parent() != NULL)
     125      this->parent()->resize();
     126  }
     127
     128
     129  void GLGuiWidget::click(const Vector2D& pos)
    104130  {
    105131    assert (!this->_pushed);
    106     this->widgetSignals[Signal_click]("none");
    107132    this->_pushed = true;
    108133
    109     this->clicked();
    110   }
    111 
    112   void GLGuiWidget::release()
     134    this->clicking(pos);
     135  }
     136
     137  void GLGuiWidget::release(const Vector2D& pos)
    113138  {
    114139    if (this->_pushed)
    115140    {
    116       this->widgetSignals[Signal_release]("none");
    117 
    118       this->released();
     141      this->releasing(pos);
    119142      this->_pushed = false;
    120143    }
     
    122145
    123146
    124   void GLGuiWidget::clicked()
     147  void GLGuiWidget::clicking(const Vector2D& pos)
    125148  {
    126149    this->frontMaterial().setDiffuse(0, 0, 1);
     
    128151  }
    129152
    130   void GLGuiWidget::released()
    131   {
    132     this->frontMat.setDiffuse(0,1,0);
     153  void GLGuiWidget::releasing(const Vector2D& pos)
     154  {
     155    this->frontMaterial().setDiffuse(0,1,0);
    133156
    134157  }
     
    146169
    147170  void GLGuiWidget::destroyed()
    148   {
    149   };
    150 
    151 
    152 
    153 
    154   /**
    155    * @brief connects a Signal to the Gui-Elements' Event.
    156    * @param sinalType the Type of Signal to set. @see GLGuiSignalType
    157    * @param signal the name of the Signal
     171  {}
     172  ;
     173
     174  void GLGuiWidget::setWidgetSize(const Vector2D& size)
     175  {
     176    this->setSize2D(size);
     177    this->resize();
     178
     179  }
     180
     181
     182  void GLGuiWidget::setWidgetSize(float x, float y)
     183  {
     184    this->setWidgetSize(Vector2D(x, y));
     185  }
     186
     187
     188
     189  void GLGuiWidget::connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor)
     190  {
     191    sender->connect(signal, receiver, executor);
     192  }
     193
     194  void GLGuiWidget::connect(Signal& signal, BaseObject* receiver, Slot executor)
     195  {
     196    signal.push_back(SignalConnector(receiver, executor));
     197  }
     198
     199
     200  void GLGuiWidget::show()
     201  {
     202    this->setVisibility(true);
     203  }
     204
     205
     206  void GLGuiWidget::hide()
     207  {
     208    this->setVisibility(false);
     209  }
     210
     211
     212  /**
     213   * USE THIS FUNCTION ONLY FROM DERIVED CLASS
    158214   */
    159   void GLGuiWidget::connectSignal(SignalType signalType, BaseObject* object, const Executor* signal)
    160   {
    161     if (signalType >= this->widgetSignals.size())
    162       return;
    163 
    164 //    if (this->widgetSignals[signalType] != NULL)
    165 //      PRINTF(2)("Already connected a Signal to '%s::%s' type %s... overwriting\n", this->getClassName(), this->getName(), "TEST");
    166 
    167     this->widgetSignals[signalType] = SignalConnector(object, signal);
    168   }
    169 
    170   /**
    171    * @brief removes a Signal from a Gui-ELements' Event
    172    * @param signalType the type of Signal to remove.
    173    */
    174   void GLGuiWidget::disconnectSignal(SignalType signalType)
    175   {
    176     if (signalType >= this->widgetSignals.size())
    177       return;
    178 
    179     this->widgetSignals[signalType] = SignalConnector();
    180   }
    181 
    182 
    183   void GLGuiWidget::show()
    184   {
    185     this->setVisibility(true);
    186   }
    187 
    188   void GLGuiWidget::hide()
    189   {
    190     this->setVisibility(false);
    191   }
    192 
    193 
    194215  void GLGuiWidget::draw() const
    195216  {
    196     this->backMat.select();
    197 
    198     glBegin(GL_QUADS);
    199     glTexCoord2i(0,0); glVertex2d(0, 0);
    200     glTexCoord2i(0,1); glVertex2d(0, this->getSizeY2D());
    201     glTexCoord2i(1,1); glVertex2d(this->getSizeX2D(), this->getSizeY2D());
    202     glTexCoord2i(1,0); glVertex2d(this->getSizeX2D(), 0);
    203     glEnd();
     217    this->backMaterial().select();
     218    this->drawRect(this->backRect());
    204219  }
    205220
  • trunk/src/lib/gui/gl_gui/glgui_widget.h

    r7919 r8035  
    2424namespace OrxGui
    2525{
    26   typedef enum
    27   {
    28     Signal_click     = 0,
    29     Signal_release,
    30     Signal_rollOn,
    31     Signal_rollOff,
    32     Signal_open,
    33     Signal_close,
    34     Signal_destroy,
    35 
    36     SignalCount,
    37   } SignalType;
    38 
    3926
    4027  class GLGuiCursor;
     
    4936  class GLGuiWidget : public Element2D
    5037  {
    51 
    52   private:
    53 
    5438  public:
    55     GLGuiWidget();
     39    GLGuiWidget(GLGuiWidget* parent = NULL);
    5640    virtual ~GLGuiWidget();
    5741
     
    5943    void hide();
    6044
    61     /// INTERCONNECTIVITY
    62     void connectSignal(SignalType signalType, BaseObject* obj, const Executor* signal);
    63     void disconnectSignal(SignalType signalType);
    6445
     46    void setParentWidget(GLGuiWidget* parent);
     47    GLGuiWidget* parent() const { return this->_parent; }
    6548
    6649    /// FOCUS
     
    8265
    8366    /// CLICK
    84     void click();
    85     void release();
     67    void click(const Vector2D& pos);
     68    void release(const Vector2D& pos);
    8669    bool clickable() const { return this->_clickable; };
    8770    void setClickable(bool clickable = true) { this->_clickable = clickable; };
     71
     72    static void connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor);
     73    void connect(Signal& signal, BaseObject* receiver, Slot executor);
     74
     75    void disconnect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver);
     76
     77
     78    /// MATERIAL (looks)
     79    Material& backMaterial() { return this->_backMat; };
     80    const Material& backMaterial() const { return this->_backMat; };
     81    Rect2D& backRect() { return this->_backRect; };
     82    const Rect2D& backRect() const { return this->_backRect; };
     83
     84    Material& frontMaterial() { return this->_frontMat; };
     85    const Material& frontMaterial() const { return this->_frontMat; };
     86    Rect2D& frontRect() { return this->_frontRect; };
     87    const Rect2D& frontRect() const { return this->_frontRect; };
     88
     89    float borderSize() const { return this->_borderSize; };
     90    void setBorderSize(float borderSize);
     91
     92    void setWidgetSize(const Vector2D& size);
     93    void setWidgetSize(float x, float y);
     94
     95
     96    void setBackgroundColor(float x, float y, float z) { this->backMaterial().setDiffuse(x,y,z); };
     97
     98    inline void drawRect(const Rect2D& rect) const {
     99      glBegin(GL_QUADS);
     100      glTexCoord2i(0,0); glVertex2d(rect.left(), rect.top());
     101      glTexCoord2i(0,1); glVertex2d(rect.left(), rect.bottom());
     102      glTexCoord2i(1,1); glVertex2d(rect.right(), rect.bottom());
     103      glTexCoord2i(1,0); glVertex2d(rect.right(), rect.top());
     104      glEnd();
     105    }
     106
    88107
    89108    virtual void update() {};
    90109    virtual void draw() const;
    91110
    92 
    93     /// MATERIAL (looks)
    94     Material& backMaterial() { return this->backMat; };
    95     const Material& backMaterial() const { return this->backMat; };
    96 
    97     Material& frontMaterial() { return this->frontMat; };
    98     const Material& frontMaterial() const { return this->frontMat; };
    99 
    100111    /** @param the Event to process. @returns true if the Event has been consumed*/
    101112    virtual bool processEvent(const Event& event) { };
    102113
     114  protected:
    103115
    104     DeclareSignal(testSignal, ());
     116    /// LOOKS
     117    virtual void resize();
    105118
    106   protected:
    107         // if something was clickt on the GUI-widget.
    108     virtual void clicked();
    109     virtual void released();
     119    // if something was clickt on the GUI-widget.
     120    virtual void clicking(const Vector2D& pos);
     121    virtual void releasing(const Vector2D& pos);
    110122    virtual void receivedFocus();
    111123    virtual void removedFocus();
     
    114126
    115127
    116     inline void startDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
     128    inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
    117129    inline void endDraw() const { glPopMatrix(); };
    118130
     
    122134
    123135  private:
     136    GLGuiWidget*                   _parent;           //!< The parent of this Widget.
     137
    124138    /// LOOKS
    125     Material                       backMat;
    126     Rect2D                         backRect;
     139    Material                       _backMat;
     140    Rect2D                         _backRect;
    127141
    128     Material                       frontMat;
    129     Rect2D                         frontRect;
     142    Material                       _frontMat;
     143    Rect2D                         _frontRect;
    130144
    131 
    132     /// SIGNALS
    133     std::vector<SignalConnector>   widgetSignals;
     145    float                          _borderSize;
    134146
    135147    /// EVENTS
     
    139151    bool                           _pushed;
    140152
    141     static GLGuiWidget*            _focused;
    142     static GLGuiWidget*            _inputGrabber;
     153
     154    static GLGuiWidget*            _selected;         //!< The currently selected Widget.
     155    static GLGuiWidget*            _focused;          //!< The currently Focused Widget.
     156
     157    static GLGuiWidget*            _inputGrabber;     //!< The Widget that grabs input.
    143158  };
    144159}
  • trunk/src/lib/gui/gl_gui/signal_connector.cc

    r7855 r8035  
    2121{
    2222
     23  /**
     24   * @brief creates a clean SignalConnector
     25   */
    2326  SignalConnector::SignalConnector( )
    2427  {
     
    2730  }
    2831
     32  /**
     33   * @brief Creates a SignalConnector out of an ObjectPointer, and an Executor.
     34   * @param object the Object the Executor will apply to.
     35   * @param executor the Executor that will be executed.
     36   * @return a new SignalConnector.
     37   */
    2938  SignalConnector::SignalConnector(BaseObject* object, const Executor* executor)
    3039  {
     
    3342  };
    3443
     44  /**
     45   * @brief Creates a SignalConnector as a copy of another one.
     46   * @param signalConnector The SignalConnector to copy.
     47   */
    3548  SignalConnector::SignalConnector(const SignalConnector& signalConnector)
    3649  {
     
    3952  }
    4053
     54  /**
     55   * @brief deletes a SignalConnector.
     56   *
     57   * frees the stored executor
     58   */
    4159  SignalConnector::~SignalConnector()
    4260  {
     
    4462  }
    4563
     64  /**
     65   * @brief assignes a SignalConnector to the current one
     66   * @param signalConnector the SignalConnector to assign to this one
     67   * @return A Reference to this SignalConnector.
     68   */
    4669  SignalConnector& SignalConnector::operator=(const SignalConnector& signalConnector)
    4770  {
     
    5174  }
    5275
    53   void SignalConnector::operator()(const std::string& parameters) const
     76
     77  /**
     78   * @brief compares two SignalConnectors.
     79   * @param signalConnector the SignalConnector to compare against this one.
     80   * @return true if the Connectors are the same.
     81   */
     82  bool SignalConnector::operator==(const SignalConnector& signalConnector) const
     83  {
     84    return (this->object == signalConnector.object /* && this->exec == signalConnector.exec */ );
     85  }
     86
     87
     88  /**
     89   * @brief Executes the SignalConnector.
     90   */
     91  void SignalConnector::operator()() const
     92  {
     93    if (this->isValid())
     94      (*this->exec)(this->object, 0, NULL);
     95  }
     96
     97  /**
     98   * @brief Executes the SignalConnector.
     99   * @param value0 First Value.
     100   */
     101  void SignalConnector::operator()(const MultiType& value0) const
    54102  {
    55103    if (exec != NULL && object != NULL)
    56       (*this->exec)(this->object, parameters);
     104      (*this->exec)(this->object, 1, &value0);
    57105  }
    58106
     107  /**
     108   * @brief Executes the SignalConnector.
     109   * @param value0 First Value
     110   * @param value1 Second Value
     111   */
     112  void SignalConnector::operator()(const MultiType& value0, const MultiType& value1) const
     113  {
     114    if (exec != NULL && object != NULL)
     115    {
     116      MultiType mt[] = { value0, value1 };
     117      (*this->exec)(this->object, 2, mt);
     118    }
     119  }
     120
     121  /**
     122   * @brief Executes the SignalConnector.
     123   * @param value0 First Value
     124   * @param value1 Second Value
     125   * @param value2 Third Value
     126   */
     127  void SignalConnector::operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2) const
     128  {
     129    if (exec != NULL && object != NULL)
     130    {
     131      MultiType mt[] = { value0, value1, value2 };
     132      (*this->exec)(this->object, 3, mt);
     133    }
     134  }
     135
     136  /**
     137   * @brief Executes the SignalConnector.
     138   * @param value0 First Value
     139   * @param value1 Second Value
     140   * @param value2 Third Value
     141   * @param value3 Fourth Value
     142   */
     143  void SignalConnector::operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2, const MultiType& value3) const
     144  {
     145    if (exec != NULL && object != NULL)
     146    {
     147      MultiType mt[] = { value0, value1, value2, value3 };
     148      (*this->exec)(this->object, 4, mt);
     149    }
     150  }
     151
     152  /**
     153   * @brief Executes the SignalConnector.
     154   * @param value0 First Value
     155   * @param value1 Second Value
     156   * @param value2 Third Value
     157   * @param value3 Fourth Value
     158   * @param value3 Fifth Value
     159   */
     160  void SignalConnector::operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2, const MultiType& value3, const MultiType& value4) const
     161  {
     162    if (exec != NULL && object != NULL)
     163    {
     164      MultiType mt[] = { value0, value1, value2, value3, value4 };
     165      (*this->exec)(this->object, 5, mt);
     166    }
     167  }
    59168}
  • trunk/src/lib/gui/gl_gui/signal_connector.h

    r7919 r8035  
    1212{
    1313
    14 #define DeclareSignal(name, params) \
     14  //////////////// TO BE IGNORED BY YOU /////
     15#define DeclareSignalBegin(SignalName) \
    1516  public: \
    16    void signal_ ##connect ##name(const SignalConnector& connector) { \
    17      name ## connected.push_back(connector); \
     17   void signal_ ## connect ## SignalName(const SignalConnector& connector) { \
     18     SignalName ## connected.push_back(connector); \
     19}\
     20   Signal& getSignalVector_##SignalName () { return this->SignalName ## connected; }; \
     21  private:
     22
     23#define DeclareSignalEnd(SignalName) \
     24  Signal SignalName ## connected
     25  /////////////////////////////////////////////
     26
     27
     28  /**
     29   * @brief declares a new Signal.
     30   * @param SignalName the Name of the Signal.
     31   */
     32#define DeclareSignal0(SignalName) \
     33  DeclareSignalBegin(SignalName) \
     34   void  SignalName () { \
     35     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     36       SignalName ## connected[i] (); \
    1837   }\
    19   private: \
    20    void  signal_ ## name params { \
    21      for (unsigned int i = 0; i < name ## connected . size(); i++) \
    22        name ## connected[i] ("TEST"); \
    23    }\
    24    std::vector<SignalConnector> name ## connected
     38     DeclareSignalEnd(SignalName)
    2539
    26   //! A class for Conncting Signals to Objects, inside of the GUI
     40
     41  /**
     42   * @brief declares a new Signal.
     43   * @param SignalName the Name of the Signal.
     44   * @param param0 the first Parameter the Function takes
     45   */
     46#define DeclareSignal1(SignalName, param0) \
     47  DeclareSignalBegin(SignalName) \
     48   void  SignalName (param0 val0) { \
     49     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     50       SignalName ## connected[i] (val0); \
     51    }\
     52    DeclareSignalEnd(SignalName)
     53
     54  /**
     55   * @brief declares a new Signal.
     56   * @param SignalName the Name of the Signal.
     57   * @param param0 the first Parameter the Function takes
     58   * @param param1 the second Parameter the Function takes
     59   */
     60#define DeclareSignal2(SignalName, param0, param1) \
     61  DeclareSignalBegin(SignalName) \
     62   void  SignalName (param0 val0, param1 val1) { \
     63     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     64       SignalName ## connected[i] (val0, val1); \
     65}\
     66    DeclareSignalEnd(SignalName)
     67
     68
     69
     70  /**
     71   * @brief declares a new Signal.
     72   * @param SignalName the Name of the Signal.
     73   * @param param0 the first Parameter the Function takes
     74   * @param param1 the second Parameter the Function takes
     75   * @param param2 the third Parameter the Function takes
     76   */
     77#define DeclareSignal3(SignalName, param0, param1, param2) \
     78  DeclareSignalBegin(SignalName) \
     79   void  SignalName (param0 val0, param1 val1, param2 val2) { \
     80     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     81       SignalName ## connected[i] (val0, val1, val2); \
     82}\
     83    DeclareSignalEnd(SignalName)
     84
     85  /**
     86   * @brief declares a new Signal.
     87   * @param SignalName the Name of the Signal.
     88   * @param param0 the first Parameter the Function takes
     89   * @param param1 the second Parameter the Function takes
     90   * @param param2 the third Parameter the Function takes
     91   * @param param3 the fourth Parameter the Function takes
     92   */
     93#define DeclareSignal4(SignalName, param0, param1, param2, param3) \
     94  DeclareSignalBegin(SignalName) \
     95   void  SignalName (param0 val0, param1 val1, param2 val2, param3 val3) { \
     96     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     97       SignalName ## connected[i] (val0, val1, val2, val3); \
     98}\
     99    DeclareSignalEnd(SignalName)
     100
     101
     102  /**
     103   * @brief declares a new Signal.
     104   * @param SignalName the Name of the Signal.
     105   * @param param0 the first Parameter the Function takes
     106   * @param param1 the second Parameter the Function takes
     107   * @param param2 the third Parameter the Function takes
     108   * @param param4 the fifth Parameter the Function takes
     109   */
     110#define DeclareSignal5(SignalName, param0, param1, param2, param3, param4) \
     111  DeclareSignalBegin(SignalName) \
     112   void  SignalName (param0 val0, param1 val1, param2 val2, param3 val3, param4 val4) { \
     113     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     114       SignalName ## connected[i] (val0, val1, val2, val3, val4); \
     115}\
     116    DeclareSignalEnd(SignalName)
     117
     118
     119  /**
     120   * @brief selects a Signal.
     121   * @param SignalName the Signal to be retrieved.
     122   */
     123#define SIGNAL(Object, SignalName) \
     124    Object->getSignalVector_##SignalName()
     125
     126  /**
     127   * @brief defines a Slot, the sink of a Signal.
     128   * @param Class the Class the Slot belongs to.
     129   * @param function the Function to Connect to.
     130   */
     131#define SLOT(Class, function) \
     132    createExecutor<Class>(&Class::function)
     133
     134  /**
     135   * @brief emits function
     136   */
     137#define emit(function) function
     138
     139  //! A class for Conncting Signals to Objects, inside of the Graphical user interface.
     140  /**
     141   * The SignalConnector binds an Object to a Functional (Executor)
     142   * The Usage is quite easy in the Widget for this:
     143   *
     144   * int the header (Class Definition) you can add a definition of a Signal with:
     145   * @verbatim DeclareSignal3(my_signal, int, int, float)
     146   * and a Signal with the the Parameters int,int and float will be created.
     147   *
     148   * now you can use the connect function of GLWidget to connect this Signal to a Slot.
     149   * @see GLGuiWidget::connect
     150   */
    27151  class SignalConnector
    28152  {
     
    34158
    35159    SignalConnector& operator=(const SignalConnector& signalConnector);
     160    bool operator==(const SignalConnector& signalConnector) const;
    36161
    37     void operator()(const std::string& parameters) const;
    38     void execute(const std::string& parameters) const { (*this)(parameters); };
     162    void operator()() const;
     163    void operator()(const MultiType& value0) const;
     164    void operator()(const MultiType& value0, const MultiType& value1) const;
     165    void operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2) const;
     166    void operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2, const MultiType& value3) const;
     167    void operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2, const MultiType& value3, const MultiType& value4) const;
    39168
     169    /** checks wether the SignalConnector is valid @return true on valid. */
     170    bool isValid() const { return (this->object && this->exec); };
     171    /** @brief checks if the SignalConnector is clean, invalid @returns true if invalid */
    40172    bool isClean() const { return (this->object == NULL || this->exec == NULL); }
    41173
     
    45177    const Executor*      exec;           //!< The Executor, that will be called, on object.
    46178  };
     179
     180  //! TypeDefinition for SignalLists
     181  typedef std::vector<SignalConnector> Signal;
     182  //! TypeDefinition for a Slot.
     183  typedef Executor*                    Slot;
     184
    47185}
    48186#endif /* _SIGNAL_CONNECTOR_H */
Note: See TracChangeset for help on using the changeset viewer.