Gorgon Game Engine
WindowManager.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include "Geometry/Point.h"
6 #include "Geometry/Size.h"
7 #include "Geometry/Rectangle.h"
9 #include "Utils/Assert.h"
10 #include "Event.h"
11 #include "Containers/Image.h"
12 #include "Resource/GID.h"
13 
14 namespace Gorgon {
15 
17  namespace internal {
18  struct windowdata;
19  }
21 
22  class Window;
23 
27  namespace WindowManager {
28 
30  namespace internal {
31  Gorgon::internal::windowdata *getdata(const Window&);
32 
33  void switchcontext(Gorgon::internal::windowdata &data);
34  void finalizerender(Gorgon::internal::windowdata &data);
35 
36  struct icondata;
37  struct pointerdata;
38  struct monitordata;
39  }
41 
43  class Icon {
44  friend class Gorgon::Window;
45  public:
46  explicit Icon(const Containers::Image &image);
47 
48  Icon(const Icon &) = delete;
49 
50  Icon(Icon &&icon);
51 
52  Icon &operator =(const Icon &) = delete;
53 
54  Icon &operator =(Icon &&icon);
55 
56  Icon();
57 
58  void Destroy();
59 
60  void FromImage(const Containers::Image &image);
61 
62  ~Icon();
63 
64  private:
65  internal::icondata *data;
66  };
67 
71  class Pointer {
72  public:
74 
76 
77  private:
78  internal::pointerdata *data;
79  };
80 
81  /*
82  * Represents a monitor.
83  */
84  class Monitor {
85  friend struct internal::monitordata;
86  friend void addpadding(const Monitor*, int, int, int, int);
87  public:
90  return area.GetSize();
91  }
92 
96  return area.TopLeft();
97  }
98 
101  return area;
102  }
103 
106  return usable;
107  }
108 
110  bool IsPrimary() const {
111  return isprimary;
112  }
113 
115  std::string GetName() const {
116  return name;
117  }
118 
119  ~Monitor();
120 
122  static Monitor &Primary() {
123 #ifndef NDEBUG
124  ASSERT(primary, "WindowManager module is not initialized or there are no connected monitors.");
125 #endif
126 
127  return *primary;
128  }
129 
132  return monitors;
133  }
134 
135 
137  static const Monitor *FromLocation(Geometry::Point location) {
138  for(auto &monitor : monitors) {
139  if(IsInside(monitor.GetArea(), location)) {
140  return &monitor;
141  }
142  }
143 
144  return nullptr;
145  }
146 
151  static void Refresh(bool force=false);
152 
156  static bool IsChangeEventSupported();
157 
162 
163  private:
164  Monitor();
165  internal::monitordata *data;
166 
167  Geometry::Rectangle area = {0,0,0,0};
168  Geometry::Bounds usable = {0,0,0,0};
169  bool isprimary = false;
170 
171  std::string name;
172 
173  static Containers::Collection<Monitor> monitors;
174  static Monitor *primary;
175  };
176 
178  void Initialize();
179 
181  intptr_t CurrentContext();
182 
193  std::vector<Resource::GID::Type> GetClipboardFormats();
194 
201 
208  void SetClipboardText(const std::string &text, Resource::GID::Type type = Resource::GID::Text,
209  bool unicode = true, bool append = false);
210 
215  std::vector<std::string> GetClipboardList(Resource::GID::Type type = Resource::GID::FileList);
216 
220  void SetClipboardList(std::vector<std::string> list, Resource::GID::Type type = Resource::GID::FileList, bool append = false);
221 
227 
230  void SetClipboardBitmap(Containers::Image img, bool append = false);
231  }
232 }
Gorgon::Geometry::basic_Rectangle::TopLeft
basic_Point< T_ > TopLeft() const
Returns the top left coordinates of the rectangle.
Definition: Rectangle.h:198
Gorgon::Geometry::basic_Bounds
This class represents boundaries of 2D objects.
Definition: Bounds.h:27
Gorgon::WindowManager::Initialize
void Initialize()
Initializes window manager system.
Definition: WindowManager.cpp:40
Gorgon::Window
This class represents a window.
Definition: Window.h:31
Gorgon::Geometry::IsInside
bool IsInside(const basic_Bounds< T_ > &b, const basic_Point< T_ > &p)
Checks whether the given point is inside this bounds.
Definition: Bounds.h:514
Gorgon::Containers::Image
basic_Image< Byte > Image
Definition: Image.h:1364
Gorgon::WindowManager::Monitor::FromLocation
static const Monitor * FromLocation(Geometry::Point location)
Returns the monitor from the given location. If none found, will return nullptr.
Definition: WindowManager.h:137
Gorgon::WindowManager::GetClipboardFormats
std::vector< Resource::GID::Type > GetClipboardFormats()
Returns the list of formats that is in the clipboard supported by the Gorgon Library.
Definition: Clipboard.cpp:223
Rectangle.h
contains the Rectangle class
Gorgon::WindowManager::Monitor::IsPrimary
bool IsPrimary() const
Whether this display is primary.
Definition: WindowManager.h:110
Gorgon::Event
This class provides event mechanism.
Definition: Event.h:134
Gorgon::WindowManager::Monitor::GetUsable
Geometry::Bounds GetUsable() const
Returns the area usable rectangle of the monitor. This region excludes any panels on the screen.
Definition: WindowManager.h:105
Gorgon::WindowManager::Icon::Destroy
void Destroy()
Definition: X11.cpp:274
Collection.h
contains collection, a vector of references.
Gorgon::WindowManager::Monitor::addpadding
friend void addpadding(const Monitor *, int, int, int, int)
Definition: Monitor.cpp:27
Point.h
contains point class.
Size.h
contains the Size class
Gorgon::Resource::GID::Text
constexpr Type Text
Stores text data, no longer a resource.
Definition: GID.h:134
Gorgon::WindowManager::internal::getdata
Gorgon::internal::windowdata * getdata(const Window &w)
Definition: Window.cpp:15
GID.h
contains Gorgon IDs
Gorgon::WindowManager::Monitor::Refresh
static void Refresh(bool force=false)
Asks WindowManager to refresh the list of monitors.
Definition: Monitor.cpp:86
Gorgon::WindowManager::Icon::FromImage
void FromImage(const Containers::Image &image)
Definition: X11.cpp:260
Gorgon::Geometry::basic_Rectangle::GetSize
basic_Size< T_ > GetSize() const
Returns the size of the rectangle.
Definition: Rectangle.h:218
Gorgon::WindowManager::Monitor::GetArea
Geometry::Rectangle GetArea() const
Returns the area of the entire monitor including shift for multihead displays.
Definition: WindowManager.h:100
Gorgon::WindowManager::Monitor::GetSize
Geometry::Size GetSize() const
Returns the size of this monitor in pixels.
Definition: WindowManager.h:89
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Geometry::basic_Size
This class represents a 2D geometric size.
Definition: Size.h:23
Gorgon::WindowManager::Monitor::GetName
std::string GetName() const
Returns the name of the monitor.
Definition: WindowManager.h:115
Gorgon::WindowManager::Monitor::~Monitor
~Monitor()
Definition: Monitor.cpp:23
Gorgon::WindowManager::Pointer::~Pointer
~Pointer()
Gorgon::WindowManager::Monitor::GetLocation
Geometry::Point GetLocation() const
Returns the location of this monitor relative to the other monitors in pixels.
Definition: WindowManager.h:95
Gorgon::WindowManager::Monitor::Primary
static Monitor & Primary()
Returns the default monitor.
Definition: WindowManager.h:122
Gorgon::WindowManager::SetClipboardList
void SetClipboardList(std::vector< std::string > list, Resource::GID::Type type=Resource::GID::FileList, bool append=false)
Sets a list of strings to the clipboard.
Definition: Clipboard.cpp:493
ASSERT
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
Gorgon::WindowManager::GetClipboardText
std::string GetClipboardText(Resource::GID::Type type=Resource::GID::Text)
Returns the clipboard text.
Definition: Clipboard.cpp:249
Gorgon::Containers::Collection
Collection is a container for reference typed objects.
Definition: Collection.h:21
Gorgon::WindowManager::Icon::operator=
Icon & operator=(const Icon &)=delete
Gorgon::WindowManager::Icon::Icon
Icon()
Definition: X11.cpp:239
Gorgon::Resource::GID::FileList
constexpr Type FileList
List of local files, not a resource.
Definition: GID.h:143
Gorgon::WindowManager::GetClipboardBitmap
Containers::Image GetClipboardBitmap()
Returns a bitmap from the clipboard.
Definition: Clipboard.cpp:541
Gorgon::Geometry::basic_Point
This class represents a 2D point.
Definition: Point.h:32
Gorgon::WindowManager::Monitor::Monitors
static const Containers::Collection< Monitor > & Monitors()
Returns all monitors connected to this device.
Definition: WindowManager.h:131
Image.h
Event.h
contains event distribution mechanism
Gorgon::GL::UBOBindingPoint::Type
Type
Definition: Shader.h:14
Gorgon::Containers::basic_Image
This class is a container for image data.
Definition: Image.h:19
Gorgon::WindowManager::Monitor::IsChangeEventSupported
static bool IsChangeEventSupported()
In some cases, Changed event is not supported.
Definition: Monitor.cpp:179
Gorgon::WindowManager::Icon
Represents an icon object that can be used as window icon.
Definition: WindowManager.h:43
Gorgon::WindowManager::GetClipboardList
std::vector< std::string > GetClipboardList(Resource::GID::Type type=Resource::GID::FileList)
Returns a list of strings from the clipboard.
Definition: Clipboard.cpp:383
Gorgon::WindowManager::Monitor::ChangedEvent
static Event ChangedEvent
Fires when window manager raises an event about a change in the monitor or screen layout.
Definition: WindowManager.h:161
Gorgon::WindowManager::Icon::Icon
Icon(const Icon &)=delete
Gorgon::WindowManager::Icon::~Icon
~Icon()
Definition: X11.cpp:282
Gorgon::WindowManager::SetClipboardText
void SetClipboardText(const std::string &text, Resource::GID::Type type=Resource::GID::Text, bool unicode=true, bool append=false)
Sets the clipboard text to given string.
Definition: Clipboard.cpp:350
Gorgon::Geometry::basic_Rectangle
Represents a rectangle in a 2D space.
Definition: Rectangle.h:19
Gorgon::WindowManager::CurrentContext
intptr_t CurrentContext()
Returns an identifier for the current context.
Definition: WindowManager.cpp:34
Gorgon::WindowManager::Pointer::Pointer
Pointer()
Gorgon::WindowManager::Pointer
Represents a hardware/OS pointer graphic.
Definition: WindowManager.h:71
Gorgon::internal::windowdata
Definition: X11.h:34
Gorgon::WindowManager::Monitor
Definition: WindowManager.h:84
Assert.h
Gorgon::WindowManager::SetClipboardBitmap
void SetClipboardBitmap(Containers::Image img, bool append=false)
Changes the clipboard to the given image.
Definition: Clipboard.cpp:668