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.

105 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_JUSTIFICATIONPROPERTY_JUCEHEADER__
  19. #define __JUCER_JUSTIFICATIONPROPERTY_JUCEHEADER__
  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 (const Justification& newJustification) = 0;
  47. virtual const 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 flags = getJustification().getFlags();
  78. for (int i = numElementsInArray (types); --i >= 0;)
  79. if (types[i] == flags)
  80. return i;
  81. return -1;
  82. }
  83. };
  84. #endif // __JUCER_JUSTIFICATIONPROPERTY_JUCEHEADER__