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.

128 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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_DRAWABLEDOCUMENT_JUCEHEADER__
  19. #define __JUCER_DRAWABLEDOCUMENT_JUCEHEADER__
  20. #include "../../jucer_Headers.h"
  21. #include "../Project/jucer_Project.h"
  22. #include "../../utility/jucer_Coordinate.h"
  23. #include "../../utility/jucer_MarkerListBase.h"
  24. //==============================================================================
  25. class DrawableDocument : public ValueTree::Listener,
  26. public ChangeBroadcaster
  27. {
  28. public:
  29. //==============================================================================
  30. DrawableDocument (Project* project, const File& drawableFile);
  31. ~DrawableDocument();
  32. //==============================================================================
  33. void setName (const String& name);
  34. const String getName() const;
  35. bool reload();
  36. bool save();
  37. bool hasChangedSinceLastSave() const;
  38. void changed();
  39. ValueTree& getRoot() { return root; }
  40. ValueTree getRootDrawableNode() const;
  41. void addRectangle();
  42. void addCircle();
  43. void addImage (const File& imageFile);
  44. Value getCanvasWidth() const { return getRootValueNonUndoable ("width"); }
  45. Value getCanvasHeight() const { return getRootValueNonUndoable ("height"); }
  46. static const String getIdFor (const ValueTree& object);
  47. //==============================================================================
  48. class MarkerList : public MarkerListBase
  49. {
  50. public:
  51. MarkerList (DrawableDocument& document, bool isX);
  52. ~MarkerList() {}
  53. const Coordinate findMarker (const String& name, bool isHorizontal) const;
  54. bool createProperties (Array <PropertyComponent*>& props, const String& itemId);
  55. void addMarkerMenuItems (const ValueTree& markerState, const Coordinate& coord, PopupMenu& menu, bool isAnchor1);
  56. const String getChosenMarkerMenuItem (const Coordinate& coord, int itemId) const;
  57. UndoManager* getUndoManager() const;
  58. const String getNonexistentMarkerName (const String& name);
  59. void renameAnchor (const String& oldName, const String& newName);
  60. private:
  61. DrawableDocument& document;
  62. MarkerList (const MarkerList&);
  63. MarkerList& operator= (const MarkerList&);
  64. };
  65. MarkerList& getMarkerListX() const { return *markersX; }
  66. MarkerList& getMarkerListY() const { return *markersY; }
  67. MarkerList& getMarkerList (bool isX) const { return isX ? *markersX : *markersY; }
  68. const String getNonexistentMarkerName (const String& name);
  69. void renameAnchor (const String& oldName, const String& newName);
  70. //==============================================================================
  71. void valueTreePropertyChanged (ValueTree& tree, const var::identifier& name);
  72. void valueTreeChildrenChanged (ValueTree& tree);
  73. void valueTreeParentChanged (ValueTree& tree);
  74. //==============================================================================
  75. UndoManager* getUndoManager() const throw() { return &undoManager; }
  76. private:
  77. Project* project;
  78. File drawableFile;
  79. ValueTree root;
  80. ScopedPointer<MarkerList> markersX, markersY;
  81. mutable UndoManager undoManager;
  82. bool saveAsXml, needsSaving;
  83. void checkRootObject();
  84. Value getRootValueUndoable (const var::identifier& name) const { return root.getPropertyAsValue (name, getUndoManager()); }
  85. Value getRootValueNonUndoable (const var::identifier& name) const { return root.getPropertyAsValue (name, 0); }
  86. void save (OutputStream& output);
  87. bool load (InputStream& input);
  88. void addMissingIds (ValueTree tree) const;
  89. void addDrawable (Drawable& d);
  90. const Coordinate findMarker (const String& name, bool isHorizontal) const;
  91. void addMarkerMenuItem (int i, const Coordinate& coord, const String& name, PopupMenu& menu,
  92. bool isAnchor1, const String& fullCoordName);
  93. };
  94. #endif // __JUCER_DRAWABLEDOCUMENT_JUCEHEADER__