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.

117 lines
4.7KB

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