mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
x11 thread workaround
This commit is contained in:
@@ -9,31 +9,33 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
EventLoop loop;
|
EventLoop loop;
|
||||||
SfmlSurface surface(&loop);
|
|
||||||
|
|
||||||
surface.set_window<GridWindow<SfmlSurface, BwPixel, 2, 2>>();
|
|
||||||
|
|
||||||
GridWindow<SfmlSurface, BwPixel, 2, 2>* window =
|
|
||||||
static_cast<GridWindow<SfmlSurface, BwPixel, 2, 2>*>(surface.get_window());
|
|
||||||
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(0, 0, &loop, "hello");
|
|
||||||
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(0, 1, &loop, "hello1");
|
|
||||||
window->set_window<GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>>(1, 0);
|
|
||||||
GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>* window2 =
|
|
||||||
static_cast<GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>*>(
|
|
||||||
window->get_subsurface(1, 0).get_window());
|
|
||||||
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(1, 1, &loop, "hello3");
|
|
||||||
|
|
||||||
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
|
|
||||||
0, 0, &loop, "hello2");
|
|
||||||
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
|
|
||||||
0, 1, &loop, "hello4");
|
|
||||||
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
|
|
||||||
1, 0, &loop, "hello5");
|
|
||||||
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
|
|
||||||
1, 1, &loop, "hello6");
|
|
||||||
|
|
||||||
|
SfmlSurface* surface_ptr;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
std::thread loop_thread{[&] {
|
std::thread loop_thread{[&] {
|
||||||
|
SfmlSurface surface(&loop);
|
||||||
|
surface_ptr = &surface;
|
||||||
|
|
||||||
|
surface.set_window<GridWindow<SfmlSurface, BwPixel, 2, 2>>();
|
||||||
|
|
||||||
|
GridWindow<SfmlSurface, BwPixel, 2, 2>* window =
|
||||||
|
static_cast<GridWindow<SfmlSurface, BwPixel, 2, 2>*>(surface.get_window());
|
||||||
|
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(0, 0, &loop, "hello");
|
||||||
|
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(0, 1, &loop, "hello1");
|
||||||
|
window->set_window<GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>>(1, 0);
|
||||||
|
GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>* window2 =
|
||||||
|
static_cast<GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>*>(
|
||||||
|
window->get_subsurface(1, 0).get_window());
|
||||||
|
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(1, 1, &loop, "hello3");
|
||||||
|
|
||||||
|
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
|
||||||
|
0, 0, &loop, "hello2");
|
||||||
|
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
|
||||||
|
0, 1, &loop, "hello4");
|
||||||
|
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
|
||||||
|
1, 0, &loop, "hello5");
|
||||||
|
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
|
||||||
|
1, 1, &loop, "hello6");
|
||||||
loop.run([&] {
|
loop.run([&] {
|
||||||
surface._sf_window.clear();
|
surface._sf_window.clear();
|
||||||
surface._texture.update(surface._image);
|
surface._texture.update(surface._image);
|
||||||
@@ -45,19 +47,19 @@ int main() {
|
|||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
|
|
||||||
while (surface._sf_window.isOpen()) {
|
while (surface_ptr->_sf_window.isOpen()) {
|
||||||
while (const std::optional event = surface._sf_window.pollEvent()) {
|
while (const std::optional event = surface_ptr->_sf_window.pollEvent()) {
|
||||||
if (event->is<sf::Event::Closed>()) {
|
if (event->is<sf::Event::Closed>()) {
|
||||||
surface._sf_window.close();
|
surface_ptr->_sf_window.close();
|
||||||
loop.push(LoopQuitEvent{});
|
loop.push(LoopQuitEvent{});
|
||||||
}
|
}
|
||||||
if (event->is<sf::Event::Resized>()) {
|
if (event->is<sf::Event::Resized>()) {
|
||||||
auto newSize = event->getIf<sf::Event::Resized>()->size;
|
auto newSize = event->getIf<sf::Event::Resized>()->size;
|
||||||
surface.push(SurfaceResizeEvent{newSize.x, newSize.y});
|
surface_ptr->push(SurfaceResizeEvent{newSize.x, newSize.y});
|
||||||
}
|
}
|
||||||
if (event->is<sf::Event::KeyPressed>()) {
|
if (event->is<sf::Event::KeyPressed>()) {
|
||||||
auto key = event->getIf<sf::Event::KeyPressed>();
|
auto key = event->getIf<sf::Event::KeyPressed>();
|
||||||
surface.push(KeyboardEvent{static_cast<Key>(key->code)});
|
surface_ptr->push(KeyboardEvent{static_cast<Key>(key->code)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user