Ocean
win/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_WIN_BITMAP_WINDOW_H
9 #define META_OCEAN_PLATFORM_WIN_BITMAP_WINDOW_H
10 
11 #include "ocean/platform/win/Win.h"
14 
15 namespace Ocean
16 {
17 
18 namespace Platform
19 {
20 
21 namespace Win
22 {
23 
24 /**
25  * This class implements a main window.
26  * @ingroup platformwin
27  */
28 class OCEAN_PLATFORM_WIN_EXPORT BitmapWindow : virtual public Window
29 {
30  public:
31 
32  /**
33  * Definition of several display modes.
34  */
36  {
37  /// An invalid display mode.
38  DM_INVALID = 0,
39  // The bitmap is stretch to cover the entire window, the aspect ratio is not preserved.
41  // The bitmap is resized (enlarged or reduced) to fit into the window, the aspect ratio is preserved.
42  DM_FIT_TO_SCREEN
43  };
44 
45  public:
46 
47  /**
48  * Creates a new bitmap window.
49  * @param instance Application instance
50  * @param name The name of the window
51  */
52  BitmapWindow(HINSTANCE instance, const std::wstring& name);
53 
54  /**
55  * Destructs the bitmap window.
56  */
57  ~BitmapWindow() override;
58 
59  /**
60  * Returns the bitmap of this windows.
61  * @return Window bitmap
62  */
63  inline const Bitmap& bitmap() const;
64 
65  /**
66  * Sets the bitmap of this window.
67  * @param bitmap The bitmap to set, an invalid bitmap to remove a previously set bitmap
68  */
69  void setBitmap(const Bitmap& bitmap);
70 
71  /**
72  * Sets the frame for this window.
73  * @param frame The frame to set, an invalid frame to remove a previously set frame
74  */
75  void setFrame(const Frame& frame);
76 
77  /**
78  * Sets the display mode of this bitmap window.
79  * @param mode The mode to be set
80  */
81  void setDisplayMode(const DisplayMode mode);
82 
83  /**
84  * Adjusts the windows size to the bitmap size.
85  */
87 
88  protected:
89 
90  /**
91  * Allows the modification of the window class before registration.
92  * @see Window::modifyWindowClass().
93  */
94  void modifyWindowClass(WNDCLASSW& windowClass) override;
95 
96  /**
97  * Function for window resize event.
98  * @see Window::onResize().
99  */
100  void onResize(const unsigned int clientWidth, const unsigned int clientHeight) override;
101 
102  /**
103  * Repaints the window.
104  * @see Window::onPaint().
105  */
106  void onPaint() override;
107 
108  /**
109  * Function for mouse double click events.
110  * @see Window::onMouseDoubleClick().
111  */
112  void onMouseDoubleClick(const MouseButton button, const int x, const int y) override;
113 
114  /**
115  * Converts window positions to bitmap positions.
116  * @param windowX Horizontal window position
117  * @param windowY Vertical window position
118  * @param bitmapX Resulting horizontal bitmap position
119  * @param bitmapY Resulting vertical bitmap position
120  * @return True, if succeeded
121  */
122  bool window2bitmap(const int windowX, const int windowY, int& bitmapX, int& bitmapY);
123 
124  protected:
125 
126  /// Window bitmap
128 
129  /// Width of the stretched bitmap.
130  unsigned int stretchWidth_ = 0u;
131 
132  /// Height of the stretched bitmap.
133  unsigned int stretchHeight_ = 0u;
134 
135  /// Horizontal position of the stretched bitmap.
136  unsigned int stretchLeft_ = 0u;
137 
138  /// Vertical position of the stretched bitmap.
139  unsigned int stretchTop_ = 0u;
140 
141  /// The display mode which is used to display the bitmap within the window.
142  DisplayMode displayMode_ = DM_FIT_TO_SCREEN;
143 
144  /// Window lock.
146 };
147 
148 inline const Bitmap& BitmapWindow::bitmap() const
149 {
150  return bitmap_;
151 }
152 
153 }
154 
155 }
156 
157 }
158 
159 #endif // META_OCEAN_PLATFORM_WIN_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
This class implements a Windows device independent bitmap.
Definition: win/Bitmap.h:30
This class implements a main window.
Definition: win/BitmapWindow.h:29
const Bitmap & bitmap() const
Returns the bitmap of this windows.
Definition: win/BitmapWindow.h:148
void modifyWindowClass(WNDCLASSW &windowClass) override
Allows the modification of the window class before registration.
void onMouseDoubleClick(const MouseButton button, const int x, const int y) override
Function for mouse double click events.
void setBitmap(const Bitmap &bitmap)
Sets the bitmap of this window.
Lock lock_
Window lock.
Definition: win/BitmapWindow.h:145
DisplayMode
Definition of several display modes.
Definition: win/BitmapWindow.h:36
@ DM_STRETCH_TO_SCREEN
Definition: win/BitmapWindow.h:40
void setFrame(const Frame &frame)
Sets the frame for this window.
bool window2bitmap(const int windowX, const int windowY, int &bitmapX, int &bitmapY)
Converts window positions to bitmap positions.
void onPaint() override
Repaints the window.
void adjustToBitmapSize()
Adjusts the windows size to the bitmap size.
void setDisplayMode(const DisplayMode mode)
Sets the display mode of this bitmap window.
BitmapWindow(HINSTANCE instance, const std::wstring &name)
Creates a new bitmap window.
void onResize(const unsigned int clientWidth, const unsigned int clientHeight) override
Function for window resize event.
~BitmapWindow() override
Destructs the bitmap window.
Bitmap bitmap_
Window bitmap.
Definition: win/BitmapWindow.h:127
This class is the base class for all windows.
Definition: Window.h:31
MouseButton
Definition of several mouse buttons.
Definition: Window.h:38
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15