display_window.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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
32 #pragma once
33
34 #include "../../Core/Signals/signal.h"
35 #include "../display_target.h"
36 #include <memory>
37
38 #if !defined(WIN32) && !defined(__ANDROID__) && !defined(__APPLE__)
39 // We prefer not to include Xlib.h in clanlib (to prevent namespace issues when "using namespace clan")
40 struct _XDisplay;
41 typedef struct _XDisplay Display;
42 typedef unsigned long Window;
43 #endif
44
45 #if defined(__ANDROID__)
46 struct ANativeWindow;
47 #endif
48
49
50 namespace clan
51 {
54
55 class Sizef;
56 class Rectf;
57 class Display;
58 class GraphicContext;
59 class DisplayWindowMode;
60 class DisplayWindowDescription;
61 struct DisplayWindowHandle;
62 class InputContext;
63 class Pointf;
64 class Cursor;
65 class DisplayWindowProvider;
66 class DisplayWindow_Impl;
67 class PixelBuffer;
68
70 enum class StandardCursor
71 {
72 arrow,
73 appstarting,
74 cross,
75 hand,
76 ibeam,
77 no,
78 size_all,
79 size_nesw,
80 size_ns,
81 size_nwse,
82 size_we,
83 uparrow,
84 wait
85 };
86
87 struct DisplayWindowHandle
88 {
89 #ifdef WIN32
90 HWND hwnd = 0;
91 #elif defined(__ANDROID__)
92 ANativeWindow *window = 0;
93 #elif defined(__APPLE__)
94 #else
95 ::Display *display = 0;
96 ::Window window = 0;
97 #endif
98 };
99
101 class DisplayWindow
102 {
105 public:
107 DisplayWindow();
108
118 DisplayWindow(
119 const std::string &title,
120 float width,
121 float height,
122 bool start_fullscreen = false,
123 bool allow_resize = false,
124 int flipping_buffers = 2);
125
130 DisplayWindow(
131 const DisplayWindowDescription &description);
132
136 DisplayWindow(DisplayWindowProvider *provider);
137
138 ~DisplayWindow();
139
143 public:
145 Rectf get_geometry() const;
146
148 Rectf get_viewport() const;
149
151 bool is_fullscreen() const;
152
154 bool has_focus() const;
155
157 GraphicContext& get_gc() const;
158
160 InputContext get_ic() const;
161
163 Signal<void()> &sig_lost_focus();
164
166 Signal<void()> &sig_got_focus();
167
169 Signal<void(float, float)> &sig_resize();
170
172 Signal<void(const Rectf &)> &sig_paint();
173
175 Signal<void()> &sig_window_close();
176
178 Signal<void()> &sig_window_destroy();
179
181 Signal<void()> &sig_window_minimized();
182
184 Signal<void()> &sig_window_maximized();
185
187 Signal<void()> &sig_window_restored();
188
190 Signal<void()> &sig_window_moved();
191
193 Signal<void()> &sig_window_flip();
194
196 std::function<void(Rectf &)> &func_window_resize();
197
199 std::function<bool()> &func_minimize_clicked();
200
201 #ifdef WIN32
202 std::function<bool(HWND, UINT, WPARAM, LPARAM)> &func_window_message();
204 #endif
205
207 bool is_null() const { return !impl; }
208
210 void throw_if_null() const;
211
213 bool is_visible() const;
214
216 bool is_minimized() const;
217
219 bool is_maximized() const;
220
222 DisplayWindowProvider *get_provider() const;
223
225 bool is_clipboard_text_available() const;
226
228 bool is_clipboard_image_available() const;
229
231 std::string get_clipboard_text() const;
232
235 PixelBuffer get_clipboard_image() const;
236
238 Sizef get_minimum_size(bool client_area=false);
239
241 Sizef get_maximum_size(bool client_area=false);
242
244 std::string get_title() const;
245
248 DisplayWindowHandle get_handle() const;
249
253 public:
255 Pointf client_to_screen(const Pointf &client);
256
258 Pointf screen_to_client(const Pointf &screen);
259
261 void capture_mouse(bool capture);
262
264 void request_repaint(const Rectf &rect);
265
267 void set_title(const std::string &title);
268
273 void set_position(const Rectf &pos, bool client_area);
274
279 void set_position(float x, float y);
280
284 void set_enabled(bool enable);
285
290 void set_visible(bool visible, bool activate);
291
297 void set_size(float width, float height, bool client_area);
298
300 void set_minimum_size(float width, float height, bool client_area);
301
303 void set_maximum_size(float width, float height, bool client_area);
304
306 void minimize();
307
309 void restore();
310
312 void maximize();
313
315 void show(bool activate = true);
316
318 void hide();
319
321 void bring_to_front();
322
326 void update(const Rectf &rect);
327
339 void flip(int interval = -1);
340
342 void show_cursor();
343
345 void set_cursor(const Cursor &cursor);
346
350 void set_cursor(StandardCursor type);
351
352 #ifdef WIN32
353 void set_cursor_handle(HCURSOR cursor);
355 #endif
356
358 void hide_cursor();
359
361 void set_clipboard_text(const std::string &text);
362
364 void set_clipboard_image(const PixelBuffer &buf);
365
367 void set_large_icon(const PixelBuffer &image);
368
370 void set_small_icon(const PixelBuffer &image);
371
376 void enable_alpha_channel(const Rectf &blur_rect);
377
381 void extend_frame_into_client_area(float left, float top, float right, float bottom);
382
386 private:
387 std::shared_ptr<DisplayWindow_Impl> impl;
388
390 };
391
392 }
393
clan::DisplayWindow::sig_window_maximized
Signal< void()> & sig_window_maximized()
Signal emitted when window is maximized.
clan::DisplayWindow::DisplayWindow
DisplayWindow()
Constructs a null instance.
clan::DisplayWindow::set_maximum_size
void set_maximum_size(float width, float height, bool client_area)
Maximum size a window can be resized to by the application user.
clan::DisplayWindow::is_fullscreen
bool is_fullscreen() const
Returns true if window is currently running fullscreen.
clan
Definition: clanapp.h:35
clan::StandardCursor
StandardCursor
Standard Cursor.
Definition: display_window.h:70
clan::DisplayWindow::sig_window_restored
Signal< void()> & sig_window_restored()
Signal emitted when window is restored.
clan::DisplayWindow::bring_to_front
void bring_to_front()
Raises the window on top of other windows.
clan::StandardCursor::ibeam
clan::DisplayWindow::sig_got_focus
Signal< void()> & sig_got_focus()
Signal emitted when window gain focus.
clan::DisplayWindow::sig_window_moved
Signal< void()> & sig_window_moved()
Signal emitted after a window has been moved.
clan::StandardCursor::size_all
clan::DisplayWindow::client_to_screen
Pointf client_to_screen(const Pointf &client)
Convert from window client coordinates to screen coordinates.
clan::DisplayWindow::sig_resize
Signal< void(float, float)> & sig_resize()
Signal emitted when window is resized.
clan::PixelBuffer
Pixel data container.
Definition: pixel_buffer.h:68
clan::DisplayWindow::capture_mouse
void capture_mouse(bool capture)
Capture/Release the mouse.
clan::DisplayWindowHandle
Definition: display_window.h:87
clan::Key::x
clan::DisplayWindow::get_geometry
Rectf get_geometry() const
Returns the position and size of the window frame.
clan::Cursor
Mouse cursor class.
Definition: cursor.h:47
clan::DisplayWindow::is_maximized
bool is_maximized() const
Returns true if the window is maximized.
clan::BrushType::image
clan::DisplayWindow::maximize
void maximize()
Maximizes the window.
clan::DisplayWindow::get_viewport
Rectf get_viewport() const
Returns the drawable area of the window (excluding window frame).
clan::DisplayWindow::screen_to_client
Pointf screen_to_client(const Pointf &screen)
Convert from screen coordinates to client coordinates.
clan::StandardCursor::cross
clan::DisplayWindow::get_ic
InputContext get_ic() const
Return the input context for the window.
clan::DisplayWindow::show_cursor
void show_cursor()
Shows the mouse cursor.
clan::DisplayWindow::set_enabled
void set_enabled(bool enable)
Set enabled.
clan::Display
Top level display class.
Definition: Sources/API/Display/display.h:49
clan::DisplayWindow::set_clipboard_image
void set_clipboard_image(const PixelBuffer &buf)
Stores an image in the clipboard.
clan::DisplayWindow::set_position
void set_position(const Rectf &pos, bool client_area)
Set window position and size.
clan::DisplayWindow::sig_window_destroy
Signal< void()> & sig_window_destroy()
Signal emitted when window is destroyed.
clan::DisplayWindow::enable_alpha_channel
void enable_alpha_channel(const Rectf &blur_rect)
Enable alpha channel for this window.
clan::StandardCursor::uparrow
clan::StyleTokenType::string
@ keyword
clan::DisplayWindow::func_window_resize
std::function< void(Rectf &)> & func_window_resize()
Callback called when a window is being resized.
clan::StandardCursor::hand
clan::DisplayWindow::flip
void flip(int interval=-1)
Flip back buffer to front, making changes visible on screen.
clan::DisplayWindow::get_provider
DisplayWindowProvider * get_provider() const
Returns the display window provider.
clan::DisplayWindow::set_title
void set_title(const std::string &title)
Change window title.
clan::Rectf
2D (left,top,right,bottom) rectangle structure - Float
Definition: rect.h:484
clan::Key::y
clan::DisplayWindow::sig_window_minimized
Signal< void()> & sig_window_minimized()
Signal emitted when window is minimized.
clan::StandardCursor::arrow
clan::DisplayWindow::set_cursor
void set_cursor(const Cursor &cursor)
Sets the current cursor icon.
clan::DisplayWindow::get_title
std::string get_title() const
Returns the window title.
clan::DisplayWindowHandle::display
::Display * display
Definition: display_window.h:95
clan::DisplayWindow::is_null
bool is_null() const
Returns true if this object is invalid.
Definition: display_window.h:207
clan::StandardCursor::wait
clan::DisplayWindow::set_large_icon
void set_large_icon(const PixelBuffer &image)
Sets the large icon used for this window.
clan::DisplayWindow::sig_paint
Signal< void(const Rectf &)> & sig_paint()
Signal emitted when an area of the window is invalidated.
clan::Signal< void()>
clan::DisplayWindow::hide
void hide()
Hides the window.
clan::DisplayWindow::get_clipboard_image
PixelBuffer get_clipboard_image() const
Returns an image stored in the clipboard.
clan::StandardCursor::size_nesw
clan::DisplayWindow::~DisplayWindow
~DisplayWindow()
clan::DisplayWindow::sig_window_flip
Signal< void()> & sig_window_flip()
Signal emitted when window flip() was called.
clan::DisplayWindow::restore
void restore()
Restores the window.
clan::StandardCursor::size_nwse
clan::DisplayWindow::minimize
void minimize()
Minimizes the window.
clan::DisplayWindow::set_size
void set_size(float width, float height, bool client_area)
Resize window.
clan::DisplayWindow::extend_frame_into_client_area
void extend_frame_into_client_area(float left, float top, float right, float bottom)
Exend the window frame into the client area.
clan::GraphicContext
Interface to drawing graphics.
Definition: graphic_context.h:257
clan::InputContext
InputContext.
Definition: input_context.h:44
clan::DisplayWindow::is_clipboard_image_available
bool is_clipboard_image_available() const
Returns true if an image is available in the clipboard.
clan::StandardCursor::size_we
clan::Key::left
clan::DisplayWindow::set_clipboard_text
void set_clipboard_text(const std::string &text)
Stores text in the clipboard.
clan::StandardCursor::appstarting
clan::DisplayWindowDescription
Display window description class.
Definition: display_window_description.h:62
clan::DisplayWindow::is_clipboard_text_available
bool is_clipboard_text_available() const
Returns true if text is available in the clipboard.
clan::Key::right
clan::DisplayWindow::sig_lost_focus
Signal< void()> & sig_lost_focus()
Signal emitted when window lost focus.
clan::DisplayWindow::get_gc
GraphicContext & get_gc() const
Return the graphic context for the window.
clan::DisplayWindowProvider
Interface for implementing a DisplayWindow target.
Definition: display_window_provider.h:102
clan::DisplayWindow::set_minimum_size
void set_minimum_size(float width, float height, bool client_area)
Minimum size a window can be resized to by the application user.
clan::DisplayWindow::set_small_icon
void set_small_icon(const PixelBuffer &image)
Sets the small icon used for this window.
clan::DisplayWindow::get_maximum_size
Sizef get_maximum_size(bool client_area=false)
Returns the maximum size the window can be resized to by the application user.
clan::DisplayWindow::sig_window_close
Signal< void()> & sig_window_close()
Signal emitted when window is closed.
clan::DisplayWindowHandle::window
::Window window
Definition: display_window.h:96
clan::DisplayWindow::get_handle
DisplayWindowHandle get_handle() const
clan::DisplayWindow::has_focus
bool has_focus() const
Returns true if window has focus.
clan::DisplayWindow::hide_cursor
void hide_cursor()
Hides the mouse cursor.
clan::Pointf
2D (x,y) point structure - Float
Definition: point.h:72
clan::DisplayWindow::func_minimize_clicked
std::function< bool()> & func_minimize_clicked()
Callback called when a window is asked to minimize itself.
clan::StandardCursor::size_ns
clan::DisplayWindow::is_minimized
bool is_minimized() const
Returns true if the window is minimized.
clan::DisplayWindow::set_visible
void set_visible(bool visible, bool activate)
Set visible.
clan::DisplayWindow::show
void show(bool activate=true)
Displays the window in its current size and position.
clan::DisplayWindow::update
void update(const Rectf &rect)
Copy the specified rectangle area from back buffer to front buffer.
clan::DisplayWindow::is_visible
bool is_visible() const
returns true if this display window is visible
clan::DisplayWindow
Top-level window class.
Definition: display_window.h:101
clan::DisplayWindow::throw_if_null
void throw_if_null() const
Throw an exception if this object is invalid.
clan::DisplayWindow::get_clipboard_text
std::string get_clipboard_text() const
Returns the text stored in the clipboard.
clan::StandardCursor::no
clan::DisplayWindow::get_minimum_size
Sizef get_minimum_size(bool client_area=false)
Returns the minimum size the window can be resized to by the application user.
clan::Sizef
2D (width,height) size structure - Float
Definition: size.h:169
clan::DisplayWindow::request_repaint
void request_repaint(const Rectf &rect)
Invalidates a region of a screen, causing a repaint.