window_manager.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 */
28 
29 #pragma once
30 
31 #include <memory>
32 #include "../../Core/Math/point.h"
33 #include "window_controller.h"
34 
35 namespace clan
36 {
37  class View;
38  class WindowManagerImpl;
39 
42  {
43  public:
44  WindowManager();
46 
48  void set_exit_on_last_close(bool enable = true);
49 
51  void present_main(const std::shared_ptr<WindowController> &controller);
52 
53  template<typename T, typename... Types>
54  std::shared_ptr<T> present_main(Types &&... args)
55  {
56  auto controller = std::make_shared<T>(std::forward<Types>(args)...);
57  present_main(controller);
58  return controller;
59  }
60 
62  void present_modal(View *owner, const std::shared_ptr<WindowController> &controller);
63 
64  template<typename T, typename... Types>
65  std::shared_ptr<T> present_modal(View *owner, Types &&... args)
66  {
67  auto controller = std::make_shared<T>(std::forward<Types>(args)...);
68  present_modal(owner, controller);
69  return controller;
70  }
71 
73  void present_popup(View *owner, const Pointf &pos, const std::shared_ptr<WindowController> &controller);
74 
75  template<typename T, typename... Types>
76  std::shared_ptr<T> present_popup(View *owner, const Pointf &pos, Types &&... args)
77  {
78  auto controller = std::make_shared<T>(std::forward<Types>(args)...);
79  present_popup(owner, controller);
80  return controller;
81  }
82 
83  private:
84  WindowManager(const WindowManager &) = delete;
85  WindowManager &operator=(const WindowManager &) = delete;
86 
87  std::unique_ptr<WindowManagerImpl> impl;
88  friend class WindowController;
89  };
90 }
Base class for controllers managing windows.
Definition: window_controller.h:40
Definition: clanapp.h:35
View for an area of the user interface.
Definition: view.h:65
std::shared_ptr< T > present_modal(View *owner, Types &&...args)
Definition: window_manager.h:65
void present_main(const std::shared_ptr< WindowController > &controller)
Shows a main window.
Manages one or more windows.
Definition: window_manager.h:41
void present_popup(View *owner, const Pointf &pos, const std::shared_ptr< WindowController > &controller)
Shows a popup window.
std::shared_ptr< T > present_popup(View *owner, const Pointf &pos, Types &&...args)
Definition: window_manager.h:76
void present_modal(View *owner, const std::shared_ptr< WindowController > &controller)
Shows a modal dialog.
void set_exit_on_last_close(bool enable=true)
Notifices RunLoop to exit when last presented window is dismissed.
std::shared_ptr< T > present_main(Types &&...args)
Definition: window_manager.h:54
2D (x,y) point structure - Float
Definition: point.h:71