Files
cardboy/Firmware/sdk/sfml-port/src/SfmlWindow.cpp
2025-07-31 16:12:35 +02:00

38 lines
1.3 KiB
C++

//
// Created by Stepan Usatiuk on 26.07.2025.
//
#include "SfmlWindow.hpp"
void SfmlSurface::draw_pixel_impl(unsigned x, unsigned y, const BwPixel& pixel) {
_image.setPixel({x, y}, pixel.on ? sf::Color::Black : sf::Color::White);
}
unsigned SfmlSurface::get_width_impl() const { return _image.getSize().x; }
unsigned SfmlSurface::get_height_impl() const { return _image.getSize().y; }
EventHandlingResult SfmlSurface::handle(SurfaceResizeEvent event) {
_sf_window.clear();
_image.resize({event.width, event.height});
_texture.resize({event.width, event.height});
_texture.update(_image);
_sprite = sf::Sprite(_texture);
sf::FloatRect view({0, 0}, {static_cast<float>(event.width), static_cast<float>(event.height)});
_sf_window.setView(sf::View(view));
return _window->handle(event);
}
SfmlSurface::SfmlSurface(EventLoop* loop) :
Surface<SfmlSurface, BwPixel>(),
EventQueue<SfmlSurface, KeyboardEvent, SurfaceEvent, SurfaceResizeEvent>(loop, this),
_sf_window(sf::VideoMode({640, 480}), "Test"), _image({640, 480}, sf::Color::White), _texture(_image),
_sprite(_texture) {
_sf_window.setFramerateLimit(60);
_sf_window.clear();
_sf_window.draw(_sprite);
_sf_window.display();
}
SfmlSurface::~SfmlSurface() {}