ofxOui - UI Components for OpenFrameworks

ofxOuiDraggableButton.hpp
Go to the documentation of this file.
1 /*
2  * ofxOuiDraggableButton.hpp
3  *
4  * Draggable button
5  *
6  * This code has been authored by Jules Francoise <jfrancoi@sfu.ca>
7  * during his postdoc contract at Simon Fraser University (MovingStories
8  * project).
9  * See:
10  * http://julesfrancoise.com/
11  * http://movingstories.ca/
12  *
13  * Copyright (C) 2016 Jules Francoise.
14  *
15  * This Source Code Form is subject to the terms of the Mozilla Public
16  * License, v. 2.0. If a copy of the MPL was not distributed with this
17  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
18  */
19 
20 #ifndef ofxOuiDraggableButton_hpp
21 #define ofxOuiDraggableButton_hpp
22 
23 #include "ofxOuiButton.hpp"
24 
25 namespace ofxOui {
26 
31 class DraggableButton : public Button {
32  public:
36  class DropEvent : public ofEventArgs {
37  public:
44  DropEvent(DraggableButton *sender_, int x_, int y_);
45 
50 
54  int x;
55 
59  int y;
60  };
61 
69  DraggableButton(int x_ = 0, int y_ = 0, int width_ = 0, int height_ = 0);
70 
74  virtual ~DraggableButton();
75 
84  template <typename T, typename args, class ListenerClass>
85  void onDrop(T *owner, void (ListenerClass::*listenerMethod)(args)) {
86  using namespace std::placeholders;
87  if (owner)
88  drop_event_callback_ = std::bind(listenerMethod, owner, _1);
89  else
90  drop_event_callback_ = nullptr;
91  }
92 
96  virtual void setReferencePosition();
97 
98  protected:
99  virtual void mousePressed(ofMouseEventArgs &e);
100  virtual void mouseDragged(ofMouseEventArgs &e);
101  virtual void mouseReleased(ofMouseEventArgs &e);
102 
104  bool dragging_;
105  ofPoint mouse_offset_;
107  std::function<void(DraggableButton::DropEvent &)> drop_event_callback_;
108 };
109 }
110 
111 #endif
Event arguments for Drag and Drop events.
Definition: ofxOuiDraggableButton.hpp:36
virtual ~DraggableButton()
Destructor.
Definition: ofxOuiDraggableButton.cpp:36
virtual void mouseDragged(ofMouseEventArgs &e)
Definition: ofxOuiDraggableButton.cpp:53
virtual void mousePressed(ofMouseEventArgs &e)
Definition: ofxOuiDraggableButton.cpp:43
DraggableButton(int x_=0, int y_=0, int width_=0, int height_=0)
Constructor.
Definition: ofxOuiDraggableButton.cpp:22
DropEvent(DraggableButton *sender_, int x_, int y_)
Constructor.
Definition: ofxOuiDraggableButton.cpp:82
Draggable Button (specialization of button)
Definition: ofxOuiDraggableButton.hpp:31
void onDrop(T *owner, void(ListenerClass::*listenerMethod)(args))
Set callback function for drag and drop events.
Definition: ofxOuiDraggableButton.hpp:85
Button component (allows both button and toggle modes)
Definition: ofxOuiButton.hpp:31
virtual void mouseReleased(ofMouseEventArgs &e)
Definition: ofxOuiDraggableButton.cpp:63
std::function< void(DraggableButton::DropEvent &)> drop_event_callback_
Definition: ofxOuiDraggableButton.hpp:107
Definition: ofxOuiColormap.hpp:25
bool mouse_pressed_inside_
Definition: ofxOuiDraggableButton.hpp:103
ofPoint mouse_offset_
Definition: ofxOuiDraggableButton.hpp:105
ofPoint reference_position_
Definition: ofxOuiDraggableButton.hpp:106
int y
y drop position
Definition: ofxOuiDraggableButton.hpp:59
int x
x drop position
Definition: ofxOuiDraggableButton.hpp:54
virtual void setReferencePosition()
Sets the reference position of the button.
Definition: ofxOuiDraggableButton.cpp:77
bool dragging_
Definition: ofxOuiDraggableButton.hpp:104
DraggableButton * sender
pointer to the sender component
Definition: ofxOuiDraggableButton.hpp:49