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.

121 lines
4.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  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 (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, int index, bool undoable);
  43. PaintElement* addNewElement (PaintElement* elementToCopy, int index, bool undoable);
  44. void removeElement (PaintElement* element, bool undoable);
  45. void elementToFront (PaintElement* element, bool undoable);
  46. void elementToBack (PaintElement* element, bool undoable);
  47. Colour getBackgroundColour() const noexcept { return backgroundColour; }
  48. void setBackgroundColour (Colour newColour) noexcept;
  49. void fillWithBackground (Graphics& g, 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 alignTop();
  63. void alignRight();
  64. void alignBottom();
  65. void alignLeft();
  66. void groupSelected();
  67. void ungroupSelected();
  68. void startDragging (const Rectangle<int>& parentArea);
  69. void dragSelectedComps (int dxFromDragStart, int dyFromDragStart, const Rectangle<int>& parentArea);
  70. void endDragging();
  71. void bringLostItemsBackOnScreen (const Rectangle<int>& parentArea);
  72. //==============================================================================
  73. void setDocument (JucerDocument* const doc) { document = doc; }
  74. JucerDocument* getDocument() const noexcept { return document; }
  75. //==============================================================================
  76. static const char* xmlTagName;
  77. XmlElement* createXml() const;
  78. bool loadFromXml (const XmlElement& xml);
  79. void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode) const;
  80. void applyCustomPaintSnippets (StringArray&);
  81. //==============================================================================
  82. void moveElementZOrder (int oldIndex, int newIndex);
  83. private:
  84. OwnedArray<PaintElement> elements;
  85. SelectedItemSet <PaintElement*> selectedElements;
  86. SelectedItemSet <PathPoint*> selectedPoints;
  87. JucerDocument* document;
  88. Colour backgroundColour;
  89. };