SUPER Space invader : Turbo edition DX - VS GOD 1.0.0
A simple space invader ripoff
mingl.h
Go to the documentation of this file.
1
11#ifndef MINGL_H
12#define MINGL_H
13
14#include <map>
15#include <memory> // shared_ptr
16#include <queue>
17#include <string>
18#include <vector>
19
20#include <GL/freeglut.h>
21
22#include "graphics/idrawable.h"
23#include "graphics/rgbacolor.h"
24#include "graphics/vec2d.h"
25
26#include "event/event_manager.h"
27
32// Pour les polices et l'affichage des chaines de caractères, voir: https://www.opengl.org/resources/libraries/glut/spec3/node76.html
33
34class MinGL
35{
36
37public:
47 typedef std::pair<unsigned, bool> KeyType_t; // cle, spécial
48
55 typedef std::map<KeyType_t, bool> KeyMap_t;
56
67 MinGL(const std::string& name, const nsGraphics::Vec2D& windowSize = nsGraphics::Vec2D(640, 480),
68 const nsGraphics::Vec2D& windowPosition = nsGraphics::Vec2D(128, 128),
69 const nsGraphics::RGBAcolor& backgroundColor = nsGraphics::KWhite);
70
76
81 static void initGlut()
82 {
83 int tmp = 0;
84 glutInit(&tmp, NULL);
85 }
86
92
98
104 bool isPressed(const KeyType_t& key);
105
111 void resetKey(const KeyType_t& key);
112
118
124
130
136
141 void setBackgroundColor(const nsGraphics::RGBAcolor& backgroundColor);
142
148
154 void setWindowSize(const nsGraphics::Vec2D& windowSize);
155
161
167 void setWindowPosition(const nsGraphics::Vec2D &windowPosition);
168
173 const std::string& getWindowName() const;
174
180 void setWindowName(const std::string &windowName);
181
186 bool isOpen() const;
187
188private:
189 // Les données membres en tant que tel
190
194 std::string m_windowName;
195
199 nsGraphics::RGBAcolor m_bgColor;
200
204 KeyMap_t m_keyboardMap;
205
209 short m_glutWindowId = 0;
210
214 nsEvent::EventManager m_eventManager;
215
219 bool m_windowIsOpen;
220
221 // Les handlers
222
229 void callReshape(int h, int w);
230
235 void callDisplay();
236
245 void callMouse(int button, int state, int x = 0, int y = 0);
246
253 void callMotion(int x, int y);
254
261 void callPassiveMotion(int x, int y);
262
270 void callKeyboard(unsigned char key, int x = 0, int y = 0);
271
279 void callKeyboardUp(unsigned char key, int x = 0, int y = 0);
280
288 void callKeyboardSpecial(int key, int x = 0, int y = 0);
289
297 void callKeyboardUpSpecial(int key, int x = 0, int y = 0);
298
303 void callClose();
304
305}; // class MinGL
306
307#endif // MINGL_H
Classe de base de minGL 2.
Definition: mingl.h:35
bool isOpen() const
Retourne si la fenêtre est ouverte.
std::map< KeyType_t, bool > KeyMap_t
KeyMap_t : Map représentant des touches et leurs état (pressée ou non).
Definition: mingl.h:55
~MinGL()
Destructeur de la classe MinGL.
static void initGlut()
Initialise la bibliothèque freeglut.
Definition: mingl.h:81
nsGraphics::Vec2D getWindowPosition() const
Récupère la Position de la fenêtre.
void setBackgroundColor(const nsGraphics::RGBAcolor &backgroundColor)
Règle la couleur de fond de la fenêtre.
void setWindowName(const std::string &windowName)
Règle le nom de la fenêtre.
const std::string & getWindowName() const
Récupère le nom de la fenêtre.
void finishFrame()
Préviens minGL que la frame est terminée.
void setWindowSize(const nsGraphics::Vec2D &windowSize)
Règle la taille de la fenêtre.
void initGraphic()
Initialise minGL et ouvre la fenêtre.
const nsGraphics::RGBAcolor & getBackgroundColor() const
Récupère la couleur de fond de la fenêtre.
std::pair< unsigned, bool > KeyType_t
KeyType_t : Représente une touche du clavier.
Definition: mingl.h:47
void clearScreen()
Efface l'écran avec la couleur de fond spécifiée.
bool isPressed(const KeyType_t &key)
Renvoie l'état d'une touche du clavier (pressée ou non)
void setWindowPosition(const nsGraphics::Vec2D &windowPosition)
Règle la Position de la fenêtre.
nsGraphics::Vec2D getWindowSize() const
Récupère la taille de la fenêtre.
void stopGraphic()
Ferme la fenêtre et minGL proprement.
void resetKey(const KeyType_t &key)
Force une touche a être relâchée.
nsEvent::EventManager & getEventManager()
Récupère le gestionnaire d'évènements minGL.
MinGL(const std::string &name, const nsGraphics::Vec2D &windowSize=nsGraphics::Vec2D(640, 480), const nsGraphics::Vec2D &windowPosition=nsGraphics::Vec2D(128, 128), const nsGraphics::RGBAcolor &backgroundColor=nsGraphics::KWhite)
Constructeur pour la classe MinGL.
Gère une queue d'événement entrants.
Definition: event_manager.h:25
Classe représentant un couleur RGBA8888.
Definition: rgbacolor.h:26
Classe représentant un vecteur deux-dimensionnel.
Definition: vec2d.h:26
Gestionnaire d'événements de minGL.
Interface pour un objet affichable.
const RGBAcolor KWhite
Definition: rgbacolor.h:158
Représente une couleur RGBA.
Représente un vecteur sur deux dimensions.