Cleaning up

This commit is contained in:
AnonymusRaccoon
2020-02-13 17:13:46 +01:00
parent 49b1cab5a8
commit 6fca2293ee
3 changed files with 39 additions and 31 deletions
+31 -25
View File
@@ -12,52 +12,58 @@
namespace ComSquare::Renderer
{
SFRenderer::SFRenderer(unsigned int height, unsigned int width, int maxFPS)
{
sf::Image icon;
this->shouldExit = false;
this->_videoMode = {width, height, 32};
this->_window.create(this->_videoMode, "ComSquare Emulator", sf::Style::Default);
if (icon.loadFromFile("../ressources/Logo.png"))
this->_window.setIcon(314, 314, icon.getPixelsPtr());
this->_window.setFramerateLimit(maxFPS);
this->_texture.create(width, height);
this->_sprite.setTexture(this->_texture);
this->_pixelBuffer = new sf::Color[height * width];
}
SFRenderer::~SFRenderer()
{
delete []this->_pixelBuffer;
}
void SFRenderer::setWindowName(std::string newWindowName)
{
this->window.setTitle(newWindowName + " - ComSquare");
this->_window.setTitle(newWindowName + " - ComSquare");
}
void SFRenderer::drawScreen()
{
this->texture.update(reinterpret_cast<sf::Uint8 *>(this->pixelBuffer));
this->sprite.setTexture(this->texture);
this->window.draw(this->sprite);
this->window.display();
this->_texture.update(reinterpret_cast<sf::Uint8 *>(this->_pixelBuffer));
this->_sprite.setTexture(this->_texture);
this->_window.draw(this->_sprite);
this->_window.display();
}
void SFRenderer::putPixel(unsigned y, unsigned x, uint32_t rgba)
{
if (x >= this->videoMode.width)
throw InvalidPixelPosition("Width", x, this->videoMode.width);
if (y >= this->videoMode.height)
throw InvalidPixelPosition("Height", y, this->videoMode.height);
if (x >= this->_videoMode.width)
throw InvalidPixelPosition("Width", x, this->_videoMode.width);
if (y >= this->_videoMode.height)
throw InvalidPixelPosition("Height", y, this->_videoMode.height);
sf::Color pixels;
pixels.r = rgba >> 24U;
pixels.g = rgba >> 16U;
pixels.b = rgba >> 8U;
pixels.a = rgba >> 0U;
this->pixelBuffer[this->videoMode.width * y + x] = pixels;
}
SFRenderer::SFRenderer(unsigned int height, unsigned int width, int maxFPS)
{
sf::Image icon;
this->shouldExit = false;
this->videoMode = {width, height, 32};
this->window.create(this->videoMode, "ComSquare Emulator", sf::Style::Default);
if (icon.loadFromFile("../ressources/Logo.png"))
this->window.setIcon(314, 314, icon.getPixelsPtr());
this->window.setFramerateLimit(maxFPS);
this->texture.create(width, height);
this->sprite.setTexture(this->texture);
this->pixelBuffer = new sf::Color[height * width];
this->_pixelBuffer[this->_videoMode.width * y + x] = pixels;
}
void SFRenderer::getEvents()
{
sf::Event event;
while (this->window.pollEvent(event)) {
while (this->_window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
this->shouldExit = true;
break;