DISTRHO Plugin Framework
 All Classes Functions Variables Modules Pages
ImageSlider.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
6  * or without fee is hereby granted, provided that the above copyright notice and this
7  * permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef DGL_IMAGE_SLIDER_HPP_INCLUDED
18 #define DGL_IMAGE_SLIDER_HPP_INCLUDED
19 
20 #include "Image.hpp"
21 #include "Widget.hpp"
22 
23 START_NAMESPACE_DGL
24 
25 // -----------------------------------------------------------------------
26 
27 class ImageSlider : public Widget
28 {
29 public:
30  class Callback
31  {
32  public:
33  virtual ~Callback() {}
34  virtual void imageSliderDragStarted(ImageSlider* imageSlider) = 0;
35  virtual void imageSliderDragFinished(ImageSlider* imageSlider) = 0;
36  virtual void imageSliderValueChanged(ImageSlider* imageSlider, float value) = 0;
37  };
38 
39  explicit ImageSlider(Window& parent, const Image& image) noexcept;
40  explicit ImageSlider(Widget* widget, const Image& image) noexcept;
41  explicit ImageSlider(const ImageSlider& imageSlider) noexcept;
42  ImageSlider& operator=(const ImageSlider& imageSlider) noexcept;
43 
44  float getValue() const noexcept;
45 
46  void setStartPos(const Point<int>& startPos) noexcept;
47  void setStartPos(int x, int y) noexcept;
48  void setEndPos(const Point<int>& endPos) noexcept;
49  void setEndPos(int x, int y) noexcept;
50 
51  void setInverted(bool inverted) noexcept;
52  void setRange(float min, float max) noexcept;
53  void setStep(float step) noexcept;
54  void setValue(float value, bool sendCallback = false) noexcept;
55 
56  void setCallback(Callback* callback) noexcept;
57 
58 protected:
59  void onDisplay() override;
60  bool onMouse(const MouseEvent&) override;
61  bool onMotion(const MotionEvent&) override;
62 
63 private:
64  Image fImage;
65  float fMinimum;
66  float fMaximum;
67  float fStep;
68  float fValue;
69  float fValueTmp;
70 
71  bool fDragging;
72  bool fInverted;
73  int fStartedX;
74  int fStartedY;
75 
76  Callback* fCallback;
77 
78  Point<int> fStartPos;
79  Point<int> fEndPos;
80  Rectangle<int> fSliderArea;
81 
82  void _recheckArea() noexcept;
83 
84  // these should not be used
85  void setAbsoluteX(int) const noexcept {}
86  void setAbsoluteY(int) const noexcept {}
87  void setAbsolutePos(int, int) const noexcept {}
88  void setAbsolutePos(const Point<int>&) const noexcept {}
89  void setNeedsFullViewport(bool) const noexcept {}
90 
91  DISTRHO_LEAK_DETECTOR(ImageSlider)
92 };
93 
94 // -----------------------------------------------------------------------
95 
96 END_NAMESPACE_DGL
97 
98 #endif // DGL_IMAGE_SLIDER_HPP_INCLUDED
Definition: Window.hpp:30
Definition: ImageSlider.hpp:30
bool onMotion(const MotionEvent &) override
Definition: Geometry.hpp:40
Definition: Widget.hpp:128
bool onMouse(const MouseEvent &) override
void onDisplay() override
Definition: Widget.hpp:51
Definition: Geometry.hpp:30
Definition: Widget.hpp:110
Definition: Image.hpp:38
Definition: ImageSlider.hpp:27