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

Author Topic: window.getSize() ???  (Read 24817 times)

0 Members and 3 Guests are viewing this topic.

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
window.getSize() ???
« on: June 02, 2015, 12:03:15 pm »
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 )
« Last Edit: June 02, 2015, 12:23:52 pm by Redee »

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: window.getSize() ???
« Reply #1 on: June 02, 2015, 12:48:53 pm »
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 )).

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: window.getSize() ???
« Reply #2 on: June 02, 2015, 01:53:40 pm »
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.

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: window.getSize() ???
« Reply #3 on: June 02, 2015, 03:14:50 pm »
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.
« Last Edit: June 02, 2015, 03:16:42 pm by Redee »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: window.getSize() ???
« Reply #4 on: June 03, 2015, 01:25:58 am »
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;
}
« Last Edit: June 03, 2015, 02:11:11 am by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Re: window.getSize() ???
« Reply #5 on: June 03, 2015, 01:42:06 am »
You original SFML code works for me; it outputs:
150
150
150
150

On which OS?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: AW: Re: window.getSize() ???
« Reply #6 on: June 03, 2015, 02:09:08 am »
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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: window.getSize() ???
« Reply #7 on: June 03, 2015, 11:17:50 am »
I used Sfml 2.1 WinXPsp3

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: window.getSize() ???
« Reply #8 on: June 03, 2015, 08:11:15 pm »
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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: window.getSize() ???
« Reply #9 on: June 03, 2015, 11:06:03 pm »
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..