Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
commit
2f524481c1
974 changed files with 295448 additions and 0 deletions
116
samples/wxwidgets/Main.cpp
Normal file
116
samples/wxwidgets/Main.cpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// 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.SetCenter(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.SetX(Event.GetX());
|
||||
mySprite.SetY(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(680, 280))
|
||||
{
|
||||
// Error log text box
|
||||
wxTextCtrl* ErrorLog = new wxTextCtrl(this, wxID_ANY, wxT(""), wxPoint(440, 20), wxSize(200, 200), wxTE_MULTILINE | wxTE_READONLY | wxHSCROLL);
|
||||
std::cerr.rdbuf(ErrorLog);
|
||||
std::cerr << "-- This is the error log --" << std::endl;
|
||||
|
||||
// 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);
|
18
samples/wxwidgets/Makefile
Normal file
18
samples/wxwidgets/Makefile
Normal file
|
@ -0,0 +1,18 @@
|
|||
EXEC = wxwidgets
|
||||
OBJ = Main.o wxSFMLCanvas.o
|
||||
|
||||
all: $(EXEC)
|
||||
|
||||
wxwidgets: $(OBJ)
|
||||
$(CC) $(LDFLAGS) -o $(EXECPATH)/$@ $(OBJ) -lsfml-graphics -lsfml-window -lsfml-system `wx-config --libs` `pkg-config --libs gtk+-2.0`
|
||||
|
||||
%.o: %.cpp
|
||||
$(CC) -o $@ -c $< $(CFLAGS) -I/usr/include/gtk-2.0 `wx-config --cppflags` `pkg-config --cflags gtk+-2.0`
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
@rm -rf *.o
|
||||
|
||||
mrproper: clean
|
||||
@rm -rf $(EXECPATH)/$(EXEC)
|
105
samples/wxwidgets/wxSFMLCanvas.cpp
Normal file
105
samples/wxwidgets/wxSFMLCanvas.cpp
Normal file
|
@ -0,0 +1,105 @@
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include "wxSFMLCanvas.hpp"
|
||||
|
||||
// Platform-specific includes
|
||||
#ifdef __WXGTK__
|
||||
#include <gdk/gdkx.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <wx/gtk/win_gtk.h>
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Event table
|
||||
////////////////////////////////////////////////////////////
|
||||
BEGIN_EVENT_TABLE(wxSFMLCanvas, wxControl)
|
||||
EVT_IDLE(wxSFMLCanvas::OnIdle)
|
||||
EVT_PAINT(wxSFMLCanvas::OnPaint)
|
||||
EVT_ERASE_BACKGROUND(wxSFMLCanvas::OnEraseBackground)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the wxSFMLCanvas
|
||||
////////////////////////////////////////////////////////////
|
||||
wxSFMLCanvas::wxSFMLCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style) :
|
||||
wxControl(Parent, Id, Position, Size, Style)
|
||||
{
|
||||
#ifdef __WXGTK__
|
||||
|
||||
// GTK implementation requires to go deeper to find the low-level X11 identifier of the widget
|
||||
gtk_widget_realize(m_wxwindow);
|
||||
gtk_widget_set_double_buffered(m_wxwindow, false);
|
||||
GdkWindow* Win = GTK_PIZZA(m_wxwindow)->bin_window;
|
||||
XFlush(GDK_WINDOW_XDISPLAY(Win));
|
||||
sf::RenderWindow::Create(GDK_WINDOW_XWINDOW(Win));
|
||||
|
||||
#else
|
||||
|
||||
// Tested under Windows XP only (should work with X11 and other Windows versions - no idea about MacOS)
|
||||
sf::RenderWindow::Create(GetHandle());
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
////////////////////////////////////////////////////////////
|
||||
wxSFMLCanvas::~wxSFMLCanvas()
|
||||
{
|
||||
// Nothing to do...
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Notification for the derived class that moment is good
|
||||
/// for doing its update and drawing stuff
|
||||
////////////////////////////////////////////////////////////
|
||||
void wxSFMLCanvas::OnUpdate()
|
||||
{
|
||||
// Nothing to do by default...
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Called when the control is idle - we can refresh our
|
||||
/// SFML window
|
||||
////////////////////////////////////////////////////////////
|
||||
void wxSFMLCanvas::OnIdle(wxIdleEvent&)
|
||||
{
|
||||
// Send a paint message when the control is idle, to ensure maximum framerate
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Called when the control is repainted - we can display our
|
||||
/// SFML window
|
||||
////////////////////////////////////////////////////////////
|
||||
void wxSFMLCanvas::OnPaint(wxPaintEvent&)
|
||||
{
|
||||
// Make sure the control is able to be repainted
|
||||
wxPaintDC Dc(this);
|
||||
|
||||
// Let the derived class do its specific stuff
|
||||
OnUpdate();
|
||||
|
||||
// Display on screen
|
||||
Display();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Called when the control needs to draw its background
|
||||
////////////////////////////////////////////////////////////
|
||||
void wxSFMLCanvas::OnEraseBackground(wxEraseEvent&)
|
||||
{
|
||||
// Don't do anything. We intercept this event in order to prevent the
|
||||
// parent class to draw the background before repainting the window,
|
||||
// which would cause some flickering
|
||||
}
|
70
samples/wxwidgets/wxSFMLCanvas.hpp
Normal file
70
samples/wxwidgets/wxSFMLCanvas.hpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
|
||||
#ifndef WXSFMLCANVAS_HPP
|
||||
#define WXSFMLCANVAS_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <wx/wx.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// wxSFMLCanvas allows to run SFML in a wxWidgets control
|
||||
////////////////////////////////////////////////////////////
|
||||
class wxSFMLCanvas : public wxControl, public sf::RenderWindow
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the wxSFMLCanvas
|
||||
///
|
||||
/// \param Parent : Parent of the control (NULL by default)
|
||||
/// \param Id : Identifier of the control (-1 by default)
|
||||
/// \param Position : Position of the control (wxDefaultPosition by default)
|
||||
/// \param Size : Size of the control (wxDefaultSize by default)
|
||||
/// \param Style : Style of the control (0 by default)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
wxSFMLCanvas(wxWindow* Parent = NULL, wxWindowID Id = -1, const wxPoint& Position = wxDefaultPosition, const wxSize& Size = wxDefaultSize, long Style = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~wxSFMLCanvas();
|
||||
|
||||
private :
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Notification for the derived class that moment is good
|
||||
/// for doing its update and drawing stuff
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void OnUpdate();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Called when the window is idle - we can refresh our
|
||||
/// SFML window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void OnIdle(wxIdleEvent&);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Called when the window is repainted - we can display our
|
||||
/// SFML window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void OnPaint(wxPaintEvent&);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Called when the window needs to draw its background
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void OnEraseBackground(wxEraseEvent&);
|
||||
};
|
||||
|
||||
|
||||
#endif // WXSFMLCANVAS_HPP
|
Loading…
Add table
Add a link
Reference in a new issue