2010-07-26 20:42:11 -07:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
2011-01-30 14:39:22 -08:00
|
|
|
Copyright (C) 2005-2011 Warzone 2100 Project
|
2010-07-26 20:42:11 -07:00
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2010-05-15 19:46:43 -07:00
|
|
|
#ifndef WZAPP_H
|
|
|
|
#define WZAPP_H
|
|
|
|
|
|
|
|
#include <QtGui/QApplication>
|
2011-02-05 09:35:56 -08:00
|
|
|
#include <QtGui/QImageReader>
|
2010-05-15 19:46:43 -07:00
|
|
|
#include <QtCore/QTimer>
|
|
|
|
#include <QtOpenGL/QGLWidget>
|
|
|
|
#include <QtCore/QBuffer>
|
|
|
|
#include <QtCore/QTime>
|
|
|
|
#include <QtCore/QThread>
|
|
|
|
#include <QtCore/QMutex>
|
|
|
|
#include <QtCore/QSemaphore>
|
2011-04-01 11:31:15 -07:00
|
|
|
#include <QtCore/QSettings>
|
2011-04-21 03:58:51 -07:00
|
|
|
#include <physfs.h>
|
2010-05-15 19:46:43 -07:00
|
|
|
|
2010-05-19 19:05:30 -07:00
|
|
|
// Get platform defines before checking for them.
|
|
|
|
// Qt headers MUST come before platform specific stuff!
|
|
|
|
#include "lib/framework/frame.h"
|
|
|
|
#include "lib/framework/cursors.h"
|
2011-01-14 10:26:55 -08:00
|
|
|
#include "lib/ivis_opengl/textdraw.h"
|
2010-05-19 19:05:30 -07:00
|
|
|
#include "input.h"
|
|
|
|
|
2011-04-01 11:31:15 -07:00
|
|
|
class WzConfig : public QSettings
|
|
|
|
{
|
|
|
|
public:
|
2011-04-23 16:03:25 -07:00
|
|
|
WzConfig(const QString &name, QObject *parent = 0) : QSettings(QString("wz::") + name, QSettings::IniFormat, parent) {}
|
2011-04-06 13:06:17 -07:00
|
|
|
Vector3f vector3f(const QString &name);
|
|
|
|
void setVector3f(const QString &name, const Vector3f &v);
|
|
|
|
Vector3i vector3i(const QString &name);
|
|
|
|
void setVector3i(const QString &name, const Vector3i &v);
|
2011-04-18 02:08:27 -07:00
|
|
|
Vector2i vector2i(const QString &name);
|
|
|
|
void setVector2i(const QString &name, const Vector2i &v);
|
2011-04-01 11:31:15 -07:00
|
|
|
};
|
|
|
|
|
2010-05-15 19:46:43 -07:00
|
|
|
class WzMainWindow : public QGLWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
2011-01-30 14:39:22 -08:00
|
|
|
void loadCursor(CURSOR cursor, int x, int y, QImageReader &buffer);
|
2010-05-15 19:46:43 -07:00
|
|
|
void mouseMoveEvent(QMouseEvent *event);
|
|
|
|
void mousePressEvent(QMouseEvent *event);
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event);
|
|
|
|
void wheelEvent(QWheelEvent *event);
|
|
|
|
void keyPressEvent(QKeyEvent *event);
|
|
|
|
void keyReleaseEvent(QKeyEvent *event);
|
|
|
|
void inputMethodEvent(QInputMethodEvent *event);
|
|
|
|
void realHandleKeyEvent(QKeyEvent *event, bool pressed);
|
|
|
|
void focusOutEvent(QFocusEvent *event);
|
|
|
|
MOUSE_KEY_CODE buttonToIdx(Qt::MouseButton button);
|
|
|
|
|
|
|
|
QCursor *cursors[CURSOR_MAX];
|
|
|
|
QTimer *timer;
|
|
|
|
QTime tickCount;
|
2011-05-13 06:14:19 -07:00
|
|
|
QFont regularFont, boldFont, smallFont, scaledFont;
|
2010-05-15 19:46:43 -07:00
|
|
|
bool notReadyToPaint; ///< HACK Don't draw during initial show(), since some global variables apparently aren't set up.
|
|
|
|
static WzMainWindow *myself;
|
|
|
|
|
|
|
|
public:
|
|
|
|
WzMainWindow(const QGLFormat &format, QWidget *parent = 0);
|
|
|
|
~WzMainWindow();
|
|
|
|
void initializeGL();
|
|
|
|
void resizeGL(int w, int h);
|
|
|
|
void paintGL();
|
|
|
|
static WzMainWindow *instance();
|
|
|
|
void setCursor(CURSOR index);
|
|
|
|
void setCursor(QCursor cursor);
|
|
|
|
void setFontType(enum iV_fonts FontID);
|
|
|
|
void setFontSize(float size);
|
|
|
|
int ticks() { return tickCount.elapsed(); }
|
|
|
|
void setReadyToPaint() { notReadyToPaint = false; }
|
2010-10-30 08:06:36 -07:00
|
|
|
void drawPixmap(int XPos, int YPos, QPixmap *pix);
|
2010-05-15 19:46:43 -07:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void tick();
|
|
|
|
void close();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _wzThread : public QThread
|
|
|
|
{
|
|
|
|
_wzThread(int (*threadFunc_)(void *), void *data_) : threadFunc(threadFunc_), data(data_) {}
|
|
|
|
void run()
|
|
|
|
{
|
|
|
|
ret = (*threadFunc)(data);
|
|
|
|
}
|
|
|
|
int (*threadFunc)(void *);
|
|
|
|
void *data;
|
|
|
|
int ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This one couldn't be easier...
|
|
|
|
struct _wzMutex : public QMutex
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _wzSemaphore : public QSemaphore
|
|
|
|
{
|
|
|
|
_wzSemaphore(int startValue = 0) : QSemaphore(startValue) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|