SFML working nicely can open and close the window and set a title

This commit is contained in:
Clément Le Bihan
2020-02-04 15:42:19 +01:00
parent 98168435c1
commit 250f01ec77
4 changed files with 20 additions and 2 deletions
+4
View File
@@ -21,6 +21,10 @@ int main(int argc, char **argv)
bus.mapComponents(snes);
Renderer::SFRenderer renderer(600, 800, 60);
renderer.setWindowName("Fire Emblem : Three Houses");
while (!renderer.shouldExit) {
renderer.getEvents();
}
return 0;
}
+1 -1
View File
@@ -14,7 +14,7 @@ namespace ComSquare::Renderer
//! @brief Set a new name to the window, if there is already a name it will be overwrite
virtual void setWindowName(std::string) = 0;
//! @brief Tells to the program if the window has been closed, and therefore if he should stop
bool shouldExit;
bool shouldExit = true;
//! @brief Render the buffer to the window
virtual void drawScreen() = 0;
//! @brief Set a pixel to the coordinates x, y with the color rgba
+13 -1
View File
@@ -8,12 +8,13 @@
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics//RenderWindow.hpp>
#include <iostream>
namespace ComSquare::Renderer
{
void SFRenderer::setWindowName(std::string newWindowName)
{
this->window.setTitle(newWindowName);
this->window.setTitle(newWindowName + " - ComSquare");
}
void SFRenderer::drawScreen()
@@ -40,4 +41,15 @@ namespace ComSquare::Renderer
this->texture.create(width, height);
}
void SFRenderer::getEvents()
{
sf::Event event;
while (this->window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
this->shouldExit = true;
break;
}
}
}
}
+2
View File
@@ -39,6 +39,8 @@ namespace ComSquare::Renderer
//! @param Y vertical index.
//! @param rgba The color of the pixel.
void putPixel(int x, int y, uint8_t rgba) override ;
//! @brief Get the inputs from the Window
void getEvents();
//! @brief Constructor that return the window component of the SFML.
//! @param height height of the window.
//! @param width width of the window.