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.

102 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. //==============================================================================
  21. class JustificationProperty : public ChoicePropertyComponent
  22. {
  23. public:
  24. JustificationProperty (const String& name, const bool onlyHorizontalOptions)
  25. : ChoicePropertyComponent (name)
  26. {
  27. if (onlyHorizontalOptions)
  28. {
  29. choices.add ("centre");
  30. choices.add ("left");
  31. choices.add ("right");
  32. }
  33. else
  34. {
  35. choices.add ("centred");
  36. choices.add ("centred left");
  37. choices.add ("centred right");
  38. choices.add ("centred top");
  39. choices.add ("centred bottom");
  40. choices.add ("top left");
  41. choices.add ("top right");
  42. choices.add ("bottom left");
  43. choices.add ("bottom right");
  44. }
  45. }
  46. //==============================================================================
  47. virtual void setJustification (Justification newJustification) = 0;
  48. virtual Justification getJustification() const = 0;
  49. //==============================================================================
  50. void setIndex (int newIndex)
  51. {
  52. const int types[] = { Justification::centred,
  53. Justification::centredLeft,
  54. Justification::centredRight,
  55. Justification::centredTop,
  56. Justification::centredBottom,
  57. Justification::topLeft,
  58. Justification::topRight,
  59. Justification::bottomLeft,
  60. Justification::bottomRight };
  61. if (((unsigned int) newIndex) < (unsigned int) numElementsInArray (types)
  62. && types [newIndex] != getJustification().getFlags())
  63. {
  64. setJustification (Justification (types [newIndex]));
  65. }
  66. }
  67. int getIndex() const
  68. {
  69. const int types[] = { Justification::centred,
  70. Justification::centredLeft,
  71. Justification::centredRight,
  72. Justification::centredTop,
  73. Justification::centredBottom,
  74. Justification::topLeft,
  75. Justification::topRight,
  76. Justification::bottomLeft,
  77. Justification::bottomRight };
  78. const int rawFlags = getJustification().getFlags();
  79. for (int i = numElementsInArray (types); --i >= 0;)
  80. if (types[i] == rawFlags)
  81. return i;
  82. return -1;
  83. }
  84. };