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.

120 lines
4.8KB

  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_PAINTROUTINE_JUCEHEADER__
  18. #define __JUCER_PAINTROUTINE_JUCEHEADER__
  19. #include "paintelements/jucer_PaintElement.h"
  20. class JucerDocument;
  21. class PathPoint;
  22. //==============================================================================
  23. /**
  24. Contains a set of PaintElements that constitute some kind of paint() method.
  25. */
  26. class PaintRoutine
  27. {
  28. public:
  29. //==============================================================================
  30. PaintRoutine();
  31. ~PaintRoutine();
  32. //==============================================================================
  33. void changed();
  34. bool perform (UndoableAction* action, const String& actionName);
  35. //==============================================================================
  36. int getNumElements() const noexcept { return elements.size(); }
  37. PaintElement* getElement (const int index) const noexcept { return elements [index]; }
  38. int indexOfElement (PaintElement* e) const noexcept { return elements.indexOf (e); }
  39. bool containsElement (PaintElement* e) const noexcept { return elements.contains (e); }
  40. //==============================================================================
  41. void clear();
  42. PaintElement* addElementFromXml (const XmlElement& xml, const int index, const bool undoable);
  43. PaintElement* addNewElement (PaintElement* elementToCopy, const int index, const bool undoable);
  44. void removeElement (PaintElement* element, const bool undoable);
  45. void elementToFront (PaintElement* element, const bool undoable);
  46. void elementToBack (PaintElement* element, const bool undoable);
  47. const Colour getBackgroundColour() const noexcept { return backgroundColour; }
  48. void setBackgroundColour (Colour newColour) noexcept;
  49. void fillWithBackground (Graphics& g, const bool drawOpaqueBackground);
  50. void drawElements (Graphics& g, const Rectangle<int>& relativeTo);
  51. void dropImageAt (const File& f, int x, int y);
  52. //==============================================================================
  53. SelectedItemSet <PaintElement*>& getSelectedElements() noexcept { return selectedElements; }
  54. SelectedItemSet <PathPoint*>& getSelectedPoints() noexcept { return selectedPoints; }
  55. static const char* const clipboardXmlTag;
  56. void copySelectedToClipboard();
  57. void paste();
  58. void deleteSelected();
  59. void selectAll();
  60. void selectedToFront();
  61. void selectedToBack();
  62. void groupSelected();
  63. void ungroupSelected();
  64. void startDragging (const Rectangle<int>& parentArea);
  65. void dragSelectedComps (int dxFromDragStart, int dyFromDragStart, const Rectangle<int>& parentArea);
  66. void endDragging();
  67. void bringLostItemsBackOnScreen (const Rectangle<int>& parentArea);
  68. //==============================================================================
  69. void setDocument (JucerDocument* const doc) { document = doc; }
  70. JucerDocument* getDocument() const noexcept { return document; }
  71. //==============================================================================
  72. static const char* xmlTagName;
  73. XmlElement* createXml() const;
  74. bool loadFromXml (const XmlElement& xml);
  75. void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode) const;
  76. //==============================================================================
  77. private:
  78. OwnedArray <PaintElement> elements;
  79. SelectedItemSet <PaintElement*> selectedElements;
  80. SelectedItemSet <PathPoint*> selectedPoints;
  81. JucerDocument* document;
  82. Colour backgroundColour;
  83. friend class DeleteElementAction;
  84. friend class FrontOrBackElementAction;
  85. void moveElementZOrder (int oldIndex, int newIndex);
  86. };
  87. #endif // __JUCER_PAINTROUTINE_JUCEHEADER__