P-E-R-R-Y
Utilitaires, contrats et vendors du moteur, en une seule doc
Loading...
Searching...
No Matches
SfmlGraphicModule.hpp
Go to the documentation of this file.
1
12
13#ifndef SFMLGRAPHIC_MODULE_HPP
14#define SFMLGRAPHIC_MODULE_HPP
15
16#include "IGraphic2Module.hpp"
17
18#include "window/SfmlWindow.hpp"
19
20#include "event/SfmlGamepad.hpp"
22#include "event/SfmlMouse.hpp"
23
24#include "graphic/SfmlFont.hpp"
27#include "graphic/SfmlText.hpp"
29
35
36public:
37 SfmlGraphicModule() = default;
38 ~SfmlGraphicModule() = default;
39
40 const char *type() const override { return IGraphic2Module::contract; }
41 const char *name() const override { return "sfml"; }
42
57 const char *const *claims() const override {
58 static const char *claimed[] = { "opengl", nullptr };
59 return claimed;
60 }
61
71 graphic::IWindow2 *createWindow(int32_t screenWidth, int32_t screenHeight, std::string title) override {
72 SfmlWindow *created = new SfmlWindow(screenWidth, screenHeight, title);
73
74 if (!_window)
75 _window = created;
76 return created;
77 }
79 if (window == _window)
80 _window = nullptr;
81 delete window;
82 }
83
84 graphic::IWindow2 *window() override { return _window; }
85
86 /* La fenetre est LUE, contrairement a raylib : sfml attache son etat
87 * d'entree a une fenetre precise, il faut donc dire laquelle. Elle est
88 * donnee a la construction et n'est jamais rebranchee ensuite. */
90 return new SfmlKeyboard(*static_cast<SfmlWindow *>(window));
91 }
92 void deleteKeyboard(graphic::IKeyboard *keyboard) override { delete keyboard; }
93
95 return new SfmlMouse(*static_cast<SfmlWindow *>(window));
96 }
97 void deleteMouse(graphic::IMouse *mouse) override { delete mouse; }
98
100 return new SfmlGamepad(*static_cast<SfmlWindow *>(window));
101 }
102 void deleteGamepad(graphic::IGamepad *gamepad) override { delete gamepad; }
103
104 // texture
105 graphic::ITexture *createTexture(std::string path) override {
106 return new SfmlTexture(path);
107 }
108 void deleteTexture(graphic::ITexture *texture) override {
109 delete texture;
110 }
111
112 // font
113 graphic::IFont *createFont(std::string path) override {
114 return new SfmlFont(path);
115 }
116 void deleteFont(graphic::IFont *font) override {
117 delete font;
118 }
119
120 // polygon
121 graphic::IPolygon *createPolygon(std::vector<Vector2f> points) override {
122 return new SfmlPolygon(points);
123 }
124 void deletePolygon(graphic::IPolygon *polygon) override {
125 delete polygon;
126 }
127
128 // sprite
130 return new SfmlSprite(*static_cast<SfmlTexture *>(texture));
131 }
132 void deleteSprite(graphic::ISprite *sprite) override {
133 delete sprite;
134 }
135
136 // text
137 graphic::IText *createText(std::string text, graphic::IFont *font) override {
138 return new SfmlText(text, *static_cast<SfmlFont *>(font));
139 }
140 void deleteText(graphic::IText *text) override {
141 delete text;
142 }
143
144private:
146 graphic::IWindow2 *_window = nullptr;
147};
148
150
151#endif /* !SFMLGRAPHIC_MODULE_HPP */
A vendor's 2D factory : window, input, loaded resources and the objects that reference them....
Definition IGraphic2Module.hpp:37
static constexpr const char * contract
Definition IGraphic2Module.hpp:45
Sfml Font class - owns the loaded font. SfmlText only references it (sf::Text itself already takes a ...
Definition SfmlFont.hpp:27
Unlike raylib's GamepadButton (normalized Xbox-style layout), sf::Joystick exposes raw numbered butto...
Definition SfmlGamepad.hpp:35
graphic::ISprite * createSprite(graphic::ITexture *texture) override
Definition SfmlGraphicModule.hpp:129
void deleteMouse(graphic::IMouse *mouse) override
Definition SfmlGraphicModule.hpp:97
const char *const * claims() const override
Revendique "opengl" : aucun autre vendor OpenGL en meme temps.
Definition SfmlGraphicModule.hpp:57
graphic::IPolygon * createPolygon(std::vector< Vector2f > points) override
Definition SfmlGraphicModule.hpp:121
const char * type() const override
Le contrat qu'il remplit : "graphic2", "audio", "game"...
Definition SfmlGraphicModule.hpp:40
graphic::IWindow2 * createWindow(int32_t screenWidth, int32_t screenHeight, std::string title) override
Ouvre une fenetre. sfml sait en tenir plusieurs.
Definition SfmlGraphicModule.hpp:71
graphic::IFont * createFont(std::string path) override
Definition SfmlGraphicModule.hpp:113
SfmlGraphicModule()=default
void deleteWindow(graphic::IWindow2 *window) override
Definition SfmlGraphicModule.hpp:78
graphic::IGamepad * createGamepad(graphic::IWindow *window) override
Definition SfmlGraphicModule.hpp:99
void deleteSprite(graphic::ISprite *sprite) override
Definition SfmlGraphicModule.hpp:132
void deleteTexture(graphic::ITexture *texture) override
Definition SfmlGraphicModule.hpp:108
void deleteFont(graphic::IFont *font) override
Definition SfmlGraphicModule.hpp:116
graphic::IKeyboard * createKeyboard(graphic::IWindow *window) override
Definition SfmlGraphicModule.hpp:89
graphic::IMouse * createMouse(graphic::IWindow *window) override
Definition SfmlGraphicModule.hpp:94
graphic::IWindow2 * window() override
La fenetre ouverte de ce vendor, nullptr s'il n'y en a pas.
Definition SfmlGraphicModule.hpp:84
void deleteGamepad(graphic::IGamepad *gamepad) override
Definition SfmlGraphicModule.hpp:102
void deletePolygon(graphic::IPolygon *polygon) override
Definition SfmlGraphicModule.hpp:124
const char * name() const override
Le fournisseur : "raylib", "sfml", "console"...
Definition SfmlGraphicModule.hpp:41
graphic::IText * createText(std::string text, graphic::IFont *font) override
Definition SfmlGraphicModule.hpp:137
~SfmlGraphicModule()=default
void deleteText(graphic::IText *text) override
Definition SfmlGraphicModule.hpp:140
graphic::ITexture * createTexture(std::string path) override
Definition SfmlGraphicModule.hpp:105
void deleteKeyboard(graphic::IKeyboard *keyboard) override
Definition SfmlGraphicModule.hpp:92
Maps the contract's keys to sfml scancodes, and reads the state the window accumulated while popping ...
Definition SfmlKeyboard.hpp:41
Maps the contract's buttons to sfml buttons, and reads the state the window accumulated while popping...
Definition SfmlMouse.hpp:29
Definition SfmlPolygon.hpp:25
Sfml Sprite class - references a SfmlTexture, does not own it. Deleting the sprite never touches the ...
Definition SfmlSprite.hpp:27
Sfml Text class - references a SfmlFont, does not own it. Deleting the text never touches the font.
Definition SfmlText.hpp:28
Sfml Texture class - owns the loaded texture. SfmlSprite only references it (sf::Sprite itself alread...
Definition SfmlTexture.hpp:28
Sfml Window class - implements IWindow2 only, sfml has no 3D.
Definition SfmlWindow.hpp:46
Loaded font data, independent of any IText that references it. Deleting every IText built with a font...
Definition IFont.hpp:22
Gamepad interface. Not every window can hand one out (a terminal backend has no controller) - IWindow...
Definition IGamepad.hpp:26
Keyboard interface.
Definition IKeyboard.hpp:78
Mouse interface.
Definition IMouse.hpp:30
Polygon interface.
Definition IPolygon.hpp:34
Sprite interface.
Definition ISprite.hpp:22
Text interface.
Definition IText.hpp:26
Loaded pixel data, independent of any ISprite that references it. Deleting every ISprite built from a...
Definition ITexture.hpp:23
A window that can draw 2D. Adds only the 2D drawing surface on top of IWindow's lifecycle/input.
Definition IWindow2.hpp:25
Window lifecycle. No drawing here : every window, 2D-capable or not, has to open, close and pump its ...
Definition IWindow.hpp:27