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.

167 lines
4.9KB

  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 "jucer_ColouredElement.h"
  21. #include "../Properties/jucer_FilePropertyComponent.h"
  22. #include "jucer_ImageResourceProperty.h"
  23. #include "jucer_PaintElementUndoableAction.h"
  24. //==============================================================================
  25. class PaintElementImage : public PaintElement
  26. {
  27. public:
  28. PaintElementImage (PaintRoutine*);
  29. ~PaintElementImage();
  30. enum StretchMode
  31. {
  32. stretched = 0,
  33. proportional = 1,
  34. proportionalReducingOnly = 2
  35. };
  36. const Drawable* getDrawable();
  37. void draw (Graphics&, const ComponentLayout*, const Rectangle<int>&) override;
  38. //==============================================================================
  39. void getEditableProperties (Array <PropertyComponent*>&, bool) override;
  40. void fillInGeneratedCode (GeneratedCode&, String&) override;
  41. void applyCustomPaintSnippets (StringArray& snippets) override;
  42. //==============================================================================
  43. class SetResourceAction : public PaintElementUndoableAction <PaintElementImage>
  44. {
  45. public:
  46. SetResourceAction (PaintElementImage* const, const String&);
  47. bool perform();
  48. bool undo();
  49. private:
  50. String newResource, oldResource;
  51. };
  52. void setResource (const String&, const bool);
  53. String getResource() const;
  54. //==============================================================================
  55. class SetOpacityAction : public PaintElementUndoableAction <PaintElementImage>
  56. {
  57. public:
  58. SetOpacityAction (PaintElementImage* const, const double);
  59. bool perform();
  60. bool undo();
  61. private:
  62. double newOpacity, oldOpacity;
  63. };
  64. void setOpacity (double, const bool);
  65. double getOpacity() const noexcept;
  66. //==============================================================================
  67. static const char* getTagName() noexcept;
  68. void resetToImageSize();
  69. //==============================================================================
  70. class SetStretchModeAction : public PaintElementUndoableAction <PaintElementImage>
  71. {
  72. public:
  73. SetStretchModeAction (PaintElementImage* const, const StretchMode);
  74. bool perform();
  75. bool undo();
  76. private:
  77. StretchMode newValue, oldValue;
  78. };
  79. StretchMode getStretchMode() const noexcept;
  80. void setStretchMode (const StretchMode, const bool);
  81. //==============================================================================
  82. XmlElement* createXml() const override;
  83. bool loadFromXml (const XmlElement&) override;
  84. private:
  85. String resourceName;
  86. double opacity;
  87. StretchMode mode;
  88. String customPaintCode;
  89. //==============================================================================
  90. class ImageElementResourceProperty : public ImageResourceProperty <PaintElementImage>
  91. {
  92. public:
  93. ImageElementResourceProperty (PaintElementImage* const);
  94. void setResource (const String&);
  95. String getResource() const;
  96. };
  97. //==============================================================================
  98. class OpacityProperty : public SliderPropertyComponent
  99. {
  100. public:
  101. OpacityProperty (PaintElementImage* const);
  102. void setValue (double);
  103. double getValue() const;
  104. ElementListener<PaintElementImage> listener;
  105. };
  106. class StretchModeProperty : public ChoicePropertyComponent
  107. {
  108. public:
  109. StretchModeProperty (PaintElementImage* const);
  110. void setIndex (int);
  111. int getIndex() const;
  112. ElementListener<PaintElementImage> listener;
  113. };
  114. class ResetSizeProperty : public ButtonPropertyComponent
  115. {
  116. public:
  117. ResetSizeProperty (PaintElementImage* const);
  118. void buttonClicked();
  119. String getButtonText() const;
  120. private:
  121. PaintElementImage* const element;
  122. };
  123. };