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.

99 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. class JustificationProperty : public ChoicePropertyComponent
  19. {
  20. public:
  21. JustificationProperty (const String& name, const bool onlyHorizontalOptions)
  22. : ChoicePropertyComponent (name)
  23. {
  24. if (onlyHorizontalOptions)
  25. {
  26. choices.add ("centre");
  27. choices.add ("left");
  28. choices.add ("right");
  29. }
  30. else
  31. {
  32. choices.add ("centred");
  33. choices.add ("centred left");
  34. choices.add ("centred right");
  35. choices.add ("centred top");
  36. choices.add ("centred bottom");
  37. choices.add ("top left");
  38. choices.add ("top right");
  39. choices.add ("bottom left");
  40. choices.add ("bottom right");
  41. }
  42. }
  43. //==============================================================================
  44. virtual void setJustification (Justification newJustification) = 0;
  45. virtual Justification getJustification() const = 0;
  46. //==============================================================================
  47. void setIndex (int newIndex)
  48. {
  49. const int types[] = { Justification::centred,
  50. Justification::centredLeft,
  51. Justification::centredRight,
  52. Justification::centredTop,
  53. Justification::centredBottom,
  54. Justification::topLeft,
  55. Justification::topRight,
  56. Justification::bottomLeft,
  57. Justification::bottomRight };
  58. if (((unsigned int) newIndex) < (unsigned int) numElementsInArray (types)
  59. && types [newIndex] != getJustification().getFlags())
  60. {
  61. setJustification (Justification (types [newIndex]));
  62. }
  63. }
  64. int getIndex() const
  65. {
  66. const int types[] = { Justification::centred,
  67. Justification::centredLeft,
  68. Justification::centredRight,
  69. Justification::centredTop,
  70. Justification::centredBottom,
  71. Justification::topLeft,
  72. Justification::topRight,
  73. Justification::bottomLeft,
  74. Justification::bottomRight };
  75. const int rawFlags = getJustification().getFlags();
  76. for (int i = numElementsInArray (types); --i >= 0;)
  77. if (types[i] == rawFlags)
  78. return i;
  79. return -1;
  80. }
  81. };