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.

170 lines
5.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. #pragma once
  18. #include "../jucer_GeneratedCode.h"
  19. #include "../ui/jucer_RelativePositionedRectangle.h"
  20. class FillType;
  21. class PaintRoutine;
  22. class JucerDocument;
  23. class ElementSiblingComponent;
  24. //==============================================================================
  25. /**
  26. Base class for objects that can be used in a PaintRoutine.
  27. */
  28. class PaintElement : public Component,
  29. public ChangeListener,
  30. public ComponentBoundsConstrainer
  31. {
  32. public:
  33. //==============================================================================
  34. PaintElement (PaintRoutine* owner, const String& typeName);
  35. virtual ~PaintElement();
  36. //==============================================================================
  37. virtual void setInitialBounds (int parentWidth, int parentHeight);
  38. virtual Rectangle<int> getCurrentBounds (const Rectangle<int>& activeArea) const;
  39. virtual void setCurrentBounds (const Rectangle<int>& newBounds, const Rectangle<int>& activeArea, const bool undoable);
  40. const RelativePositionedRectangle& getPosition() const;
  41. void setPosition (const RelativePositionedRectangle& newPosition, const bool undoable);
  42. void updateBounds (const Rectangle<int>& activeArea);
  43. const String& getTypeName() const noexcept { return typeName; }
  44. PaintRoutine* getOwner() const noexcept { return owner; }
  45. //==============================================================================
  46. virtual void draw (Graphics& g,
  47. const ComponentLayout* layout,
  48. const Rectangle<int>& parentArea) = 0;
  49. virtual void drawExtraEditorGraphics (Graphics& g, const Rectangle<int>& relativeTo);
  50. virtual void getEditableProperties (Array<PropertyComponent*>& props);
  51. virtual void showPopupMenu();
  52. //==============================================================================
  53. virtual XmlElement* createXml() const = 0;
  54. virtual bool loadFromXml (const XmlElement& xml) = 0;
  55. //==============================================================================
  56. virtual void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode) = 0;
  57. JucerDocument* getDocument() const;
  58. virtual void changed();
  59. bool perform (UndoableAction* action, const String& actionName);
  60. //==============================================================================
  61. void paint (Graphics& g);
  62. void resized();
  63. void mouseDown (const MouseEvent& e);
  64. void mouseDrag (const MouseEvent& e);
  65. void mouseUp (const MouseEvent& e);
  66. void changeListenerCallback (ChangeBroadcaster*);
  67. void parentHierarchyChanged();
  68. int borderThickness;
  69. protected:
  70. PaintRoutine* const owner;
  71. RelativePositionedRectangle position;
  72. void resizeStart();
  73. void resizeEnd();
  74. void checkBounds (Rectangle<int>& bounds,
  75. const Rectangle<int>& previousBounds,
  76. const Rectangle<int>& limits,
  77. bool isStretchingTop,
  78. bool isStretchingLeft,
  79. bool isStretchingBottom,
  80. bool isStretchingRight);
  81. void applyBoundsToComponent (Component* component, const Rectangle<int>& bounds);
  82. Rectangle<int> getCurrentAbsoluteBounds() const;
  83. void getCurrentAbsoluteBoundsDouble (double& x, double& y, double& w, double& h) const;
  84. virtual void selectionChanged (const bool isSelected);
  85. virtual void createSiblingComponents();
  86. void siblingComponentsChanged();
  87. OwnedArray <ElementSiblingComponent> siblingComponents;
  88. void updateSiblingComps();
  89. private:
  90. ScopedPointer<ResizableBorderComponent> border;
  91. String typeName;
  92. bool selected, dragging, mouseDownSelectStatus;
  93. double originalAspectRatio;
  94. ChangeBroadcaster selfChangeListenerList;
  95. };
  96. //==============================================================================
  97. template <typename ElementType>
  98. class ElementListener : public ChangeListener
  99. {
  100. public:
  101. ElementListener (ElementType* e)
  102. : owner (e), broadcaster (*owner->getDocument()),
  103. propToRefresh (nullptr)
  104. {
  105. broadcaster.addChangeListener (this);
  106. }
  107. ~ElementListener()
  108. {
  109. jassert (propToRefresh != nullptr);
  110. broadcaster.removeChangeListener (this);
  111. }
  112. void setPropertyToRefresh (PropertyComponent& pc)
  113. {
  114. propToRefresh = &pc;
  115. }
  116. void changeListenerCallback (ChangeBroadcaster*)
  117. {
  118. jassert (propToRefresh != nullptr);
  119. if (propToRefresh != nullptr)
  120. propToRefresh->refresh();
  121. }
  122. mutable Component::SafePointer<ElementType> owner;
  123. ChangeBroadcaster& broadcaster;
  124. PropertyComponent* propToRefresh;
  125. JUCE_DECLARE_NON_COPYABLE (ElementListener)
  126. };