QSFML
QSFMLCanvas.hpp
Go to the documentation of this file.
1 /* =========================================================== *
2  * QSFML (c) Kamil Koczurek | koczurekk@gmail.com *
3  * GNU GPL v3 License http://www.gnu.org/licenses/gpl-3.0.html *
4  * =========================================================== */
5 
8 
31 #ifndef QSFMLCANVAS_H
32 #define QSFMLCANVAS_H
33 
34 #include <SFML/Graphics/RenderWindow.hpp>
35 #include <SFML/Window/Event.hpp>
36 
37 #include <QMouseEvent>
38 #include <QWheelEvent>
39 #include <QKeyEvent>
40 #include <qdebug.h>
41 #include <QWidget>
42 #include <QTimer>
43 
45 namespace qsf {
52  : public QWidget,
53  public sf::RenderWindow {
54  public:
64  explicit QSFMLWidget(QWidget *parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime = 7); //Defauld frame time should give about 144 FPS
65 
69  virtual ~QSFMLWidget();
70 
78  virtual void showEvent(QShowEvent*);
79 
85  virtual QPaintEngine* paintEngine() const;
86 
94  virtual void paintEvent(QPaintEvent*);
95 
97  virtual void OnInit();
98 
100  virtual void OnUpdate();
101 
120  virtual void OnDestroy();
121 
138  bool pollEvent(sf::Event & ev);
139 
140  private:
141  bool _initialized;
142  QTimer refreshTimer;
143  sf::Time _frameTime;
144  sf::Clock frameClock;
145  std::vector<sf::Event> SfEvents;
146 
147  /* =============== *
148  * EVENTS HANDLING *
149  * =============== */
150  //Mouse buttons
151  void mousePressEvent(QMouseEvent *e);
152  void mouseReleaseEvent(QMouseEvent *e);
153 
154  //Mouse wheel
155  void wheelEvent(QWheelEvent *e);
156 
157  //Keyboard
158  void keyPressEvent(QKeyEvent *e);
159  void keyReleaseEvent(QKeyEvent *e);
160 
161  //Resize event
162  void resizeEvent(QResizeEvent *event);
163 
164  protected:
168  bool isInitialized();
169 
173  sf::Time getDeltaTime();
174 
181  void pushEvent(sf::Event & ev);
182  };
183 }
184 #endif // QSMLCANVAS_H
virtual void paintEvent(QPaintEvent *)
Manages OnUpdate()
Definition: QSFMLCanvas.cpp:50
virtual void showEvent(QShowEvent *)
Basic widget init.
Definition: QSFMLCanvas.cpp:34
void pushEvent(sf::Event &ev)
Push event to queue.
Definition: QSFMLCanvas.cpp:69
bool isInitialized()
Is initialized?
Definition: QSFMLCanvas.cpp:73
QSFMLWidget(QWidget *parent, const QPoint &Position, const QSize &Size, unsigned int FrameTime=7)
Default constructor.
Definition: QSFMLCanvas.cpp:14
bool pollEvent(sf::Event &ev)
Get event.
Definition: QSFMLCanvas.cpp:60
Namespace containing all qsf classes and methods.
Definition: Image.cpp:3
virtual void OnDestroy()
Called after destroying widget.
Definition: QSFMLCanvas.cpp:58
sf::Time getDeltaTime()
Frame delta time.
Definition: QSFMLCanvas.cpp:77
virtual QPaintEngine * paintEngine() const
Does nothing.
Definition: QSFMLCanvas.cpp:47
virtual void OnUpdate()
Called every frame.
Definition: QSFMLCanvas.cpp:57
virtual void OnInit()
Called after creating sf::RenderWindow.
Definition: QSFMLCanvas.cpp:56
Qt widget used as SFML window.
Definition: QSFMLCanvas.hpp:51
virtual ~QSFMLWidget()
Destructor.
Definition: QSFMLCanvas.cpp:29