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.

165 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCER_PAINTELEMENT_JUCEHEADER__
  18. #define __JUCER_PAINTELEMENT_JUCEHEADER__
  19. #include "../jucer_GeneratedCode.h"
  20. #include "../ui/jucer_RelativePositionedRectangle.h"
  21. class FillType;
  22. class PaintRoutine;
  23. class JucerDocument;
  24. class ElementSiblingComponent;
  25. //==============================================================================
  26. /**
  27. Base class for objects that can be used in a PaintRoutine.
  28. */
  29. class PaintElement : public Component,
  30. public ChangeListener,
  31. public ComponentBoundsConstrainer
  32. {
  33. public:
  34. //==============================================================================
  35. PaintElement (PaintRoutine* owner, const String& typeName);
  36. virtual ~PaintElement();
  37. //==============================================================================
  38. virtual void setInitialBounds (int parentWidth, int parentHeight);
  39. virtual Rectangle<int> getCurrentBounds (const Rectangle<int>& activeArea) const;
  40. virtual void setCurrentBounds (const Rectangle<int>& newBounds, const Rectangle<int>& activeArea, const bool undoable);
  41. const RelativePositionedRectangle& getPosition() const;
  42. void setPosition (const RelativePositionedRectangle& newPosition, const bool undoable);
  43. void updateBounds (const Rectangle<int>& activeArea);
  44. const String& getTypeName() const noexcept { return typeName; }
  45. PaintRoutine* getOwner() const noexcept { return owner; }
  46. //==============================================================================
  47. virtual void draw (Graphics& g,
  48. const ComponentLayout* layout,
  49. const Rectangle<int>& parentArea) = 0;
  50. virtual void drawExtraEditorGraphics (Graphics& g, const Rectangle<int>& relativeTo);
  51. virtual void getEditableProperties (Array <PropertyComponent*>& properties);
  52. virtual void showPopupMenu();
  53. //==============================================================================
  54. virtual XmlElement* createXml() const = 0;
  55. virtual bool loadFromXml (const XmlElement& xml) = 0;
  56. //==============================================================================
  57. virtual void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode) = 0;
  58. JucerDocument* getDocument() const;
  59. virtual void changed();
  60. bool perform (UndoableAction* action, const String& actionName);
  61. //==============================================================================
  62. void paint (Graphics& g);
  63. void resized();
  64. void mouseDown (const MouseEvent& e);
  65. void mouseDrag (const MouseEvent& e);
  66. void mouseUp (const MouseEvent& e);
  67. void changeListenerCallback (ChangeBroadcaster*);
  68. void parentHierarchyChanged();
  69. int borderThickness;
  70. protected:
  71. PaintRoutine* const owner;
  72. RelativePositionedRectangle position;
  73. void resizeStart();
  74. void resizeEnd();
  75. void checkBounds (Rectangle<int>& bounds,
  76. const Rectangle<int>& previousBounds,
  77. const Rectangle<int>& limits,
  78. bool isStretchingTop,
  79. bool isStretchingLeft,
  80. bool isStretchingBottom,
  81. bool isStretchingRight);
  82. void applyBoundsToComponent (Component* component, const Rectangle<int>& bounds);
  83. Rectangle<int> getCurrentAbsoluteBounds() const;
  84. void getCurrentAbsoluteBoundsDouble (double& x, double& y, double& w, double& h) const;
  85. virtual void selectionChanged (const bool isSelected);
  86. virtual void createSiblingComponents();
  87. void siblingComponentsChanged();
  88. OwnedArray <ElementSiblingComponent> siblingComponents;
  89. void updateSiblingComps();
  90. private:
  91. ScopedPointer<ResizableBorderComponent> border;
  92. String typeName;
  93. bool selected, dragging, mouseDownSelectStatus;
  94. double originalAspectRatio;
  95. ChangeBroadcaster selfChangeListenerList;
  96. };
  97. //==============================================================================
  98. template <typename ElementType>
  99. class ElementListenerBase : public ChangeListener
  100. {
  101. public:
  102. ElementListenerBase (ElementType* const e)
  103. : owner (e), broadcaster (*owner->getDocument())
  104. {
  105. broadcaster.addChangeListener (this);
  106. }
  107. ~ElementListenerBase()
  108. {
  109. broadcaster.removeChangeListener (this);
  110. }
  111. void changeListenerCallback (ChangeBroadcaster*)
  112. {
  113. if (PropertyComponent* pc = dynamic_cast <PropertyComponent*> (this))
  114. pc->refresh();
  115. }
  116. mutable Component::SafePointer<ElementType> owner;
  117. ChangeBroadcaster& broadcaster;
  118. JUCE_DECLARE_NON_COPYABLE (ElementListenerBase)
  119. };
  120. #endif // __JUCER_PAINTELEMENT_JUCEHEADER__