Browse Source

Added a method ResizableWindow::setDraggable()

tags/2021-05-28
jules 10 years ago
parent
commit
a73e8d6b80
2 changed files with 20 additions and 6 deletions
  1. +9
    -1
      modules/juce_gui_basics/windows/juce_ResizableWindow.cpp
  2. +11
    -5
      modules/juce_gui_basics/windows/juce_ResizableWindow.h

+ 9
- 1
modules/juce_gui_basics/windows/juce_ResizableWindow.cpp View File

@@ -27,6 +27,7 @@ ResizableWindow::ResizableWindow (const String& name, bool shouldAddToDesktop)
ownsContentComponent (false), ownsContentComponent (false),
resizeToFitContent (false), resizeToFitContent (false),
fullscreen (false), fullscreen (false),
canDrag (true),
dragStarted (false), dragStarted (false),
constrainer (nullptr) constrainer (nullptr)
#if JUCE_DEBUG #if JUCE_DEBUG
@@ -41,6 +42,8 @@ ResizableWindow::ResizableWindow (const String& name, Colour bkgnd, bool shouldA
ownsContentComponent (false), ownsContentComponent (false),
resizeToFitContent (false), resizeToFitContent (false),
fullscreen (false), fullscreen (false),
canDrag (true),
dragStarted (false),
constrainer (nullptr) constrainer (nullptr)
#if JUCE_DEBUG #if JUCE_DEBUG
, hasBeenResized (false) , hasBeenResized (false)
@@ -314,6 +317,11 @@ void ResizableWindow::setResizeLimits (const int newMinimumWidth,
setBoundsConstrained (getBounds()); setBoundsConstrained (getBounds());
} }
void ResizableWindow::setDraggable (bool shouldBeDraggable) noexcept
{
canDrag = shouldBeDraggable;
}
void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer) void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
{ {
if (constrainer != newConstrainer) if (constrainer != newConstrainer)
@@ -571,7 +579,7 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s)
//============================================================================== //==============================================================================
void ResizableWindow::mouseDown (const MouseEvent& e) void ResizableWindow::mouseDown (const MouseEvent& e)
{ {
if (! isFullScreen())
if (canDrag && ! isFullScreen())
{ {
dragStarted = true; dragStarted = true;
dragger.startDraggingComponent (this, e); dragger.startDraggingComponent (this, e);


+ 11
- 5
modules/juce_gui_basics/windows/juce_ResizableWindow.h View File

@@ -140,6 +140,12 @@ public:
int newMaximumWidth, int newMaximumWidth,
int newMaximumHeight) noexcept; int newMaximumHeight) noexcept;
/** Can be used to enable or disable user-dragging of the window. */
void setDraggable (bool shouldBeDraggable) noexcept;
/** Returns true if the window can be dragged around by the user. */
bool isDraggable() const noexcept { return canDrag; }
/** Returns the bounds constrainer object that this window is using. /** Returns the bounds constrainer object that this window is using.
You can access this to change its properties. You can access this to change its properties.
*/ */
@@ -370,20 +376,20 @@ protected:
void addAndMakeVisible (Component*, int zOrder = -1); void addAndMakeVisible (Component*, int zOrder = -1);
#endif #endif
ScopedPointer <ResizableCornerComponent> resizableCorner;
ScopedPointer <ResizableBorderComponent> resizableBorder;
ScopedPointer<ResizableCornerComponent> resizableCorner;
ScopedPointer<ResizableBorderComponent> resizableBorder;
private: private:
//============================================================================== //==============================================================================
Component::SafePointer<Component> contentComponent; Component::SafePointer<Component> contentComponent;
bool ownsContentComponent, resizeToFitContent, fullscreen, dragStarted;
bool ownsContentComponent, resizeToFitContent, fullscreen, canDrag, dragStarted;
ComponentDragger dragger; ComponentDragger dragger;
Rectangle<int> lastNonFullScreenPos; Rectangle<int> lastNonFullScreenPos;
ComponentBoundsConstrainer defaultConstrainer; ComponentBoundsConstrainer defaultConstrainer;
ComponentBoundsConstrainer* constrainer; ComponentBoundsConstrainer* constrainer;
#if JUCE_DEBUG
#if JUCE_DEBUG
bool hasBeenResized; bool hasBeenResized;
#endif
#endif
void initialise (bool addToDesktop); void initialise (bool addToDesktop);
void updateLastPosIfNotFullScreen(); void updateLastPosIfNotFullScreen();


Loading…
Cancel
Save