Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Window.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 Julien Bernard
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  * Part of this file comes from SFML, with the same license:
22  * Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
23  */
24 #ifndef GF_WINDOW_H
25 #define GF_WINDOW_H
26 
27 #include <string>
28 
29 #include "Clock.h"
30 #include "Flags.h"
31 #include "Library.h"
32 #include "Portability.h"
33 #include "StringRef.h"
34 #include "Time.h"
35 #include "Vector.h"
36 
37 struct SDL_Window;
38 
39 namespace gf {
40 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 inline namespace v1 {
42 #endif
43 
44  struct Event;
45  class Cursor;
46 
51  enum class WindowHints : uint32_t {
52  Resizable = 0x0001,
53  Visible = 0x0002,
54  Decorated = 0x0004,
55  };
56 
57 #ifndef DOXYGEN_SHOULD_SKIP_THIS
58 }
59 
60 template<>
61 struct EnableBitmaskOperators<WindowHints> {
62  static constexpr bool value = true;
63 };
64 
65 inline namespace v1 {
66 #endif
67 
81  class GF_API Window {
82  public:
83 
96  Window(StringRef title, Vector2i size, Flags<WindowHints> hints = All);
97 
103  ~Window();
104 
108  Window(const Window&) = delete;
109 
113  Window& operator=(const Window&) = delete;
114 
126  bool isOpen();
127 
136  void close();
137 
150  void setTitle(StringRef title);
151 
158  Vector2i getPosition() const;
159 
166  void setPosition(Vector2i position);
167 
174  Vector2i getSize() const;
175 
182  void setSize(Vector2i size);
183 
191  Vector2i getFramebufferSize() const;
192 
198  void setFullscreen(bool full = true);
199 
203  void toggleFullscreen();
204 
210  bool isFullscreen() const {
211  return m_isFullscreen;
212  }
213 
226  bool isMinimized() const;
227 
231  void minimize();
232 
238  void restore();
239 
245  bool isMaximized() const;
246 
250  void maximize();
251 
257  bool isVisible() const;
258 
263  void show();
264 
269  void hide();
270 
279  void setVisible(bool visible = true);
280 
286  bool isDecorated() const;
287 
294  void setDecorated(bool decorated = true);
295 
301  bool isFocused() const;
302 
308  bool isResizable() const;
309 
318  void setResizable(bool resizable = true);
319 
320 
349  bool pollEvent(Event& event);
350 
375  bool waitEvent(Event& event);
376 
395  void setVerticalSyncEnabled(bool enabled);
396 
403  bool isVerticalSyncEnabled() const;
404 
414  void setFramerateLimit(unsigned int limit);
415 
425  void display();
426 
442  void setMouseCursorVisible(bool visible);
443 
456  void setMouseCursorGrabbed(bool grabbed);
457 
458 
468  void setMouseCursor(const Cursor& cursor);
469 
472  friend class SharedGraphics;
473 
474  private:
475  void attachGLContext();
476  void detachGLContext();
477 
478  private:
479  Library m_lib; // to automatically initialize SDL
480 
481  private:
482  SDL_Window *m_window;
483  void *m_mainContext;
484  void *m_sharedContext;
485  bool m_shouldClose;
486  bool m_isFullscreen;
487 
488  // framerate limit handling
489  Clock m_clock;
490  Time m_duration;
491 
492  unsigned m_vao;
493  };
494 
495 #ifndef DOXYGEN_SHOULD_SKIP_THIS
496 }
497 #endif
498 
499 }
500 
501 #endif // GL_WINDOW_H
Is the window resizable?
bool isFullscreen() const
Check if the window is fullscreen or not.
Definition: Window.h:210
Bitfield relying on an enumeration.
Definition: Flags.h:46
A shared OpenGL context with the main thread.
Definition: SharedGraphics.h:41
constexpr AllType All
Constant to represent "all".
Definition: Types.h:61
WindowHints
Hints for window creation.
Definition: Window.h:51
The cell is visible (computed by FoV)
Represents a time value.
Definition: Time.h:65
Is the window decorated?
The namespace for gf classes.
Definition: Action.h:35
A class to represent the library.
Definition: Library.h:44
An OS window.
Definition: Window.h:81
A constant reference to a string and its size.
Definition: StringRef.h:41
A mouse cursor.
Definition: Cursor.h:63
Defines a system event and its parameters.
Definition: Event.h:101
Utility class that measures the elapsed time.
Definition: Clock.h:61
An event is pending on the sockets.
Definition: SocketSelector.h:47