10 #include <SFML/Audio.hpp>
11 #include <SFML/Graphics.hpp>
14 #include "unordered_map"
21 #include <imgui-SFML.h>
50 sf::Clock &
getClock()
override {
return _clock; }
66 const sf::Texture &
getTexture()
const override {
return _texture; };
72 _texture.loadFromFile(filename, area.
getBaseRect());
92 const sf::View &
getBaseView()
const override {
return _view; }
100 auto center = _view.getCenter();
109 _view.setViewport(sf::FloatRect{startingPoint.
x, startingPoint.
y, width, height});
117 class Window :
public IWindow<sf::RenderWindow, sf::View, sf::Event, sf::Drawable>
129 Debug::DebugMenu &debugMenu,
int width = 1920,
int height = 1080,
const std::string &title =
"Game window")
130 : _window(sf::VideoMode(width, height), title), _title(title), _debugMenu(debugMenu)
134 Window(
int width = 1920,
int height = 1080,
const std::string &title =
"Game window")
135 : _window(sf::VideoMode(width, height), title), _title(title)
141 const sf::RenderWindow &
getWindow()
const override {
return _window; }
144 sf::RenderWindow &
getWindow()
override {
return _window; }
147 void draw(
const sf::Drawable &drawable)
override { _window.draw(drawable); }
156 bool isOpen()
const override {
return _window.isOpen(); }
162 bool result = _window.pollEvent(event.
getEvent());
164 ImGui::SFML::ProcessEvent(_window, event.
getEvent());
169 void close()
override { _window.close(); }
171 void display()
override { _window.display(); };
173 void clear()
override { _window.clear(); };
178 void create(
int width,
int height,
const std::string &title)
override
180 _window.create(sf::VideoMode(width, height), title);
188 sf::Vector2f coord = _window.mapPixelToCoords(sf::Vector2i(pos.
x, pos.
y));
194 void initDebug()
override
196 if (!ImGui::SFML::Init(_window))
197 throw Error::ImGuiSFMLInitError();
198 ImGuiIO &io = ImGui::GetIO();
199 io.IniFilename = NULL;
200 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
203 void shutdownDebug()
override { ImGui::SFML::Shutdown(); }
205 void drawDebug()
override
207 ImGui::SFML::Update(_window, _debugClock.getClock().restart());
209 ImGui::SFML::Render(_window);
214 sf::RenderWindow _window;
217 Debug::DebugMenu &_debugMenu;
232 const sf::Text &
getText()
const {
return _text; }
237 void load(
const std::string &text,
const sf::Font &font,
size_t size)
239 _text.setString(text);
241 _text.setCharacterSize(size);
245 _text.setPosition(
static_cast<int>(position.
x),
static_cast<int>(position.
y));
247 void setString(
const std::string &
string) { _text.setString(
string); }
251 return Rectf(_text.getLocalBounds().left, _text.getLocalBounds().top, _text.getLocalBounds().width,
252 _text.getLocalBounds().height);
268 const sf::Music &
getMusic()
const override {
return _music; }
271 void load(
const std::string &filename)
273 _music.openFromFile(filename);
274 _filename = filename;
278 if (_music.getStatus() == sf::Music::Status::Stopped) {
288 std::string _filename;
301 const sf::Font &
getFont()
const override {
return _font; };
304 void load(
const std::string &filename)
override { _font.loadFromFile(filename); }
319 const sf::Sprite &
getSprite()
const override {
return _sprite; };
325 _sprite.setTexture(texture.
getTexture(), resetRect);
331 _sprite.setPosition(sf::Vector2f{position.
x, position.
y});
342 void setScale(
const float &x,
const float &y) { _sprite.setScale(x, y); };
352 static const std::unordered_map<Input::Keyboard::Key, sf::Keyboard::Key>
sfKeys;
358 bool isReleased = prevKeyStates[key] && sf::Keyboard::isKeyPressed(sfKeys.at(key)) ==
false;
359 prevKeyStates[key] = sf::Keyboard::isKeyPressed(sfKeys.at(key));
365 static std::unordered_map<Input::Keyboard::Key, bool> prevKeyStates;
Definition: SfmlTypes.hpp:44
Clock()=default
Default constructor for Clock.
sf::Clock & getClock() override
Returns the wrapped sf::Clock.
Definition: SfmlTypes.hpp:50
Class representing a font wrapper for sf::Font.
Definition: SfmlTypes.hpp:293
Font()
Default constructor for Font.
Definition: SfmlTypes.hpp:296
~Font()=default
Destructor for Font.
const sf::Font & getFont() const override
Returns the wrapped sf::Font.
Definition: SfmlTypes.hpp:301
void load(const std::string &filename) override
Loads the font from a file.
Definition: SfmlTypes.hpp:304
Interface for clock.
Definition: RenderInterfaces.hpp:48
Interface for event.
Definition: RenderInterfaces.hpp:122
virtual T & getEvent()=0
Get the event stored.
Interfaces for the text font.
Definition: RenderInterfaces.hpp:19
interface for music handling
Definition: RenderInterfaces.hpp:79
Interface for rectangle.
Definition: RenderInterfaces.hpp:35
virtual const M< T > getBaseRect() const =0
Get the rectangle stored.
Interface for sprite.
Definition: RenderInterfaces.hpp:99
Interface for texture.
Definition: RenderInterfaces.hpp:62
virtual const T & getTexture() const =0
Get the texture stored.
Interface for view.
Definition: RenderInterfaces.hpp:133
virtual const T & getBaseView() const =0
Get the view stored.
Interface for the window.
Definition: RenderInterfaces.hpp:152
Class representing a music wrapper for sf::Music.
Definition: SfmlTypes.hpp:260
~Music()=default
Destructor for Music.
const sf::Music & getMusic() const override
Returns the wrapped sf::Music.
Definition: SfmlTypes.hpp:268
Music()
Default constructor for Music.
Definition: SfmlTypes.hpp:263
const std::string & getFilename() const
Returns the filename of the loaded music.
Definition: SfmlTypes.hpp:284
void load(const std::string &filename)
Loads music from a file.
Definition: SfmlTypes.hpp:271
void play() override
play the loaded music
Definition: SfmlTypes.hpp:276
T height
Definition: Rect.hpp:40
T top
Definition: Rect.hpp:38
T left
Definition: Rect.hpp:37
const sf::Rect< T > getBaseRect() const override
get the rect stored in the class
Definition: Rect.hpp:44
T width
Definition: Rect.hpp:39
Class representing a custom event wrapper for sf::Event.
Definition: SfmlTypes.hpp:29
SEvent()=default
Default constructor for SEvent.
sf::Event & getEvent() override
Returns the wrapped sf::Event.
Definition: SfmlTypes.hpp:35
sf::Event::EventType & type
Reference to the EventType of the wrapped sf::Event.
Definition: SfmlTypes.hpp:37
Class representing a sprite wrapper for sf::Sprite with additional functionality.
Definition: SfmlTypes.hpp:311
void setTextureRect(const IRect< int, sf::Rect > &newRect) override
Sets the texture rectangle of the sprite.
Definition: SfmlTypes.hpp:335
void load(const ITexture< sf::Texture, sf::Rect > &texture, bool resetRect=false) override
Loads the sprite with a specified texture and optional reset of the texture rectangle.
Definition: SfmlTypes.hpp:323
void setScale(const float &x, const float &y)
Definition: SfmlTypes.hpp:342
Sprite()
Default constructor for Sprite.
Definition: SfmlTypes.hpp:314
~Sprite()=default
Destructor for Sprite.
void setRect(const Recti &rect)
Sets the texture rectangle of the sprite using a custom rectangle.
Definition: SfmlTypes.hpp:341
void setPosition(const Vector2< float > position) override
Sets the position of the sprite.
Definition: SfmlTypes.hpp:329
const sf::Sprite & getSprite() const override
Returns the wrapped sf::Sprite.
Definition: SfmlTypes.hpp:319
Class representing a text wrapper for sf::Text with basic functionality.
Definition: SfmlTypes.hpp:224
void load(const std::string &text, const sf::Font &font, size_t size)
Loads text with specified font and size.
Definition: SfmlTypes.hpp:237
Text()
Default constructor for Text.
Definition: SfmlTypes.hpp:227
~Text()=default
Destructor for Text.
void setString(const std::string &string)
Definition: SfmlTypes.hpp:247
Rectf getLocalBounds() const
Definition: SfmlTypes.hpp:249
void setPosition(const Vector2< float > &position)
Definition: SfmlTypes.hpp:243
const sf::Text & getText() const
Returns the wrapped sf::Text.
Definition: SfmlTypes.hpp:232
Class representing a texture wrapper for sf::Texture with an associated area.
Definition: SfmlTypes.hpp:58
void load(const std::string &filename, const IRect< int, sf::Rect > &area) override
Loads a texture from a file with a specified area.
Definition: SfmlTypes.hpp:70
~Texture()=default
Destructor for Texture.
Texture()=default
Default constructor for Texture.
const sf::Texture & getTexture() const override
Returns the wrapped sf::Texture.
Definition: SfmlTypes.hpp:66
T y
Definition: Vector.hpp:101
T x
Definition: Vector.hpp:98
Class representing a view wrapper for sf::View.
Definition: SfmlTypes.hpp:81
void setViewPort(const Vector2< float > &startingPoint, float width, float height) override
set a viewport rectangle
Definition: SfmlTypes.hpp:107
View(const Rect< float > &rect)
Constructor for View.
Definition: SfmlTypes.hpp:87
Vector2< float > getCenter() const override
get the center of the view
Definition: SfmlTypes.hpp:98
View()=default
default constructor
const sf::View & getBaseView() const override
Returns the wrapped sf::View.
Definition: SfmlTypes.hpp:92
void setCenter(const Vector2< float > ¢er) override
set center of the view
Definition: SfmlTypes.hpp:95
~View()=default
Destructor for View.
Class representing a window wrapper for sf::RenderWindow with additional functionality.
Definition: SfmlTypes.hpp:118
Window(int width=1920, int height=1080, const std::string &title="Game window")
Constructor for Window.
Definition: SfmlTypes.hpp:134
sf::RenderWindow & getWindow() override
Returns the wrapped sf::RenderWindow.
Definition: SfmlTypes.hpp:144
Vector2< float > mapPixelToCoords(const Vector2< int > &pos)
Maps pixel coordinates to world coordinates.
Definition: SfmlTypes.hpp:186
void setFramerateLimit(const float rate) override
Set the maximum framerate of the window.
Definition: SfmlTypes.hpp:153
bool isOpen() const override
Checks if the window is open.
Definition: SfmlTypes.hpp:156
void display() override
Displays the contents of the window.
Definition: SfmlTypes.hpp:171
void draw(const sf::Drawable &drawable) override
Draws a sf::Drawable object on the window.
Definition: SfmlTypes.hpp:147
bool pollEvent(IEvent< sf::Event > &event) override
Polls and retrieves the next event.
Definition: SfmlTypes.hpp:160
void close() override
Closes the window.
Definition: SfmlTypes.hpp:169
void clear() override
Clears the contents of the window.
Definition: SfmlTypes.hpp:173
void create(int width, int height, const std::string &title) override
Creates a new window with the specified dimensions and title.
Definition: SfmlTypes.hpp:178
const sf::RenderWindow & getWindow() const override
Returns the wrapped sf::RenderWindow.
Definition: SfmlTypes.hpp:141
void setView(const IView< sf::View > &view) override
Sets the view of the window.
Definition: SfmlTypes.hpp:150
Definition: AssetManager.hpp:15
std::size_t EventType
value to describe the event type
Definition: Event.hpp:23
Rect< float > Rectf
Definition: Rect.hpp:88
Event
enum of all event types
Definition: Event.hpp:30