display_window.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries UICore may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Harry Storbacka
28 ** Kenneth Gangstoe
29 */
30 
31 #pragma once
32 
33 #include "../../Core/Signals/signal.h"
34 #include "../display_target.h"
35 #include <memory>
36 
37 #if !defined(WIN32) && !defined(__ANDROID__) && !defined(__APPLE__)
38 // We prefer not to include Xlib.h in uicorelib (to prevent namespace issues when "using namespace uicore")
39 struct _XDisplay;
40 typedef struct _XDisplay Display;
41 typedef unsigned long Window;
42 #endif
43 
44 #if defined(__ANDROID__)
45 struct ANativeWindow;
46 #endif
47 
48 namespace uicore
49 {
50  class Sizef;
51  class Rectf;
52  class Display;
53  class GraphicContext;
54  typedef std::shared_ptr<GraphicContext> GraphicContextPtr;
55  class DisplayWindowMode;
56  class DisplayWindowDescription;
57  struct DisplayWindowHandle;
58  class InputDevice;
59  typedef std::shared_ptr<InputDevice> InputDevicePtr;
60  class Pointf;
61  class Cursor;
62  typedef std::shared_ptr<Cursor> CursorPtr;
63  class DisplayWindowProvider;
64  class DisplayWindow_Impl;
65  class PixelBuffer;
66  typedef std::shared_ptr<PixelBuffer> PixelBufferPtr;
67 
69  enum class StandardCursor
70  {
71  arrow,
73  cross,
74  hand,
75  ibeam,
76  no,
77  size_all,
78  size_nesw,
79  size_ns,
80  size_nwse,
81  size_we,
82  uparrow,
83  wait
84  };
85 
87  {
88 #ifdef WIN32
89  HWND hwnd = 0;
90 #elif defined(__ANDROID__)
91  ANativeWindow *window = 0;
92 #elif defined(__APPLE__)
93 #else
94  ::Display *display = 0;
95  ::Window window = 0;
96  int screen = -1;
97 #endif
98  };
99 
102  {
103  public:
113  static std::shared_ptr<DisplayWindow> create(const std::string &title, float width, float height, bool start_fullscreen = false, bool allow_resize = true, int flipping_buffers = 2);
114  static std::shared_ptr<DisplayWindow> create(const DisplayWindowDescription &description);
115 
117  virtual Rectf geometry() const = 0;
118 
120  virtual Rectf viewport() const = 0;
121 
123  virtual bool is_fullscreen() const = 0;
124 
126  virtual bool has_focus() const = 0;
127 
129  virtual const GraphicContextPtr &gc() const = 0;
130 
132  virtual const InputDevicePtr &keyboard() const = 0;
133 
135  virtual const InputDevicePtr &mouse() const = 0;
136 
138  virtual const std::vector<InputDevicePtr> &game_controllers() const = 0;
139 
141  const InputDevicePtr &input_device(const std::string &device_name) const;
142 
144  virtual Signal<void()> &sig_lost_focus() = 0;
145 
147  virtual Signal<void()> &sig_got_focus() = 0;
148 
150  virtual Signal<void(float, float)> &sig_resize() = 0;
151 
153  virtual Signal<void()> &sig_paint() = 0;
154 
156  virtual Signal<void()> &sig_window_close() = 0;
157 
159  virtual Signal<void()> &sig_window_destroy() = 0;
160 
162  virtual Signal<void()> &sig_window_minimized() = 0;
163 
165  virtual Signal<void()> &sig_window_maximized() = 0;
166 
168  virtual Signal<void()> &sig_window_restored() = 0;
169 
171  virtual Signal<void()> &sig_window_moved() = 0;
172 
174  virtual Signal<void()> &sig_window_flip() = 0;
175 
177  virtual std::function<void(Rectf &)> &func_window_resize() = 0;
178 
180  virtual std::function<bool()> &func_minimize_clicked() = 0;
181 
182 #ifdef WIN32
183  virtual std::function<bool(HWND, UINT, WPARAM, LPARAM)> &func_window_message() = 0;
185 
187  virtual Signal<void(HWND, UINT, WPARAM, LPARAM)> &sig_window_message() = 0;
188 #endif
189 
191  virtual bool is_visible() const = 0;
192 
194  virtual bool is_minimized() const = 0;
195 
197  virtual bool is_maximized() const = 0;
198 
200  virtual bool is_clipboard_text_available() const = 0;
201 
203  virtual bool is_clipboard_image_available() const = 0;
204 
206  virtual std::string clipboard_text() const = 0;
207 
210  virtual PixelBufferPtr clipboard_image() const = 0;
211 
213  virtual Sizef minimum_size(bool client_area = false) = 0;
214 
216  virtual Sizef maximum_size(bool client_area = false) = 0;
217 
219  virtual std::string title() const = 0;
220 
222  virtual DisplayWindowHandle handle() const = 0;
223 
225  virtual Pointf client_to_screen(const Pointf &client) = 0;
226 
228  virtual Pointf screen_to_client(const Pointf &screen) = 0;
229 
231  virtual void capture_mouse(bool capture) = 0;
232 
234  virtual void request_repaint() = 0;
235 
237  virtual void set_title(const std::string &title) = 0;
238 
243  virtual void set_position(const Rectf &pos, bool client_area) = 0;
244 
249  virtual void set_position(float x, float y) = 0;
250 
252  virtual void set_enabled(bool enable) = 0;
253 
255  void set_visible(bool visible, bool activate);
256 
262  virtual void set_size(float width, float height, bool client_area) = 0;
263 
265  virtual void set_minimum_size(float width, float height, bool client_area) = 0;
266 
268  virtual void set_maximum_size(float width, float height, bool client_area) = 0;
269 
271  virtual void minimize() = 0;
272 
274  virtual void restore() = 0;
275 
277  virtual void maximize() = 0;
278 
281  virtual void toggle_fullscreen() = 0;
282 
284  virtual void show(bool activate = true) = 0;
285 
287  virtual void hide() = 0;
288 
290  virtual void bring_to_front() = 0;
291 
305  virtual void flip(int interval = -1) = 0;
306 
308  virtual void show_cursor() = 0;
309 
311  virtual void set_cursor(const CursorPtr &cursor) = 0;
312 
316  virtual void set_cursor(StandardCursor type) = 0;
317 
318 #ifdef WIN32
319  virtual void set_cursor_handle(HCURSOR cursor) = 0;
321 #endif
322 
324  virtual void hide_cursor() = 0;
325 
327  virtual void set_clipboard_text(const std::string &text) = 0;
328 
330  virtual void set_clipboard_image(const PixelBufferPtr &buf) = 0;
331 
333  virtual void set_large_icon(const PixelBufferPtr &image) = 0;
334 
336  virtual void set_small_icon(const PixelBufferPtr &image) = 0;
337 
342  virtual void enable_alpha_channel(const Rectf &blur_rect) = 0;
343 
347  virtual void extend_frame_into_client_area(float left, float top, float right, float bottom) = 0;
348  };
349 
350  typedef std::shared_ptr<DisplayWindow> DisplayWindowPtr;
351 }
virtual DisplayWindowHandle handle() const =0
Returns an platform-specific internal display window handle object.
virtual bool is_maximized() const =0
Returns true if the window is maximized.
virtual bool is_clipboard_image_available() const =0
Returns true if an image is available in the clipboard.
virtual void set_clipboard_text(const std::string &text)=0
Stores text in the clipboard.
virtual void toggle_fullscreen()=0
virtual void set_cursor(const CursorPtr &cursor)=0
Sets the current cursor icon.
virtual void set_title(const std::string &title)=0
Change window title.
int screen
Definition: display_window.h:96
virtual Signal< void()> & sig_window_restored()=0
Signal emitted when window is restored.
virtual void extend_frame_into_client_area(float left, float top, float right, float bottom)=0
Exend the window frame into the client area.
virtual bool is_visible() const =0
returns true if this display window is visible
virtual void set_position(const Rectf &pos, bool client_area)=0
Set window position and size.
Top-level window class.
Definition: display_window.h:101
virtual std::string title() const =0
Returns the window title.
virtual const InputDevicePtr & keyboard() const =0
Returns the keyboard input device.
virtual void set_maximum_size(float width, float height, bool client_area)=0
Maximum size a window can be resized to by the application user.
virtual bool is_fullscreen() const =0
Returns true if window is currently running fullscreen.
2D (x,y) point structure - Float
Definition: point.h:68
virtual void set_size(float width, float height, bool client_area)=0
Resize window.
virtual Signal< void()> & sig_window_moved()=0
Signal emitted after a window has been moved.
virtual bool has_focus() const =0
Returns true if window has focus.
virtual std::string clipboard_text() const =0
Returns the text stored in the clipboard.
virtual Rectf viewport() const =0
Returns the drawable area of the window (excluding window frame).
virtual Signal< void()> & sig_window_destroy()=0
Signal emitted when window is destroyed.
std::shared_ptr< Cursor > CursorPtr
Definition: cursor.h:52
Pixel data container.
Definition: pixel_buffer.h:52
const InputDevicePtr & input_device(const std::string &device_name) const
Returns the input device with the given device name.
virtual void request_repaint()=0
Invalidates the screen, causing a repaint.
std::shared_ptr< DisplayWindow > DisplayWindowPtr
Definition: canvas.h:41
virtual const InputDevicePtr & mouse() const =0
Returns the mouse input device.
Definition: display_window.h:86
virtual Pointf screen_to_client(const Pointf &screen)=0
Convert from screen coordinates to client coordinates.
virtual Rectf geometry() const =0
Returns the position and size of the window frame.
virtual Pointf client_to_screen(const Pointf &client)=0
Convert from window client coordinates to screen coordinates.
virtual void set_large_icon(const PixelBufferPtr &image)=0
Sets the large icon used for this window.
InputDevice.
Definition: input_device.h:41
virtual Signal< void()> & sig_paint()=0
Signal emitted when the window is invalidated.
virtual PixelBufferPtr clipboard_image() const =0
Returns an image stored in the clipboard. Returns a null pixelbuffer if no image is available...
virtual void capture_mouse(bool capture)=0
Capture/Release the mouse.
virtual void restore()=0
Restores the window.
virtual void set_minimum_size(float width, float height, bool client_area)=0
Minimum size a window can be resized to by the application user.
virtual Sizef maximum_size(bool client_area=false)=0
Returns the maximum size the window can be resized to by the application user.
virtual void set_clipboard_image(const PixelBufferPtr &buf)=0
Stores an image in the clipboard.
StandardCursor
Standard Cursor.
Definition: display_window.h:69
virtual void hide_cursor()=0
Hides the mouse cursor.
virtual void bring_to_front()=0
Raises the window on top of other windows.
void set_visible(bool visible, bool activate)
Set visible.
virtual void set_enabled(bool enable)=0
Set enabled.
virtual void enable_alpha_channel(const Rectf &blur_rect)=0
Enable alpha channel for this window.
2D (width,height) size structure - Float
Definition: size.h:180
virtual Signal< void()> & sig_lost_focus()=0
Signal emitted when window lost focus.
virtual Signal< void()> & sig_window_close()=0
Signal emitted when window is closed.
virtual bool is_clipboard_text_available() const =0
Returns true if text is available in the clipboard.
virtual bool is_minimized() const =0
Returns true if the window is minimized.
::Window window
Definition: display_window.h:95
virtual std::function< bool()> & func_minimize_clicked()=0
Callback called when a window is asked to minimize itself.
2D (left,top,right,bottom) rectangle structure - Float
Definition: rect.h:505
virtual Signal< void()> & sig_window_flip()=0
Signal emitted when window flip() was called.
virtual void minimize()=0
Minimizes the window.
Definition: signal.h:101
virtual Signal< void(float, float)> & sig_resize()=0
Signal emitted when window is resized.
virtual Signal< void()> & sig_window_minimized()=0
Signal emitted when window is minimized.
static std::shared_ptr< DisplayWindow > create(const std::string &title, float width, float height, bool start_fullscreen=false, bool allow_resize=true, int flipping_buffers=2)
Constructs a window.
virtual std::function< void(Rectf &)> & func_window_resize()=0
Callback called when a window is being resized.
::Display * display
Definition: display_window.h:94
virtual void show_cursor()=0
Shows the mouse cursor.
Display window description class.
Definition: display_window_description.h:47
std::shared_ptr< PixelBuffer > PixelBufferPtr
Definition: d3d_target.h:39
std::shared_ptr< GraphicContext > GraphicContextPtr
Definition: d3d_target.h:49
virtual void flip(int interval=-1)=0
Flip back buffer to front, making changes visible on screen.
virtual void show(bool activate=true)=0
Displays the window in its current size and position.
std::shared_ptr< InputDevice > InputDevicePtr
Definition: display_window.h:58
Mouse cursor class.
Definition: cursor.h:40
virtual void hide()=0
Hides the window.
Definition: Application/application.h:35
virtual const GraphicContextPtr & gc() const =0
Return the graphic context for the window.
virtual void maximize()=0
Maximizes the window.
virtual Signal< void()> & sig_window_maximized()=0
Signal emitted when window is maximized.
virtual const std::vector< InputDevicePtr > & game_controllers() const =0
Returns the game controller input device.
virtual void set_small_icon(const PixelBufferPtr &image)=0
Sets the small icon used for this window.
virtual Sizef minimum_size(bool client_area=false)=0
Returns the minimum size the window can be resized to by the application user.
virtual Signal< void()> & sig_got_focus()=0
Signal emitted when window gain focus.