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.

101 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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. //==============================================================================
  20. class JustificationProperty : public ChoicePropertyComponent
  21. {
  22. public:
  23. JustificationProperty (const String& name, const bool onlyHorizontalOptions)
  24. : ChoicePropertyComponent (name)
  25. {
  26. if (onlyHorizontalOptions)
  27. {
  28. choices.add ("centre");
  29. choices.add ("left");
  30. choices.add ("right");
  31. }
  32. else
  33. {
  34. choices.add ("centred");
  35. choices.add ("centred left");
  36. choices.add ("centred right");
  37. choices.add ("centred top");
  38. choices.add ("centred bottom");
  39. choices.add ("top left");
  40. choices.add ("top right");
  41. choices.add ("bottom left");
  42. choices.add ("bottom right");
  43. }
  44. }
  45. //==============================================================================
  46. virtual void setJustification (Justification newJustification) = 0;
  47. virtual Justification getJustification() const = 0;
  48. //==============================================================================
  49. void setIndex (int newIndex)
  50. {
  51. const int types[] = { Justification::centred,
  52. Justification::centredLeft,
  53. Justification::centredRight,
  54. Justification::centredTop,
  55. Justification::centredBottom,
  56. Justification::topLeft,
  57. Justification::topRight,
  58. Justification::bottomLeft,
  59. Justification::bottomRight };
  60. if (((unsigned int) newIndex) < (unsigned int) numElementsInArray (types)
  61. && types [newIndex] != getJustification().getFlags())
  62. {
  63. setJustification (Justification (types [newIndex]));
  64. }
  65. }
  66. int getIndex() const
  67. {
  68. const int types[] = { Justification::centred,
  69. Justification::centredLeft,
  70. Justification::centredRight,
  71. Justification::centredTop,
  72. Justification::centredBottom,
  73. Justification::topLeft,
  74. Justification::topRight,
  75. Justification::bottomLeft,
  76. Justification::bottomRight };
  77. const int rawFlags = getJustification().getFlags();
  78. for (int i = numElementsInArray (types); --i >= 0;)
  79. if (types[i] == rawFlags)
  80. return i;
  81. return -1;
  82. }
  83. };