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