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.

159 lines
4.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. #include "jucer_ColouredElement.h"
  15. #include "../Properties/jucer_FilePropertyComponent.h"
  16. #include "jucer_ImageResourceProperty.h"
  17. #include "jucer_PaintElementUndoableAction.h"
  18. //==============================================================================
  19. class PaintElementImage : public PaintElement
  20. {
  21. public:
  22. PaintElementImage (PaintRoutine*);
  23. ~PaintElementImage() override;
  24. enum StretchMode
  25. {
  26. stretched = 0,
  27. proportional = 1,
  28. proportionalReducingOnly = 2
  29. };
  30. const Drawable* getDrawable();
  31. void draw (Graphics&, const ComponentLayout*, const Rectangle<int>&) override;
  32. //==============================================================================
  33. void getEditableProperties (Array <PropertyComponent*>&, bool) override;
  34. void fillInGeneratedCode (GeneratedCode&, String&) override;
  35. void applyCustomPaintSnippets (StringArray& snippets) override;
  36. //==============================================================================
  37. class SetResourceAction : public PaintElementUndoableAction <PaintElementImage>
  38. {
  39. public:
  40. SetResourceAction (PaintElementImage* const, const String&);
  41. bool perform();
  42. bool undo();
  43. private:
  44. String newResource, oldResource;
  45. };
  46. void setResource (const String&, const bool);
  47. String getResource() const;
  48. //==============================================================================
  49. class SetOpacityAction : public PaintElementUndoableAction <PaintElementImage>
  50. {
  51. public:
  52. SetOpacityAction (PaintElementImage* const, const double);
  53. bool perform();
  54. bool undo();
  55. private:
  56. double newOpacity, oldOpacity;
  57. };
  58. void setOpacity (double, const bool);
  59. double getOpacity() const noexcept;
  60. //==============================================================================
  61. static const char* getTagName() noexcept;
  62. void resetToImageSize();
  63. //==============================================================================
  64. class SetStretchModeAction : public PaintElementUndoableAction <PaintElementImage>
  65. {
  66. public:
  67. SetStretchModeAction (PaintElementImage* const, const StretchMode);
  68. bool perform();
  69. bool undo();
  70. private:
  71. StretchMode newValue, oldValue;
  72. };
  73. StretchMode getStretchMode() const noexcept;
  74. void setStretchMode (const StretchMode, const bool);
  75. //==============================================================================
  76. XmlElement* createXml() const override;
  77. bool loadFromXml (const XmlElement&) override;
  78. private:
  79. String resourceName;
  80. double opacity;
  81. StretchMode mode;
  82. String customPaintCode;
  83. //==============================================================================
  84. class ImageElementResourceProperty : public ImageResourceProperty <PaintElementImage>
  85. {
  86. public:
  87. ImageElementResourceProperty (PaintElementImage* const);
  88. void setResource (const String&);
  89. String getResource() const;
  90. };
  91. //==============================================================================
  92. class OpacityProperty : public SliderPropertyComponent
  93. {
  94. public:
  95. OpacityProperty (PaintElementImage* const);
  96. void setValue (double);
  97. double getValue() const;
  98. ElementListener<PaintElementImage> listener;
  99. };
  100. class StretchModeProperty : public ChoicePropertyComponent
  101. {
  102. public:
  103. StretchModeProperty (PaintElementImage* const);
  104. void setIndex (int);
  105. int getIndex() const;
  106. ElementListener<PaintElementImage> listener;
  107. };
  108. class ResetSizeProperty : public ButtonPropertyComponent
  109. {
  110. public:
  111. ResetSizeProperty (PaintElementImage* const);
  112. void buttonClicked();
  113. String getButtonText() const;
  114. private:
  115. PaintElementImage* const element;
  116. };
  117. };