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.

172 lines
5.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. #include "../jucer_GeneratedCode.h"
  21. #include "../ui/jucer_RelativePositionedRectangle.h"
  22. class FillType;
  23. class PaintRoutine;
  24. class JucerDocument;
  25. class ElementSiblingComponent;
  26. //==============================================================================
  27. /**
  28. Base class for objects that can be used in a PaintRoutine.
  29. */
  30. class PaintElement : public Component,
  31. public ChangeListener,
  32. public ComponentBoundsConstrainer
  33. {
  34. public:
  35. //==============================================================================
  36. PaintElement (PaintRoutine* owner, const String& typeName);
  37. virtual ~PaintElement();
  38. //==============================================================================
  39. virtual void setInitialBounds (int parentWidth, int parentHeight);
  40. virtual Rectangle<int> getCurrentBounds (const Rectangle<int>& activeArea) const;
  41. virtual void setCurrentBounds (const Rectangle<int>& newBounds, const Rectangle<int>& activeArea, const bool undoable);
  42. const RelativePositionedRectangle& getPosition() const;
  43. void setPosition (const RelativePositionedRectangle& newPosition, const bool undoable);
  44. void updateBounds (const Rectangle<int>& activeArea);
  45. const String& getTypeName() const noexcept { return typeName; }
  46. PaintRoutine* getOwner() const noexcept { return owner; }
  47. //==============================================================================
  48. virtual void draw (Graphics& g,
  49. const ComponentLayout* layout,
  50. const Rectangle<int>& parentArea) = 0;
  51. virtual void drawExtraEditorGraphics (Graphics& g, const Rectangle<int>& relativeTo);
  52. virtual void getEditableProperties (Array<PropertyComponent*>& props);
  53. virtual void showPopupMenu();
  54. //==============================================================================
  55. virtual XmlElement* createXml() const = 0;
  56. virtual bool loadFromXml (const XmlElement& xml) = 0;
  57. //==============================================================================
  58. virtual void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode) = 0;
  59. JucerDocument* getDocument() const;
  60. virtual void changed();
  61. bool perform (UndoableAction* action, const String& actionName);
  62. //==============================================================================
  63. void paint (Graphics& g);
  64. void resized();
  65. void mouseDown (const MouseEvent& e);
  66. void mouseDrag (const MouseEvent& e);
  67. void mouseUp (const MouseEvent& e);
  68. void changeListenerCallback (ChangeBroadcaster*);
  69. void parentHierarchyChanged();
  70. int borderThickness;
  71. protected:
  72. PaintRoutine* const owner;
  73. RelativePositionedRectangle position;
  74. void resizeStart();
  75. void resizeEnd();
  76. void checkBounds (Rectangle<int>& bounds,
  77. const Rectangle<int>& previousBounds,
  78. const Rectangle<int>& limits,
  79. bool isStretchingTop,
  80. bool isStretchingLeft,
  81. bool isStretchingBottom,
  82. bool isStretchingRight);
  83. void applyBoundsToComponent (Component* component, const Rectangle<int>& bounds);
  84. Rectangle<int> getCurrentAbsoluteBounds() const;
  85. void getCurrentAbsoluteBoundsDouble (double& x, double& y, double& w, double& h) const;
  86. virtual void selectionChanged (const bool isSelected);
  87. virtual void createSiblingComponents();
  88. void siblingComponentsChanged();
  89. OwnedArray <ElementSiblingComponent> siblingComponents;
  90. void updateSiblingComps();
  91. private:
  92. ScopedPointer<ResizableBorderComponent> border;
  93. String typeName;
  94. bool selected, dragging, mouseDownSelectStatus;
  95. double originalAspectRatio;
  96. ChangeBroadcaster selfChangeListenerList;
  97. };
  98. //==============================================================================
  99. template <typename ElementType>
  100. class ElementListener : public ChangeListener
  101. {
  102. public:
  103. ElementListener (ElementType* e)
  104. : owner (e), broadcaster (*owner->getDocument()),
  105. propToRefresh (nullptr)
  106. {
  107. broadcaster.addChangeListener (this);
  108. }
  109. ~ElementListener()
  110. {
  111. jassert (propToRefresh != nullptr);
  112. broadcaster.removeChangeListener (this);
  113. }
  114. void setPropertyToRefresh (PropertyComponent& pc)
  115. {
  116. propToRefresh = &pc;
  117. }
  118. void changeListenerCallback (ChangeBroadcaster*)
  119. {
  120. jassert (propToRefresh != nullptr);
  121. if (propToRefresh != nullptr)
  122. propToRefresh->refresh();
  123. }
  124. mutable Component::SafePointer<ElementType> owner;
  125. ChangeBroadcaster& broadcaster;
  126. PropertyComponent* propToRefresh;
  127. JUCE_DECLARE_NON_COPYABLE (ElementListener)
  128. };