Advertisement
Guest User

Untitled

a guest
Jul 13th, 2010
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. //! @author Adam Emil Skoog
  2. //! @date   2010-07-13
  3.  
  4. #include "Viewport.h"
  5.  
  6. #ifdef Q_WS_X11
  7.     #include <Qt/qx11info_x11.h>
  8.     #include <X11/Xlib.h>
  9. #endif
  10.  
  11. namespace smith
  12.  {
  13.     /**
  14.      * Constructor.
  15.      * @param width  The width, in pixels, of the viewport.
  16.      * @param height The height, in pixels, of the viewport.
  17.      */
  18.     Viewport::Viewport(const unsigned int &width,
  19.                        const unsigned int &height,
  20.                        QWidget *const parent)
  21.     :
  22.     QWidget      (parent),
  23.     tommy::Window("",tommy::PointI(1024,768),false),
  24.     initialised  (false)
  25.      {
  26.         // Set up for rendering.
  27.         setAttribute(Qt::WA_PaintOnScreen);
  28.         setAttribute(Qt::WA_NoSystemBackground);
  29.  
  30.         // Resize accordingly.
  31.         resize(width,height);
  32.         setFixedSize(width,height);
  33.  
  34.         // Set the timer.
  35.         timer.setInterval(10);
  36.        
  37.         immm.LoadFromFile("sprite.png");
  38.         sprrr.SetImage(immm);
  39.         sprrr.SetPosition(440,440);
  40.      }
  41.  
  42.     /**
  43.      * Inherited show event.
  44.      */
  45.     void Viewport::showEvent(QShowEvent *)
  46.      {
  47.         // Check whether not initialised.
  48.         if (!initialised)
  49.          {
  50.             #ifdef Q_WS_X11
  51.                 XFlush(QX11Info::display());
  52.             #endif
  53.  
  54.             // Create the SFML window with the widget handle.
  55.             Create(reinterpret_cast<sf::WindowHandle *>(winId()));
  56.  
  57.             // Set up the timer.
  58.             connect(&timer,SIGNAL(timeout()),this,SLOT(repaint()));
  59.             timer.start();
  60.  
  61.             // Now initialised.
  62.             initialised = true;
  63.  
  64.             display();
  65.          }
  66.      }
  67.  
  68.     /**
  69.      * Inherited paint event.
  70.      */
  71.     void Viewport::paintEvent(QPaintEvent *)
  72.      {
  73.         // Update.
  74.         clear(tommy::Colour::BLUE);
  75.         Draw(sprrr);
  76.         display();
  77.      }
  78.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement