openshot-audio  0.1.5
juce_Viewport.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_VIEWPORT_H_INCLUDED
26 #define JUCE_VIEWPORT_H_INCLUDED
27 
28 
29 //==============================================================================
42 class JUCE_API Viewport : public Component,
43  private ComponentListener,
44  private ScrollBar::Listener
45 {
46 public:
47  //==============================================================================
53  explicit Viewport (const String& componentName = String::empty);
54 
56  ~Viewport();
57 
58  //==============================================================================
74  void setViewedComponent (Component* newViewedComponent,
75  bool deleteComponentWhenNoLongerNeeded = true);
76 
81  Component* getViewedComponent() const noexcept { return contentComp; }
82 
83  //==============================================================================
94  void setViewPosition (int xPixelsOffset, int yPixelsOffset);
95 
106  void setViewPosition (Point<int> newPosition);
107 
115  void setViewPositionProportionately (double proportionX, double proportionY);
116 
132  bool autoScroll (int mouseX, int mouseY, int distanceFromEdge, int maximumSpeed);
133 
135  Point<int> getViewPosition() const noexcept { return lastVisibleArea.getPosition(); }
136 
138  Rectangle<int> getViewArea() const noexcept { return lastVisibleArea; }
139 
143  int getViewPositionX() const noexcept { return lastVisibleArea.getX(); }
144 
148  int getViewPositionY() const noexcept { return lastVisibleArea.getY(); }
149 
155  int getViewWidth() const noexcept { return lastVisibleArea.getWidth(); }
156 
162  int getViewHeight() const noexcept { return lastVisibleArea.getHeight(); }
163 
169  int getMaximumVisibleWidth() const;
170 
176  int getMaximumVisibleHeight() const;
177 
178  //==============================================================================
184  virtual void visibleAreaChanged (const Rectangle<int>& newVisibleArea);
185 
187  virtual void viewedComponentChanged (Component* newComponent);
188 
189  //==============================================================================
199  void setScrollBarsShown (bool showVerticalScrollbarIfNeeded,
200  bool showHorizontalScrollbarIfNeeded,
201  bool allowVerticalScrollingWithoutScrollbar = false,
202  bool allowHorizontalScrollingWithoutScrollbar = false);
203 
207  bool isVerticalScrollBarShown() const noexcept { return showVScrollbar; }
208 
212  bool isHorizontalScrollBarShown() const noexcept { return showHScrollbar; }
213 
220  void setScrollBarThickness (int thickness);
221 
226  int getScrollBarThickness() const;
227 
231  void setSingleStepSizes (int stepX, int stepY);
232 
236  ScrollBar* getVerticalScrollBar() noexcept { return &verticalScrollBar; }
237 
241  ScrollBar* getHorizontalScrollBar() noexcept { return &horizontalScrollBar; }
242 
243 
244  //==============================================================================
246  void resized() override;
248  void scrollBarMoved (ScrollBar*, double newRangeStart) override;
250  void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override;
252  bool keyPressed (const KeyPress&) override;
254  void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override;
256  void lookAndFeelChanged() override;
258  bool useMouseWheelMoveIfNeeded (const MouseEvent&, const MouseWheelDetails&);
260  static bool respondsToKey (const KeyPress&);
261 
262 private:
263  //==============================================================================
264  WeakReference<Component> contentComp;
265  Rectangle<int> lastVisibleArea;
266  int scrollBarThickness;
267  int singleStepX, singleStepY;
268  bool showHScrollbar, showVScrollbar, deleteContent;
269  bool customScrollBarThickness;
270  bool allowScrollingWithoutScrollbarV, allowScrollingWithoutScrollbarH;
271  Component contentHolder;
272  ScrollBar verticalScrollBar, horizontalScrollBar;
273 
274  Point<int> viewportPosToCompPos (Point<int>) const;
275 
276  void updateVisibleArea();
277  void deleteContentComp();
278 
279  #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
280  // If you get an error here, it's because this method's parameters have changed! See the new definition above..
281  virtual int visibleAreaChanged (int, int, int, int) { return 0; }
282  #endif
283 
285 };
286 
287 
288 #endif // JUCE_VIEWPORT_H_INCLUDED
Definition: juce_ComponentListener.h:40
Definition: juce_KeyPress.h:37
static const String empty
Definition: juce_String.h:152
int getViewPositionX() const noexcept
Definition: juce_Viewport.h:143
virtual void lookAndFeelChanged()
Definition: juce_Component.cpp:2138
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_ScrollBar.h:49
Point< int > getViewPosition() const noexcept
Definition: juce_Viewport.h:135
virtual void mouseWheelMove(const MouseEvent &event, const MouseWheelDetails &wheel) override
Definition: juce_Component.cpp:2257
int getViewWidth() const noexcept
Definition: juce_Viewport.h:155
Definition: juce_String.h:43
int getViewHeight() const noexcept
Definition: juce_Viewport.h:162
bool isHorizontalScrollBarShown() const noexcept
Definition: juce_Viewport.h:212
virtual void scrollBarMoved(ScrollBar *scrollBarThatHasMoved, double newRangeStart)=0
#define JUCE_API
Definition: juce_StandardHeader.h:139
ScrollBar * getHorizontalScrollBar() noexcept
Definition: juce_Viewport.h:241
Rectangle< int > getViewArea() const noexcept
Definition: juce_Viewport.h:138
Definition: juce_Rectangle.h:36
virtual void resized()
Definition: juce_Component.cpp:2272
int getViewPositionY() const noexcept
Definition: juce_Viewport.h:148
Definition: juce_Component.h:33
Definition: juce_MouseEvent.h:329
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
ScrollBar * getVerticalScrollBar() noexcept
Definition: juce_Viewport.h:236
Definition: juce_Viewport.h:42
Definition: juce_ScrollBar.h:274
bool isVerticalScrollBarShown() const noexcept
Definition: juce_Viewport.h:207
virtual void componentMovedOrResized(Component &component, bool wasMoved, bool wasResized)
Definition: juce_ComponentListener.cpp:25
Definition: juce_MouseEvent.h:36
Component * getViewedComponent() const noexcept
Definition: juce_Viewport.h:81
virtual bool keyPressed(const KeyPress &key)
Definition: juce_Component.cpp:3004