gramods
Loading...
Searching...
No Matches
Window.hh
1
2#ifndef GRAMODS_GRAPHICS_WINDOW
3#define GRAMODS_GRAPHICS_WINDOW
4
5// Required before gmCore/OFactory.hh for some compilers
6#include <gmCore/io_float.hh>
7#include <gmCore/io_int.hh>
8#include <gmCore/io_size.hh>
9
10#include <gmGraphics/ViewBase.hh>
11
12#include <limits>
13
14BEGIN_NAMESPACE_GMGRAPHICS;
15
16class View;
17
21class Window : public ViewBase {
22
23public:
24
25 struct event {
26 virtual ~event() {}
27 };
28
29 struct key_event : event {
30 bool up;
31 int key;
32 key_event(bool up, int key) : up(up), key(key) {}
33 virtual ~key_event() {}
34 };
35
36 Window();
37 virtual ~Window() {}
38
43 void renderFullPipeline(ViewSettings settings) override;
44
50 void traverse(Visitor *visitor) override;
51
59 void addView(std::shared_ptr<View> view) {
60 if (!view) throw gmCore::InvalidArgument("null not allowed");
61 views.push_back(view);
62 }
63
68 virtual void makeGLContextCurrent() = 0;
69
74 virtual void close() = 0;
75
82 virtual void setFullscreen(bool on) { fullscreen = on; }
83
89 virtual void setDisplay(size_t N) { display = N; }
90
98 virtual void setSize(gmCore::size2 s) { size = s; }
99
105 virtual void setPosition(gmCore::int2 p) { position = p; }
106
112 virtual gmCore::size2 getSize() { return size; }
113
120 virtual void setTitle(std::string t) { title = t; }
121
128 background_color = c;
129 }
130
135 virtual void processEvents() = 0;
136
141 virtual bool handleEvent(event *);
142
148 void addEventHandler(std::function<bool(const event*)> fun, void *tag);
149
153 void removeEventHandler(void *tag);
154
160 virtual bool isOpen() { return false; }
161
169 virtual void swap() = 0;
170
176 virtual void sync();
177
178 GM_OFI_DECLARE;
179
180protected:
181
182 std::vector<std::shared_ptr<View>> views;
183
184 bool fullscreen = false;
185 size_t display = 0;
186 std::string title = "untitled gramods window";
187 gmCore::size2 size = {640, 480};
188 gmCore::int2 position = { (std::numeric_limits<int>::max)(),
189 (std::numeric_limits<int>::max)() };
190 gmCore::float4 background_color = {0.f, 0.f, 0.f, 0.f};
191
192 std::unordered_map<void*, std::function<bool(const event*)>> event_handlers;
193};
194
195END_NAMESPACE_GMGRAPHICS;
196
197#endif
The common base for nodes taking renderers for dispatching rendering jobs.
Definition ViewBase.hh:23
The base of graphics Window implementations.
Definition Window.hh:21
virtual void swap()=0
Posts a swap buffers command to the underlying windowing system, to show the newly rendered material.
virtual void setTitle(std::string t)
Sets the title of the windows.
Definition Window.hh:120
virtual void setSize(gmCore::size2 s)
Sets the size of the drawable canvas of this window, in pixels.
Definition Window.hh:98
virtual void close()=0
Asks the Window to close itself.
virtual void setDisplay(size_t N)
Set on which display the window should be shown.
Definition Window.hh:89
virtual void processEvents()=0
Triggers the windows to process its incoming events.
virtual void setBackgroundColor(gmCore::float4 c)
Set the background color of the window.
Definition Window.hh:127
virtual gmCore::size2 getSize()
Returns the size of the drawable canvas of this window, in pixels.
Definition Window.hh:112
virtual bool isOpen()
Returns true as long as the window is open.
Definition Window.hh:160
virtual void setFullscreen(bool on)
Activates or deactivates fullscreen mode.
Definition Window.hh:82
void addView(std::shared_ptr< View > view)
Adds a view to the window.
Definition Window.hh:59
virtual void setPosition(gmCore::int2 p)
Sets the position of the window.
Definition Window.hh:105
virtual void makeGLContextCurrent()=0
Asks the Window to make its GL context current.
std::array< int, 2 > int2
Array of 2 int.
Definition io_int.hh:12
std::array< float, 4 > float4
Array of 4 float.
Definition io_float.hh:18
std::array< size_t, 2 > size2
Array of 2 size_t.
Definition io_size.hh:12
Standard exception for invalid arguments in a call to a function or object.
Definition InvalidArgument.hh:15
Definition Window.hh:25