Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
Window.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 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 
52  enum class WindowHints : uint32_t {
53  Resizable = 0x0001,
54  Visible = 0x0002,
55  Decorated = 0x0004,
56  };
57 
64 #ifndef DOXYGEN_SHOULD_SKIP_THIS
65 }
66 
67 template<>
68 struct EnableBitmaskOperators<WindowHints> {
69  static constexpr bool value = true;
70 };
71 
72 inline namespace v1 {
73 #endif
74 
88  class GF_API Window {
89  public:
90 
103  Window(StringRef title, Vector2u size, WindowFlags hints = WindowFlags(All));
104 
110  ~Window();
111 
115  Window(const Window&) = delete;
116 
120  Window& operator=(const Window&) = delete;
121 
133  bool isOpen();
134 
143  void close();
144 
157  void setTitle(StringRef title);
158 
165  Vector2i getPosition() const;
166 
173  void setPosition(Vector2i position);
174 
181  Vector2u getSize() const;
182 
189  void setSize(Vector2u size);
190 
198  Vector2u getFramebufferSize() const;
199 
205  void setFullscreen(bool full = true);
206 
210  void toggleFullscreen();
211 
217  bool isFullscreen() const {
218  return m_isFullscreen;
219  }
220 
233  bool isMinimized() const;
234 
238  void minimize();
239 
245  void restore();
246 
252  bool isMaximized() const;
253 
257  void maximize();
258 
264  bool isVisible() const;
265 
270  void show();
271 
276  void hide();
277 
286  void setVisible(bool visible = true);
287 
293  bool isDecorated() const;
294 
301  void setDecorated(bool decorated = true);
302 
308  bool isFocused() const;
309 
315  bool isResizable() const;
316 
325  void setResizable(bool resizable = true);
326 
327 
356  bool pollEvent(Event& event);
357 
382  bool waitEvent(Event& event);
383 
402  void setVerticalSyncEnabled(bool enabled);
403 
410  bool isVerticalSyncEnabled() const;
411 
421  void setFramerateLimit(unsigned int limit);
422 
432  void display();
433 
449  void setMouseCursorVisible(bool visible);
450 
463  void setMouseCursorGrabbed(bool grabbed);
464 
465 
475  void setMouseCursor(const Cursor& cursor);
476 
480  private:
481  Library m_lib; // to automatically initialize SDL
482 
483  private:
484  SDL_Window *m_window;
485  void *m_context;
486  bool m_shouldClose;
487  bool m_isFullscreen;
488 
489  // framerate limit handling
490  Clock m_clock;
491  Time m_duration;
492 
493  unsigned m_vao;
494  };
495 
496 #ifndef DOXYGEN_SHOULD_SKIP_THIS
497 }
498 #endif
499 
500 }
501 
502 #endif // GL_WINDOW_H
Is the window resizable?
bool isFullscreen() const
Check if the window is fullscreen or not.
Definition: Window.h:217
Bitfield relying on an enumeration.
Definition: Flags.h:68
constexpr AllType All
Constant to represent "all".
Definition: Types.h:61
WindowHints
Hints for window creation.
Definition: Window.h:52
The cell is visible (computed by FoV)
Represents a time value.
Definition: Time.h:74
Flags< WindowHints > WindowFlags
Flags for window creation.
Definition: Window.h:63
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:88
A constant reference to a string and its size.
Definition: StringRef.h:41
A mouse cursor.
Definition: Cursor.h:72
Defines a system event and its parameters.
Definition: Event.h:118
Utility class that measures the elapsed time.
Definition: Clock.h:67