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; 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){ void Gui::notifyJointPressed(ofMouseEventArgs & args, int jointIndex){
GuiJointEvent e; GuiJointEvent e;
e.args = args; e.args = args;
@ -72,18 +80,19 @@ void Gui::onMouseDragged(ofMouseEventArgs & args){
_scaleWidget.onMouseDragged(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(){ ScaleWidget & Gui::getScaleWidget(){
return _scaleWidget; 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 } // piMapper
} // ofx } // ofx

12
src/Application/Gui.h

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

6
src/Application/GuiBaseWidget.h

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

21
src/Application/ScaleWidget.cpp

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

6
src/Application/ScaleWidget.h

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

Loading…
Cancel
Save