sfml_impl 0.1.0
Vendor SFML 3.0.2 : IGraphic2Module / IAudioModule
Loading...
Searching...
No Matches
SfmlGraphicModule.hpp
Go to the documentation of this file.
1
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
34class SfmlGraphicModule : public IGraphic2Module {
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
43 // window
44 graphic::IWindow2 *createWindow(int32_t screenWidth, int32_t screenHeight, std::string title) override {
45 SfmlWindow *created = new SfmlWindow(screenWidth, screenHeight, title);
46
47 /* On retient la premiere : c'est celle que window() pretera aux
48 * invites. sfml sait en ouvrir plusieurs, mais une seule a le
49 * clavier - celle qui a le focus. */
50 if (!_window)
51 _window = created;
52 return created;
53 }
54 void deleteWindow(graphic::IWindow2 *window) override {
55 if (window == _window)
56 _window = nullptr;
57 delete window;
58 }
59
60 graphic::IWindow2 *window() override { return _window; }
61
62 // input - the window is handed over at construction, the way an
63 // ITexture is to an ISprite : linked once, never reconciled later
64 graphic::IKeyboard *createKeyboard(graphic::IWindow *window) override {
65 return new SfmlKeyboard(*static_cast<SfmlWindow *>(window));
66 }
67 void deleteKeyboard(graphic::IKeyboard *keyboard) override { delete keyboard; }
68
69 graphic::IMouse *createMouse(graphic::IWindow *window) override {
70 return new SfmlMouse(*static_cast<SfmlWindow *>(window));
71 }
72 void deleteMouse(graphic::IMouse *mouse) override { delete mouse; }
73
74 graphic::IGamepad *createGamepad(graphic::IWindow *window) override {
75 return new SfmlGamepad(*static_cast<SfmlWindow *>(window));
76 }
77 void deleteGamepad(graphic::IGamepad *gamepad) override { delete gamepad; }
78
79 // texture
80 graphic::ITexture *createTexture(std::string path) override {
81 return new SfmlTexture(path);
82 }
83 void deleteTexture(graphic::ITexture *texture) override {
84 delete texture;
85 }
86
87 // font
88 graphic::IFont *createFont(std::string path) override {
89 return new SfmlFont(path);
90 }
91 void deleteFont(graphic::IFont *font) override {
92 delete font;
93 }
94
95 // polygon
96 graphic::IPolygon *createPolygon(std::vector<Vector2f> points) override {
97 return new SfmlPolygon(points);
98 }
99 void deletePolygon(graphic::IPolygon *polygon) override {
100 delete polygon;
101 }
102
103 // sprite
104 graphic::ISprite *createSprite(graphic::ITexture *texture) override {
105 return new SfmlSprite(*static_cast<SfmlTexture *>(texture));
106 }
107 void deleteSprite(graphic::ISprite *sprite) override {
108 delete sprite;
109 }
110
111 // text
112 graphic::IText *createText(std::string text, graphic::IFont *font) override {
113 return new SfmlText(text, *static_cast<SfmlFont *>(font));
114 }
115 void deleteText(graphic::IText *text) override {
116 delete text;
117 }
118
119private:
121 graphic::IWindow2 *_window = nullptr;
122};
123
126#endif /* !SFMLGRAPHIC_MODULE_HPP */
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
Sfml only implements IGraphic2Module - no IGraphic3Module, sfml has no native 3D. No fake IModel here...
Definition SfmlGraphicModule.hpp:34
graphic::ISprite * createSprite(graphic::ITexture *texture) override
Definition SfmlGraphicModule.hpp:104
void deleteMouse(graphic::IMouse *mouse) override
Definition SfmlGraphicModule.hpp:72
graphic::IPolygon * createPolygon(std::vector< Vector2f > points) override
Definition SfmlGraphicModule.hpp:96
const char * type() const override
Definition SfmlGraphicModule.hpp:40
graphic::IWindow2 * createWindow(int32_t screenWidth, int32_t screenHeight, std::string title) override
Definition SfmlGraphicModule.hpp:44
graphic::IFont * createFont(std::string path) override
Definition SfmlGraphicModule.hpp:88
SfmlGraphicModule()=default
void deleteWindow(graphic::IWindow2 *window) override
Definition SfmlGraphicModule.hpp:54
graphic::IGamepad * createGamepad(graphic::IWindow *window) override
Definition SfmlGraphicModule.hpp:74
void deleteSprite(graphic::ISprite *sprite) override
Definition SfmlGraphicModule.hpp:107
void deleteTexture(graphic::ITexture *texture) override
Definition SfmlGraphicModule.hpp:83
void deleteFont(graphic::IFont *font) override
Definition SfmlGraphicModule.hpp:91
graphic::IKeyboard * createKeyboard(graphic::IWindow *window) override
Definition SfmlGraphicModule.hpp:64
graphic::IMouse * createMouse(graphic::IWindow *window) override
Definition SfmlGraphicModule.hpp:69
graphic::IWindow2 * window() override
Definition SfmlGraphicModule.hpp:60
void deleteGamepad(graphic::IGamepad *gamepad) override
Definition SfmlGraphicModule.hpp:77
void deletePolygon(graphic::IPolygon *polygon) override
Definition SfmlGraphicModule.hpp:99
const char * name() const override
Definition SfmlGraphicModule.hpp:41
graphic::IText * createText(std::string text, graphic::IFont *font) override
Definition SfmlGraphicModule.hpp:112
~SfmlGraphicModule()=default
void deleteText(graphic::IText *text) override
Definition SfmlGraphicModule.hpp:115
graphic::ITexture * createTexture(std::string path) override
Definition SfmlGraphicModule.hpp:80
void deleteKeyboard(graphic::IKeyboard *keyboard) override
Definition SfmlGraphicModule.hpp:67
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