mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 15:51:04 +08:00
45b150648d
Removed the AudioResource class git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1166 4e206d99-4929-0410-ac5d-dfc041789085
111 lines
3.4 KiB
C++
111 lines
3.4 KiB
C++
|
|
////////////////////////////////////////////////////////////
|
|
// Headers
|
|
////////////////////////////////////////////////////////////
|
|
#include "wxSFMLCanvas.hpp"
|
|
#include <iostream>
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
/// Custom SFML canvas
|
|
////////////////////////////////////////////////////////////
|
|
class MyCanvas : public wxSFMLCanvas
|
|
{
|
|
public :
|
|
|
|
////////////////////////////////////////////////////////////
|
|
/// Construct the canvas
|
|
///
|
|
////////////////////////////////////////////////////////////
|
|
MyCanvas(wxWindow* parent, wxWindowID id, const wxPoint& position, const wxSize& size, long style = 0) :
|
|
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.SetOrigin(mySprite.GetSize() / 2.f);
|
|
|
|
// Catch the mouse move event
|
|
Connect(wxEVT_MOTION, wxMouseEventHandler(MyCanvas::OnMouseMove));
|
|
}
|
|
|
|
private :
|
|
|
|
////////////////////////////////////////////////////////////
|
|
/// /see wxSFMLCanvas::OnUpdate
|
|
///
|
|
////////////////////////////////////////////////////////////
|
|
virtual void OnUpdate()
|
|
{
|
|
// 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);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////
|
|
/// Function called when the mouse cursor moves
|
|
///
|
|
////////////////////////////////////////////////////////////
|
|
void OnMouseMove(wxMouseEvent& event)
|
|
{
|
|
// Make the sprite follow the mouse cursor
|
|
mySprite.SetPosition(ConvertCoords(event.GetX(), event.GetY()));
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////
|
|
/// Member data
|
|
////////////////////////////////////////////////////////////
|
|
sf::Image myImage; ///< Some image to load...
|
|
sf::Sprite mySprite; ///< Something to draw...
|
|
};
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
/// Our main window
|
|
////////////////////////////////////////////////////////////
|
|
class MyFrame : public wxFrame
|
|
{
|
|
public :
|
|
|
|
////////////////////////////////////////////////////////////
|
|
/// Default constructor : setup the window
|
|
///
|
|
////////////////////////////////////////////////////////////
|
|
MyFrame() :
|
|
wxFrame(NULL, wxID_ANY, wxT("SFML wxWidgets"), wxDefaultPosition, wxSize(440, 280))
|
|
{
|
|
// Let's create a SFML view
|
|
new MyCanvas(this, wxID_ANY, wxPoint(20, 20), wxSize(400, 200));
|
|
}
|
|
};
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
/// Our application class
|
|
////////////////////////////////////////////////////////////
|
|
class MyApplication : public wxApp
|
|
{
|
|
private :
|
|
|
|
////////////////////////////////////////////////////////////
|
|
/// Initialize the application
|
|
///
|
|
////////////////////////////////////////////////////////////
|
|
virtual bool OnInit()
|
|
{
|
|
// Create the main window
|
|
MyFrame* mainFrame = new MyFrame;
|
|
mainFrame->Show();
|
|
|
|
return true;
|
|
}
|
|
};
|
|
|
|
IMPLEMENT_APP(MyApplication);
|