Commits

Samuel Dionne-Riel committed 63d558a

Added QtMainWindow, Qt is not supported as of now; we will work on it later.

  • Participants
  • Parent commits 4a26e7b

Comments (0)

Files changed (7)

 	INCLUDE( ${QT_USE_FILE} )
 
 	qt4_wrap_cpp(RedBox_QT_MOC_sources ${RedBox_QT_MOC_headers})
-	  
+	QT4_WRAP_UI( RedBox_QT_uis_headers ${RedBox_QT_uis} )
+	
 	INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )
 
 	FIND_PACKAGE(OpenAL REQUIRED)
 	list(APPEND RedBox_libraries_list ${OPENAL_LIBRARY})
 
 	list(APPEND RedBoxSources ${RedBox_QT_MOC_sources})
+	list(APPEND RedBoxHeaders ${RedBox_QT_uis_headers})
 
 	list(APPEND RedBox_IncludeDir_list ${QT_INCLUDE_DIR} ${QT_QTOPENGL_INCLUDE_DIR})
 	list(APPEND RedBox_libraries_list ${QT_LIBRARIES})

RedBox/RedBox/Display/Window/Qt/QtMainWindow.cpp

+#include "QtMainWindow.h"
+
+#include "PlatformFlagger.h"
+
+#include "RBOpenGL.h"
+#include "Engine.h"
+
+#include "QtKeyboard.h"
+#include "QtPointer.h"
+
+#include "InputManager.h"
+
+#include "Console.h"
+
+#include <QtGui>
+#include <QtOpenGL>
+#include <QWidget>
+#include <QGLWidget>
+#include <QMouseEvent>
+#include <QPoint>
+#include <QApplication>
+
+using namespace RedBox;
+
+QtMainWindow& QtMainWindow::getInstance() {
+	static QtMainWindow instance;
+	return instance;
+}
+
+void QtMainWindow::onRedBoxInit(int width, int height) {
+	//Do nothing... It's all done in the MyMainWindow's function.
+}
+
+QtMainWindow::QtMainWindow() : MainWindow() {
+	//I build it with new to control its lifespan.
+	application = new QApplication(Engine::getApplicationArgc(), Engine::getApplicationArgv());
+	//Then the window
+	window = new MyMainWindow();
+	//@TODO: Check what to do with this... I want to make this configurable... It is shown in the menu bar on OS X.
+	QCoreApplication::setApplicationName("RedBoxApp");
+}
+
+void QtMainWindow::setCaption(const std::string& caption) {
+	window->setWindowTitle(QString::fromStdString(caption));
+}
+	
+void QtMainWindow::show() {
+	window->show();
+	application->exec();
+}
+
+QtMainWindow::~QtMainWindow() {
+	delete window;
+	delete application;
+}
+
+
+
+
+// ----------------------------- MyMainWindow ----------------------------------
+
+#include "ui_mymainwindow.h"
+
+MyMainWindow::MyMainWindow(QWidget *parent) :
+	QMainWindow(parent), sigly::HasSlots<>(),
+	ui(new Ui::MainWindow)
+{
+	ui->setupUi(this);
+
+	this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+	//this->setFixedSize(QtRedBoxWidget::SCREEN_WIDTH, QtRedBoxWidget::SCREEN_HEIGHT);
+
+	engine = new QtRedBoxWidget(this);
+
+	setCentralWidget(engine);
+
+	setEnabled(true);
+	RedBox::Engine::onInitialize.connect(this, &MyMainWindow::onRedBoxInit);
+}
+
+MyMainWindow::~MyMainWindow() {
+    delete ui;
+}
+
+void MyMainWindow::onRedBoxInit(int width, int height) {
+	setMaximumSize(width, height);
+	QtRedBoxWidget::screenWidth = width;
+	QtRedBoxWidget::screenHeight = height;
+
+	RedBox::InputManager::getInstance().setNbKeyboards(1);
+	RedBox::InputManager::getInstance().setNbPointers(1);
+
+	RedBox::QtPointer::setParentWidget(this);
+	RedBox::QtKeyboard::setParentWidget(this);
+
+	if(engine) {
+		engine->setMaximumSize(width, height);
+	}
+}
+
+
+// ----------------------------- QtRedBoxWidget --------------------------------
+
+int QtRedBoxWidget::screenWidth = 0;
+int QtRedBoxWidget::screenHeight = 0;
+
+QtRedBoxWidget::QtRedBoxWidget(QWidget* parent): QGLWidget(parent) {
+
+	timer = new QTimer(this);
+	connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
+	timer->start(1);
+
+	this->setAutoFillBackground(false);
+	this->grabMouse();
+	this->setMouseTracking(true);
+	this->setEnabled(true);
+	this->makeCurrent();
+}
+
+QtRedBoxWidget::~QtRedBoxWidget() {
+}
+
+QSize QtRedBoxWidget::sizeHint() const {
+	return QSize(screenWidth, screenHeight);
+}
+
+QSize QtRedBoxWidget::minimumSizeHint() const {
+	return QSize(screenWidth, screenHeight);
+}
+
+void QtRedBoxWidget::initializeGL() {
+}
+
+void QtRedBoxWidget::paintGL() {
+	RedBox::Engine::pulse();
+}
+
+void QtRedBoxWidget::resizeGL(int width, int height) {
+}
+
+void QtRedBoxWidget::animate() {
+	RedBox::Engine::pulse();
+	if(!RedBox::Engine::isBufferSwapped()) {
+		this->updateGL();
+		this->swapBuffers();
+		RedBox::Engine::setBufferSwapped();
+	}
+}
+
+

RedBox/RedBox/Display/Window/Qt/QtMainWindow.h

+/**
+ * @file
+ * @ingroup WindowDisplay
+ */
+#ifndef RB_QT_MAIN_WINDOW_H
+#define RB_QT_MAIN_WINDOW_H
+
+#include <sigly.h>
+#include "MainWindow.h"
+
+#include <QMainWindow>
+#include <QtGui>
+#include <QWidget>
+#include <QGLWidget>
+
+namespace Ui {
+    class MainWindow;
+}
+
+namespace RedBox {
+	class QtRedBoxWidget : public QGLWidget {
+		Q_OBJECT
+	public:
+		static int screenWidth;
+		static int screenHeight;
+		QtRedBoxWidget(QWidget *parent = 0);
+		~QtRedBoxWidget();
+
+		QSize sizeHint() const;
+		QSize minimumSizeHint() const;
+
+	protected:
+		void initializeGL();
+		void paintGL();
+		void resizeGL(int width, int height);
+
+	private slots:
+		void animate();
+	private:
+		QTimer * timer;
+	};
+
+	class MyMainWindow : public QMainWindow, public sigly::HasSlots<> {
+		Q_OBJECT
+		public:
+			explicit MyMainWindow(QWidget *parent = 0);
+			~MyMainWindow();
+			void onRedBoxInit(int width, int height);
+		private:
+			Ui::MainWindow *ui;
+			QtRedBoxWidget* engine;
+	};
+
+
+	/**
+	 * This is an implementation of MainWindow using Qt.
+	 */
+	class QtMainWindow : public MainWindow {
+	public:
+		/// Gets the singleton instance of QtMainWindow.
+		static QtMainWindow& getInstance();
+		void onRedBoxInit(int width, int height);
+		void show();
+		void setCaption(const std::string& caption);
+	private:
+		/// Instance of the Qt Window.
+		MyMainWindow* window;
+
+		/// Instance of QApplication
+		QApplication* application;
+
+		/**
+		 * Initializes.
+		 */
+		QtMainWindow();
+		/**
+		 * Properly quits.
+		 */
+		~QtMainWindow();
+
+	};
+
+}
+
+#endif

RedBox/RedBox/Display/Window/Qt/Sources.cmake

+get_filename_component(Display_Window_QT_dir ${CMAKE_CURRENT_LIST_FILE} PATH)
+
+file(GLOB RedBox_RedBox_Display_Window_QT_Headers ${Display_Window_QT_dir}/*.h)
+file(GLOB RedBox_RedBox_Display_Window_QT_Sources ${Display_Window_QT_dir}/*.cpp)
+file(GLOB RedBox_RedBox_Display_Window_QT_ui ${Display_Window_QT_dir}/*.ui)
+
+list(APPEND Private_RedBox_Headers ${RedBox_RedBox_Display_Window_QT_Headers})
+
+list(APPEND RedBox_QT_MOC_headers ${RedBox_RedBox_Display_Window_QT_Headers})
+list(APPEND RedBox_QT_uis ${RedBox_RedBox_Display_Window_QT_ui})
+
+list(APPEND RedBoxHeaders ${RedBox_RedBox_Display_Window_QT_Headers})
+list(APPEND RedBoxSources ${RedBox_RedBox_Display_Window_QT_Sources})
+
+source_group(RedBox\\Display\\Window\\QT  FILES ${RedBox_RedBox_Display_Window_QT_Sources} ${RedBox_RedBox_Display_Window_QT_Headers})
+

RedBox/RedBox/Display/Window/Qt/mymainwindow.ui

+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="windowModality">
+   <enum>Qt::NonModal</enum>
+  </property>
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>0</width>
+    <height>0</height>
+   </rect>
+  </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="windowTitle">
+   <string></string>
+  </property>
+  <widget class="QWidget" name="centralWidget">
+   <property name="sizePolicy">
+    <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+     <horstretch>0</horstretch>
+     <verstretch>0</verstretch>
+    </sizepolicy>
+   </property>
+  </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>

RedBox/RedBox/Display/Window/Sources.cmake

 
 if(SDL)
 	include(${Display_Window_dir}/SDL/Sources.cmake)
+elseif(QT)
+	include(${Display_Window_dir}/Qt/Sources.cmake)
 endif(SDL)
 
 file(GLOB RedBox_RedBox_Display_Window_Headers ${Display_Window_dir}/*.h)

RedBox/RedBox/PlatformFlagger.h

 	#define RB_KEYBOARD_INCLUDE "QtKeyboard.h"
 	#define RB_POINTER_IMPL new QtPointer()
 	#define RB_POINTER_INCLUDE "QtPointer.h"
+
+	#define RB_MAINWINDOW_IMPL QtMainWindow::getInstance()
+	#define RB_MAINWINDOW_INCLUDE "QtMainWindow.h"
 #endif
 
 //iOS platform