summaryrefslogtreecommitdiff
path: root/samples/qt
diff options
context:
space:
mode:
authorJames Cowgill <james410@cowgill.org.uk>2013-08-23 09:57:55 +0100
committerJames Cowgill <james410@cowgill.org.uk>2013-08-23 09:57:55 +0100
commit9a298ca833d9b6a3425bb30c2e52cf04e34aeb7c (patch)
treed46630a885bcea03bbea036b86c645dc6c55708d /samples/qt
parent0969839d538a385254c6eced9648acc7299876cc (diff)
Imported Upstream version 2.1+dfsg
Diffstat (limited to 'samples/qt')
-rw-r--r--samples/qt/Main.cpp115
-rwxr-xr-xsamples/qt/Makefile18
-rw-r--r--samples/qt/QSFMLCanvas.cpp116
-rw-r--r--samples/qt/QSFMLCanvas.hpp82
4 files changed, 0 insertions, 331 deletions
diff --git a/samples/qt/Main.cpp b/samples/qt/Main.cpp
deleted file mode 100644
index 29f9dd8..0000000
--- a/samples/qt/Main.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include "QSFMLCanvas.hpp"
-#include <QApplication>
-#include <QVBoxLayout>
-#include <QFrame>
-#include <QLabel>
-
-
-////////////////////////////////////////////////////////////
-/// Custom SFML canvas
-////////////////////////////////////////////////////////////
-class MyCanvas : public QSFMLCanvas
-{
-public :
-
- ////////////////////////////////////////////////////////////
- /// Construct the canvas
- ///
- ////////////////////////////////////////////////////////////
- MyCanvas(QWidget* Parent = NULL) :
- QSFMLCanvas(QSize(100, 100), 0, Parent)
- {
-
- }
-
-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.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);
- }
-
- ////////////////////////////////////////////////////////////
- /// 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->setFont(QFont("courier new", 14, 1, false));
-
- // Create a SFML view inside the main frame
- MyCanvas* SFMLView = new MyCanvas(MainFrame);
-
- // Create the main layout
- QVBoxLayout* Layout = new QVBoxLayout;
- Layout->addWidget(Label, 0);
- Layout->addWidget(SFMLView, 1);
- MainFrame->setLayout(Layout);
-
- return App.exec();
-}
diff --git a/samples/qt/Makefile b/samples/qt/Makefile
deleted file mode 100755
index 43d09cd..0000000
--- a/samples/qt/Makefile
+++ /dev/null
@@ -1,18 +0,0 @@
-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 -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui
-
-.PHONY: clean mrproper
-
-clean:
- @rm -rf *.o
-
-mrproper: clean
- @rm -rf $(EXECPATH)/$(EXEC)
diff --git a/samples/qt/QSFMLCanvas.cpp b/samples/qt/QSFMLCanvas.cpp
deleted file mode 100644
index 2f75566..0000000
--- a/samples/qt/QSFMLCanvas.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include "QSFMLCanvas.hpp"
-#include <QEvent>
-
-// Platform-specific headers
-#ifdef Q_WS_X11
- #include <Qt/qx11info_x11.h>
- #include <X11/Xlib.h>
-#endif
-
-
-////////////////////////////////////////////////////////////
-/// Construct the QSFMLCanvas
-////////////////////////////////////////////////////////////
-QSFMLCanvas::QSFMLCanvas(const QSize& Size, unsigned int FrameTime, QWidget* Parent) :
-QWidget(Parent)
-{
- // Resize the widget
- resize(Size);
-
- // Setup some states to allow direct rendering into the widget
- setAttribute(Qt::WA_PaintOnScreen);
- setAttribute(Qt::WA_OpaquePaintEvent);
- setAttribute(Qt::WA_NoSystemBackground);
-
- // Set strong focus to enable keyboard events to be received
- setFocusPolicy(Qt::StrongFocus);
-
- // 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...
-}
-
-
-////////////////////////////////////////////////////////////
-/// Return the paint engine used by the widget to draw itself
-////////////////////////////////////////////////////////////
-QPaintEngine* QSFMLCanvas::paintEngine() const
-{
- return 0;
-}
-
-
-////////////////////////////////////////////////////////////
-/// Called each time an event is received by the widget ;
-/// we use it to catch the Polish event and initialize
-/// our SFML window
-////////////////////////////////////////////////////////////
-bool QSFMLCanvas::event(QEvent* Event)
-{
- if (Event->type() == QEvent::Polish)
- {
- // 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();
- }
-
- return QWidget::event(Event);
-}
-
-
-////////////////////////////////////////////////////////////
-/// 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();
-}
diff --git a/samples/qt/QSFMLCanvas.hpp b/samples/qt/QSFMLCanvas.hpp
deleted file mode 100644
index 22a58ea..0000000
--- a/samples/qt/QSFMLCanvas.hpp
+++ /dev/null
@@ -1,82 +0,0 @@
-
-#ifndef QSFMLCANVAS_HPP
-#define QSFMLCANVAS_HPP
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/Graphics.hpp>
-#include <QWidget>
-#include <QTimer>
-
-
-class QEvent;
-
-////////////////////////////////////////////////////////////
-/// QSFMLCanvas allows to run SFML in a Qt control
-////////////////////////////////////////////////////////////
-class QSFMLCanvas : public QWidget, public sf::RenderWindow
-{
-public :
-
- ////////////////////////////////////////////////////////////
- /// Construct the QSFMLCanvas
- ///
- /// \param Size : Initial size of the widget
- /// \param FrameTime : Frame duration, in milliseconds (0 by default)
- /// \param Parent : Parent of the widget (NULL by default)
- ///
- ////////////////////////////////////////////////////////////
- QSFMLCanvas(const QSize& Size, unsigned int FrameTime = 0, QWidget* Parent = NULL);
-
- ////////////////////////////////////////////////////////////
- /// 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();
-
- ////////////////////////////////////////////////////////////
- /// Return the paint engine used by the widget to draw itself
- ///
- ////////////////////////////////////////////////////////////
- virtual QPaintEngine* paintEngine() const;
-
- ////////////////////////////////////////////////////////////
- /// Called each time an event is received by the widget ;
- /// we use it to catch the Polish event and initialize
- /// our SFML window
- ///
- ////////////////////////////////////////////////////////////
- virtual bool event(QEvent* Event);
-
- ////////////////////////////////////////////////////////////
- /// 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
-};
-
-
-#endif // QSFMLCANVAS_HPP