Changeset 7931 in orxonox.OLD for branches/gui/src
- Timestamp:
- May 28, 2006, 8:18:03 PM (18 years ago)
- Location:
- branches/gui/src/lib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gui/src/lib/event/event_handler.cc
r7928 r7931 380 380 case SDL_MOUSEBUTTONUP: 381 381 ev.bPressed = false; 382 ev.x = event.motion.x; 383 ev.y = event.motion.y; 382 384 ev.type = event.button.button + SDLK_LAST; 383 385 break; 384 386 case SDL_MOUSEBUTTONDOWN: 385 387 ev.bPressed = true; 388 ev.x = event.motion.x; 389 ev.y = event.motion.y; 386 390 ev.type = event.button.button + SDLK_LAST; 387 391 break; -
branches/gui/src/lib/gui/gl_gui/glgui_handler.cc
r7929 r7931 108 108 if (GLGuiWidget::focused()->clickable()) 109 109 { 110 GLGuiWidget::focused()->click(Vector2D(event.x, event.y) - GLGuiWidget::focused()->getAbsCoor2D()); 110 Vector2D cursorPos = (this->cursor != NULL) ? this->cursor->getAbsCoor2D() : Vector2D(event.x, event.y); 111 GLGuiWidget::focused()->click(cursorPos - GLGuiWidget::focused()->getAbsCoor2D()); 111 112 } 112 113 } … … 114 115 { 115 116 if (GLGuiWidget::focused()->clickable()) 116 GLGuiWidget::focused()->release(Vector2D(event.x, event.y) - GLGuiWidget::focused()->getAbsCoor2D()); 117 { 118 Vector2D cursorPos = (this->cursor != NULL) ? this->cursor->getAbsCoor2D() : Vector2D(event.x, event.y); 119 GLGuiWidget::focused()->release(cursorPos - GLGuiWidget::focused()->getAbsCoor2D()); 120 } 117 121 } 118 122 } … … 139 143 140 144 } 145 146 147 Vector2D GLGuiHandler::cursorPositionOverFocusedWidget() const 148 { 149 return (this->cursor != NULL) ? this->cursor->getAbsCoor2D() : Vector2D(0,0); 150 } 151 141 152 142 153 void GLGuiHandler::draw() -
branches/gui/src/lib/gui/gl_gui/glgui_handler.h
r7919 r7931 30 30 GLGuiCursor* getCursor() const { return this->cursor; } 31 31 32 Vector2D cursorPositionOverFocusedWidget() const; 33 32 34 void activate(); 33 35 void deactivate(); -
branches/gui/src/lib/gui/gl_gui/glgui_slider.cc
r7929 r7931 17 17 18 18 #include "glgui_slider.h" 19 #include "event_def.h" 19 20 20 21 namespace OrxGui … … 35 36 */ 36 37 GLGuiSlider::~GLGuiSlider() 37 { 38 } 38 {} 39 39 40 40 /** … … 53 53 this->_maxValue = 1.0; 54 54 this->_step = 0.1; 55 this->_sliderWidth = 5.0; 56 this->grabbed = false; 55 57 56 58 this->setSize2D(100, 30); … … 61 63 void GLGuiSlider::setValue(float value) 62 64 { 63 this->_value = value; 65 if (value < this->min()) 66 this->_value = min(); 67 else if (value > max()) 68 this->_value = max(); 69 else 70 this->_value = value; 71 printf("VALUE %f\n", _value); 64 72 } 65 73 66 74 void GLGuiSlider::setMin(float minimum) 67 75 { 68 this->_minValue = minimum; 76 if (minimum <= max()) 77 this->_minValue = minimum; 78 79 if (this->value() < minimum) 80 this->_value = minimum; 69 81 } 70 82 71 83 void GLGuiSlider::setMax(float maximum) 72 84 { 73 this->_maxValue = maximum; 85 if (maximum >= min()) 86 this->_maxValue = maximum; 87 88 if (this->value() > maximum) 89 this->_value = maximum; 74 90 } 75 91 76 92 void GLGuiSlider::setRange(float minimum, float maximum) 77 93 { 78 this->_minValue = minimum; 79 this->_maxValue = maximum; 94 if (minimum < maximum) 95 { 96 this->_minValue = minimum; 97 this->_maxValue = maximum; 98 } 99 if (this->value() < minimum) 100 this->_value = minimum; 101 else if (this->value() > maximum) 102 this->_value = maximum; 80 103 } 81 104 … … 93 116 } 94 117 118 119 void GLGuiSlider::clicked(const Vector2D& pos) 120 { 121 GLGuiWidget::clicked(pos); 122 123 float sliderPosition = this->sliderPosition(); 124 if (sliderPosition > pos.x + this->_sliderWidth) 125 this->setValue(this->value() - this->step()); 126 127 else if (sliderPosition < pos.x - this->_sliderWidth) 128 this->setValue(this->value() + this->step()); 129 else 130 this->grabbed = true; 131 132 133 134 printf("clicked at position: "), pos.debug(); 135 } 136 137 void GLGuiSlider::released(const Vector2D& pos) 138 { 139 GLGuiWidget::released(pos); 140 this->grabbed = false; 141 } 142 143 void GLGuiSlider::removedFocus() 144 { 145 GLGuiWidget::removedFocus(); 146 this->grabbed = false; 147 } 148 149 float GLGuiSlider::sliderPosition() const 150 { 151 return (this->_value - this->_minValue)/( this->_maxValue - this->_minValue) * (this->getSizeX2D() - 4.0) + 2.0; 152 } 153 154 float GLGuiSlider::sliderValue(float position) const 155 { 156 return (position - 2.0) / (this->getSizeX2D() - 4.0) *( this->_maxValue - this->_minValue) +this->_minValue ; 157 } 158 159 /* virtual void GLGuiSlider::tick(float dt) 160 { 161 if (this->grabbed) 162 { 163 this->setValue( 1); 164 } 165 }*/ 166 95 167 /** 96 168 * @brief draws the GLGuiSlider … … 104 176 this->drawRect(this->frontRect()); 105 177 106 float percentagePosition = (this->_value - this->_minValue)/( this->_maxValue - this->_minValue); 107 108 this->drawRect(Rect2D(percentagePosition* this->getSizeX2D(), 2, 5, this->getSizeY2D() - 4)); 178 this->drawRect(Rect2D(this->sliderPosition()-_sliderWidth/2.0, 2, _sliderWidth, this->getSizeY2D() - 4)); 109 179 110 180 this->endDraw(); 111 181 } 182 183 bool GLGuiSlider::processEvent( const Event& event ) 184 { 185 if (this->grabbed && event.type == EV_MOUSE_MOTION) 186 { 187 this->setValue(sliderValue(event.x - this->getAbsCoor2D().x)); 188 return true; 189 } 190 return false; 191 } 112 192 } -
branches/gui/src/lib/gui/gl_gui/glgui_slider.h
r7929 r7931 43 43 void setStep(float step); 44 44 45 46 // virtual void tick(float dt); 47 virtual bool processEvent(const Event& event); 45 48 virtual void draw() const; 46 49 47 50 protected: 48 void resize(); 51 virtual void resize(); 52 53 virtual void clicked(const Vector2D& pos); 54 virtual void released(const Vector2D& pos); 55 virtual void removedFocus(); 49 56 50 57 private: 51 58 void init(); 59 float sliderPosition() const; 60 float sliderValue(float position) const; 52 61 private: 53 62 … … 60 69 float _value; 61 70 71 float _sliderWidth; 72 73 bool grabbed; 74 62 75 }; 63 76 }
Note: See TracChangeset
for help on using the changeset viewer.