-
RenderWindow win(VideoMode(400,200),"123");
Event ev;
win.setSize(Vector2u(150,150));
cout << win.GetSize().x << endl;
cout << win.GetSize().y << endl;
while(win.pollEvent(ev)){}
cout << win.GetSize().x << endl;
cout << win.GetSize().y << endl;
400
200
150
150
And question...
We directly call function to resize window, why window sizes changes only after Event logic.
Maybe some function can detect changed size before Event ?
I can get this using winAPI.... using win.getSystemHandle()... but its.... ok try do something )
-
You can do this simply like this solution >
#include <Windows.h>
#include <iostream>
using namespace std;
#include "SFML/Graphics.hpp"
using namespace sf;
RenderWindow wIn(VideoMode(400,200), "MyWindow");
wIn.SetSize(Vector2u(150,150));
WINDOWINFO wiInfo;
GetWindowInfo(wIn.getSystemHandle(), &wiInfo);
cout << "Window Render Area width" << endl;
cout << wiInfo.rcClient.right - wiInfo.rcClient.left << endl;
cout << "Window Render Area height" << endl;
cout << wiInfo.rcClient.bottom - wiInfo.rcClient.top << endl;
But for secret I its added to my Sfml Redee's mod )).
-
When resizing the window, you're actually telling Windows to resize the window. The window itself won't query it's size and rather wait for the resize event to happen/be processed (this way you're skipping all the logic from your second code snippet), which makes the whole thing a lot faster when working real-time with it.
-
In my example is actually for pre-Logic before game loop...
And its no often uses - only before build window and if you change border of window or in game options select and set new resolution.
Thats all and its fully working for me.
-
You original SFML code works for me; it outputs (on Windows 7 with SFML 2.3):
150
150
150
150
Here's a compilable version in case anyone else wants to try it:
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow win(sf::VideoMode(400, 200), "123");
sf::Event ev;
win.setSize(sf::Vector2u(150, 150));
std::cout << win.getSize().x << std::endl;
std::cout << win.getSize().y << std::endl;
while (win.pollEvent(ev)){}
std::cout << win.getSize().x << std::endl;
std::cout << win.getSize().y << std::endl;
return EXIT_SUCCESS;
}
-
You original SFML code works for me; it outputs:
150
150
150
150
On which OS?
-
You original SFML code works for me
On which OS?
I'm sorry; I should have said.
I'm using Windows. That's Windows 7 with release version of SFML 2.3.
-
I used Sfml 2.1 WinXPsp3
-
It's possible, then, that it has been fixed. You should try out v2.3 to see if it still causes this error for you.
-
Yes here in 2.3 version fixed this.
This implementation like I wrote above.
https://github.com/SFML/SFML/blob/master/src/SFML/Window/Win32/WindowImplWin32.cpp#L284
Its uses rcClient values too..