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.

94 lines
3.3KB

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