PROTO::KLUDGE  0.1
Quick prototyping library for games using SDL and OpenGL.
Window.hpp
Go to the documentation of this file.
1 #ifndef WINDOW_HPP
2 #define WINDOW_HPP
3 
4 #include <stdio.h>
5 
6 #include <SDL2/SDL.h>
7 #include <SDL2/SDL_image.h>
8 #include <SDL2/SDL_ttf.h>
9 #include <SDL2/SDL_mixer.h>
10 
11 #include "graphics/Drawable.hpp"
12 #include "graphics/GLDrawable.hpp"
13 #include "core/GLStates.hpp"
14 
15 namespace pk
16 {
17 
24 class Window
25 {
26  private:
31  Window(){};
32  public:
42  Window(const char *windowTitle, glm::ivec2 position, int width, int height, Uint32 windowFlags);
43 
44  virtual ~Window();
45 
50  void render();
51 
57  SDL_Window * const getWindow(){return m_window;};
58 
64  SDL_GLContext &getContext(){ return m_context; };
65 
71  SDL_Renderer * const getRenderer(){return m_renderer;};
72 
78  const char * getTitle(){ return m_title; };
79 
84  void setTitle(const char *title){ m_title = title; SDL_SetWindowTitle(m_window, m_title); };
85 
91  const glm::ivec2 &getPosition(){ return m_position; };
92 
99  void setPosition(glm::ivec2 position){ m_position = position; };
100 
106  glm::ivec2 getSize(){ return glm::ivec2(m_width, m_height); };
107 
113  void setSize(const glm::ivec2 &windowSize){ m_width = windowSize.x; m_height = windowSize.y; SDL_SetWindowSize(m_window, m_width, m_height);};
114 
120  const Uint32 &getFlags(){ return m_flags; };
121 
127  void setFlags(const Uint32 &flags){ m_flags = flags; };
128 
133  const SDL_Rect &getWindowRect(){ return m_rect; };
134 
140  void setWindowRect(SDL_Rect &rect){ m_rect = rect; };
141 
147  const glm::tvec4<Uint8> &getClearColor(){ return m_clearColor; };
148 
154  SDL_Color getSDLClearColor(){ SDL_Color c = {m_clearColor.r, m_clearColor.g, m_clearColor.b, m_clearColor.a}; return c; };
155 
162  void draw(GLDrawable &drawable, GLStates &states);
163 
169  void draw(Drawable &drawable);
170 
177  void draw(Drawable * const drawables);
178 
185  void clear(glm::ivec4 color = glm::ivec4());
186 
187  private:
188  SDL_GLContext m_context;
189  SDL_Window *m_window;
190  const char *m_title;
191  SDL_Renderer *m_renderer;
192  glm::ivec2 m_position;
193  int m_width;
194  int m_height;
195  Uint32 m_flags;
196  SDL_Rect m_rect;
197  glm::tvec4<Uint8> m_clearColor;
198 };
199 
200 }
201 
202 #endif // WINDOW_HPP
const char * getTitle()
Get the window&#39;s title.
Definition: Window.hpp:78
void setWindowRect(SDL_Rect &rect)
Set the SDL_Rect belonging to the Window.
Definition: Window.hpp:140
SDL_GLContext & getContext()
Definition: Window.hpp:64
Definition: Game.hpp:7
Window()
Default constructor - INACCESSIBLE!
Definition: Window.hpp:31
void clear(glm::ivec4 color=glm::ivec4())
Clear the window for rendering with SDL (not OpenGL).
glm::ivec2 m_position
Window position as a vector of integers.
Definition: Window.hpp:192
const glm::ivec2 & getPosition()
Get the position of the window on screen.
Definition: Window.hpp:91
SDL_Rect m_rect
SDL_Rect for drawing within a rectangular area of the window.
Definition: Window.hpp:196
Definition: GLDrawable.hpp:16
int m_width
Width of the Window.
Definition: Window.hpp:193
const SDL_Rect & getWindowRect()
Get the SDL_Rect belonging to the Window.
Definition: Window.hpp:133
void draw(GLDrawable &drawable, GLStates &states)
int m_height
Height of the Window.
Definition: Window.hpp:194
void setSize(const glm::ivec2 &windowSize)
Definition: Window.hpp:113
const glm::tvec4< Uint8 > & getClearColor()
Get the clear color of the Window.
Definition: Window.hpp:147
glm::tvec4< Uint8 > m_clearColor
SDL_Color for clearing the screen.
Definition: Window.hpp:197
SDL_Color getSDLClearColor()
Get the clear color of the Window in SDL_Color format.
Definition: Window.hpp:154
glm::ivec2 getSize()
Get the SDL window size (width and height).
Definition: Window.hpp:106
SDL_Renderer *const getRenderer()
Get the raw SDL_Renderer pointer (read-only).
Definition: Window.hpp:71
Stores the states used to draw OpenGL objects.
Definition: GLStates.hpp:16
void setPosition(glm::ivec2 position)
Set the position of the window on screen.
Definition: Window.hpp:99
const Uint32 & getFlags()
Get the SDL window flags.
Definition: Window.hpp:120
void setTitle(const char *title)
Set the title of the window.
Definition: Window.hpp:84
Interface for creating drawable entities. Part of the Decorator pattern for drawable objects used in ...
Definition: Drawable.hpp:15
const char * m_title
The window title.
Definition: Window.hpp:190
Class for SDL window creation and management, implemented using the Facade pattern to provide a more ...
Definition: Window.hpp:24
SDL_GLContext m_context
OpenGL context provided by SDL.
Definition: Window.hpp:188
SDL_Window * m_window
SDL_Window object.
Definition: Window.hpp:189
void setFlags(const Uint32 &flags)
Set the SDL window size (width and height).
Definition: Window.hpp:127
SDL_Renderer * m_renderer
SDL_Renderer object.
Definition: Window.hpp:191
Uint32 m_flags
Display flags for the SDL_Window.
Definition: Window.hpp:195
void render()
Render to the window.
SDL_Window *const getWindow()
Get the raw SDL_Window pointer (read-only).
Definition: Window.hpp:57
virtual ~Window()