Browse Source

Got ScaleWidget events captured by Gui

master
Krisjanis Rijnieks 9 years ago
parent
commit
1e7e65ef64
  1. 27
      src/Application/Gui.cpp
  2. 12
      src/Application/Gui.h
  3. 6
      src/Application/GuiBaseWidget.h
  4. 21
      src/Application/ScaleWidget.cpp
  5. 6
      src/Application/ScaleWidget.h

27
src/Application/Gui.cpp

@ -12,6 +12,14 @@ Gui * Gui::instance(){
return _instance;
}
Gui::Gui(){
ofAddListener(_scaleWidget.guiWidgetEvent, this, &Gui::onScaleWidgetEvent);
}
Gui::~Gui(){
ofRemoveListener(_scaleWidget.guiWidgetEvent, this, &Gui::onScaleWidgetEvent);
}
void Gui::notifyJointPressed(ofMouseEventArgs & args, int jointIndex){
GuiJointEvent e;
e.args = args;
@ -72,18 +80,19 @@ void Gui::onMouseDragged(ofMouseEventArgs & args){
_scaleWidget.onMouseDragged(args);
}
void Gui::notifyGuiWidgetEvent(ofMouseEventArgs &args, ofx::piMapper::GuiBaseWidget * widget){
GuiWidgetEvent e;
e.args = args;
e.widget = widget;
ofNotifyEvent(guiWidgetEvent, e, this);
cout << "args.Dragged: " << args.Dragged << endl;
}
ScaleWidget & Gui::getScaleWidget(){
return _scaleWidget;
}
void Gui::onScaleWidgetEvent(GuiWidgetEvent & event){
if(event.args.type == event.args.Pressed){
cout << "ScaleWidget Pressed" << endl;
}else if(event.args.type == event.args.Released){
cout << "ScaleWidget Released" << endl;
}else if(event.args.type == event.args.Dragged){
cout << "ScaleWidget Dragged" << endl;
}
}
} // piMapper
} // ofx

12
src/Application/Gui.h

@ -36,11 +36,6 @@ struct GuiBackgroundEvent{
ofMouseEventArgs args;
};
struct GuiWidgetEvent{
ofMouseEventArgs args;
GuiBaseWidget * widget;
};
class Gui {
public:
static Gui * instance();
@ -67,14 +62,17 @@ class Gui {
void notifyBackgroundPressed(ofMouseEventArgs & args);
ScaleWidget & getScaleWidget();
ofEvent <GuiWidgetEvent> guiWidgetEvent;
void notifyGuiWidgetEvent(ofMouseEventArgs & args, GuiBaseWidget * widget);
void onMousePressed(ofMouseEventArgs & args);
void onMouseReleased(ofMouseEventArgs & args);
void onMouseDragged(ofMouseEventArgs & args);
void onScaleWidgetEvent(GuiWidgetEvent & event);
private:
Gui();
~Gui();
static Gui * _instance;
ScaleWidget _scaleWidget;

6
src/Application/GuiBaseWidget.h

@ -5,6 +5,10 @@
namespace ofx {
namespace piMapper {
struct GuiWidgetEvent{
ofMouseEventArgs args;
};
class GuiBaseWidget {
public:
virtual void setup() = 0;
@ -16,6 +20,8 @@ class GuiBaseWidget {
virtual void onMouseDragged(ofMouseEventArgs & e) = 0;
virtual bool inside(float x, float y) = 0;
ofEvent <GuiWidgetEvent> guiWidgetEvent;
};
} // namespace piMapper

21
src/Application/ScaleWidget.cpp

@ -9,6 +9,8 @@ ScaleWidget::ScaleWidget(){
_handle.width = 20;
_handle.height = 20;
_scale = 1.0f;
}
void ScaleWidget::setup(){
@ -36,24 +38,35 @@ void ScaleWidget::draw(){
void ScaleWidget::onMousePressed(ofMouseEventArgs & args){
if(_handle.inside(args.x, args.y)){
std::cout << "ScaleWidget: Handle clicked" << std::endl;
_dragging = true;
_originalLine = _line;
}
GuiWidgetEvent e;
e.args = args;
ofNotifyEvent(guiWidgetEvent, e, this);
}
void ScaleWidget::onMouseReleased(ofMouseEventArgs & args){
std::cout << "ScaleWidget: Mouse released" << std::endl;
_dragging = false;
GuiWidgetEvent e;
e.args = args;
ofNotifyEvent(guiWidgetEvent, e, this);
}
void ScaleWidget::onMouseDragged(ofMouseEventArgs & args){
std::cout << "ScaleWidget: Mouse dragged" << std::endl;
if(_dragging){
_handle.x = args.x - (_handle.width / 2.0f);
_handle.y = args.y - (_handle.height / 2.0f);
_line[1].x = args.x;
_line[1].y = args.y;
}
//Gui::instance()->notifyGuiWidgetEvent(args, this);
GuiWidgetEvent e;
e.args = args;
ofNotifyEvent(guiWidgetEvent, e, this);
}
bool ScaleWidget::inside(float x, float y){

6
src/Application/ScaleWidget.h

@ -4,7 +4,6 @@
#include "ofPolyline.h"
#include "GuiBaseWidget.h"
#include "ofGraphics.h"
//#include "Gui.h"
namespace ofx {
namespace piMapper {
@ -25,11 +24,16 @@ class ScaleWidget : public GuiBaseWidget {
// This should be the size of the objet's bounding box
void setRect(ofRectangle rect);
float getScale();
private:
ofRectangle _handle;
ofPolyline _line;
ofPolyline _originalLine;
float _scale;
bool _dragging;
};

Loading…
Cancel
Save