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.

161 lines
5.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 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_PAINTELEMENTELLIPSE_JUCEHEADER__
  19. #define __JUCER_PAINTELEMENTELLIPSE_JUCEHEADER__
  20. #include "jucer_ColouredElement.h"
  21. //==============================================================================
  22. class PaintElementEllipse : public ColouredElement
  23. {
  24. public:
  25. PaintElementEllipse (PaintRoutine* owner)
  26. : ColouredElement (owner, "Ellipse", true, false)
  27. {
  28. }
  29. void draw (Graphics& g, const ComponentLayout* layout, const Rectangle<int>& parentArea)
  30. {
  31. fillType.setFillType (g, getDocument(), parentArea);
  32. Rectangle<int> r (position.getRectangle (parentArea, layout));
  33. g.fillEllipse ((float) r.getX(), (float) r.getY(), (float) r.getWidth(), (float) r.getHeight());
  34. if (isStrokePresent)
  35. {
  36. strokeType.fill.setFillType (g, getDocument(), parentArea);
  37. g.drawEllipse ((float) r.getX(), (float) r.getY(), (float) r.getWidth(), (float) r.getHeight(),
  38. getStrokeType().stroke.getStrokeThickness());
  39. }
  40. }
  41. void getEditableProperties (Array <PropertyComponent*>& properties)
  42. {
  43. ColouredElement::getEditableProperties (properties);
  44. properties.add (new ShapeToPathProperty (this));
  45. }
  46. void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode)
  47. {
  48. if (! fillType.isInvisible())
  49. {
  50. String x, y, w, h, s;
  51. positionToCode (position, code.document->getComponentLayout(), x, y, w, h);
  52. fillType.fillInGeneratedCode (code, paintMethodCode);
  53. s << "g.fillEllipse ("
  54. << castToFloat (x) << ", "
  55. << castToFloat (y) << ", "
  56. << castToFloat (w) << ", "
  57. << castToFloat (h) << ");\n\n";
  58. paintMethodCode += s;
  59. }
  60. if (isStrokePresent && ! strokeType.isInvisible())
  61. {
  62. String x, y, w, h, s;
  63. positionToCode (position, code.document->getComponentLayout(), x, y, w, h);
  64. strokeType.fill.fillInGeneratedCode (code, paintMethodCode);
  65. s << "g.drawEllipse ("
  66. << castToFloat (x) << ", "
  67. << castToFloat (y) << ", "
  68. << castToFloat (w) << ", "
  69. << castToFloat (h) << ", "
  70. << CodeHelpers::floatLiteral (strokeType.stroke.getStrokeThickness(), 3) << ");\n\n";
  71. paintMethodCode += s;
  72. }
  73. }
  74. static const char* getTagName() noexcept { return "ELLIPSE"; }
  75. XmlElement* createXml() const
  76. {
  77. XmlElement* e = new XmlElement (getTagName());
  78. position.applyToXml (*e);
  79. addColourAttributes (e);
  80. return e;
  81. }
  82. bool loadFromXml (const XmlElement& xml)
  83. {
  84. if (xml.hasTagName (getTagName()))
  85. {
  86. position.restoreFromXml (xml, position);
  87. loadColourAttributes (xml);
  88. return true;
  89. }
  90. jassertfalse;
  91. return false;
  92. }
  93. void convertToPath()
  94. {
  95. double x, y, w, h;
  96. getCurrentAbsoluteBoundsDouble (x, y, w, h);
  97. Path path;
  98. path.addEllipse ((float) x, (float) y, (float) w, (float) h);
  99. convertToNewPathElement (path);
  100. }
  101. private:
  102. //==============================================================================
  103. class ShapeToPathProperty : public ButtonPropertyComponent
  104. {
  105. public:
  106. ShapeToPathProperty (PaintElementEllipse* const e)
  107. : ButtonPropertyComponent ("path", false),
  108. element (e)
  109. {
  110. }
  111. void buttonClicked()
  112. {
  113. element->convertToPath();
  114. }
  115. String getButtonText() const
  116. {
  117. return "convert to a path";
  118. }
  119. private:
  120. PaintElementEllipse* const element;
  121. };
  122. };
  123. #endif // __JUCER_PAINTELEMENTELLIPSE_JUCEHEADER__