2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
#ifndef QSFMLCANVAS_HPP
|
|
|
|
#define QSFMLCANVAS_HPP
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Headers
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
#include <SFML/Graphics.hpp>
|
2009-06-17 04:17:56 +08:00
|
|
|
#include <QWidget>
|
|
|
|
#include <QTimer>
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
|
2009-06-17 04:17:56 +08:00
|
|
|
class QEvent;
|
|
|
|
|
2009-01-29 00:18:34 +08:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// QSFMLCanvas allows to run SFML in a Qt control
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
class QSFMLCanvas : public QWidget, public sf::RenderWindow
|
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// Construct the QSFMLCanvas
|
|
|
|
///
|
2009-07-12 06:17:24 +08:00
|
|
|
/// \param size : Initial size of the widget
|
|
|
|
/// \param frameTime : Frame duration, in milliseconds (0 by default)
|
|
|
|
/// \param parent : Parent of the widget (NULL by default)
|
2009-01-29 00:18:34 +08:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
2009-07-12 06:17:24 +08:00
|
|
|
QSFMLCanvas(const QSize& size, unsigned int frameTime = 0, QWidget* parent = NULL);
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// Destructor
|
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
virtual ~QSFMLCanvas();
|
|
|
|
|
|
|
|
private :
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// Notification for the derived class that moment is good
|
|
|
|
/// for doing initializations
|
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
virtual void OnInit();
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// Notification for the derived class that moment is good
|
|
|
|
/// for doing its update and drawing stuff
|
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
virtual void OnUpdate();
|
|
|
|
|
2009-05-04 15:41:39 +08:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// Return the paint engine used by the widget to draw itself
|
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
virtual QPaintEngine* paintEngine() const;
|
|
|
|
|
2009-01-29 00:18:34 +08:00
|
|
|
////////////////////////////////////////////////////////////
|
2009-06-17 04:17:56 +08:00
|
|
|
/// Called each time an event is received by the widget ;
|
|
|
|
/// we use it to catch the Polish event and initialize
|
|
|
|
/// our SFML window
|
2009-01-29 00:18:34 +08:00
|
|
|
///
|
2009-07-12 06:17:24 +08:00
|
|
|
/// \param event : Event's attributes
|
|
|
|
///
|
2009-01-29 00:18:34 +08:00
|
|
|
////////////////////////////////////////////////////////////
|
2009-07-12 06:17:24 +08:00
|
|
|
virtual bool event(QEvent* event);
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// Called when the widget needs to be painted ;
|
|
|
|
/// we use it to display a new frame
|
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
virtual void paintEvent(QPaintEvent*);
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Member data
|
|
|
|
////////////////////////////////////////////////////////////
|
2009-06-17 04:17:56 +08:00
|
|
|
QTimer myTimer; ///< Timer used to update the view
|
2009-01-29 00:18:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // QSFMLCANVAS_HPP
|