MxEngine
Window.h
1 // Copyright(c) 2019 - 2020, #Momo
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met :
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and /or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #include <string>
32 #include <bitset>
33 
34 #include "Utilities/Time/Time.h"
35 #include "Utilities/Math/Math.h"
36 #include "Core/Event/Events/KeyEvent.h"
37 
38 struct GLFWwindow; // from glfw header file
39 
40 enum class Profile
41 {
42  ANY,
43  COMPAT,
44  CORE,
45 };
46 
47 enum class CursorMode
48 {
49  NORMAL,
50  HIDDEN,
51  DISABLED,
52 };
53 
54 namespace MxEngine
55 {
56  class Window
57  {
58  using WindowHandle = GLFWwindow*;
59  private:
60  MxString title;
61  GLFWwindow* window = nullptr;
62  int width = 0, height = 0;
63  AppEventDispatcher* dispatcher = nullptr;
64  mutable std::bitset<350> keyHeld;
65  mutable std::bitset<350> keyPressed;
66  mutable std::bitset<350> keyReleased;
67  CursorMode cursorMode = CursorMode::NORMAL;
68  bool doubleBuffer = false;
69  Vector2 windowPosition{ 0.0f, 0.0f };
70  Vector2 cursorPosition{ 0.0f, 0.0f };
71 
72  void Destroy();
73  void Move(Window&& window);
74  public:
75  Window() = default;
76  Window(int width, int height, const MxString& title);
77  Window(const Window&) = delete;
78  Window(Window&& other) noexcept;
79  Window& operator=(const Window&) = delete;
80  Window& operator=(Window&& other) noexcept;
81  ~Window();
82 
83  int GetHeight() const;
84  int GetWidth() const;
85  bool IsOpen() const;
86  void PullEvents() const;
87  void OnUpdate();
88  Vector2 GetCursorPosition() const;
89  Vector2 GetWindowPosition() const;
90  CursorMode GetCursorMode() const;
91  const MxString& GetTitle() const;
92  bool IsKeyHeld(KeyCode key) const;
93  bool IsKeyPressed(KeyCode key) const;
94  bool IsKeyReleased(KeyCode key) const;
95  WindowHandle GetNativeHandle();
96  AppEventDispatcher& GetEventDispatcher();
97  bool IsCreated() const;
98  Window& Create();
99  Window& Close();
100  Window& SwitchContext();
101  Window& UseDebugging(bool value = true);
102  Window& UseDoubleBuffering(bool value = true);
103  Window& UseCursorMode(CursorMode cursor);
104  Window& UseCursorPosition(const Vector2& pos);
105  Window& UseTitle(const MxString& title);
106  Window& UseWindowPosition(int xpos, int ypos);
107  Window& UseWindowSize(int width, int height);
108  Window& UseEventDispatcher(AppEventDispatcher* dispatcher);
109  Window& UseProfile(int majorVersion, int minorVersion, Profile profile);
110  };
111 }
Definition: Window.h:56
Definition: Application.cpp:49