display_window.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 The ClanLib 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 ClanLib 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 clanlib (to prevent namespace issues when "using namespace clan")
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 clan
49 {
52 
53  class Sizef;
54  class Rectf;
55  class Display;
56  class GraphicContext;
57  class DisplayWindowMode;
58  class DisplayWindowDescription;
59  struct DisplayWindowHandle;
60  class InputDevice;
61  class Pointf;
62  class Cursor;
63  class DisplayWindowProvider;
64  class DisplayWindow_Impl;
65  class PixelBuffer;
66 
68  enum class StandardCursor
69  {
70  arrow,
72  cross,
73  hand,
74  ibeam,
75  no,
76  size_all,
77  size_nesw,
78  size_ns,
79  size_nwse,
80  size_we,
81  uparrow,
82  wait
83  };
84 
86  {
87 #ifdef WIN32
88  HWND hwnd = 0;
89 #elif defined(__ANDROID__)
90  ANativeWindow *window = 0;
91 #elif defined(__APPLE__)
92 #else
93  ::Display *display = 0;
94  ::Window window = 0;
95  int screen = -1;
96 #endif
97  };
98 
101  {
102  public:
104  DisplayWindow();
105 
116  const std::string &title,
117  float width,
118  float height,
119  bool start_fullscreen = false,
120  bool allow_resize = false,
121  int flipping_buffers = 2);
122 
128  const DisplayWindowDescription &description);
129 
134 
135  ~DisplayWindow();
136 
138  Rectf get_geometry() const;
139 
141  Rectf get_viewport() const;
142 
144  bool is_fullscreen() const;
145 
147  bool has_focus() const;
148 
150  GraphicContext& get_gc() const;
151 
154 
157 
159  std::vector<InputDevice> &get_game_controllers();
160 
162  InputDevice &get_input_device(const std::string &device_name);
163 
166 
169 
172 
175 
178 
181 
184 
187 
190 
193 
196 
198  std::function<void(Rectf &)> &func_window_resize();
199 
201  std::function<bool()> &func_minimize_clicked();
202 
203 #ifdef WIN32
204  std::function<bool(HWND, UINT, WPARAM, LPARAM)> &func_window_message();
206 
208  Signal<void(HWND, UINT, WPARAM, LPARAM)> &sig_window_message();
209 #endif
210 
212  bool is_null() const { return !impl; }
213  explicit operator bool() const { return bool(impl); }
214 
216  void throw_if_null() const;
217 
219  bool is_visible() const;
220 
222  bool is_minimized() const;
223 
225  bool is_maximized() const;
226 
229 
231  bool is_clipboard_text_available() const;
232 
234  bool is_clipboard_image_available() const;
235 
238 
242 
244  Sizef get_minimum_size(bool client_area = false);
245 
247  Sizef get_maximum_size(bool client_area = false);
248 
250  std::string get_title() const;
251 
255 
257  Pointf client_to_screen(const Pointf &client);
258 
260  Pointf screen_to_client(const Pointf &screen);
261 
263  void capture_mouse(bool capture);
264 
266  void request_repaint();
267 
269  void set_title(const std::string &title);
270 
275  void set_position(const Rectf &pos, bool client_area);
276 
281  void set_position(float x, float y);
282 
286  void set_enabled(bool enable);
287 
292  void set_visible(bool visible, bool activate);
293 
299  void set_size(float width, float height, bool client_area);
300 
302  void set_minimum_size(float width, float height, bool client_area);
303 
305  void set_maximum_size(float width, float height, bool client_area);
306 
308  void minimize();
309 
311  void restore();
312 
314  void maximize();
315 
318  void toggle_fullscreen();
319 
321  void show(bool activate = true);
322 
324  void hide();
325 
327  void bring_to_front();
328 
340  void flip(int interval = -1);
341 
343  void show_cursor();
344 
346  void set_cursor(const Cursor &cursor);
347 
351  void set_cursor(StandardCursor type);
352 
353 #ifdef WIN32
354  void set_cursor_handle(HCURSOR cursor);
356 #endif
357 
359  void hide_cursor();
360 
362  void set_clipboard_text(const std::string &text);
363 
365  void set_clipboard_image(const PixelBuffer &buf);
366 
368  void set_large_icon(const PixelBuffer &image);
369 
371  void set_small_icon(const PixelBuffer &image);
372 
377  void enable_alpha_channel(const Rectf &blur_rect);
378 
382  void extend_frame_into_client_area(float left, float top, float right, float bottom);
383 
384  private:
385  std::shared_ptr<DisplayWindow_Impl> impl;
386  };
387 
389 }
std::string get_title() const
Returns the window title.
Definition: clanapp.h:35
void extend_frame_into_client_area(float left, float top, float right, float bottom)
Exend the window frame into the client area.
StandardCursor
Standard Cursor.
Definition: display_window.h:68
Rectf get_viewport() const
Returns the drawable area of the window (excluding window frame).
bool is_fullscreen() const
Returns true if window is currently running fullscreen.
std::function< void(Rectf &)> & func_window_resize()
Callback called when a window is being resized.
void set_clipboard_image(const PixelBuffer &buf)
Stores an image in the clipboard.
void bring_to_front()
Raises the window on top of other windows.
void set_visible(bool visible, bool activate)
Set visible.
std::function< bool()> & func_minimize_clicked()
Callback called when a window is asked to minimize itself.
bool is_clipboard_image_available() const
Returns true if an image is available in the clipboard.
void minimize()
Minimizes the window.
std::string get_clipboard_text() const
Returns the text stored in the clipboard.
Sizef get_minimum_size(bool client_area=false)
Returns the minimum size the window can be resized to by the application user.
void set_size(float width, float height, bool client_area)
Resize window.
::Window window
Definition: display_window.h:94
Pixel data container.
Definition: pixel_buffer.h:67
Definition: display_window.h:85
Signal< void()> & sig_got_focus()
Signal emitted when window gain focus.
void maximize()
Maximizes the window.
Signal< void()> & sig_lost_focus()
Signal emitted when window lost focus.
Mouse cursor class.
Definition: cursor.h:46
DisplayWindowHandle get_handle() const
void set_position(const Rectf &pos, bool client_area)
Set window position and size.
Rectf get_geometry() const
Returns the position and size of the window frame.
DisplayWindow()
Constructs a null instance.
bool has_focus() const
Returns true if window has focus.
void capture_mouse(bool capture)
Capture/Release the mouse.
void throw_if_null() const
Throw an exception if this object is invalid.
void set_clipboard_text(const std::string &text)
Stores text in the clipboard.
bool is_clipboard_text_available() const
Returns true if text is available in the clipboard.
Signal< void()> & sig_paint()
Signal emitted when the window is invalidated.
Signal< void()> & sig_window_moved()
Signal emitted after a window has been moved.
InputDevice.
Definition: input_device.h:46
bool is_maximized() const
Returns true if the window is maximized.
GraphicContext & get_gc() const
Return the graphic context for the window.
Sizef get_maximum_size(bool client_area=false)
Returns the maximum size the window can be resized to by the application user.
void set_maximum_size(float width, float height, bool client_area)
Maximum size a window can be resized to by the application user.
void flip(int interval=-1)
Flip back buffer to front, making changes visible on screen.
2D (left,top,right,bottom) rectangle structure - Float
Definition: rect.h:502
void show(bool activate=true)
Displays the window in its current size and position.
Pointf client_to_screen(const Pointf &client)
Convert from window client coordinates to screen coordinates.
Signal< void()> & sig_window_close()
Signal emitted when window is closed.
bool is_null() const
Returns true if this object is invalid.
Definition: display_window.h:212
Signal< void()> & sig_window_destroy()
Signal emitted when window is destroyed.
Signal< void()> & sig_window_flip()
Signal emitted when window flip() was called.
Signal< void()> & sig_window_minimized()
Signal emitted when window is minimized.
int screen
Definition: display_window.h:95
void enable_alpha_channel(const Rectf &blur_rect)
Enable alpha channel for this window.
bool is_visible() const
returns true if this display window is visible
void set_title(const std::string &title)
Change window title.
void show_cursor()
Shows the mouse cursor.
bool is_minimized() const
Returns true if the window is minimized.
Interface to drawing graphics.
Definition: graphic_context.h:256
Signal< void(float, float)> & sig_resize()
Signal emitted when window is resized.
void request_repaint()
Invalidates the screen, causing a repaint.
Display window description class.
Definition: display_window_description.h:49
void set_small_icon(const PixelBuffer &image)
Sets the small icon used for this window.
::Display * display
Definition: display_window.h:93
Interface for implementing a DisplayWindow target.
Definition: display_window_provider.h:98
DisplayWindowProvider * get_provider() const
Returns the display window provider.
std::vector< InputDevice > & get_game_controllers()
Returns the game controller input device.
InputDevice & get_keyboard()
Returns the keyboard input device.
void set_cursor(const Cursor &cursor)
Sets the current cursor icon.
void hide()
Hides the window.
InputDevice & get_mouse()
Returns the mouse input device.
void set_large_icon(const PixelBuffer &image)
Sets the large icon used for this window.
2D (x,y) point structure - Float
Definition: point.h:71
void set_enabled(bool enable)
Set enabled.
Top-level window class.
Definition: display_window.h:100
InputDevice & get_input_device(const std::string &device_name)
Returns the input device with the given device name.
void restore()
Restores the window.
void hide_cursor()
Hides the mouse cursor.
Signal< void()> & sig_window_maximized()
Signal emitted when window is maximized.
void set_minimum_size(float width, float height, bool client_area)
Minimum size a window can be resized to by the application user.
Signal< void()> & sig_window_restored()
Signal emitted when window is restored.
Pointf screen_to_client(const Pointf &screen)
Convert from screen coordinates to client coordinates.
2D (width,height) size structure - Float
Definition: size.h:183
PixelBuffer get_clipboard_image() const
Returns an image stored in the clipboard.