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

Author Topic: MFC and SFML Window problem  (Read 24436 times)

0 Members and 1 Guest are viewing this topic.

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #45 on: April 14, 2014, 01:20:29 pm »
So do I have to reset the view even if I haven't defined one?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: MFC and SFML Window problem
« Reply #46 on: April 14, 2014, 01:25:46 pm »
No, you don't have to do anything, it should work. Everything that works for a standalone sf::RenderWindow should work too for an embedded one.
Laurent Gomila - SFML developer

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #47 on: April 14, 2014, 05:13:57 pm »
So what could the problem be? I can see that the window itself is resizing (the clear color is resized OK) but for some reason all is cropped if outside of the original size of the window.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: MFC and SFML Window problem
« Reply #48 on: April 14, 2014, 06:03:34 pm »
Do you get a sf::Event::Resized event?
Laurent Gomila - SFML developer

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #49 on: April 14, 2014, 06:17:24 pm »
Well I am implementing this tutorial http://sfml-dev.org/tutorials/1.6/graphics-qt.php,
and I am getting the resize event in the MyCanvas class.

I have to say that the MyCanvas is itself called as variable in a Qt Widget, thus embedding the MyCanvas (SFML).
« Last Edit: April 14, 2014, 06:18:57 pm by xumepoc »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: MFC and SFML Window problem
« Reply #50 on: April 14, 2014, 09:09:51 pm »
Quote
I am getting the resize event
If you get the sf::Event::Resized event when the widget is resized, then the sf::RenderWindow has it too, and your problem shouldn't happen :-\
Laurent Gomila - SFML developer

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #51 on: April 14, 2014, 10:09:46 pm »
I will make a small demo and will post it here (yes minimal and complete code  ::) :P ;) ;D) so you can test and if possible find the solution for it.

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #52 on: April 15, 2014, 06:04:13 am »
OK, maybe there is something wrong in the implementation that I did.

I am receiving the resize event in the MyCanvas, but how can I be sure that I am also resizing QSFMLCanvas which is the base class of MyCanvas? Because what I am thinking is that MyCanvas is resizing, but the event is not send to QSFMLCanvas too, so it stays the same size.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: MFC and SFML Window problem
« Reply #53 on: April 15, 2014, 07:48:40 am »
It's the SFML window that gives you this event, so it knows it before you ;)
Laurent Gomila - SFML developer

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #54 on: April 15, 2014, 08:24:23 am »
Then I am out of ideas :D

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #55 on: April 15, 2014, 08:56:02 am »
Sorry but can you explain a bit more in details. Because I am resizing the MyCanvas manually when I resize the main window. So basically I am resizing the SFMLCanvas widget. Does that means the RenderWindow also gets that event?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: MFC and SFML Window problem
« Reply #56 on: April 15, 2014, 10:51:30 am »
If your SFML event loop gives you a sf::Event::Resized event when you resize the canvas, then for sure the RenderWindow gets it (because you got the event from it).
Laurent Gomila - SFML developer

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #57 on: April 15, 2014, 09:59:21 pm »
Well I am now sure that the SFML window is resing along with the Qt widget, so the problem is somewhere else. When I check the viewport size I get 1000/1000, is this value real pixels or just indicating 100% from the SFML window. Because it stays constant during the resize

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: MFC and SFML Window problem
« Reply #58 on: April 15, 2014, 10:10:21 pm »
I know nothing about all this Qt stuff, but...

Quote
is this value real pixels or just indicating 100%

Viewports use floats between 0 and 1, with {0,0,1,1} representing the entire window (whatever its pixel size may be).

The view itself has a size measured in pixels (roughly speaking).

I also noticed that the default constructor for sf::View() seems to call reset(FloatRect(0, 0, 1000, 1000)); so maybe that's where your 1000s are coming from.
« Last Edit: April 15, 2014, 10:14:22 pm by Ixrec »

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #59 on: April 15, 2014, 10:35:07 pm »
Well I spoke too soon. It seems that the SFML windows IS NOT resized after all
I did to test it this time
void MyCanvas::resizeEvent(QResizeEvent *event)
{
    qDebug() << "RESIZED Widget" << event->size().width() << event->size().height();


    setSize(sf::Vector2u(event->size().width(),event->size().height()));
    qDebug() << "RESIZED SFML" << getSize().x << getSize().y;
}

which is resulting in this

RESIZED QWidget 502 470
RESIZED SFML 502 470
RESIZED QWidget 504 471
RESIZED SFML 502 470
RESIZED QWidget 504 471
RESIZED SFML 502 470
RESIZED QWidget 521 481
RESIZED SFML 502 470
RESIZED QWidget 521 481
RESIZED SFML 502 470
RESIZED QWidget 535 487
RESIZED SFML 502 470
RESIZED QWidget 535 487
RESIZED SFML 502 470
RESIZED QWidget 546 492
RESIZED SFML 502 470

So where would the problem be?