Back to index

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

Custom SFML canvas /////////////////////////////////////////////////////////. More...

Inheritance diagram for MyCanvas:
Inheritance graph
[legend]
Collaboration diagram for MyCanvas:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MyCanvas (QWidget *Parent=NULL)
 Construct the canvas.
 MyCanvas (wxWindow *Parent, wxWindowID Id, const wxPoint &Position, const wxSize &Size, long Style=0)
 Construct the canvas.

Private Member Functions

virtual void OnInit ()
 /see QSFMLCanvas::OnInit
virtual void OnUpdate ()
 /see QSFMLCanvas::OnUpdate
virtual void OnUpdate ()
 /see wxSFMLCanvas::OnUpdate
void OnMouseMove (wxMouseEvent &Event)
 Function called when the mouse cursor moves.

Private Attributes

sf::Image myImage
 Member data /////////////////////////////////////////////////////////.
sf::Sprite mySprite
 A sprite to display the image.

Detailed Description

Custom SFML canvas /////////////////////////////////////////////////////////.

Definition at line 15 of file Main.cpp.


Constructor & Destructor Documentation

MyCanvas::MyCanvas ( QWidget *  Parent = NULL) [inline]

Construct the canvas.

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

Definition at line 23 of file Main.cpp.

                                     :
    QSFMLCanvas(QSize(100, 100), 0, Parent)
    {

    }
MyCanvas::MyCanvas ( wxWindow *  Parent,
wxWindowID  Id,
const wxPoint &  Position,
const wxSize &  Size,
long  Style = 0 
) [inline]

Construct the canvas.

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

Definition at line 20 of file Main.cpp.

                                                                                                           :
    wxSFMLCanvas(Parent, Id, Position, Size, Style)
    {
        // Load an image and assign it to our sprite
        myImage.LoadFromFile("datas/wxwidgets/sfml.png");
        mySprite.SetImage(myImage);
        mySprite.SetCenter(mySprite.GetSize() / 2.f);

        // Catch the mouse move event
        Connect(wxEVT_MOTION, wxMouseEventHandler(MyCanvas::OnMouseMove));
    }

Here is the call graph for this function:


Member Function Documentation

virtual void MyCanvas::OnInit ( ) [inline, private, virtual]

/see QSFMLCanvas::OnInit

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

Reimplemented from QSFMLCanvas.

Definition at line 35 of file Main.cpp.

    {
        // Load the image
        myImage.LoadFromFile("datas/qt/sfml.png");

        // Setup the sprite
        mySprite.SetImage(myImage);
        mySprite.SetCenter(mySprite.GetSize() / 2.f);
    }
void MyCanvas::OnMouseMove ( wxMouseEvent &  Event) [inline, private]

Function called when the mouse cursor moves.

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

Definition at line 55 of file Main.cpp.

    {
        // Make the sprite follow the mouse cursor
        mySprite.SetX(Event.GetX());
        mySprite.SetY(Event.GetY());
    }

Here is the caller graph for this function:

virtual void MyCanvas::OnUpdate ( ) [inline, private, virtual]

/see wxSFMLCanvas::OnUpdate

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

Reimplemented from QSFMLCanvas.

Definition at line 38 of file Main.cpp.

    {
        // Rotate the sprite
        if (GetInput().IsMouseButtonDown(sf::Mouse::Left))  mySprite.Rotate( GetFrameTime() * 50);
        if (GetInput().IsMouseButtonDown(sf::Mouse::Right)) mySprite.Rotate(-GetFrameTime() * 50);

        // Clear the view
        Clear(sf::Color(0, 128, 128));

        // Display the sprite in the view
        Draw(mySprite);
    }

Here is the call graph for this function:

virtual void MyCanvas::OnUpdate ( ) [inline, private, virtual]

/see QSFMLCanvas::OnUpdate

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

Reimplemented from QSFMLCanvas.

Definition at line 49 of file Main.cpp.

    {
        sf::Event Event;
        while (GetEvent(Event))
        {
            // Stick the sprite to the mouse cursor
            if (Event.Type == sf::Event::MouseMoved)
            {
                mySprite.SetPosition(ConvertCoords(Event.MouseMove.X, Event.MouseMove.Y));
            }

            // Adjust the size of the default view when the widget is resized
            if (Event.Type == sf::Event::Resized)
            {
                GetDefaultView().SetFromRect(sf::FloatRect(0, 0, Event.Size.Width, Event.Size.Height));
            }
        }

        // Rotate the sprite
        mySprite.Rotate(GetFrameTime() * 100.f);

        // Clear the view
        Clear(sf::Color(0, 128, 0));

        // Draw it
        Draw(mySprite);
    }

Here is the call graph for this function:


Member Data Documentation

sf::Image MyCanvas::myImage [private]

Member data /////////////////////////////////////////////////////////.

Some image to show

Some image to load...

Definition at line 80 of file Main.cpp.

sf::Sprite MyCanvas::mySprite [private]

A sprite to display the image.

Something to draw...

Definition at line 81 of file Main.cpp.


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