ofxOui - UI Components for OpenFrameworks

ofxOuiShapeEditor.hpp
Go to the documentation of this file.
1 /*
2  * ofxOui::ShapeEditor.hpp
3  *
4  * Shape Editor (Modes : translation, scaling, rotation)
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 ofxOuiShapeEditor_hpp
21 #define ofxOuiShapeEditor_hpp
22 
23 #include "../core/ofxOuiCommon.hpp"
24 
25 namespace ofxOui {
26 
31 class ShapeEditor {
32  public:
36  enum class Selector {
37  None,
38  Shape,
39  TopLeft,
40  TopCenter,
41  TopRight,
42  MiddleLeft,
45  BottomLeft,
48  };
49 
53  enum class MouseDraggingMode { Normal, Symmetric, Rotation };
54 
58  class EditEvent : public ofEventArgs {
59  public:
63  enum class Type { Translation, Scaling, Rotation, Done };
64 
75  EditEvent(ShapeEditor *sender_, Type type_, float x_, float y_,
76  float width_, float height_, float angle_);
77 
82 
87 
91  float x;
92 
96  float y;
97 
101  float width;
102 
106  float height;
107 
111  float angle;
112  };
113 
122  template <typename T, typename args, class ListenerClass>
123  void onEditShape(T *owner, void (ListenerClass::*listenerMethod)(args)) {
124  using namespace std::placeholders;
125  if (owner)
126  shape_editor_event_callback_ = std::bind(listenerMethod, owner, _1);
127  else
129  }
130 
139  ShapeEditor(float x_ = 0, float y_ = 0, float width_ = 0, float height_ = 0,
140  float angle_ = 0);
141 
145  virtual ~ShapeEditor();
146 
150  virtual void draw();
151 
158  virtual bool inside(float x_, float y_);
159 
167  virtual ShapeEditor::Selector insideSelector(float x_, float y_);
168 
172  float x;
173 
177  float y;
178 
182  float width;
183 
187  float height;
188 
192  float angle;
193 
197  float frame_width;
198 
202  ofColor color;
203 
208 
209  protected:
210  virtual void mouseDragged(ofMouseEventArgs &e);
211  virtual void mousePressed(ofMouseEventArgs &e);
212  virtual void mouseReleased(ofMouseEventArgs &e);
213  virtual void keyPressed(ofKeyEventArgs &e);
214  virtual void keyReleased(ofKeyEventArgs &e);
215  virtual void mouseDraggedNormal(ofMouseEventArgs &e);
216  virtual void mouseDraggedSymmetric(ofMouseEventArgs &e);
217  virtual void mouseDraggedRotation(ofMouseEventArgs &e);
218 
221  ofPoint mouse_offset_;
223  std::function<void(ofxOui::ShapeEditor::EditEvent &)>
225 };
226 }
227 
228 #endif
float y
y position(top)
Definition: ofxOuiShapeEditor.hpp:177
virtual void keyReleased(ofKeyEventArgs &e)
Definition: ofxOuiShapeEditor.cpp:209
MouseDraggingMode
Type of mouse interaction mode.
Definition: ofxOuiShapeEditor.hpp:53
ofPoint mouse_offset_
Definition: ofxOuiShapeEditor.hpp:221
Type
type of editing event
Definition: ofxOuiShapeEditor.hpp:63
float width
editor width
Definition: ofxOuiShapeEditor.hpp:182
std::function< void(ofxOui::ShapeEditor::EditEvent &)> shape_editor_event_callback_
Definition: ofxOuiShapeEditor.hpp:224
virtual ShapeEditor::Selector insideSelector(float x_, float y_)
checks if a point is inside a selector of the shape editor (corner or mid-edge)
Definition: ofxOuiShapeEditor.cpp:108
float width
width of the shape editor box
Definition: ofxOuiShapeEditor.hpp:101
virtual void draw()
OF-like draw function.
Definition: ofxOuiShapeEditor.cpp:60
Selector
Index of the selector of the shape.
Definition: ofxOuiShapeEditor.hpp:36
Type type
type of editing event
Definition: ofxOuiShapeEditor.hpp:86
ShapeEditor * sender
pointer to the sender component
Definition: ofxOuiShapeEditor.hpp:81
virtual void mouseDraggedSymmetric(ofMouseEventArgs &e)
Definition: ofxOuiShapeEditor.cpp:258
virtual void mousePressed(ofMouseEventArgs &e)
Definition: ofxOuiShapeEditor.cpp:155
float height
editor height
Definition: ofxOuiShapeEditor.hpp:187
float reference_angle_
Definition: ofxOuiShapeEditor.hpp:222
float angle
editor angle
Definition: ofxOuiShapeEditor.hpp:192
float frame_width
width of the editor frame
Definition: ofxOuiShapeEditor.hpp:197
ShapeEditor(float x_=0, float y_=0, float width_=0, float height_=0, float angle_=0)
Constructor.
Definition: ofxOuiShapeEditor.cpp:22
virtual ~ShapeEditor()
Destructor.
Definition: ofxOuiShapeEditor.cpp:46
virtual void mouseDragged(ofMouseEventArgs &e)
Definition: ofxOuiShapeEditor.cpp:169
float height
height of the shape editor box
Definition: ofxOuiShapeEditor.hpp:106
virtual void mouseDraggedNormal(ofMouseEventArgs &e)
Definition: ofxOuiShapeEditor.cpp:220
float x
x position of the shape editor box
Definition: ofxOuiShapeEditor.hpp:91
Definition: ofxOuiColormap.hpp:25
ofColor color
color of the editor frame
Definition: ofxOuiShapeEditor.hpp:202
virtual void keyPressed(ofKeyEventArgs &e)
Definition: ofxOuiShapeEditor.cpp:199
float angle
angle of the shape editor box
Definition: ofxOuiShapeEditor.hpp:111
float y
y position of the shape editor box
Definition: ofxOuiShapeEditor.hpp:96
Selector dragging_
Definition: ofxOuiShapeEditor.hpp:219
float x
x position (left)
Definition: ofxOuiShapeEditor.hpp:172
float selector_size
size of the corner and edge selectors
Definition: ofxOuiShapeEditor.hpp:207
MouseDraggingMode dragging_mode_
Definition: ofxOuiShapeEditor.hpp:220
virtual bool inside(float x_, float y_)
checks if a point is inside the shape editor
Definition: ofxOuiShapeEditor.cpp:101
virtual void mouseReleased(ofMouseEventArgs &e)
Definition: ofxOuiShapeEditor.cpp:189
virtual void mouseDraggedRotation(ofMouseEventArgs &e)
Definition: ofxOuiShapeEditor.cpp:274
Event arguments for shape editing events.
Definition: ofxOuiShapeEditor.hpp:58
void onEditShape(T *owner, void(ListenerClass::*listenerMethod)(args))
Set callback function for shape editing events.
Definition: ofxOuiShapeEditor.hpp:123
Shape editor.
Definition: ofxOuiShapeEditor.hpp:31