openshot-audio  0.1.6
juce_Justification.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_JUSTIFICATION_H_INCLUDED
26 #define JUCE_JUSTIFICATION_H_INCLUDED
27 
28 
29 //==============================================================================
39 {
40 public:
41  //==============================================================================
43  Justification (int justificationFlags) noexcept : flags (justificationFlags) {}
44 
46  Justification (const Justification& other) noexcept : flags (other.flags) {}
47 
50  {
51  flags = other.flags;
52  return *this;
53  }
54 
55  bool operator== (const Justification& other) const noexcept { return flags == other.flags; }
56  bool operator!= (const Justification& other) const noexcept { return flags != other.flags; }
57 
58  //==============================================================================
60  inline int getFlags() const noexcept { return flags; }
61 
65  inline bool testFlags (int flagsToTest) const noexcept { return (flags & flagsToTest) != 0; }
66 
69 
72 
73  //==============================================================================
79  template <typename ValueType>
80  void applyToRectangle (ValueType& x, ValueType& y, ValueType w, ValueType h,
81  ValueType spaceX, ValueType spaceY, ValueType spaceW, ValueType spaceH) const noexcept
82  {
83  x = spaceX;
84  if ((flags & horizontallyCentred) != 0) x += (spaceW - w) / (ValueType) 2;
85  else if ((flags & right) != 0) x += spaceW - w;
86 
87  y = spaceY;
88  if ((flags & verticallyCentred) != 0) y += (spaceH - h) / (ValueType) 2;
89  else if ((flags & bottom) != 0) y += spaceH - h;
90  }
91 
94  template <typename ValueType>
96  const Rectangle<ValueType>& targetSpace) const noexcept
97  {
98  ValueType x = areaToAdjust.getX(), y = areaToAdjust.getY();
99  applyToRectangle (x, y, areaToAdjust.getWidth(), areaToAdjust.getHeight(),
100  targetSpace.getX(), targetSpace.getY(), targetSpace.getWidth(), targetSpace.getHeight());
101  return areaToAdjust.withPosition (x, y);
102  }
103 
104  //==============================================================================
106  enum Flags
107  {
108  //==============================================================================
110  left = 1,
111 
113  right = 2,
114 
118 
119  //==============================================================================
121  top = 8,
122 
124  bottom = 16,
125 
129 
130  //==============================================================================
135 
136  //==============================================================================
140  centred = 36,
141 
146 
151 
156 
161 
165  topLeft = 9,
166 
170  topRight = 10,
171 
176 
181  };
182 
183 
184 private:
185  //==============================================================================
186  int flags;
187 };
188 
189 #endif // JUCE_JUSTIFICATION_H_INCLUDED
int getFlags() const noexcept
Definition: juce_Justification.h:60
Justification(const Justification &other) noexcept
Definition: juce_Justification.h:46
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_Justification.h:175
Definition: juce_Justification.h:38
Definition: juce_Justification.h:113
Definition: juce_Justification.h:124
#define const
Definition: juce_Justification.h:110
bool operator==(const Justification &other) const noexcept
Definition: juce_Justification.h:55
Definition: juce_Rectangle.h:36
int getOnlyHorizontalFlags() const noexcept
Definition: juce_Justification.h:71
const Rectangle< ValueType > appliedToRectangle(const Rectangle< ValueType > &areaToAdjust, const Rectangle< ValueType > &targetSpace) const noexcept
Definition: juce_Justification.h:95
Definition: juce_Justification.h:145
Justification(int justificationFlags) noexcept
Definition: juce_Justification.h:43
Definition: juce_Justification.h:170
int getOnlyVerticalFlags() const noexcept
Definition: juce_Justification.h:68
Definition: juce_Justification.h:180
Definition: juce_Justification.h:150
Definition: juce_Justification.h:128
void applyToRectangle(ValueType &x, ValueType &y, ValueType w, ValueType h, ValueType spaceX, ValueType spaceY, ValueType spaceW, ValueType spaceH) const noexcept
Definition: juce_Justification.h:80
Definition: juce_Justification.h:160
Definition: juce_Justification.h:140
Definition: juce_Justification.h:165
Definition: juce_Justification.h:121
bool operator!=(const Justification &other) const noexcept
Definition: juce_Justification.h:56
Definition: juce_Justification.h:155
bool testFlags(int flagsToTest) const noexcept
Definition: juce_Justification.h:65
Definition: juce_Justification.h:117
Definition: juce_Justification.h:134
Justification & operator=(const Justification &other) noexcept
Definition: juce_Justification.h:49
Flags
Definition: juce_Justification.h:106