Ocean
Loading...
Searching...
No Matches
FlippedView.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_PLATFORM_APPLE_MACOS_FLIPPED_VIEW_H
9#define META_OCEAN_PLATFORM_APPLE_MACOS_FLIPPED_VIEW_H
10
12
13#include "ocean/math/Vector2.h"
14
15#ifndef __OBJC__
16 #error Platform::Apple::MacOS::FlippedView.h needs to be included from an ObjectiveC++ file
17#endif
18
19#include <AppKit/AppKit.h>
20
21namespace Ocean
22{
23
24namespace Platform
25{
26
27namespace Apple
28{
29
30namespace MacOS
31{
32
33/**
34 * This class wrapps an MacOS NSView object and flips the coordinate system.
35 * @ingroup platformapplemacos
36 */
38{
39 protected:
40
41 /**
42 * Definition of a vector holding 8 bit values.
43 */
44 typedef std::vector<unsigned char> EnabledStates;
45
46 /**
47 * Definition of a vector holding view objects.
48 */
49 typedef std::vector<NSView*> NSViews;
50
51 public:
52
53 /**
54 * Creates an invalid object.
55 */
56 FlippedView() = default;
57
58 /**
59 * Move constructor.
60 * @param view View object to move
61 */
62 FlippedView(FlippedView&& view) noexcept;
63
64 /**
65 * Not existing copy constructor.
66 * @param view View object to copy
67 */
68 FlippedView(const FlippedView& view) = delete;
69
70 /**
71 * Creates a new view object with specified size and dimension.
72 * @param rect The rect defining the size and dimension
73 */
74 explicit FlippedView(const NSRect& rect);
75
76 /**
77 * Creates a new view object with specified size and dimension.
78 * @param left The horizontal start position of this view, with range (-infinity, infinity)
79 * @param top The vertical start position of this view in pixel, with range (-infinity, infinity)
80 * @param width The width of the view in pixel, with range [0, infinity)
81 * @param height The height of the view in pixel, with range [0, infinity)
82 */
83 FlippedView(const int left, const int top, const unsigned int width, const unsigned int height);
84
85 /**
86 * Destructs a flipped view object.
87 */
88 virtual ~FlippedView();
89
90 /**
91 * Returns whether this view is enabled.
92 * Beware: You should not modified the 'enable statements' of any child control is this view is disabled.
93 * @return True, if so
94 */
95 inline bool isEnabled() const;
96
97 /**
98 * Enables or disables this view.
99 * @param enable True, to enable the view; False, to disable the view
100 */
101 void setEnabled(const bool enable);
102
103 /**
104 * Returns the MacOS specific view object.
105 * @return The view object
106 */
107 inline NSView* nsView();
108
109 /**
110 * Returns whether this object wrapps a valid NSView object.
111 * @return True, if so
112 */
113 inline bool isValid() const;
114
115 /**
116 * The event function before this view will be redrawn.
117 */
118 virtual void onRedrawing();
119
120 /**
121 * The draw event function actually displaying this view.
122 */
123 virtual void onDraw();
124
125 /**
126 * The function for left mouse button down events.
127 * @param mouseLocation The location of the mouse within the coordinate symste of this view
128 */
129 virtual void onMouseDownLeft(const Vector2& mouseLocation);
130
131 /**
132 * The function for left mouse button up events.
133 * @param mouseLocation The location of the mouse within the coordinate symste of this view
134 */
135 virtual void onMouseUpLeft(const Vector2& mouseLocation);
136
137 /**
138 * Returns whether this object wrapps a valid NSView object.
139 * @return True, if so
140 */
141 explicit inline operator bool() const;
142
143 /**
144 * Move operator.
145 * @param view View object to be moved
146 * @return Reference to this object
147 */
149
150 /**
151 * Not existing assign operator.
152 * @param view View object to be copied
153 * @return Reference to this object
154 */
155 FlippedView& operator=(const FlippedView& view) = delete;
156
157 protected:
158
159 /// The MacOS specific NSView object.
160 NSView* nsView_ = nullptr;
161
162 /// True, if the view is enabled.
163 bool enabled_ = false;
164
165 /// The child controls for which a corresponding recover enabled statement has been determined.
166 NSMutableArray* childControls_ = nullptr;
167
168 /// The enable statements of all child controls which have been determined as this view got disabled.
170};
171
172inline bool FlippedView::isEnabled() const
173{
174 return enabled_;
175}
176
177inline NSView* FlippedView::nsView()
178{
179 return nsView_;
180}
181
182inline bool FlippedView::isValid() const
183{
184 return nsView_ != nullptr;
185}
186
187inline FlippedView::operator bool() const
188{
189 return isValid();
190}
191
192}
193
194}
195
196}
197
198}
199
200#endif // META_OCEAN_PLATFORM_APPLE_MACOS_FLIPPED_VIEW_H
This class wrapps an MacOS NSView object and flips the coordinate system.
Definition FlippedView.h:38
FlippedView(const FlippedView &view)=delete
Not existing copy constructor.
bool isValid() const
Returns whether this object wrapps a valid NSView object.
Definition FlippedView.h:182
FlippedView()=default
Creates an invalid object.
virtual void onMouseDownLeft(const Vector2 &mouseLocation)
The function for left mouse button down events.
virtual void onMouseUpLeft(const Vector2 &mouseLocation)
The function for left mouse button up events.
virtual void onRedrawing()
The event function before this view will be redrawn.
NSMutableArray * childControls_
The child controls for which a corresponding recover enabled statement has been determined.
Definition FlippedView.h:166
bool enabled_
True, if the view is enabled.
Definition FlippedView.h:163
bool isEnabled() const
Returns whether this view is enabled.
Definition FlippedView.h:172
FlippedView & operator=(FlippedView &&view) noexcept
Move operator.
NSView * nsView()
Returns the MacOS specific view object.
Definition FlippedView.h:177
FlippedView & operator=(const FlippedView &view)=delete
Not existing assign operator.
EnabledStates recoverChildControls_
The enable statements of all child controls which have been determined as this view got disabled.
Definition FlippedView.h:169
void setEnabled(const bool enable)
Enables or disables this view.
std::vector< unsigned char > EnabledStates
Definition of a vector holding 8 bit values.
Definition FlippedView.h:44
FlippedView(const NSRect &rect)
Creates a new view object with specified size and dimension.
FlippedView(const int left, const int top, const unsigned int width, const unsigned int height)
Creates a new view object with specified size and dimension.
FlippedView(FlippedView &&view) noexcept
Move constructor.
std::vector< NSView * > NSViews
Definition of a vector holding view objects.
Definition FlippedView.h:49
virtual void onDraw()
The draw event function actually displaying this view.
virtual ~FlippedView()
Destructs a flipped view object.
NSView * nsView_
The MacOS specific NSView object.
Definition FlippedView.h:160
The namespace covering the entire Ocean framework.
Definition Accessor.h:15