Gamedev Framework (gf)  0.7.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 
231  void minimize();
232 
238  void restore();
239 
243  void maximize();
244 
249  void show();
250 
255  void hide();
256 
265  void setVisible(bool visible = true);
266 
273  void setDecorated(bool decorated = true);
274 
280  bool isFocused() const;
281 
287  bool isMinimized() const;
288 
294  bool isResizable() const;
295 
301  bool isVisible() const;
302 
308  bool isDecorated() const;
309 
338  bool pollEvent(Event& event);
339 
364  bool waitEvent(Event& event);
365 
384  void setVerticalSyncEnabled(bool enabled);
385 
392  bool isVerticalSyncEnabled() const;
393 
403  void setFramerateLimit(unsigned int limit);
404 
414  void display();
415 
431  void setMouseCursorVisible(bool visible);
432 
445  void setMouseCursorGrabbed(bool grabbed);
446 
447 
457  void setMouseCursor(const Cursor& cursor);
458 
462  private:
463  Library m_lib; // to automatically initialize SDL
464 
465  private:
466  SDL_Window *m_window;
467  void *m_context;
468  bool m_shouldClose;
469  bool m_isFullscreen;
470 
471  // framerate limit handling
472  Clock m_clock;
473  Time m_duration;
474  };
475 
476 #ifndef DOXYGEN_SHOULD_SKIP_THIS
477 }
478 #endif
479 
480 }
481 
482 #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:73
Flags< WindowHints > WindowFlags
Flags for window creation.
Definition: Window.h:63
Is the window decorated?
The namespace for gf classes.
Definition: Action.h:34
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