Ocean
wxwidgets/BitmapWindow.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_BITMAP_WINDOW_H
9 #define META_OCEAN_PLATFORM_WXWIDGETS_BITMAP_WINDOW_H
10 
12 
13 #include "ocean/base/Frame.h"
14 
15 #include "ocean/math/Numeric.h"
16 
17 namespace Ocean
18 {
19 
20 namespace Platform
21 {
22 
23 namespace WxWidgets
24 {
25 
26 /**
27  * This class implements the main window.
28  * @ingroup platformwxw
29  */
30 class OCEAN_PLATFORM_WXWIDGETS_EXPORT BitmapWindow : public wxScrolledWindow
31 {
32  public:
33 
34  /**
35  * Definition of several display modes.
36  */
38  {
39  // User display mode.
41  // Stretch display mode.
43  // Enlarge display mode.
45  /// Fullscreen zoom display mode.
47  /// Shrink display mode.
48  DM_SHRINK_TO_SCREEN
49  };
50 
51  public:
52 
53  /**
54  * Creates a new main window object.
55  * @param title Tile of the bitmap window to be created
56  * @param parent Parent window
57  * @param pos Position of the bitmap window
58  * @param size Size of the bitmap window
59  */
60  BitmapWindow(const wxString& title, wxWindow* parent = nullptr, const wxPoint& pos = wxPoint(-1, -1), const wxSize& size = wxSize(-1, -1));
61 
62  /**
63  * Sets or changes the bitmap of this bitmap window.
64  * @param bitmap Bitmap to be set
65  * @param resetZoom True, to reset the zoom; False, to keep the zoom as it is
66  */
67  void setBitmap(const wxBitmap& bitmap, const bool resetZoom = true);
68 
69  /**
70  * Sets or changes the bitmap of this bitmap window by a given frame.
71  * @param frame The frame to be set
72  * @param resetZoom True, to reset the zoom; False, to keep the zoom as it is
73  * @return True, if succeeded
74  */
75  bool setFrame(const Frame& frame, const bool resetZoom = true);
76 
77  /**
78  * Sets the display mode of this bitmap window.
79  * @param mode Mode to be set
80  */
81  void setDisplayMode(const DisplayMode mode);
82 
83  /**
84  * Sets the zoom of the bitmap window.
85  * @param zoom Zoom to be set
86  */
87  void setZoom(const Scalar zoom);
88 
89  /**
90  * Enables scroll bars if necessary.
91  * @param enable True, to enable the scrollbars
92  */
93  void setEnableScrollbars(const bool enable);
94 
95  protected:
96 
97  /// WxWidgets event table.
99 
100  protected:
101 
102  /**
103  * Paint event function.
104  * @param event Event command
105  */
106  virtual void onPaint(wxPaintEvent& event);
107 
108  /**
109  * Paint event function.
110  * @param event Event command
111  * @param dc Device context
112  */
113  virtual void onPaintOverlay(wxPaintEvent& event, wxPaintDC& dc);
114 
115  /**
116  * Size event function.
117  * @param event Event command
118  */
119  virtual void onSize(wxSizeEvent& event);
120 
121  /**
122  * Left mouse click down event function.
123  * @param event Event command
124  */
125  virtual void onMouseLeftDown(wxMouseEvent& event);
126 
127  /**
128  * Left mouse click up event function.
129  * @param event Event command
130  */
131  virtual void onMouseLeftUp(wxMouseEvent& event);
132 
133  /**
134  * Left mouse double click down event function.
135  * @param event Event command
136  */
137  virtual void onMouseLeftDblClick(wxMouseEvent& event);
138 
139  /**
140  * Middle mouse click down event function.
141  * @param event Event command
142  */
143  virtual void onMouseMiddleDown(wxMouseEvent& event);
144 
145  /**
146  * Middle mouse click up event function.
147  * @param event Event command
148  */
149  virtual void onMouseMiddleUp(wxMouseEvent& event);
150 
151  /**
152  * Right mouse click down event function.
153  * @param event Event command
154  */
155  virtual void onMouseRightDown(wxMouseEvent& event);
156 
157  /**
158  * Right mouse click up event function.
159  * @param event Event command
160  */
161  virtual void onMouseRightUp(wxMouseEvent& event);
162 
163  /**
164  * Right mouse double click down event function.
165  * @param event Event command
166  */
167  virtual void onMouseRightDblClick(wxMouseEvent& event);
168 
169  /**
170  * Mouse wheel event function.
171  * @param event Event command
172  */
173  virtual void onMouseWheel(wxMouseEvent& event);
174 
175  /**
176  * Mouse move event function.
177  * @param event Event command
178  */
179  virtual void onMouseMove(wxMouseEvent& event);
180 
181  /**
182  * Background erase event function.
183  * @param event Event command
184  */
185  void onEraseBackground(wxEraseEvent& event);
186 
187  /**
188  * Paints the bitmap of this window at the center of this window.
189  * @param dc Device context in which the bitmap will be painted
190  * @param clientWidth Client width of this window
191  * @param clientHeight Client height of this window
192  * @param bitmapWidth The display width of the bitmap
193  * @param bitmapHeight The display height of the bitmap
194  */
195  void paintCenter(wxDC& dc, const int clientWidth, const int clientHeight, const int bitmapWidth, const int bitmapHeight);
196 
197  /**
198  * Paints the bitmap of this window centered in the window with a zoom of 1.0.
199  * The bitmap of this window must have a valid dimension, with range [1, infinity)x[1, infinity)
200  * @param dc Device context in which the bitmap will be painted
201  * @param clientWidth Client width of this window, with range [1, infinity)
202  * @param clientHeight Client height of this window, with range [1, infininty)
203  */
204  void paintSubset(wxDC& dc, const int clientWidth, const int clientHeight);
205 
206  /**
207  * Paints the bitmap of this window centered in the window while the size of the bitmap is scaled to the larges size (with correct aspect ratio) so that the entire bitmap is still visible.
208  * The bitmap of this window must have a valid dimension, with range [1, infinity)x[1, infinity)
209  * @param dc Device context in which the bitmap will be painted
210  * @param clientWidth Client width of this window, with range [1, infinity)
211  * @param clientHeight Client height of this window, with range [1, infininty)
212  */
213  void paintFit2Client(wxDC& dc, const int clientWidth, const int clientHeight);
214 
215  /**
216  * Paints the bitmap of this window centered in the window while the size of the bitmap is scaled (with correct aspect ratio) so that the entire window is filled with the bitmap.
217  * The bitmap of this window must have a valid dimension, with range [1, infinity)x[1, infinity)
218  * @param dc Device context in which the bitmap will be painted
219  * @param clientWidth Client width of this window, with range [1, infinity)
220  * @param clientHeight Client height of this window, with range [1, infininty)
221  */
222  void paintFit2Fullscreen(wxDC& dc, const int clientWidth, const int clientHeight);
223 
224  /**
225  * Returns the width of the zoomed bitmap in pixel.
226  * @return Zoomed bitmap width
227  */
228  int zoomedWidth() const;
229 
230  /**
231  * Returns the height of the zoomed bitmap in pixel.
232  * @return Zoomed bitmap height
233  */
234  int zoomedHeight() const;
235 
236  /**
237  * Calculates the bitmap position for a given window position.
238  * @param x Horizontal window position
239  * @param y Vertical window position
240  * @param xBitmap Resulting horizontal bitmap position
241  * @param yBitmap Resulting vertical bitmap position
242  * @param allowPositionOutsideBitmap True, to allow output positions lying outside the actual bitmap; False, to fail when a given bitmap position is outside the actual bitmap
243  * @return True, if the given point lies inside the bitmap
244  */
245  bool window2bitmap(const int x, const int y, Scalar& xBitmap, Scalar& yBitmap, const bool allowPositionOutsideBitmap = false);
246 
247  /**
248  * Calculates the bitmap position for a given virtual window position.
249  * @param xVirtual Horizontal window position
250  * @param yVirtual Vertical window position
251  * @param xBitmap Resulting horizontal bitmap position
252  * @param yBitmap Resulting vertical bitmap position
253  * @return True, if the given point lies inside the bitmap
254  */
255  bool virtualWindow2bitmap(const int xVirtual, const int yVirtual, Scalar& xBitmap, Scalar& yBitmap);
256 
257  /**
258  * Calculates the virtual window position for a given bitmap position.
259  * @param xBitmap Horizontal bitmap position
260  * @param yBitmap Vertical bitmap position
261  * @param xVirtual Resulting horizontal virtual position
262  * @param yVirtual Resulting vertical virtual position
263  * @param allowPositionOutsideBitmap True, to allow input positions lying outside the actual bitmap; False, to fail when a given bitmap position is outside the actual bitmap
264  * @return True, if the given point could be converted to a point located in the virtual window; False, if no point could be converted
265  */
266  bool bitmap2virtualWindow(const Scalar xBitmap, const Scalar yBitmap, Scalar& xVirtual, Scalar& yVirtual, const bool allowPositionOutsideBitmap = false);
267 
268  /**
269  * Calculates the window position for a given bitmap position.
270  * @param xBitmap Horizontal bitmap position
271  * @param yBitmap Vertical bitmap position
272  * @param x Resulting horizontal window position
273  * @param y Resulting vertical window position
274  * @return True, if the given point lies inside the bitmap
275  */
276  bool bitmap2window(const int xBitmap, const int yBitmap, Scalar& x, Scalar& y);
277 
278  /**
279  * Calculates the window position for a given bitmap position.
280  * @param xBitmap Horizontal bitmap position
281  * @param yBitmap Vertical bitmap position
282  * @param x Resulting horizontal window position
283  * @param y Resulting vertical window position
284  * @return True, if the given point lies inside the bitmap
285  */
286  bool bitmap2window(const Scalar xBitmap, const Scalar yBitmap, Scalar& x, Scalar& y);
287 
288  protected:
289 
290  /// Bitmap of the window.
291  wxBitmap bitmap_;
292 
293  /// Bitmap horizontal display position.
294  int displayBitmapLeft_ = NumericT<int>::minValue();
295 
296  /// Bitmap vertical display position.
297  int displayBitmapTop_ = NumericT<int>::minValue();
298 
299  /// Bitmap display width.
300  int displayBitmapWidth_ = NumericT<int>::minValue();
301 
302  /// Bitmap display height.
303  int displayBitmapHeight_ = NumericT<int>::minValue();
304 
305  /// Display mode.
306  DisplayMode displayMode_ = DM_SHRINK_TO_SCREEN;
307 
308  /// Scrollbar enable state.
309  bool scrollbarsEnabled_ = true;
310 
311  /// Zoom factor for user display mode.
312  double zoom_ = 1.0;
313 
314  /// Previous horizontal middle mouse position.
315  double previousMouseMiddleBitmapX_ = NumericD::minValue();
316 
317  /// Previous vertical middle mouse position.
318  double previousMouseMiddleBitmapY = NumericD::minValue();
319 
320  /// Previous horizontal mouse position.
321  int previousMouseX_ = -1;
322 
323  /// Previous vertical mouse position.
324  int previousMouseY_ = -1;
325 
326  /// Bitmap lock.
328 };
329 
330 }
331 
332 }
333 
334 }
335 
336 #endif // META_OCEAN_PLATFORM_WXWIDGETS_BITMAP_WINDOW_H
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements a recursive lock object.
Definition: Lock.h:31
static constexpr T minValue()
Returns the min scalar value.
Definition: Numeric.h:3250
This class implements the main window.
Definition: wxwidgets/BitmapWindow.h:31
virtual void onPaintOverlay(wxPaintEvent &event, wxPaintDC &dc)
Paint event function.
virtual void onMouseMove(wxMouseEvent &event)
Mouse move event function.
virtual void onMouseRightUp(wxMouseEvent &event)
Right mouse click up event function.
virtual void onMouseLeftUp(wxMouseEvent &event)
Left mouse click up event function.
void paintFit2Client(wxDC &dc, const int clientWidth, const int clientHeight)
Paints the bitmap of this window centered in the window while the size of the bitmap is scaled to the...
virtual void onMouseLeftDown(wxMouseEvent &event)
Left mouse click down event function.
void setZoom(const Scalar zoom)
Sets the zoom of the bitmap window.
int zoomedHeight() const
Returns the height of the zoomed bitmap in pixel.
virtual void onMouseRightDown(wxMouseEvent &event)
Right mouse click down event function.
bool virtualWindow2bitmap(const int xVirtual, const int yVirtual, Scalar &xBitmap, Scalar &yBitmap)
Calculates the bitmap position for a given virtual window position.
void setDisplayMode(const DisplayMode mode)
Sets the display mode of this bitmap window.
DisplayMode
Definition of several display modes.
Definition: wxwidgets/BitmapWindow.h:38
@ DM_STRETCH
Definition: wxwidgets/BitmapWindow.h:42
@ DM_ZOOM_TO_FULLSCREEN
Fullscreen zoom display mode.
Definition: wxwidgets/BitmapWindow.h:46
@ DM_USER
Definition: wxwidgets/BitmapWindow.h:40
@ DM_ENLARGE_TO_SCREEN
Definition: wxwidgets/BitmapWindow.h:44
virtual void onMouseRightDblClick(wxMouseEvent &event)
Right mouse double click down event function.
void onEraseBackground(wxEraseEvent &event)
Background erase event function.
virtual void onMouseLeftDblClick(wxMouseEvent &event)
Left mouse double click down event function.
Ocean::Lock bitmapLock_
Bitmap lock.
Definition: wxwidgets/BitmapWindow.h:327
virtual void onMouseMiddleDown(wxMouseEvent &event)
Middle mouse click down event function.
virtual void onPaint(wxPaintEvent &event)
Paint event function.
virtual void onMouseWheel(wxMouseEvent &event)
Mouse wheel event function.
void paintSubset(wxDC &dc, const int clientWidth, const int clientHeight)
Paints the bitmap of this window centered in the window with a zoom of 1.0.
bool setFrame(const Frame &frame, const bool resetZoom=true)
Sets or changes the bitmap of this bitmap window by a given frame.
wxBitmap bitmap_
Bitmap of the window.
Definition: wxwidgets/BitmapWindow.h:291
DECLARE_EVENT_TABLE()
WxWidgets event table.
int zoomedWidth() const
Returns the width of the zoomed bitmap in pixel.
bool bitmap2virtualWindow(const Scalar xBitmap, const Scalar yBitmap, Scalar &xVirtual, Scalar &yVirtual, const bool allowPositionOutsideBitmap=false)
Calculates the virtual window position for a given bitmap position.
void paintFit2Fullscreen(wxDC &dc, const int clientWidth, const int clientHeight)
Paints the bitmap of this window centered in the window while the size of the bitmap is scaled (with ...
bool bitmap2window(const int xBitmap, const int yBitmap, Scalar &x, Scalar &y)
Calculates the window position for a given bitmap position.
void paintCenter(wxDC &dc, const int clientWidth, const int clientHeight, const int bitmapWidth, const int bitmapHeight)
Paints the bitmap of this window at the center of this window.
BitmapWindow(const wxString &title, wxWindow *parent=nullptr, const wxPoint &pos=wxPoint(-1, -1), const wxSize &size=wxSize(-1, -1))
Creates a new main window object.
void setEnableScrollbars(const bool enable)
Enables scroll bars if necessary.
bool bitmap2window(const Scalar xBitmap, const Scalar yBitmap, Scalar &x, Scalar &y)
Calculates the window position for a given bitmap position.
bool window2bitmap(const int x, const int y, Scalar &xBitmap, Scalar &yBitmap, const bool allowPositionOutsideBitmap=false)
Calculates the bitmap position for a given window position.
virtual void onSize(wxSizeEvent &event)
Size event function.
void setBitmap(const wxBitmap &bitmap, const bool resetZoom=true)
Sets or changes the bitmap of this bitmap window.
virtual void onMouseMiddleUp(wxMouseEvent &event)
Middle mouse click up event function.
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15