Back to index

libsfml  1.6+dfsg2
Public Member Functions | Private Member Functions | Private Attributes
QSFMLCanvas Class Reference

QSFMLCanvas allows to run SFML in a Qt control /////////////////////////////////////////////////////////. More...

#include <QSFMLCanvas.hpp>

Inheritance diagram for QSFMLCanvas:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 QSFMLCanvas (const QSize &Size, unsigned int FrameTime=0, QWidget *Parent=NULL)
 Construct the QSFMLCanvas.
virtual ~QSFMLCanvas ()
 Destructor.

Private Member Functions

virtual void OnInit ()
 Notification for the derived class that moment is good for doing initializations.
virtual void OnUpdate ()
 Notification for the derived class that moment is good for doing its update and drawing stuff.
virtual QPaintEngine * paintEngine () const
 Return the paint engine used by the widget to draw itself.
virtual bool event (QEvent *Event)
 Called each time an event is received by the widget ; we use it to catch the Polish event and initialize our SFML window.
virtual void paintEvent (QPaintEvent *)
 Called when the widget needs to be painted ; we use it to display a new frame.

Private Attributes

QTimer myTimer
 Timer used to update the view.

Detailed Description

QSFMLCanvas allows to run SFML in a Qt control /////////////////////////////////////////////////////////.

Definition at line 18 of file QSFMLCanvas.hpp.


Constructor & Destructor Documentation

QSFMLCanvas::QSFMLCanvas ( const QSize &  Size,
unsigned int  FrameTime = 0,
QWidget *  Parent = NULL 
)

Construct the QSFMLCanvas.

Construct the QSFMLCanvas /////////////////////////////////////////////////////////.

Parameters:
Size: Initial size of the widget
FrameTime: Frame duration, in milliseconds (0 by default)
Parent: Parent of the widget (NULL by default)

/////////////////////////////////////////////////////////

Definition at line 18 of file QSFMLCanvas.cpp.

                                                                                   :
QWidget(Parent)
{
    // Resize the widget
    resize(Size);

    // Setup some states to allow direct rendering into the widget
    setAttribute(Qt::WA_PaintOnScreen);
    setAttribute(Qt::WA_OpaquePaintEvent);
    setAttribute(Qt::WA_NoSystemBackground);

    // Set strong focus to enable keyboard events to be received
    setFocusPolicy(Qt::StrongFocus);

    // Setup the timer
    myTimer.setInterval(FrameTime);
}

Destructor.

Destructor /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 40 of file QSFMLCanvas.cpp.

{
    // Nothing to do...
}

Member Function Documentation

bool QSFMLCanvas::event ( QEvent *  Event) [private, virtual]

Called each time an event is received by the widget ; we use it to catch the Polish event and initialize our SFML window.

Called each time an event is received by the widget ; we use it to catch the Polish event and initialize our SFML window /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 80 of file QSFMLCanvas.cpp.

{
    if (Event->type() == QEvent::Polish)
    {
        // Under X11, we need to flush the commands sent to the server to ensure that
        // SFML will get an updated view of the windows
        #ifdef Q_WS_X11
            XFlush(QX11Info::display());
        #endif

        // Create the SFML window with the widget handle
        Create(winId());

        // Let the derived class do its specific stuff
        OnInit();

        // Setup the timer to trigger a refresh at specified framerate
        connect(&myTimer, SIGNAL(timeout()), this, SLOT(repaint()));
        myTimer.start();
    }

    return QWidget::event(Event);
}

Here is the call graph for this function:

void QSFMLCanvas::OnInit ( ) [private, virtual]

Notification for the derived class that moment is good for doing initializations.

Notification for the derived class that moment is good for doing initializations /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Reimplemented in MyCanvas.

Definition at line 50 of file QSFMLCanvas.cpp.

{
    // Nothing to do by default...
}

Here is the caller graph for this function:

void QSFMLCanvas::OnUpdate ( ) [private, virtual]

Notification for the derived class that moment is good for doing its update and drawing stuff.

Notification for the derived class that moment is good for doing its update and drawing stuff /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Reimplemented in MyCanvas, and MyCanvas.

Definition at line 60 of file QSFMLCanvas.cpp.

{
    // Nothing to do by default...
}

Here is the caller graph for this function:

QPaintEngine * QSFMLCanvas::paintEngine ( ) const [private, virtual]

Return the paint engine used by the widget to draw itself.

Return the paint engine used by the widget to draw itself /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 69 of file QSFMLCanvas.cpp.

{
    return 0;
}
void QSFMLCanvas::paintEvent ( QPaintEvent *  ) [private, virtual]

Called when the widget needs to be painted ; we use it to display a new frame.

Called when the widget needs to be painted ; we use it to display a new frame /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 109 of file QSFMLCanvas.cpp.

{
    // Let the derived class do its specific stuff
    OnUpdate();

    // Display on screen
    Display();
}

Here is the call graph for this function:


Member Data Documentation

QTimer QSFMLCanvas::myTimer [private]

Timer used to update the view.

Definition at line 78 of file QSFMLCanvas.hpp.


The documentation for this class was generated from the following files: