ofxOui - UI Components for OpenFrameworks

ofxOuiMultiSlider.hpp
Go to the documentation of this file.
1 /*
2  * ofxOuiMultiSlider.hpp
3  *
4  * MultiSlider
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 ofxOuiMultiSlider_hpp
21 #define ofxOuiMultiSlider_hpp
22 
23 #include "ofxOuiComponent.hpp"
24 
25 namespace ofxOui {
26 
31 class MultiSlider : public Component {
32  public:
36  enum class Layout { Horizontal, Vertical };
37 
41  enum class Origin { Lower, Upper, Zero };
42 
46  class ValueEvent : public ofEventArgs {
47  public:
54  ValueEvent(MultiSlider* sender_, int index_, float value_);
55 
60 
64  int index;
65 
69  float value;
70  };
71 
80  template <typename T, typename args, class ListenerClass>
81  void onEditSlider(T* owner, void (ListenerClass::*listenerMethod)(args)) {
82  using namespace std::placeholders;
83  if (owner)
84  multislider_event_callback_ = std::bind(listenerMethod, owner, _1);
85  else
87  }
88 
96  MultiSlider(int x_ = 0, int y_ = 0, int width_ = 0, int height_ = 0);
97 
101  virtual ~MultiSlider();
102 
106  virtual void update();
107 
111  vector<float> values;
112 
116  float min = 0.;
117 
121  float max = 1.;
122 
127 
132 
133  protected:
134  virtual void drawLabel();
135  void clipValues();
136  virtual void mouseDragged(ofMouseEventArgs& e);
137  virtual void mousePressed(ofMouseEventArgs& e);
138 
139  ofRectangle slider_rect_;
140  bool dragging_ = false;
142  std::function<void(MultiSlider::ValueEvent&)> multislider_event_callback_;
143 };
144 }
145 
146 #endif
void onEditSlider(T *owner, void(ListenerClass::*listenerMethod)(args))
Set callback function for slider editing events.
Definition: ofxOuiMultiSlider.hpp:81
virtual void drawLabel()
Definition: ofxOuiMultiSlider.cpp:48
Event arguments for slider editing events.
Definition: ofxOuiMultiSlider.hpp:46
Layout
Display Layout.
Definition: ofxOuiMultiSlider.hpp:36
void clipValues()
Definition: ofxOuiMultiSlider.cpp:108
MultiSlider * sender
pointer to the sender component
Definition: ofxOuiMultiSlider.hpp:59
MultiSlider.
Definition: ofxOuiMultiSlider.hpp:31
virtual void mousePressed(ofMouseEventArgs &e)
Definition: ofxOuiMultiSlider.cpp:114
virtual void update()
OF-like update function.
Definition: ofxOuiMultiSlider.cpp:40
Layout layout
Display Layout.
Definition: ofxOuiMultiSlider.hpp:126
float value
value of the modified slider
Definition: ofxOuiMultiSlider.hpp:69
virtual void mouseDragged(ofMouseEventArgs &e)
Definition: ofxOuiMultiSlider.cpp:151
Base UI Component (equivalent to a label)
Definition: ofxOuiComponent.hpp:33
int index
index of the modified slider
Definition: ofxOuiMultiSlider.hpp:64
float min
Minimum value of each slider.
Definition: ofxOuiMultiSlider.hpp:116
ofRectangle slider_rect_
Definition: ofxOuiMultiSlider.hpp:139
virtual ~MultiSlider()
Destructor.
Definition: ofxOuiMultiSlider.cpp:33
float max
Maximum value of each slider.
Definition: ofxOuiMultiSlider.hpp:121
Definition: ofxOuiColormap.hpp:25
bool dragging_
Definition: ofxOuiMultiSlider.hpp:140
Origin origin
Origin of the slider filling.
Definition: ofxOuiMultiSlider.hpp:131
MultiSlider(int x_=0, int y_=0, int width_=0, int height_=0)
Constructor.
Definition: ofxOuiMultiSlider.cpp:22
ofVec2f previous_position_
Definition: ofxOuiMultiSlider.hpp:141
Origin
Origin of the slider filling.
Definition: ofxOuiMultiSlider.hpp:41
std::function< void(MultiSlider::ValueEvent &)> multislider_event_callback_
Definition: ofxOuiMultiSlider.hpp:142
vector< float > values
Slider values.
Definition: ofxOuiMultiSlider.hpp:111