Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //! @author Adam Emil Skoog
- //! @date 2010-07-13
- #include "Viewport.h"
- #ifdef Q_WS_X11
- #include <Qt/qx11info_x11.h>
- #include <X11/Xlib.h>
- #endif
- namespace smith
- {
- /**
- * Constructor.
- * @param width The width, in pixels, of the viewport.
- * @param height The height, in pixels, of the viewport.
- */
- Viewport::Viewport(const unsigned int &width,
- const unsigned int &height,
- QWidget *const parent)
- :
- QWidget (parent),
- tommy::Window("",tommy::PointI(1024,768),false),
- initialised (false)
- {
- // Set up for rendering.
- setAttribute(Qt::WA_PaintOnScreen);
- setAttribute(Qt::WA_NoSystemBackground);
- // Resize accordingly.
- resize(width,height);
- setFixedSize(width,height);
- // Set the timer.
- timer.setInterval(10);
- immm.LoadFromFile("sprite.png");
- sprrr.SetImage(immm);
- sprrr.SetPosition(440,440);
- }
- /**
- * Inherited show event.
- */
- void Viewport::showEvent(QShowEvent *)
- {
- // Check whether not initialised.
- if (!initialised)
- {
- #ifdef Q_WS_X11
- XFlush(QX11Info::display());
- #endif
- // Create the SFML window with the widget handle.
- Create(reinterpret_cast<sf::WindowHandle *>(winId()));
- // Set up the timer.
- connect(&timer,SIGNAL(timeout()),this,SLOT(repaint()));
- timer.start();
- // Now initialised.
- initialised = true;
- display();
- }
- }
- /**
- * Inherited paint event.
- */
- void Viewport::paintEvent(QPaintEvent *)
- {
- // Update.
- clear(tommy::Colour::BLUE);
- Draw(sprrr);
- display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement