openshot-audio  0.1.4
juce_ResizableBorderComponent.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_RESIZABLEBORDERCOMPONENT_H_INCLUDED
26 #define JUCE_RESIZABLEBORDERCOMPONENT_H_INCLUDED
27 
28 
29 //==============================================================================
46 {
47 public:
48  //==============================================================================
66  ResizableBorderComponent (Component* componentToResize,
67  ComponentBoundsConstrainer* constrainer);
68 
71 
72 
73  //==============================================================================
78  void setBorderThickness (const BorderSize<int>& newBorderSize);
79 
84  BorderSize<int> getBorderThickness() const;
85 
86 
87  //==============================================================================
91  class Zone
92  {
93  public:
94  //==============================================================================
95  enum Zones
96  {
97  centre = 0,
98  left = 1,
99  top = 2,
100  right = 4,
101  bottom = 8
102  };
103 
104  //==============================================================================
106  explicit Zone (int zoneFlags) noexcept;
107 
108  Zone() noexcept;
109  Zone (const Zone&) noexcept;
110  Zone& operator= (const Zone&) noexcept;
111 
112  bool operator== (const Zone&) const noexcept;
113  bool operator!= (const Zone&) const noexcept;
114 
115  //==============================================================================
119  static Zone fromPositionOnBorder (const Rectangle<int>& totalSize,
120  const BorderSize<int>& border,
121  Point<int> position);
122 
124  MouseCursor getMouseCursor() const noexcept;
125 
127  bool isDraggingWholeObject() const noexcept { return zone == centre; }
129  bool isDraggingLeftEdge() const noexcept { return (zone & left) != 0; }
131  bool isDraggingRightEdge() const noexcept { return (zone & right) != 0; }
133  bool isDraggingTopEdge() const noexcept { return (zone & top) != 0; }
135  bool isDraggingBottomEdge() const noexcept { return (zone & bottom) != 0; }
136 
140  template <typename ValueType>
142  const Point<ValueType>& distance) const noexcept
143  {
144  if (isDraggingWholeObject())
145  return original + distance;
146 
147  if (isDraggingLeftEdge()) original.setLeft (jmin (original.getRight(), original.getX() + distance.x));
148  if (isDraggingRightEdge()) original.setWidth (jmax (ValueType(), original.getWidth() + distance.x));
149  if (isDraggingTopEdge()) original.setTop (jmin (original.getBottom(), original.getY() + distance.y));
150  if (isDraggingBottomEdge()) original.setHeight (jmax (ValueType(), original.getHeight() + distance.y));
151 
152  return original;
153  }
154 
156  int getZoneFlags() const noexcept { return zone; }
157 
158  private:
159  //==============================================================================
160  int zone;
161  };
162 
164  Zone getCurrentZone() const noexcept { return mouseZone; }
165 
166 protected:
168  void paint (Graphics&) override;
170  void mouseEnter (const MouseEvent&) override;
172  void mouseMove (const MouseEvent&) override;
174  void mouseDown (const MouseEvent&) override;
176  void mouseDrag (const MouseEvent&) override;
178  void mouseUp (const MouseEvent&) override;
180  bool hitTest (int x, int y) override;
181 
182 private:
183  WeakReference<Component> component;
184  ComponentBoundsConstrainer* constrainer;
186  Rectangle<int> originalBounds;
187  Zone mouseZone;
188 
189  void updateMouseZone (const MouseEvent&);
190 
192 };
193 
194 
195 #endif // JUCE_RESIZABLEBORDERCOMPONENT_H_INCLUDED
Definition: juce_MouseCursor.h:36
#define noexcept
Definition: juce_CompilerSupport.h:141
Type jmin(const Type a, const Type b)
Definition: juce_core.h:113
Rectangle< ValueType > resizeRectangleBy(Rectangle< ValueType > original, const Point< ValueType > &distance) const noexcept
Definition: juce_ResizableBorderComponent.h:141
Definition: juce_Point.h:39
#define JUCE_API
Definition: juce_StandardHeader.h:139
const int borderSize
Definition: juce_gui_basics.cpp:30
int getZoneFlags() const noexcept
Definition: juce_ResizableBorderComponent.h:156
Definition: juce_Rectangle.h:36
bool isDraggingTopEdge() const noexcept
Definition: juce_ResizableBorderComponent.h:133
Definition: juce_ResizableBorderComponent.h:45
Definition: juce_Component.h:33
Type jmax(const Type a, const Type b)
Definition: juce_core.h:101
bool isDraggingBottomEdge() const noexcept
Definition: juce_ResizableBorderComponent.h:135
Definition: juce_ResizableBorderComponent.h:91
Definition: juce_BorderSize.h:39
bool isDraggingRightEdge() const noexcept
Definition: juce_ResizableBorderComponent.h:131
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
Definition: juce_GraphicsContext.h:42
bool isDraggingLeftEdge() const noexcept
Definition: juce_ResizableBorderComponent.h:129
Definition: juce_ComponentBoundsConstrainer.h:41
Zone getCurrentZone() const noexcept
Definition: juce_ResizableBorderComponent.h:164
Definition: juce_MouseEvent.h:36
Zones
Definition: juce_ResizableBorderComponent.h:95