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:
laurentgom 2009-01-28 16:18:34 +00:00
commit 2f524481c1
974 changed files with 295448 additions and 0 deletions

107
samples/qt/Main.cpp Normal file
View file

@ -0,0 +1,107 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "QSFMLCanvas.hpp"
#include <Qt/qapplication.h>
#include <Qt/qframe.h>
#include <Qt/qlabel.h>
#include <Qt/qevent.h>
////////////////////////////////////////////////////////////
/// Custom SFML canvas
////////////////////////////////////////////////////////////
class MyCanvas : public QSFMLCanvas
{
public :
////////////////////////////////////////////////////////////
/// Construct the canvas
///
////////////////////////////////////////////////////////////
MyCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size) :
QSFMLCanvas(Parent, Position, Size)
{
}
private :
////////////////////////////////////////////////////////////
/// /see QSFMLCanvas::OnInit
///
////////////////////////////////////////////////////////////
virtual void OnInit()
{
// Load the image
myImage.LoadFromFile("datas/qt/sfml.png");
// Setup the sprite
mySprite.SetImage(myImage);
mySprite.SetCenter(mySprite.GetSize() / 2.f);
}
////////////////////////////////////////////////////////////
/// /see QSFMLCanvas::OnUpdate
///
////////////////////////////////////////////////////////////
virtual void OnUpdate()
{
sf::Event Event;
while (GetEvent(Event))
{
// Stick the sprite to the mouse cursor
if (Event.Type == sf::Event::MouseMoved)
{
mySprite.SetX(Event.MouseMove.X);
mySprite.SetY(Event.MouseMove.Y);
}
}
// Rotate the sprite
mySprite.Rotate(GetFrameTime() * 100.f);
// Clear the view
Clear(sf::Color(0, 128, 0));
// Draw it
Draw(mySprite);
}
////////////////////////////////////////////////////////////
/// Member data
////////////////////////////////////////////////////////////
sf::Image myImage; ///< Some image to show
sf::Sprite mySprite; ///< A sprite to display the image
};
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
QApplication App(argc, argv);
// Create the main frame
QFrame* MainFrame = new QFrame;
MainFrame->setWindowTitle("Qt SFML");
MainFrame->resize(400, 400);
MainFrame->show();
// Create a label for showing some text
QLabel* Label = new QLabel("This is a SFML window\nembedded into a Qt frame :", MainFrame);
Label->move(20, 10);
Label->setFont(QFont("courier new", 14, 1, false));
Label->show();
// Create a SFML view inside the main frame
MyCanvas* SFMLView = new MyCanvas(MainFrame, QPoint(20, 60), QSize(360, 320));
SFMLView->show();
return App.exec();
}

18
samples/qt/Makefile Normal file
View file

@ -0,0 +1,18 @@
EXEC = qt
OBJ = Main.o QSFMLCanvas.o
all: $(EXEC)
qt: $(OBJ)
$(CC) $(LDFLAGS) -o $(EXECPATH)/$@ $(OBJ) -lsfml-graphics -lsfml-window -lsfml-system -lQtCore -lQtGui -lX11
%.o: %.cpp
$(CC) -o $@ -c $< $(CFLAGS) -I/usr/include/qt4
.PHONY: clean mrproper
clean:
@rm -rf *.o
mrproper: clean
@rm -rf $(EXECPATH)/$(EXEC)

106
samples/qt/QSFMLCanvas.cpp Normal file
View file

@ -0,0 +1,106 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "QSFMLCanvas.hpp"
// Platform-specific headers
#ifdef Q_WS_X11
#include <Qt/qx11info_x11.h>
#include <X11/Xlib.h>
#endif
////////////////////////////////////////////////////////////
/// Construct the QSFMLCanvas
////////////////////////////////////////////////////////////
QSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime) :
QWidget (Parent),
myInitialized (false)
{
// Setup some states to allow direct rendering into the widget
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
// Set strong focus to enable keyboard events to be received
setFocusPolicy(Qt::StrongFocus);
// Setup the widget geometry
move(Position);
resize(Size);
// Setup the timer
myTimer.setInterval(FrameTime);
}
////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////
QSFMLCanvas::~QSFMLCanvas()
{
// Nothing to do...
}
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing initializations
////////////////////////////////////////////////////////////
void QSFMLCanvas::OnInit()
{
// Nothing to do by default...
}
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing its update and drawing stuff
////////////////////////////////////////////////////////////
void QSFMLCanvas::OnUpdate()
{
// Nothing to do by default...
}
////////////////////////////////////////////////////////////
/// Called when the widget is shown ;
/// we use it to initialize our SFML window
////////////////////////////////////////////////////////////
void QSFMLCanvas::showEvent(QShowEvent*)
{
if (!myInitialized)
{
// 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();
myInitialized = true;
}
}
////////////////////////////////////////////////////////////
/// Called when the widget needs to be painted ;
/// we use it to display a new frame
////////////////////////////////////////////////////////////
void QSFMLCanvas::paintEvent(QPaintEvent*)
{
// Let the derived class do its specific stuff
OnUpdate();
// Display on screen
Display();
}

View file

@ -0,0 +1,75 @@
#ifndef QSFMLCANVAS_HPP
#define QSFMLCANVAS_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <Qt/qwidget.h>
#include <Qt/qtimer.h>
////////////////////////////////////////////////////////////
/// QSFMLCanvas allows to run SFML in a Qt control
////////////////////////////////////////////////////////////
class QSFMLCanvas : public QWidget, public sf::RenderWindow
{
public :
////////////////////////////////////////////////////////////
/// Construct the QSFMLCanvas
///
/// \param Parent : Parent of the widget
/// \param Position : Position of the widget
/// \param Size : Size of the widget
/// \param FrameTime : Frame duration, in milliseconds (0 by default)
///
////////////////////////////////////////////////////////////
QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime = 0);
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
virtual ~QSFMLCanvas();
private :
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing initializations
///
////////////////////////////////////////////////////////////
virtual void OnInit();
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing its update and drawing stuff
///
////////////////////////////////////////////////////////////
virtual void OnUpdate();
////////////////////////////////////////////////////////////
/// Called when the widget is shown ;
/// we use it to initialize our SFML window
///
////////////////////////////////////////////////////////////
virtual void showEvent(QShowEvent*);
////////////////////////////////////////////////////////////
/// Called when the widget needs to be painted ;
/// we use it to display a new frame
///
////////////////////////////////////////////////////////////
virtual void paintEvent(QPaintEvent*);
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
QTimer myTimer; ///< Timer used to update the view
bool myInitialized; ///< Tell whether the SFML window has been initialized or not
};
#endif // QSFMLCANVAS_HPP