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.

166 lines
5.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 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 __JUCER_PAINTELEMENT_JUCEHEADER__
  19. #define __JUCER_PAINTELEMENT_JUCEHEADER__
  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*>& properties);
  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 ElementListenerBase : public ChangeListener
  101. {
  102. public:
  103. ElementListenerBase (ElementType* const e)
  104. : owner (e), broadcaster (*owner->getDocument())
  105. {
  106. broadcaster.addChangeListener (this);
  107. }
  108. ~ElementListenerBase()
  109. {
  110. broadcaster.removeChangeListener (this);
  111. }
  112. void changeListenerCallback (ChangeBroadcaster*)
  113. {
  114. if (PropertyComponent* pc = dynamic_cast <PropertyComponent*> (this))
  115. pc->refresh();
  116. }
  117. mutable Component::SafePointer<ElementType> owner;
  118. ChangeBroadcaster& broadcaster;
  119. JUCE_DECLARE_NON_COPYABLE (ElementListenerBase)
  120. };
  121. #endif // __JUCER_PAINTELEMENT_JUCEHEADER__