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.

103 lines
3.7KB

  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. #ifndef JUCER_JUSTIFICATIONPROPERTY_H_INCLUDED
  18. #define JUCER_JUSTIFICATIONPROPERTY_H_INCLUDED
  19. class JustificationProperty : public ChoicePropertyComponent
  20. {
  21. public:
  22. JustificationProperty (const String& name, const bool onlyHorizontalOptions)
  23. : ChoicePropertyComponent (name)
  24. {
  25. if (onlyHorizontalOptions)
  26. {
  27. choices.add ("centre");
  28. choices.add ("left");
  29. choices.add ("right");
  30. }
  31. else
  32. {
  33. choices.add ("centred");
  34. choices.add ("centred left");
  35. choices.add ("centred right");
  36. choices.add ("centred top");
  37. choices.add ("centred bottom");
  38. choices.add ("top left");
  39. choices.add ("top right");
  40. choices.add ("bottom left");
  41. choices.add ("bottom right");
  42. }
  43. }
  44. //==============================================================================
  45. virtual void setJustification (Justification newJustification) = 0;
  46. virtual Justification getJustification() const = 0;
  47. //==============================================================================
  48. void setIndex (int newIndex)
  49. {
  50. const int types[] = { Justification::centred,
  51. Justification::centredLeft,
  52. Justification::centredRight,
  53. Justification::centredTop,
  54. Justification::centredBottom,
  55. Justification::topLeft,
  56. Justification::topRight,
  57. Justification::bottomLeft,
  58. Justification::bottomRight };
  59. if (((unsigned int) newIndex) < (unsigned int) numElementsInArray (types)
  60. && types [newIndex] != getJustification().getFlags())
  61. {
  62. setJustification (Justification (types [newIndex]));
  63. }
  64. }
  65. int getIndex() const
  66. {
  67. const int types[] = { Justification::centred,
  68. Justification::centredLeft,
  69. Justification::centredRight,
  70. Justification::centredTop,
  71. Justification::centredBottom,
  72. Justification::topLeft,
  73. Justification::topRight,
  74. Justification::bottomLeft,
  75. Justification::bottomRight };
  76. const int rawFlags = getJustification().getFlags();
  77. for (int i = numElementsInArray (types); --i >= 0;)
  78. if (types[i] == rawFlags)
  79. return i;
  80. return -1;
  81. }
  82. };
  83. #endif // JUCER_JUSTIFICATIONPROPERTY_H_INCLUDED