Ocean
wxwidgets/Screen.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_WXWIDGETS_SCREEN_H
9 #define META_OCEAN_PLATFORM_WXWIDGETS_SCREEN_H
10 
12 
14 #include "ocean/cv/PixelPosition.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Platform
20 {
21 
22 namespace WxWidgets
23 {
24 
25 /**
26  * This class implements functions allowing to control screens and windows on screens.
27  * @ingroup platformwxwidgets
28  */
29 class OCEAN_PLATFORM_WXWIDGETS_EXPORT Screen
30 {
31  public:
32 
33  /**
34  * Returns the width of the primary display in pixel.
35  * @return Primary display width in pixel, with range [0, infinity)
36  */
37  static int primaryDisplayWidth();
38 
39  /**
40  * Returns the height of the primary display in pixel.
41  * @return Primary display height in pixel, with range [0, infinity)
42  */
43  static int primaryDisplayHeight();
44 
45  /**
46  * Returns the width of the virtual display in pixel.
47  * The virtual display is bounded by all screens.
48  * @return Virtual display width in pixel, with range [0, infinity)
49  */
50  static int virtualDisplayWidth();
51 
52  /**
53  * Returns the height of the virtual display in pixel.
54  * The virtual display is bounded by all screens.
55  * @return Virtual display height in pixel, with range [0, infinity)
56  */
57  static int virtualDisplayHeight();
58 
59  /**
60  * Returns the bounding box of the virtual display with pixel resolution.
61  * @return The bounding box of the virtual display
62  */
64 
65  /**
66  * Returns the most suitable position (top left on Windows and bottom left on OS X platforms) of a window that has to be placed on the (virtual) screen.
67  * The final position ensures that the window lies inside the bounding box of the (virtual) screen.
68  * @param windowWidth The width of the window for which the position will be determined in pixel, with range (0, infinity)
69  * @param windowHeight The height of the window for which the pose will be determined in pixel, with range (0, infinity)
70  * @param left Optional proposed left position of the window, which will be adjusted to fit into the virtual screen
71  * @param top Optional proposed top position of the window, which will be adjusted to fit into the virtual screen
72  * @param parent Optional handle of a parent (or associated) window to which the resulting position should match if no proposed position is provided
73  * @return The resulting top left position of the window
74  */
75  static CV::PixelPositionI suitableWindowPosition(const unsigned int windowWidth, const unsigned int windowHeight, const int left = NumericT<int>::minValue(), const int top = NumericT<int>::minValue(), const OCEAN_WXWIDGETS_HANDLE parent = nullptr);
76 
77 #ifdef __APPLE__
78 
79  /**
80  * Returns the most suitable position (top left on Windows and bottom left on OS X platforms) of a window that has to be placed on the (virtual) screen.
81  * The final position ensures that the window lies inside the bounding box of the (virtual) screen.
82  * @param windowWidth The width of the window for which the position will be determined in pixel, with range (0, infinity)
83  * @param windowHeight The height of the window for which the pose will be determined in pixel, with range (0, infinity)
84  * @param left Optional proposed left position of the window, which will be adjusted to fit into the virtual screen
85  * @param top Optional proposed top position of the window, which will be adjusted to fit into the virtual screen
86  * @param parent Optional handle of a parent (or associated) window to which the resulting position should match if no proposed position is provided
87  * @return The resulting top left position of the window
88  */
89  static CV::PixelPositionI suitableWindowPositionApple(const unsigned int windowWidth, const unsigned int windowHeight, const int left = NumericT<int>::minValue(), const int top = NumericT<int>::minValue(), const OCEAN_WXWIDGETS_HANDLE parent = nullptr);
90 
91 #endif
92 
93  /**
94  * Returns the scaling factor transforming the number of (backing) pixels defined in the (virtual) display coordinate system to the number of pixels defined in the (native/physical) screen coordinate system for a specified window.
95  * @param window The window for which the scaling factor is determined, nullptr to determine the scale factor of the default screen
96  * @return The resulting scale factor with range (0, infinity)
97  */
98  static double scaleFactor(const wxWindow* window);
99 
100 #ifdef __APPLE__
101 
102  /**
103  * Returns the scaling factor transforming the number of (backing) pixels defined in the (virtual) display coordinate system to the number of pixels defined in the (native/physical) screen coordinate system for a specified window.
104  * @param window The window for which the scaling factor is determined, nullptr to determine the scale factor of the default screen
105  * @return The resulting scale factor with range (0, infinity)
106  */
107  static double scaleFactorApple(const wxWindow* window);
108 
109 #endif
110 
111  /**
112  * Converts a given pixel value defined in the (virtual) display coordinate system to the pixel value defined in the (native/physical) screen coordinate system.
113  * Beware: On Apple-platforms this function does not apply any scaling, the value is returned directly.
114  * @param pixel Pixel value to convert, with range (-infinity, infinity)
115  * @param window The window for which the transformed/scaled pixel value is determined, nullptr to determine the pixel value for the default screen
116  * @return The converted pixel value for the (native/pyhsical) screen coordinate system, with range (-infinity, infinity)
117  */
118  static inline int scalePixel(const int pixel, const wxWindow* window);
119 
120  /**
121  * Converts a given size value defined in the (virtual) display coordinate system to the size value defined in the (native/physical) screen coordinate system.
122  * Beware: On Apple-platforms this function does not apply any scaling, the value is returned directly.
123  * @param size Size value to convert, with range (-infinity, infinity)x(-infinity, infinity)
124  * @param window The window for which the transformed/scaled size value is determined, nullptr to determine the size value for the default screen
125  * @return The converted size value for the (native/pyhsical) screen coordinate system, with range (-infinity, infinity)x(-infinity, infinity)
126  */
127  static inline wxSize scaleSize(const wxSize& size, const wxWindow* window);
128 
129  /**
130  * Converts a given point value defined in the (virtual) display coordinate system to the point value defined in the (native/physical) screen coordinate system.
131  * Beware: On Apple-platforms this function does not apply any scaling, the value is returned directly.
132  * @param point Point value to convert, with range (-infinity, infinity)x(-infinity, infinity)
133  * @param window The window for which the transformed/scaled point value is determined, nullptr to determine the point value for the default screen
134  * @return The converted point value for the (native/pyhsical) screen coordinate system, with range (-infinity, infinity)x(-infinity, infinity)
135  */
136  static inline wxPoint scalePoint(const wxPoint& point, const wxWindow* window);
137 
138  /**
139  * Converts a given pixel value by a given scale factor.
140  * Beware: On Apple-platforms this function does not apply any scaling, the value is returned directly.
141  * @param pixel Pixel value to convert, with range (-infinity, infinity)
142  * @param scaleFactor The scale factor to be applied, with range (-infinity, infinity)
143  * @return The resulting converted pixel value (-infinity, infinity)
144  */
145  static inline int scalePixelByFactor(const int pixel, const double scaleFactor);
146 
147  /**
148  * Converts a given size value by a given scale factor.
149  * Beware: On Apple-platforms this function does not apply any scaling, the value is returned directly.
150  * @param size Size value to convert, with range (-infinity, infinity)x(-infinity, infinity)
151  * @param scaleFactor The scale factor to be applied, with range (-infinity, infinity)
152  * @return The converted size value, with range (-infinity, infinity)x(-infinity, infinity)
153  */
154  static inline wxSize scaleSizeByFactor(const wxSize& size, const double scaleFactor);
155 
156  /**
157  * Converts a given point value by a given scale factor.
158  * Beware: On Apple-platforms this function does not apply any scaling, the value is returned directly.
159  * @param point Point value to convert, with range (-infinity, infinity)x(-infinity, infinity)
160  * @param scaleFactor The scale factor to be applied, with range (-infinity, infinity)
161  * @return The converted point value , with range (-infinity, infinity)x(-infinity, infinity)
162  */
163  static inline wxPoint scalePointByFactor(const wxPoint& point, const double scaleFactor);
164 };
165 
166 inline int Screen::scalePixel(const int pixel, const wxWindow* window)
167 {
168 #ifdef __APPLE__
169  return pixel;
170 #else
171  return scalePixelByFactor(pixel, scaleFactor(window));
172 #endif
173 }
174 
175 inline wxSize Screen::scaleSize(const wxSize& size, const wxWindow* window)
176 {
177 #ifdef __APPLE__
178  return size;
179 #else
180  return scaleSizeByFactor(size, scaleFactor(window));
181 #endif
182 }
183 
184 inline wxPoint Screen::scalePoint(const wxPoint& point, const wxWindow* window)
185 {
186 #ifdef __APPLE__
187  return point;
188 #else
189  return scalePointByFactor(point, scaleFactor(window));
190 #endif
191 }
192 
193 inline int Screen::scalePixelByFactor(const int pixel, const double scaleFactor)
194 {
195 #ifdef __APPLE__
196  return pixel;
197 #else
198  return NumericD::round32(double(pixel) * scaleFactor);
199 #endif
200 }
201 
202 inline wxSize Screen::scaleSizeByFactor(const wxSize& size, const double scaleFactor)
203 {
204 #ifdef __APPLE__
205  return size;
206 #else
207  return wxSize(NumericD::round32(double(size.x) * scaleFactor), NumericD::round32(double(size.y) * scaleFactor));
208 #endif
209 }
210 
211 inline wxPoint Screen::scalePointByFactor(const wxPoint& point, const double scaleFactor)
212 {
213 #ifdef __APPLE__
214  return point;
215 #else
216  return wxPoint(NumericD::round32(double(point.x) * scaleFactor), NumericD::round32(double(point.y) * scaleFactor));
217 #endif
218 }
219 
220 }
221 
222 }
223 
224 }
225 
226 #endif // META_OCEAN_PLATFORM_WXWIDGETS_SCREEN_H
This class implements a 2D bounding box with pixel precision.
Definition: PixelBoundingBox.h:57
This class implements a 2D pixel position with pixel precision.
Definition: PixelPosition.h:65
This class provides basic numeric functionalities.
Definition: Numeric.h:57
static constexpr int32_t round32(const T value)
Returns the rounded 32 bit integer value of a given value.
Definition: Numeric.h:2064
This class implements functions allowing to control screens and windows on screens.
Definition: wxwidgets/Screen.h:30
static double scaleFactor(const wxWindow *window)
Returns the scaling factor transforming the number of (backing) pixels defined in the (virtual) displ...
static wxSize scaleSize(const wxSize &size, const wxWindow *window)
Converts a given size value defined in the (virtual) display coordinate system to the size value defi...
Definition: wxwidgets/Screen.h:175
static int virtualDisplayHeight()
Returns the height of the virtual display in pixel.
static wxSize scaleSizeByFactor(const wxSize &size, const double scaleFactor)
Converts a given size value by a given scale factor.
Definition: wxwidgets/Screen.h:202
static wxPoint scalePointByFactor(const wxPoint &point, const double scaleFactor)
Converts a given point value by a given scale factor.
Definition: wxwidgets/Screen.h:211
static wxPoint scalePoint(const wxPoint &point, const wxWindow *window)
Converts a given point value defined in the (virtual) display coordinate system to the point value de...
Definition: wxwidgets/Screen.h:184
static CV::PixelPositionI suitableWindowPositionApple(const unsigned int windowWidth, const unsigned int windowHeight, const int left=NumericT< int >::minValue(), const int top=NumericT< int >::minValue(), const OCEAN_WXWIDGETS_HANDLE parent=nullptr)
Returns the most suitable position (top left on Windows and bottom left on OS X platforms) of a windo...
static int primaryDisplayHeight()
Returns the height of the primary display in pixel.
static int primaryDisplayWidth()
Returns the width of the primary display in pixel.
static double scaleFactorApple(const wxWindow *window)
Returns the scaling factor transforming the number of (backing) pixels defined in the (virtual) displ...
static CV::PixelPositionI suitableWindowPosition(const unsigned int windowWidth, const unsigned int windowHeight, const int left=NumericT< int >::minValue(), const int top=NumericT< int >::minValue(), const OCEAN_WXWIDGETS_HANDLE parent=nullptr)
Returns the most suitable position (top left on Windows and bottom left on OS X platforms) of a windo...
static CV::PixelBoundingBoxI virtualDisplayBoundingBox()
Returns the bounding box of the virtual display with pixel resolution.
static int virtualDisplayWidth()
Returns the width of the virtual display in pixel.
static int scalePixelByFactor(const int pixel, const double scaleFactor)
Converts a given pixel value by a given scale factor.
Definition: wxwidgets/Screen.h:193
static int scalePixel(const int pixel, const wxWindow *window)
Converts a given pixel value defined in the (virtual) display coordinate system to the pixel value de...
Definition: wxwidgets/Screen.h:166
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15