Changeset 8035 in orxonox.OLD for trunk/src/lib/gui
- Timestamp:
- May 31, 2006, 4:20:51 PM (18 years ago)
- Location:
- trunk/src/lib/gui/gl_gui
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/gui/gl_gui/Makefile.am
r7919 r8035 25 25 glgui_inputline.cc \ 26 26 glgui_textfield.cc \ 27 glgui_image.cc \ 27 28 glgui_window.cc \ 28 29 glgui_cursor.cc … … 47 48 glgui_inputline.h \ 48 49 glgui_textfield.h \ 50 glgui_image.h \ 49 51 glgui_window.h \ 50 52 glgui_cursor.h -
trunk/src/lib/gui/gl_gui/glgui.h
r7919 r8035 7 7 #define _GLGUI_H 8 8 9 #include "glgui_defs.h" 9 10 #include "glgui_handler.h" 10 11 … … 17 18 //#include "glgui_colorselector.h" 18 19 #include "glgui_pushbutton.h" 20 #include "glgui_slider.h" 19 21 #include "glgui_cursor.h" 20 22 #include "glgui_inputline.h" 21 23 #include "glgui_textfield.h" 24 #include "glgui_image.h" 22 25 23 26 -
trunk/src/lib/gui/gl_gui/glgui_bar.cc
r7919 r8035 60 60 void GLGuiBar::draw() const 61 61 { 62 this-> startDraw();62 this->beginDraw(); 63 63 64 64 GLGuiWidget::draw(); -
trunk/src/lib/gui/gl_gui/glgui_box.cc
r7779 r8035 23 23 * standard constructor 24 24 */ 25 GLGuiBox::GLGuiBox ( BoxType type)25 GLGuiBox::GLGuiBox (OrxGui::Orientation orientation) 26 26 { 27 27 this->init(); 28 28 29 this->set Type (type);29 this->setOrientation(orientation); 30 30 } 31 31 … … 47 47 void GLGuiBox::pack(GLGuiWidget* widget) 48 48 { 49 if (widget == NULL) 50 return; 49 assert (widget != NULL); 51 50 52 51 this->children.push_back(widget); 52 widget->setParentWidget(this); 53 54 this->resize(); 53 55 } 54 56 … … 56 58 void GLGuiBox::unpack(GLGuiWidget* widget) 57 59 { 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()) 59 64 { 60 this->children.clear(); 65 (*delWidget)->setParentWidget(NULL); 66 this->children.erase(delWidget); 61 67 } 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(); 66 75 } 67 76 68 77 void GLGuiBox::showAll() 69 78 { 70 std:: list<GLGuiWidget*>::iterator itC = this->children.begin();79 std::vector<GLGuiWidget*>::iterator itC = this->children.begin(); 71 80 while (itC != this->children.end()) 72 81 { … … 79 88 80 89 this->show(); 81 82 90 } 83 91 84 92 void GLGuiBox::hideAll() 85 93 { 86 std:: list<GLGuiWidget*>::iterator itC = this->children.begin();94 std::vector<GLGuiWidget*>::iterator itC = this->children.begin(); 87 95 while (itC != this->children.end()) 88 96 { … … 97 105 } 98 106 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 } 99 155 100 156 /** 101 * draws the GLGuiBox157 * @brief draws the GLGuiBox 102 158 */ 103 159 void GLGuiBox::draw() const 104 160 { 161 this->beginDraw(); 162 GLGuiWidget::draw(); 163 this->endDraw(); 105 164 } 106 165 } -
trunk/src/lib/gui/gl_gui/glgui_box.h
r7779 r8035 9 9 10 10 #include "glgui_container.h" 11 11 #include "glgui_defs.h" 12 12 13 13 namespace OrxGui 14 14 { 15 typedef enum16 {17 Box_H,18 Box_V,19 } BoxType;20 21 15 //! This is BOX part of the openglGUI class 22 16 /** … … 27 21 28 22 public: 29 GLGuiBox( BoxType type = Box_H);23 GLGuiBox(OrxGui::Orientation orientation = OrxGui::Vertical); 30 24 virtual ~GLGuiBox(); 31 25 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; }; 34 30 35 31 virtual void pack(GLGuiWidget* widget); 36 32 virtual void unpack(GLGuiWidget* widget); 33 virtual void clear(); 34 37 35 virtual void showAll(); 38 36 virtual void hideAll(); … … 40 38 virtual void draw() const; 41 39 40 protected: 41 virtual void resize(); 42 42 43 private: 43 BoxType type; 44 std::list<GLGuiWidget*> children; 44 void init(); 45 46 Orientation _orientation; 47 std::vector<GLGuiWidget*> children; 45 48 }; 46 49 } -
trunk/src/lib/gui/gl_gui/glgui_button.cc
r7919 r8035 67 67 } 68 68 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 69 80 /** 70 81 * @brief draws the GLGuiButton -
trunk/src/lib/gui/gl_gui/glgui_button.h
r7919 r8035 32 32 { 33 33 34 public:35 GLGuiButton(const std::string& label);36 virtual ~GLGuiButton();34 public: 35 GLGuiButton(const std::string& label); 36 virtual ~GLGuiButton(); 37 37 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); 40 40 41 virtual void resize() = 0;41 virtual void draw() const; 42 42 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); 44 49 45 50 private: … … 47 52 48 53 49 protected:50 54 51 Text label;55 protected: 52 56 53 private: 54 ButtonState state; 57 Text label; 58 59 private: 60 ButtonState state; 55 61 }; 56 62 } -
trunk/src/lib/gui/gl_gui/glgui_checkbutton.cc
r7919 r8035 52 52 } 53 53 54 void GLGuiCheckButton::setActivity(bool bActive) 55 { 56 this->bActive = bActive; 57 emit(this->toggled(this->bActive)); 58 } 54 59 55 60 void GLGuiCheckButton::toggleActiveState() 56 61 { 57 this-> bActive = !this->bActive;62 this->setActivity(!this->isActive()); 58 63 } 59 64 … … 62 67 this->label.setRelCoor2D(25, 5); 63 68 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()); 64 72 } 65 73 66 74 67 void GLGuiCheckButton::releas ed()75 void GLGuiCheckButton::releasing(const Vector2D& pos) 68 76 { 69 printf("%s released\n", this->getLabel().c_str()); 70 GLGuiWidget::released(); 77 GLGuiButton::releasing(pos); 71 78 this->toggleActiveState(); 72 79 } 80 81 73 82 74 83 /** … … 77 86 void GLGuiCheckButton::draw() const 78 87 { 79 this-> startDraw();88 this->beginDraw(); 80 89 GLGuiButton::draw(); 81 90 82 91 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()); 89 93 90 94 if (this->bActive) 91 95 { 96 glBegin(GL_QUADS); 92 97 glColor3f( 1, 1 ,1); 93 98 glTexCoord2i(0,0); glVertex2d(8, 8); … … 117 122 else 118 123 { 124 glBegin(GL_QUADS); 119 125 glColor3f(0, 0, 0); 120 126 glTexCoord2i(0,0); glVertex2d(8, 8); … … 125 131 } 126 132 127 128 133 this->endDraw(); 129 // this->label->draw();130 // printf("test");131 134 } 132 135 } -
trunk/src/lib/gui/gl_gui/glgui_checkbutton.h
r7919 r8035 26 26 virtual ~GLGuiCheckButton(); 27 27 28 virtual void resize();29 virtual void released();30 28 31 29 bool isActive() { return this->bActive; }; … … 35 33 virtual void draw() const; 36 34 virtual void update() {}; 35 36 DeclareSignal1(toggled, bool); 37 38 protected: 39 virtual void resize(); 40 virtual void releasing(const Vector2D& pos); 37 41 38 42 private: -
trunk/src/lib/gui/gl_gui/glgui_container.h
r7779 r8035 25 25 virtual ~GLGuiContainer(); 26 26 27 void init(); 28 29 30 void setBorderWidth(float borderwidth); 31 32 27 /** @brief packs a widget into this one. */ 33 28 virtual void pack(GLGuiWidget* widget) = 0; 34 29 /** unpacks a Widget from this container. @param widget the GLGuiWidget to unpack, if NULL all subwidgets will be unpackt. */ 35 30 virtual void unpack(GLGuiWidget* widget) = 0; 31 /** @brief clears all Widgets out. */ 32 virtual void clear() = 0; 33 36 34 virtual void hideAll() = 0; 37 35 virtual void showAll() = 0; … … 41 39 42 40 private: 43 41 void init(); 44 42 }; 45 43 } -
trunk/src/lib/gui/gl_gui/glgui_cursor.cc
r7919 r8035 59 59 this->backMaterial().setDiffuse(1.0,0.0,0.0); 60 60 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); 62 63 this->setAbsCoor2D(100, 100); 63 64 this->setLayer(E2D_LAYER_ABOVE_ALL); 64 65 this->color = 0.0f; 65 66 67 this->resize(); 66 68 } 67 69 … … 74 76 this->backMaterial().setDiffuse(color.x, color.y, color.z); 75 77 76 if (this->movement != Vector2D())78 //if (this->movement != Vector2D()) 77 79 { 78 80 newPos += movement; … … 88 90 89 91 90 this->setAbsCoorSoft2D(newPos, 10);91 92 movement = Vector2D(); 92 93 } 94 this->setAbsCoor2D(newPos); 93 95 } 94 96 … … 98 100 void GLGuiCursor::draw() const 99 101 { 100 this-> startDraw();102 this->beginDraw(); 101 103 GLGuiWidget::draw(); 102 104 this->endDraw(); -
trunk/src/lib/gui/gl_gui/glgui_handler.cc
r7919 r8035 107 107 { 108 108 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 } 110 113 } 111 114 else 112 115 { 113 116 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 } 115 121 } 116 122 } … … 137 143 138 144 } 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 139 168 140 169 void GLGuiHandler::draw() -
trunk/src/lib/gui/gl_gui/glgui_handler.h
r7919 r8035 30 30 GLGuiCursor* getCursor() const { return this->cursor; } 31 31 32 Vector2D cursorPositionOverFocusedWidget() const; 33 const Vector2D& cursorPositionAbs() const; 34 Vector2D cursorPositionRel(const GLGuiWidget* const widget) const; 35 32 36 void activate(); 33 37 void deactivate(); -
trunk/src/lib/gui/gl_gui/glgui_image.cc
r7779 r8035 43 43 void GLGuiImage::init() 44 44 { 45 this->setClassID(CL_GLGUI_ , "GLGuiImage");45 this->setClassID(CL_GLGUI_IMAGE, "GLGuiImage"); 46 46 47 this->frontMaterial().setDiffuseMap(this->texture); 48 this->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 49 50 this->resize(); 47 51 } 48 52 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 49 83 /** 50 * draws the GLGuiImage84 * @brief draws the GLGuiImage 51 85 */ 52 void GLGuiImage::draw() 86 void GLGuiImage::draw() const 53 87 { 88 this->beginDraw(); 89 GLGuiWidget::draw(); 90 91 this->frontMaterial().select(); 92 this->drawRect(this->frontRect()); 93 this->endDraw(); 54 94 } 55 95 } -
trunk/src/lib/gui/gl_gui/glgui_image.h
r7779 r8035 8 8 #define _GLGUI_IMAGE_H 9 9 10 #include " base_object.h"10 #include "glgui_widget.h" 11 11 12 12 // FORWARD DECLARATION … … 26 26 virtual ~GLGuiImage(); 27 27 28 void init(); 29 void loadImageFromFile(const char* fileName); 28 void loadImageFromTexture(const Texture& texture); 29 30 void loadImageFromFile(const std::string& fileName); 30 31 void loadImageFromSDLSurface(SDL_Surface* surface); 31 void loadImageFromDisplayList(GLuint displayList);32 void loadImageFromDisplayList(GLuint texture); 32 33 33 virtual void draw(); 34 virtual void draw() const; 35 36 DeclareSignal0(imageChanged); 34 37 35 38 private: 39 void init(); 40 virtual void resize(); 36 41 42 private: 43 Texture texture; 37 44 }; 38 45 } -
trunk/src/lib/gui/gl_gui/glgui_inputline.cc
r7919 r8035 21 21 { 22 22 /** 23 * standard constructor23 * @brief standard constructor 24 24 */ 25 25 GLGuiInputLine::GLGuiInputLine () 26 26 { 27 27 this->init(); 28 29 } 30 31 32 /** 33 * standard deconstructor 34 */ 28 } 29 30 31 /** 32 * @brief standard deconstructor 33 */ 35 34 GLGuiInputLine::~GLGuiInputLine() 36 35 {} … … 41 40 42 41 /** 43 * initializes the GUI-element42 * @brief initializes the GUI-element 44 43 */ 45 44 void GLGuiInputLine::init() … … 52 51 this->text.setRelCoor2D(4,4); 53 52 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 */ 56 61 void GLGuiInputLine::setText(const std::string& text) 57 62 { 58 63 this->text.setText(text); 59 64 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 */ 62 73 void GLGuiInputLine::append(const std::string& appendText) 63 74 { 64 75 this->text.append(appendText); 65 76 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 */ 68 85 void GLGuiInputLine::appendCharacter(char character) 69 86 { 70 87 this->text.appendCharacter(character); 71 88 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 */ 75 97 void GLGuiInputLine::removeCharacters(unsigned int chars) 76 98 { 77 99 this->text.removeCharacters(chars); 78 100 this->resize(); 79 } 80 81 101 emit(this->textChanged(this->text.getText())); 102 } 103 104 105 /** 106 * removes the focus from this Widget. 107 */ 82 108 void GLGuiInputLine::removedFocus() 83 109 { … … 88 114 89 115 116 /** 117 * Processes an Event. 118 * @param event The event to be processed 119 * @return true if the event was catched. 120 */ 90 121 bool GLGuiInputLine::processEvent(const Event& event) 91 122 { … … 126 157 127 158 159 /** 160 * @brief Resizes the Widget to the new Size-constraints. 161 */ 128 162 void GLGuiInputLine::resize() 129 163 { 130 164 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 */ 134 175 void GLGuiInputLine::tick(float dt) 135 176 { … … 156 197 157 198 /** 158 * draws the GLGuiInputLine199 * @brief draws the GLGuiInputLine 159 200 */ 160 201 void GLGuiInputLine::draw() const 161 202 { 162 this-> startDraw();203 this->beginDraw(); 163 204 GLGuiWidget::draw(); 164 205 165 206 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 174 209 this->endDraw(); 175 210 } -
trunk/src/lib/gui/gl_gui/glgui_inputline.h
r7919 r8035 16 16 { 17 17 18 //! This is part of the openglGUI class18 //! This is InputLine part of the openglGUI class 19 19 /** 20 * The InputLine is a Widget, that displays a Line, that can be manipulated through 21 * Writing Text on it. 20 22 * 23 * Whenever the Text is changed the textChanged signal is emitted. 21 24 */ 22 25 class GLGuiInputLine : public OrxGui::GLGuiWidget … … 27 30 virtual ~GLGuiInputLine(); 28 31 29 void init(); 32 33 /** @returns the text of the inputLine */ 34 const std::string& getText() const { return this->text.getText(); }; 30 35 31 36 void setText(const std::string& text); … … 33 38 void appendCharacter(char character); 34 39 void removeCharacters(unsigned int chars); 35 const std::string& getName() const { return this->text.getText(); };36 37 40 38 41 virtual void removedFocus(); … … 43 46 virtual bool processEvent(const Event& event); 44 47 45 private: 46 void resize(); 48 DeclareSignal1(textChanged, const std::string&); 47 49 50 private: 51 void init(); 52 void resize(); 48 53 49 54 private: … … 55 60 float delayNext; //!< How much time must pass before next output. 56 61 57 static float repeatDelay; 58 static float repeatRate; 59 60 62 static float repeatDelay; //!< Repead Delay. 63 static float repeatRate; //!< Repeat Rate. 61 64 }; 62 65 } -
trunk/src/lib/gui/gl_gui/glgui_pushbutton.cc
r7919 r8035 47 47 this->label.setRelCoor2D(5, 5); 48 48 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); 49 53 } 50 54 … … 70 74 } 71 75 72 void GLGuiPushButton::click ed()76 void GLGuiPushButton::clicking(const Vector2D& pos) 73 77 { 74 78 printf("%s clicked\n", this->getLabel().c_str()); 75 GLGui Widget::clicked();79 GLGuiButton::clicking(pos); 76 80 } 77 81 78 82 79 void GLGuiPushButton::releas ed()83 void GLGuiPushButton::releasing(const Vector2D& pos) 80 84 { 81 85 printf("%s released\n", this->getLabel().c_str()); 82 GLGui Widget::released();86 GLGuiButton::releasing(pos); 83 87 } 84 88 … … 90 94 void GLGuiPushButton::draw() const 91 95 { 92 this-> startDraw();96 this->beginDraw(); 93 97 GLGuiButton::draw(); 94 98 95 99 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()); 104 101 this->endDraw(); 105 102 // this->label->draw(); -
trunk/src/lib/gui/gl_gui/glgui_pushbutton.h
r7919 r8035 27 27 28 28 29 virtual void resize();30 31 virtual void receivedFocus();32 virtual void removedFocus();33 virtual void clicked();34 virtual void released();35 29 36 30 37 31 virtual void draw() const; 38 32 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 39 42 private: 40 43 void init(); -
trunk/src/lib/gui/gl_gui/glgui_slider.cc
r7919 r8035 17 17 18 18 #include "glgui_slider.h" 19 #include "event_def.h" 20 21 #include "glgui_handler.h" 19 22 20 23 namespace OrxGui … … 22 25 23 26 /** 24 * standard constructor25 */27 * @brief standard constructor 28 */ 26 29 GLGuiSlider::GLGuiSlider () 27 30 { … … 32 35 33 36 /** 34 * standard deconstructor35 */37 * @brief standard deconstructor 38 */ 36 39 GLGuiSlider::~GLGuiSlider() 37 { 38 } 39 40 /** 41 * initializes the GUI-element 40 {} 41 42 /** 43 * @brief initializes the GUI-element 42 44 */ 43 45 void GLGuiSlider::init() 44 46 { 47 45 48 this->setClassID(CL_GLGUI_SLIDER, "GLGuiSlider"); 46 49 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 51 224 */ 52 225 void GLGuiSlider::draw() const 53 226 { 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; 54 260 } 55 261 } -
trunk/src/lib/gui/gl_gui/glgui_slider.h
r7919 r8035 17 17 //! This is part of the openglGUI class 18 18 /** 19 * 19 * The Slider is a Widget, with a Range and a Value. 20 20 */ 21 21 class GLGuiSlider : public GLGuiWidget … … 26 26 virtual ~GLGuiSlider(); 27 27 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: 28 64 void init(); 29 30 virtual void draw() const;65 float sliderPosition() const; 66 float sliderValue(float position) const; 31 67 32 68 private: … … 35 71 float _maxValue; 36 72 float _minValue; 73 float _step; 37 74 38 75 float _value; 76 77 float _sliderWidth; 78 79 bool grabbed; 39 80 40 81 }; -
trunk/src/lib/gui/gl_gui/glgui_text.h
r7779 r8035 26 26 virtual ~GLGuiText(); 27 27 28 void setText(); 29 30 virtual void draw(); 31 32 private: 28 33 void init(); 29 34 30 virtual void draw();31 35 32 36 private: -
trunk/src/lib/gui/gl_gui/glgui_textfield.cc
r7919 r8035 43 43 { 44 44 this->setClassID(CL_GLGUI_TEXTFIELD, "GLGuiTextfield"); 45 46 47 45 } 48 46 49 47 /** 50 * draws the GLGuiTextfield48 * @brief draws the GLGuiTextfield 51 49 */ 52 50 void GLGuiTextfield::draw() const 53 51 { 52 this->beginDraw(); 53 GLGuiWidget::draw(); 54 55 this->frontMaterial().select(); 56 this->drawRect(this->frontRect()); 57 this->endDraw(); 54 58 } 55 59 } -
trunk/src/lib/gui/gl_gui/glgui_widget.cc
r7919 r8035 28 28 29 29 /** 30 * standard constructor30 * @brief standard constructor 31 31 */ 32 GLGuiWidget::GLGuiWidget ( 32 GLGuiWidget::GLGuiWidget (GLGuiWidget* parent) 33 33 { 34 34 this->init(); 35 } 36 37 38 /** 39 * standard deconstructor 35 36 this->setParentWidget(parent); 37 } 38 39 40 /** 41 * @brief standard deconstructor 40 42 */ 41 43 GLGuiWidget::~GLGuiWidget() … … 45 47 } 46 48 49 GLGuiWidget* GLGuiWidget::_selected = NULL; 47 50 GLGuiWidget* GLGuiWidget::_focused = NULL; 48 51 GLGuiWidget* GLGuiWidget::_inputGrabber = NULL; … … 63 66 this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE); 64 67 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 } 71 81 72 82 /** @brief gives focus to this widget */ … … 93 103 { 94 104 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); 96 106 } 97 107 … … 101 111 } 102 112 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) 104 130 { 105 131 assert (!this->_pushed); 106 this->widgetSignals[Signal_click]("none");107 132 this->_pushed = true; 108 133 109 this->click ed();110 } 111 112 void GLGuiWidget::release( )134 this->clicking(pos); 135 } 136 137 void GLGuiWidget::release(const Vector2D& pos) 113 138 { 114 139 if (this->_pushed) 115 140 { 116 this->widgetSignals[Signal_release]("none"); 117 118 this->released(); 141 this->releasing(pos); 119 142 this->_pushed = false; 120 143 } … … 122 145 123 146 124 void GLGuiWidget::click ed()147 void GLGuiWidget::clicking(const Vector2D& pos) 125 148 { 126 149 this->frontMaterial().setDiffuse(0, 0, 1); … … 128 151 } 129 152 130 void GLGuiWidget::releas ed()131 { 132 this->frontMat .setDiffuse(0,1,0);153 void GLGuiWidget::releasing(const Vector2D& pos) 154 { 155 this->frontMaterial().setDiffuse(0,1,0); 133 156 134 157 } … … 146 169 147 170 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 158 214 */ 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' Event172 * @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 194 215 void GLGuiWidget::draw() const 195 216 { 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()); 204 219 } 205 220 -
trunk/src/lib/gui/gl_gui/glgui_widget.h
r7919 r8035 24 24 namespace OrxGui 25 25 { 26 typedef enum27 {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 39 26 40 27 class GLGuiCursor; … … 49 36 class GLGuiWidget : public Element2D 50 37 { 51 52 private:53 54 38 public: 55 GLGuiWidget( );39 GLGuiWidget(GLGuiWidget* parent = NULL); 56 40 virtual ~GLGuiWidget(); 57 41 … … 59 43 void hide(); 60 44 61 /// INTERCONNECTIVITY62 void connectSignal(SignalType signalType, BaseObject* obj, const Executor* signal);63 void disconnectSignal(SignalType signalType);64 45 46 void setParentWidget(GLGuiWidget* parent); 47 GLGuiWidget* parent() const { return this->_parent; } 65 48 66 49 /// FOCUS … … 82 65 83 66 /// CLICK 84 void click( );85 void release( );67 void click(const Vector2D& pos); 68 void release(const Vector2D& pos); 86 69 bool clickable() const { return this->_clickable; }; 87 70 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 88 107 89 108 virtual void update() {}; 90 109 virtual void draw() const; 91 110 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 100 111 /** @param the Event to process. @returns true if the Event has been consumed*/ 101 112 virtual bool processEvent(const Event& event) { }; 102 113 114 protected: 103 115 104 DeclareSignal(testSignal, ()); 116 /// LOOKS 117 virtual void resize(); 105 118 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); 110 122 virtual void receivedFocus(); 111 123 virtual void removedFocus(); … … 114 126 115 127 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); }; 117 129 inline void endDraw() const { glPopMatrix(); }; 118 130 … … 122 134 123 135 private: 136 GLGuiWidget* _parent; //!< The parent of this Widget. 137 124 138 /// LOOKS 125 Material backMat;126 Rect2D backRect;139 Material _backMat; 140 Rect2D _backRect; 127 141 128 Material frontMat;129 Rect2D frontRect;142 Material _frontMat; 143 Rect2D _frontRect; 130 144 131 132 /// SIGNALS 133 std::vector<SignalConnector> widgetSignals; 145 float _borderSize; 134 146 135 147 /// EVENTS … … 139 151 bool _pushed; 140 152 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. 143 158 }; 144 159 } -
trunk/src/lib/gui/gl_gui/signal_connector.cc
r7855 r8035 21 21 { 22 22 23 /** 24 * @brief creates a clean SignalConnector 25 */ 23 26 SignalConnector::SignalConnector( ) 24 27 { … … 27 30 } 28 31 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 */ 29 38 SignalConnector::SignalConnector(BaseObject* object, const Executor* executor) 30 39 { … … 33 42 }; 34 43 44 /** 45 * @brief Creates a SignalConnector as a copy of another one. 46 * @param signalConnector The SignalConnector to copy. 47 */ 35 48 SignalConnector::SignalConnector(const SignalConnector& signalConnector) 36 49 { … … 39 52 } 40 53 54 /** 55 * @brief deletes a SignalConnector. 56 * 57 * frees the stored executor 58 */ 41 59 SignalConnector::~SignalConnector() 42 60 { … … 44 62 } 45 63 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 */ 46 69 SignalConnector& SignalConnector::operator=(const SignalConnector& signalConnector) 47 70 { … … 51 74 } 52 75 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 54 102 { 55 103 if (exec != NULL && object != NULL) 56 (*this->exec)(this->object, parameters);104 (*this->exec)(this->object, 1, &value0); 57 105 } 58 106 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 } 59 168 } -
trunk/src/lib/gui/gl_gui/signal_connector.h
r7919 r8035 12 12 { 13 13 14 #define DeclareSignal(name, params) \ 14 //////////////// TO BE IGNORED BY YOU ///// 15 #define DeclareSignalBegin(SignalName) \ 15 16 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] (); \ 18 37 }\ 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) 25 39 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 */ 27 151 class SignalConnector 28 152 { … … 34 158 35 159 SignalConnector& operator=(const SignalConnector& signalConnector); 160 bool operator==(const SignalConnector& signalConnector) const; 36 161 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; 39 168 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 */ 40 172 bool isClean() const { return (this->object == NULL || this->exec == NULL); } 41 173 … … 45 177 const Executor* exec; //!< The Executor, that will be called, on object. 46 178 }; 179 180 //! TypeDefinition for SignalLists 181 typedef std::vector<SignalConnector> Signal; 182 //! TypeDefinition for a Slot. 183 typedef Executor* Slot; 184 47 185 } 48 186 #endif /* _SIGNAL_CONNECTOR_H */
Note: See TracChangeset
for help on using the changeset viewer.