DISTRHO Plugin Framework
SubWidget.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2021 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_SUBWIDGET_HPP_INCLUDED
18 #define DGL_SUBWIDGET_HPP_INCLUDED
19 
20 #include "Widget.hpp"
21 
22 START_NAMESPACE_DGL
23 
24 // --------------------------------------------------------------------------------------------------------------------
25 
26 /**
27  Sub-Widget class.
28 
29  This class is the main entry point for creating any reusable widgets from within DGL.
30  It can be freely positioned from within a parent widget, thus being named subwidget.
31 
32  Many subwidgets can share the same parent, and subwidgets themselves can also have its own subwidgets.
33  It is subwidgets all the way down.
34 
35  TODO check absolute vs relative position and see what makes more sense.
36 
37  @see CairoSubWidget
38  */
39 class SubWidget : public Widget
40 {
41 public:
42  /**
43  Constructor.
44  */
45  explicit SubWidget(Widget* parentWidget);
46 
47  /**
48  Destructor.
49  */
50  virtual ~SubWidget();
51 
52  /**
53  Check if this widget contains the point defined by @a x and @a y.
54  */
55  // TODO rename as containsRelativePos
56  template<typename T>
57  bool contains(T x, T y) const noexcept;
58 
59  /**
60  Check if this widget contains the point @a pos.
61  */
62  // TODO rename as containsRelativePos
63  template<typename T>
64  bool contains(const Point<T>& pos) const noexcept;
65 
66  /**
67  Get absolute X.
68  */
69  int getAbsoluteX() const noexcept;
70 
71  /**
72  Get absolute Y.
73  */
74  int getAbsoluteY() const noexcept;
75 
76  /**
77  Get absolute position.
78  */
79  Point<int> getAbsolutePos() const noexcept;
80 
81  /**
82  Get absolute area of this subwidget.
83  This is the same as `Rectangle<int>(getAbsolutePos(), getSize());`
84  @see getConstrainedAbsoluteArea()
85  */
86  Rectangle<int> getAbsoluteArea() const noexcept;
87 
88  /**
89  Get absolute area of this subwidget, with special consideration for not allowing negative values.
90  @see getAbsoluteArea()
91  */
93 
94  /**
95  Set absolute X.
96  */
97  void setAbsoluteX(int x) noexcept;
98 
99  /**
100  Set absolute Y.
101  */
102  void setAbsoluteY(int y) noexcept;
103 
104  /**
105  Set absolute position using @a x and @a y values.
106  */
107  void setAbsolutePos(int x, int y) noexcept;
108 
109  /**
110  Set absolute position.
111  */
112  void setAbsolutePos(const Point<int>& pos) noexcept;
113 
114  /**
115  Get parent Widget, as passed in the constructor.
116  */
117  Widget* getParentWidget() const noexcept;
118 
119  /**
120  Request repaint of this subwidget's area to the window this widget belongs to.
121  */
122  void repaint() noexcept override;
123 
124  /**
125  Indicate that this subwidget will draw out of bounds, and thus needs the entire viewport available for drawing.
126  */
127  void setNeedsFullViewportDrawing(bool needsFullViewportForDrawing = true);
128 
129 protected:
130  /**
131  A function called when the subwidget's absolute position is changed.
132  */
133  virtual void onPositionChanged(const PositionChangedEvent&);
134 
135 private:
136  struct PrivateData;
137  PrivateData* const pData;
138  friend class Widget;
139  template <class BaseWidget> friend class NanoBaseWidget;
140  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SubWidget)
141 };
142 
143 // --------------------------------------------------------------------------------------------------------------------
144 
145 END_NAMESPACE_DGL
146 
147 #endif // DGL_SUBWIDGET_HPP_INCLUDED
148 
SubWidget::getAbsoluteArea
Rectangle< int > getAbsoluteArea() const noexcept
NanoBaseWidget
Definition: NanoVG.hpp:881
SubWidget::getAbsoluteX
int getAbsoluteX() const noexcept
SubWidget::setAbsolutePos
void setAbsolutePos(int x, int y) noexcept
SubWidget::setAbsoluteY
void setAbsoluteY(int y) noexcept
Rectangle
Definition: Geometry.hpp:30
SubWidget::setAbsoluteX
void setAbsoluteX(int x) noexcept
SubWidget::setNeedsFullViewportDrawing
void setNeedsFullViewportDrawing(bool needsFullViewportForDrawing=true)
SubWidget::getAbsoluteY
int getAbsoluteY() const noexcept
Widget::PositionChangedEvent
Definition: Widget.hpp:241
SubWidget::getConstrainedAbsoluteArea
Rectangle< uint > getConstrainedAbsoluteArea() const noexcept
SubWidget::repaint
void repaint() noexcept override
SubWidget::contains
bool contains(T x, T y) const noexcept
SubWidget::onPositionChanged
virtual void onPositionChanged(const PositionChangedEvent &)
SubWidget::getParentWidget
Widget * getParentWidget() const noexcept
Point
Definition: Geometry.hpp:40
SubWidget
Definition: SubWidget.hpp:39
SubWidget::getAbsolutePos
Point< int > getAbsolutePos() const noexcept
Widget
Definition: Widget.hpp:53
SubWidget::~SubWidget
virtual ~SubWidget()