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

Author Topic: SFML + GUI Issue  (Read 8628 times)

0 Members and 1 Guest are viewing this topic.

Kharyus

  • Newbie
  • *
  • Posts: 7
    • View Profile
SFML + GUI Issue
« on: July 30, 2015, 05:56:48 pm »
Hello. :)
I'm having trouble using SFML with PyQt. I assume this is not something specific to the integration with PyQt since i had the same problem when i was trying to use SFML + WxWidgets.

Basically the problem is that when i resize my 'SFML + GUI' window the paintable area does not follow the new dimensions and a part of the window just stays black. Another issue is that when i resize the window, it grows upwards instead of downwards.
http://www.tiikoni.com/tis/view/?id=ad30d78
http://www.tiikoni.com/tis/view/?id=ea4d499
(the koala is rotating)

I wanted to know if there are some flags i need to adjust, if anyone had this problem before, or if anyone has any lead towards the issue. Thanks for your time.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: SFML + GUI Issue
« Reply #1 on: August 03, 2015, 09:31:26 am »
What SFML version and what platform?

Kharyus

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: SFML + GUI Issue
« Reply #2 on: August 03, 2015, 04:49:36 pm »
Hi Tank, thanks for taking the time to reply.

I'm currently getting these issues using PySFML 1.3.0, Windows 7 64-bit, Python 3.3, PyQt4.
Got those same issues before using SFML-2.1, Windows 7 64-bit, WxWidgets and also trying it on my Debian laptop.
I have tried to delete and recreate again the window on the resize event, the paintable area would then be the size of the new window but it was an awful solution with many other issues.

The main reason i'm trying to integrate a GUI with SFML is because i want a multi-platform file browser on that "Open File" button. I'd not mind switching to yet another GUI library if it has the feature i need and it works.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: SFML + GUI Issue
« Reply #3 on: August 07, 2015, 09:59:36 am »
If it also happened with SFML 2.1, then I have no idea, sorry. :|

Kharyus

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: SFML + GUI Issue
« Reply #4 on: August 14, 2015, 01:25:49 pm »
Managed to make it work.  ;D

It's frustrating and embarassing :-[, the solution was what i was trying to do, but in a way that actually works. I was trying to change the "_HandledWindow" by its size, height, width and view proprierties, passing coordinates, but what i was actually supposed to do is
_HandledWindow.view.size = (x,y)
Did not even need this in the end, just needed to use the solution below.

To make it work, every time that the window is resized, you must pass a new viewport to the sfml window so it knows it's new dimensions. This also fix the "growing upwards instead of downwards" problem.
# Main Frame
class MainFrame(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        #The reason this is here is to avoid instanciating too many objects
        self.view = sf.View()

    def resizeEvent(self,resizeEvent):
        print("resized")
        #The line below makes the visible area expand/retract instead of zooming in/out
        self.view.reset(sf.Rectangle((0,0),(sfmlwidgetpointer.width(),sfmlwidget.height())))
        self.view.viewport = sf.Rectangle((0,0),(1,1))
        sfmlwidget._HandledWindow.view = self.view

mainframe = MainFrame()
...
sfmlwidget = SFMLCanvas(mainframe, position, size)
...

The problem was the programmer today, who could've known? Nobody.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: SFML + GUI Issue
« Reply #5 on: August 15, 2015, 08:12:07 pm »
Ahhhh, that, I think I misunderstood the problem.

This SFML tutorial even mentions the "problem": http://www.sfml-dev.org/tutorials/2.3/window-events.php. Might be enough to adjust the view in your case.

"size =..." might not work because the property returns a copy of the size. This is very tricky and a pitfall I ran into multiple times, e.g. by doing "sprite.position.x = 5" - this does NOT work. I don't know if it's intended, though.

Sonkun, please enlight us. ;)

 

anything