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.

166 lines
4.9KB

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