Gamedev Framework (gf)  0.5.0
A C++11 framework for 2D games
Window.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2017 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 
51  enum class WindowHints : uint32_t {
52  Resizable = 0x0001,
53  Visible = 0x0002,
54  Decorated = 0x0004,
55  };
56 
63 #ifndef DOXYGEN_SHOULD_SKIP_THIS
64 }
65 
66 template<>
67 struct EnableBitmaskOperators<WindowHints> {
68  static constexpr bool value = true;
69 };
70 
71 inline namespace v1 {
72 #endif
73 
87  class GF_API Window {
88  public:
89 
102  Window(StringRef title, Vector2u size, WindowFlags hints = WindowFlags(All));
103 
109  ~Window();
110 
114  Window(const Window&) = delete;
115 
119  Window& operator=(const Window&) = delete;
120 
132  bool isOpen();
133 
142  void close();
143 
156  void setTitle(StringRef title);
157 
164  Vector2i getPosition() const;
165 
172  void setPosition(Vector2i position);
173 
180  Vector2u getSize() const;
181 
188  void setSize(Vector2u size);
189 
197  Vector2u getFramebufferSize() const;
198 
204  void setFullscreen(bool full = true);
205 
209  void toggleFullscreen();
210 
216  bool isFullscreen() const {
217  return m_isFullscreen;
218  }
219 
230  void minimize();
231 
237  void restore();
238 
242  void maximize();
243 
248  void show();
249 
254  void hide();
255 
264  void setVisible(bool visible = true);
265 
272  void setDecorated(bool decorated = true);
273 
279  bool isFocused() const;
280 
286  bool isMinimized() const;
287 
293  bool isResizable() const;
294 
300  bool isVisible() const;
301 
307  bool isDecorated() const;
308 
337  bool pollEvent(Event& event);
338 
363  bool waitEvent(Event& event);
364 
383  void setVerticalSyncEnabled(bool enabled);
384 
391  bool isVerticalSyncEnabled() const;
392 
402  void setFramerateLimit(unsigned int limit);
403 
413  void display();
414 
430  void setMouseCursorVisible(bool visible);
431 
444  void setMouseCursorGrabbed(bool grabbed);
445 
449  private:
450  Library m_lib; // to automatically initialize SDL
451 
452  private:
453  SDL_Window *m_window;
454  void *m_context;
455  bool m_shouldClose;
456  bool m_isFullscreen;
457 
458  // framerate limit handling
459  Clock m_clock;
460  Time m_duration;
461  };
462 
463 #ifndef DOXYGEN_SHOULD_SKIP_THIS
464 }
465 #endif
466 
467 }
468 
469 #endif // GL_WINDOW_H
Is the window resizable?
bool isFullscreen() const
Check if the window is fullscreen or not.
Definition: Window.h:216
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:51
Represents a time value.
Definition: Time.h:73
Flags< WindowHints > WindowFlags
Flags for window creation.
Definition: Window.h:62
Is the window decorated?
The namespace for gf classes.
Definition: Action.h:34
A class to represent the library.
Definition: Library.h:44
Is the window visible?
An OS window.
Definition: Window.h:87
A constant reference to a string and its size.
Definition: StringRef.h:41
Defines a system event and its parameters.
Definition: Event.h:118
Utility class that measures the elapsed time.
Definition: Clock.h:67