Back to index

libsfml  1.6+dfsg2
Main.cpp
Go to the documentation of this file.
00001 
00003 // Headers
00005 #include "wxSFMLCanvas.hpp"
00006 #include <iostream>
00007 
00008 
00012 class MyCanvas : public wxSFMLCanvas
00013 {
00014 public :
00015 
00020     MyCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style = 0) :
00021     wxSFMLCanvas(Parent, Id, Position, Size, Style)
00022     {
00023         // Load an image and assign it to our sprite
00024         myImage.LoadFromFile("datas/wxwidgets/sfml.png");
00025         mySprite.SetImage(myImage);
00026         mySprite.SetCenter(mySprite.GetSize() / 2.f);
00027 
00028         // Catch the mouse move event
00029         Connect(wxEVT_MOTION, wxMouseEventHandler(MyCanvas::OnMouseMove));
00030     }
00031 
00032 private :
00033 
00038     virtual void OnUpdate()
00039     {
00040         // Rotate the sprite
00041         if (GetInput().IsMouseButtonDown(sf::Mouse::Left))  mySprite.Rotate( GetFrameTime() * 50);
00042         if (GetInput().IsMouseButtonDown(sf::Mouse::Right)) mySprite.Rotate(-GetFrameTime() * 50);
00043 
00044         // Clear the view
00045         Clear(sf::Color(0, 128, 128));
00046 
00047         // Display the sprite in the view
00048         Draw(mySprite);
00049     }
00050 
00055     void OnMouseMove(wxMouseEvent& Event)
00056     {
00057         // Make the sprite follow the mouse cursor
00058         mySprite.SetX(Event.GetX());
00059         mySprite.SetY(Event.GetY());
00060     }
00061 
00065     sf::Image  myImage;  
00066     sf::Sprite mySprite; 
00067 };
00068 
00069 
00073 class MyFrame : public wxFrame
00074 {
00075 public :
00076 
00081     MyFrame() :
00082     wxFrame(NULL, wxID_ANY, wxT("SFML wxWidgets"), wxDefaultPosition, wxSize(440, 280))
00083     {
00084         // Let's create a SFML view
00085         new MyCanvas(this, wxID_ANY, wxPoint(20, 20), wxSize(400, 200));
00086     }
00087 };
00088 
00089 
00093 class MyApplication : public wxApp
00094 {
00095 private :
00096 
00101     virtual bool OnInit()
00102     {
00103         // Create the main window
00104         MyFrame* MainFrame = new MyFrame;
00105         MainFrame->Show();
00106 
00107         return true;
00108     }
00109 };
00110 
00111 IMPLEMENT_APP(MyApplication);