3 changed files with 133 additions and 0 deletions
@ -0,0 +1,22 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "ofEvents.h" |
||||
|
|
||||
|
namespace ofx { |
||||
|
namespace piMapper { |
||||
|
|
||||
|
class GuiBaseWidget { |
||||
|
public: |
||||
|
virtual void setup() = 0; |
||||
|
virtual void update() = 0; |
||||
|
virtual void draw() = 0; |
||||
|
|
||||
|
virtual void onMousePressed(ofMouseEventArgs & e) = 0; |
||||
|
virtual void onMouseReleased(ofMouseEventArgs & e) = 0; |
||||
|
virtual void onMouseDragged(ofMouseEventArgs & e) = 0; |
||||
|
|
||||
|
virtual bool inside(float x, float y) = 0; |
||||
|
}; |
||||
|
|
||||
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
@ -0,0 +1,74 @@ |
|||||
|
#include "ScaleWidget.h" |
||||
|
|
||||
|
namespace ofx { |
||||
|
namespace piMapper { |
||||
|
|
||||
|
ScaleWidget::ScaleWidget(){ |
||||
|
_line.addVertex(ofPoint(0, 0)); |
||||
|
_line.addVertex(ofPoint(0, 0)); |
||||
|
|
||||
|
_handle.width = 20; |
||||
|
_handle.height = 20; |
||||
|
} |
||||
|
|
||||
|
void ScaleWidget::setup(){ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void ScaleWidget::update(){ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void ScaleWidget::draw(){ |
||||
|
ofPushStyle(); |
||||
|
|
||||
|
ofSetColor(255, 255, 255); |
||||
|
ofNoFill(); |
||||
|
|
||||
|
ofSetLineWidth(1); |
||||
|
_line.draw(); |
||||
|
|
||||
|
ofSetLineWidth(2); |
||||
|
ofDrawRectangle(_handle); |
||||
|
|
||||
|
ofPopStyle(); |
||||
|
} |
||||
|
|
||||
|
void ScaleWidget::onMousePressed(ofMouseEventArgs & e){ |
||||
|
if(_handle.inside(e.x, e.y)){ |
||||
|
std::cout << "Handle clicked" << std::endl; |
||||
|
_dragging = true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void ScaleWidget::onMouseReleased(ofMouseEventArgs & e){ |
||||
|
_dragging = false; |
||||
|
} |
||||
|
|
||||
|
void ScaleWidget::onMouseDragged(ofMouseEventArgs & e){ |
||||
|
if(_dragging){ |
||||
|
_handle.x = e.x; |
||||
|
_handle.y = e.y; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
bool ScaleWidget::inside(float x, float y){ |
||||
|
ofPoint p = ofPoint(x, y); |
||||
|
return _handle.inside(p); |
||||
|
} |
||||
|
|
||||
|
void ScaleWidget::setRect(ofRectangle rect){ |
||||
|
ofPoint center = rect.getCenter(); |
||||
|
|
||||
|
_line.getVertices()[0].x = center.x; |
||||
|
_line.getVertices()[0].y = center.y; |
||||
|
|
||||
|
_line.getVertices()[1].x = rect.x + rect.width; |
||||
|
_line.getVertices()[1].y = rect.y; |
||||
|
|
||||
|
_handle.x = rect.x + rect.width; |
||||
|
_handle.y = rect.y; |
||||
|
} |
||||
|
|
||||
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
@ -0,0 +1,37 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "ofRectangle.h" |
||||
|
#include "ofPolyline.h" |
||||
|
#include "GuiBaseWidget.h" |
||||
|
#include "ofGraphics.h" |
||||
|
|
||||
|
namespace ofx { |
||||
|
namespace piMapper { |
||||
|
|
||||
|
class ScaleWidget : GuiBaseWidget { |
||||
|
public: |
||||
|
ScaleWidget(); |
||||
|
|
||||
|
void setup(); |
||||
|
void update(); |
||||
|
void draw(); |
||||
|
|
||||
|
void onMousePressed(ofMouseEventArgs & e); |
||||
|
void onMouseReleased(ofMouseEventArgs & e); |
||||
|
void onMouseDragged(ofMouseEventArgs & e); |
||||
|
|
||||
|
bool inside(float x, float y); |
||||
|
|
||||
|
// This should be the size of the objet's bounding box
|
||||
|
void setRect(ofRectangle rect); |
||||
|
|
||||
|
private: |
||||
|
ofRectangle _handle; |
||||
|
|
||||
|
ofPolyline _line; |
||||
|
|
||||
|
bool _dragging; |
||||
|
}; |
||||
|
|
||||
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
Loading…
Reference in new issue