Bomberman
Window.hpp
Go to the documentation of this file.
1 /*
2 ** EPITECH PROJECT, 2021
3 ** Bomberman
4 ** File description:
5 ** Window
6 */
7 
8 #ifndef WINDOW_HPP_
9 #define WINDOW_HPP_
10 
11 #include <raylib.h>
12 #include <string>
13 #include <optional>
14 #include "Vector/Vector2.hpp"
15 #include "Vector/Vector3.hpp"
16 #include "Controllers/Keyboard.hpp"
17 #include "Camera/Camera2D.hpp"
18 #include "Camera/Camera3D.hpp"
19 #include "Color.hpp"
20 
21 namespace RAY {
23  class Image;
24  namespace Drawables {
25  class IDrawable;
26  class ADrawable3D;
27  namespace Drawables3D
28  {
29  class Model;
30  }
31  }
32  class Window {
33  private:
35  static std::optional<Window> _instance;
36  public:
38  static Window &getInstance();
39 
41  static Window &getInstance(int width, int height, const std::string &title, unsigned flags = 0, bool openNow = true) noexcept;
42 
44  Window(Window &&) = default;
45 
47  Window(const Window &window) = delete;
48 
50  Window &operator=(const Window &window) = delete;
51 
53  ~Window() = default;
54 
56  bool open(void);
57 
59  bool shouldClose(void) const;
60 
62  void close(void);
63 
65  bool isFocused(void) const;
66 
68  const RAY::Vector2 &getDimensions(void);
69 
71  RAY::Window &setDimensions(const Vector2 &dims);
72 
75  void setVisibleCursor(bool visible);
76 
79  void enableCursor(bool enable);
80 
82  bool cursorIsVisible(void) const;
83 
85  void setIcon(RAY::Image &img);
86 
88  Vector2 getCursorPosition() const;
89 
91  void setFPS(unsigned int fps);
92 
95  void clear(Color color = BLACK);
96 
98  enum displayState {
105  };
106 
108  void beginDrawing();
110  void endDrawing();
111 
113  void useCamera(Camera::Camera2D &camera);
114 
116  void useCamera(Camera::Camera3D &camera);
117 
119  void unuseCamera(void);
120 
122  void setTitle(const std::string &title);
123 
124 
127  void draw(RAY::Drawables::IDrawable &drawable);
128 
130  void draw(const Mesh &mesh, const Material &material, const Matrix &transform);
131 
133  void drawFPS(const Vector2 &position);
135  bool isReady() const;
136 
141 
143  unsigned getConfigFlags(void) const;
144 
146  RAY::Window &setConfigFlags(unsigned flags);
147 
150 
152  bool isFullscreen(void) const;
153 
156 
158  RAY::Window &restore();
159 
160  private:
162  Window(int width, int height, std::string title, unsigned flags = 0, bool openNow = true);
163 
166 
168  std::string _title;
169 
171  bool _isOpen;
172 
174  unsigned int _flags;
175 
178  };
179 }
180 
181 #endif /* !WINDOW_HPP_ */
Vector3.hpp
RAY::Window::endDrawing
void endDrawing()
End canvas drawing and swap buffers (double buffering)
Definition: Window.cpp:129
RAY::Window::beginDrawing
void beginDrawing()
Setup canvas (framebuffer) to start drawing.
Definition: Window.cpp:124
RAY::Window::_dimensions
RAY::Vector2 _dimensions
Dimension of window.
Definition: Window.hpp:165
RAY::Window::open
bool open(void)
Initialize window and OpenGL context.
Definition: Window.cpp:45
RAY::Window::setExitKey
void setExitKey(Controller::Keyboard::Key key)
Definition: Window.cpp:194
RAY::Window::toggleFullscreen
RAY::Window & toggleFullscreen()
set window to fullscreen
Definition: Window.cpp:217
RAY::Window::_isOpen
bool _isOpen
has the window been open?
Definition: Window.hpp:171
RAY::Window::isReady
bool isReady() const
Definition: Window.cpp:189
RAY::Window::isFullscreen
bool isFullscreen(void) const
Definition: Window.cpp:204
RAY::Window::isFocused
bool isFocused(void) const
Check if window is currently focused.
Definition: Window.cpp:68
RAY::Window::displayState
displayState
Different states of the view of the window.
Definition: Window.hpp:98
RAY::Window
Definition: Window.hpp:32
RAY::Window::_displayState
enum displayState _displayState
Current window draw-state.
Definition: Window.hpp:177
RAY::Window::NONE
@ NONE
When no camera is used.
Definition: Window.hpp:104
RAY::Window::getInstance
static Window & getInstance()
Get The window's instance, if the window has not been already constructed a runtime exception is thro...
Definition: Window.cpp:18
RAY::Controller::Keyboard::Key
::KeyboardKey Key
Definition: Keyboard.hpp:18
RAY::Window::drawFPS
void drawFPS(const Vector2 &position)
Draws current FPS on the frame.
Definition: Window.cpp:184
RAY::Window::getDimensions
const RAY::Vector2 & getDimensions(void)
Get window dimensions.
Definition: Window.cpp:73
RAY::Drawables::IDrawable
Interface for any drawable.
Definition: IDrawable.hpp:18
RAY::Window::setFPS
void setFPS(unsigned int fps)
Set target FPS (maximum)
Definition: Window.cpp:114
RAY::Vector2
A Two-dimensionnal Vector data type.
Definition: Vector2.hpp:15
RAY::Window::getConfigFlags
unsigned getConfigFlags(void) const
Definition: Window.cpp:199
RAY::Window::shouldClose
bool shouldClose(void) const
Check if KEY_ESCAPE pressed or Close icon pressed.
Definition: Window.cpp:57
RAY::Camera::Camera2D
Entity representing a Camera in 2D space.
Definition: Camera2D.hpp:18
RAY::Window::close
void close(void)
Close window and unload OpenGL context.
Definition: Window.cpp:62
RAY::Window::setTitle
void setTitle(const std::string &title)
Set the window title.
Definition: Window.cpp:164
RAY
Definition: IAudio.hpp:12
RAY::Window::_title
std::string _title
Title of window.
Definition: Window.hpp:168
RAY::Window::unuseCamera
void unuseCamera(void)
Ends current view mode and returns to default mode.
Definition: Window.cpp:148
RAY::Window::setIcon
void setIcon(RAY::Image &img)
set the window icon
Definition: Window.cpp:179
RAY::Window::useCamera
void useCamera(Camera::Camera2D &camera)
Initialize 2D mode with custom camera (2D)
Definition: Window.cpp:134
Camera3D.hpp
RAY::Window::THREE_DIMENSIONNAL
@ THREE_DIMENSIONNAL
When a custom 3D camera is used.
Definition: Window.hpp:102
RAY::Window::setDimensions
RAY::Window & setDimensions(const Vector2 &dims)
Set window dimensions.
Definition: Window.cpp:80
RAY::Window::draw
void draw(RAY::Drawables::IDrawable &drawable)
draw drawable
Definition: Window.cpp:169
RAY::Matrix
::Matrix Matrix
Definition: Matrix.hpp:14
RAY::Window::setVisibleCursor
void setVisibleCursor(bool visible)
Set the cursor visibility.
Definition: Window.cpp:88
RAY::Window::maximize
RAY::Window & maximize()
set window to max size
Definition: Window.cpp:223
RAY::Window::_flags
unsigned int _flags
flags for the window (ex: FLAG_WINDOW_RESIZABLE)
Definition: Window.hpp:174
RAY::Window::_instance
static std::optional< Window > _instance
The window's instance as an optional.
Definition: Window.hpp:35
RAY::Image
Object representation of a framebuffer.
Definition: Image.hpp:20
RAY::Window::setConfigFlags
RAY::Window & setConfigFlags(unsigned flags)
Definition: Window.cpp:209
Camera2D.hpp
RAY::Window::cursorIsVisible
bool cursorIsVisible(void) const
Check if cursor is not visible.
Definition: Window.cpp:104
RAY::Color
Object representation of color.
Definition: Color.hpp:15
RAY::Window::Window
Window(Window &&)=default
A window is movable.
RAY::Camera::Camera3D
Entity representing a Camera in 3D space.
Definition: Camera3D.hpp:20
RAY::Window::getCursorPosition
Vector2 getCursorPosition() const
Get the cursor position.
Definition: Window.cpp:109
Color.hpp
RAY::Window::TWO_DIMENSIONNAL
@ TWO_DIMENSIONNAL
When a custom 2D camera is used.
Definition: Window.hpp:100
Vector2.hpp
RAY::Window::clear
void clear(Color color=BLACK)
Set background color (framebuffer clear color)
Definition: Window.cpp:119
Keyboard.hpp
RAY::Mesh
::Mesh Mesh
Vertex data definning a mesh.
Definition: Mesh.hpp:15
RAY::Window::enableCursor
void enableCursor(bool enable)
Enable/Disable the cursor.
Definition: Window.cpp:96
RAY::Window::restore
RAY::Window & restore()
reset window size
Definition: Window.cpp:229