The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_RESIZABLEBORDERCOMPONENT_JUCEHEADER__
  19. #define __JUCE_RESIZABLEBORDERCOMPONENT_JUCEHEADER__
  20. #include "juce_ComponentBoundsConstrainer.h"
  21. //==============================================================================
  22. /**
  23. A component that resizes its parent window when dragged.
  24. This component forms a frame around the edge of a component, allowing it to
  25. be dragged by the edges or corners to resize it - like the way windows are
  26. resized in MSWindows or Linux.
  27. To use it, just add it to your component, making it fill the entire parent component
  28. (there's a mouse hit-test that only traps mouse-events which land around the
  29. edge of the component, so it's even ok to put it on top of any other components
  30. you're using). Make sure you rescale the resizer component to fill the parent
  31. each time the parent's size changes.
  32. @see ResizableCornerComponent
  33. */
  34. class JUCE_API ResizableBorderComponent : public Component
  35. {
  36. public:
  37. //==============================================================================
  38. /** Creates a resizer.
  39. Pass in the target component which you want to be resized when this one is
  40. dragged.
  41. The target component will usually be a parent of the resizer component, but this
  42. isn't mandatory.
  43. Remember that when the target component is resized, it'll need to move and
  44. resize this component to keep it in place, as this won't happen automatically.
  45. If the constrainer parameter is non-zero, then this object will be used to enforce
  46. limits on the size and position that the component can be stretched to. Make sure
  47. that the constrainer isn't deleted while still in use by this object.
  48. @see ComponentBoundsConstrainer
  49. */
  50. ResizableBorderComponent (Component* componentToResize,
  51. ComponentBoundsConstrainer* constrainer);
  52. /** Destructor. */
  53. ~ResizableBorderComponent();
  54. //==============================================================================
  55. /** Specifies how many pixels wide the draggable edges of this component are.
  56. @see getBorderThickness
  57. */
  58. void setBorderThickness (const BorderSize& newBorderSize);
  59. /** Returns the number of pixels wide that the draggable edges of this component are.
  60. @see setBorderThickness
  61. */
  62. const BorderSize getBorderThickness() const;
  63. //==============================================================================
  64. juce_UseDebuggingNewOperator
  65. protected:
  66. /** @internal */
  67. void paint (Graphics& g);
  68. /** @internal */
  69. void mouseEnter (const MouseEvent& e);
  70. /** @internal */
  71. void mouseMove (const MouseEvent& e);
  72. /** @internal */
  73. void mouseDown (const MouseEvent& e);
  74. /** @internal */
  75. void mouseDrag (const MouseEvent& e);
  76. /** @internal */
  77. void mouseUp (const MouseEvent& e);
  78. /** @internal */
  79. bool hitTest (int x, int y);
  80. private:
  81. Component::SafePointer<Component> component;
  82. ComponentBoundsConstrainer* constrainer;
  83. BorderSize borderSize;
  84. Rectangle<int> originalBounds;
  85. int mouseZone;
  86. void updateMouseZone (const MouseEvent& e);
  87. ResizableBorderComponent (const ResizableBorderComponent&);
  88. ResizableBorderComponent& operator= (const ResizableBorderComponent&);
  89. };
  90. #endif // __JUCE_RESIZABLEBORDERCOMPONENT_JUCEHEADER__