Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Sic

Pages: [1]
1
Graphics / Re: Workaround for resizing window while dragging it
« on: September 08, 2023, 07:05:00 pm »
If I remember correctly, an sf::RenderWindow isn't guaranteed to be fully thread-safe so just be aware of how both threads are using it simultaneously.
Yes, that's part of my problem indeed, I have quite a hard time managing that.

Can I also ask why, in your example, you aren't using the window-specific code to paste the rectangle back onto the window? Note that SFML's display does some behind-the-scenes stuff. Possibly most notable is that it swaps the buffer (a window is double-buffered). Could this have something to so with why you aren't getting the result you expect from your code?
If you are talking about the clear() function, that doesn't change anything in my problem, by default I remove it because it helps me in certain cases but even if I put it back the problem is still the same.

There's a very complicated Windows-only solution posted on the SFML wiki.
This looks interesting thank you, however the code generates several errors because certain types are incompatible with each other in the code.

2
Graphics / Workaround for resizing window while dragging it
« on: September 03, 2023, 08:02:21 pm »
Hello,

SFML does not allow you to modify the window when it is drag by the user, which is extremely annoying.
I'm currently trying to find a workaround but I'm having a lot of trouble, there are errors, OpenGL doesn't seem to like what I'm doing and everything doesn't work as expected...

Could you help me find a workaround for this problem ? Thanks in advance.

Here is my code :

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <Windows.h>

void fonct(sf::RenderWindow * window) {
        sf::Texture texture;
        if (!texture.loadFromFile("Vernet-Battle_of_Hanau.jpg")) std::cout << "erreur" << std::endl;
        sf::Sprite sprite;
        sprite.setTexture(texture);
       
        while (window->isOpen()) {
               
                RECT rect;
                GetWindowRect(window->getSystemHandle(), &rect);
               
                int taille_x = rect.right - rect.left - (GetSystemMetrics(SM_CXMAXIMIZED) - GetSystemMetrics(SM_CXFULLSCREEN));
                int taille_y = rect.bottom - rect.top - (GetSystemMetrics(SM_CYMAXIMIZED) - GetSystemMetrics(SM_CYFULLSCREEN));
               
                sf::FloatRect visibleArea(0.f, 0.f, taille_x, taille_y);
        window->setView(sf::View(visibleArea));
               
                window->draw(sprite);
                window->display();
        }
}

int main() {
       
        sf::Mutex mutex;
        sf::Lock lock(mutex);
       
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
        window.setActive(false);
       
        sf::Thread thread(&fonct, &window);
        thread.launch();
       
        while (window.isOpen()) {
                sf::Event event;
                while (window.pollEvent(event)) {
                       
                        if (event.type == sf::Event::Closed) {
                                window.close();
                        }
                       
                        if (event.type == sf::Event::Resized) {
                                sf::FloatRect visibleArea(0.f, 0.f, event.size.width, event.size.height);
                                window.setView(sf::View(visibleArea));
                        }
                       
                }
        }
       
        thread.wait();
}

Pages: [1]