QSFML
|
Qt widget used as SFML window. More...
#include <QSFMLCanvas.hpp>
Public Member Functions | |
QSFMLWidget (QWidget *parent, const QPoint &Position, const QSize &Size, unsigned int FrameTime=7) | |
Default constructor. More... | |
virtual | ~QSFMLWidget () |
Destructor. More... | |
virtual void | showEvent (QShowEvent *) |
Basic widget init. More... | |
virtual QPaintEngine * | paintEngine () const |
Does nothing. More... | |
virtual void | paintEvent (QPaintEvent *) |
Manages OnUpdate() More... | |
virtual void | OnInit () |
Called after creating sf::RenderWindow. | |
virtual void | OnUpdate () |
Called every frame. | |
virtual void | OnDestroy () |
Called after destroying widget. More... | |
bool | pollEvent (sf::Event &ev) |
Get event. More... | |
Protected Member Functions | |
bool | isInitialized () |
Is initialized? More... | |
sf::Time | getDeltaTime () |
Frame delta time. More... | |
void | pushEvent (sf::Event &ev) |
Push event to queue. More... | |
Qt widget used as SFML window.
This class inherits QWidget and sf::RenderWindow, so sometimes you have to specify which methods you want to use as some of them (eg. setSize) coexist in both. You can use this class to move your SFML apps into Qt widget without too big changes in code.
|
explicit |
Default constructor.
[in] | parent | – Parent widget |
[in] | Position | – Defines QSFMLWidget position |
[in] | Size | – Defines QSFMLWidget size |
[in] | FrameTime | – OnUpdate() call interval |
Sets widget Qt attributes, sets proper size and position, sets up frame timer (requred to measure delta time) and prepares QTimer calling OnUpdate() every FrameTime miliseconds.
|
virtual |
Destructor.
Calls derived classes destructors due to virtual keyword and then OnDestroy() method of exactly this class, not derived one.
|
protected |
Frame delta time.
Returns last frame duration, required to move object smoothly etc.
|
protected |
Is initialized?
Returns wether widget was already initialized or not.
|
virtual |
Called after destroying widget.
It needs to be implemented semi-explictly to work. OnDestroy() is called by destructor, so only derived class destructor can do so. To keep the code clean, use OnDestroy() to clean SFML-related things and destructor to free resources etc.
Use similar code to enable OnDestroy():
|
virtual |
Does nothing.
Exists just to fit Qt requirements
|
virtual |
Manages OnUpdate()
[in] | (noname) | – not used due to class structure |
bool qsf::QSFMLWidget::pollEvent | ( | sf::Event & | ev | ) |
Get event.
[out] | ev | – non-const reference to event |
Checks if in the queue (actually vector) is any event, if no – returns false, otherwise copies event to given &ev and returns true.
Sample usage:
|
protected |
Push event to queue.
[in] | ev | – Reference to event that will be pushed to the queue |
Copies given event to the end of queue (aka vector), use only if you have some specific source of events, eg. when you want to receive them from network etc.
|
virtual |
Basic widget init.
[in] | (noname) | – not used due to class structure |