50 changes: 50 additions & 0 deletions lib/qtgame/qtgame.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef QTGAME_H
#define QTGAME_H

#include <QGLWidget>

class QtGameWidget : public QGLWidget
{
Q_OBJECT

private:
QSize mOriginalResolution, mCurrentResolution, mWantedSize, mMinimumSize;
int mOriginalRefreshRate, mCurrentRefreshRate;
int mOriginalDepth, mCurrentDepth;
QList<QSize> mResolutions;
bool mResolutionChanged;
bool mCursorTrapped;

void restoreResolution();
void updateResolutionList();
bool setResolution(const QSize res, int rate, int depth);

public:
QtGameWidget(QSize curResolution, const QGLFormat &format, QWidget *parent = 0, Qt::WindowFlags f = 0, const QGLWidget *shareWidget = 0);
~QtGameWidget() { if (mResolutionChanged) restoreResolution(); }
QList<QSize> availableResolutions() const { return mResolutions; }
bool isMouseTrapped() { return mCursorTrapped; }

public slots:
void setMinimumResolution(QSize res);

/* Not to be confused with grabMouse and releaseMouse... */
void trapMouse();
void freeMouse();

/* Overloaded functions to protect sanity of window size */
void show();
void showFullScreen();
void setWindowState(Qt::WindowStates windowState);
void showMaximized();
void showMinimized();
void showNormal();
void resize(QSize size);
void resize(int w, int h) { resize(QSize(w, h)); }
void setFixedSize(QSize size) { resize(size); }
void setFixedSize(int w, int h) { resize(w, h); }
void setFixedHeight(int h) { resize(size().width(), h); }
void setFixedWidth(int w) { resize(w, size().height()); }
};

#endif
5 changes: 4 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ warzone2100_SOURCES = \

warzone2100_LIBS = \
$(top_builddir)/lib/widget/libwidget.a \
$(top_builddir)/lib/qtgame/libqtgame.a \
$(top_builddir)/lib/sequence/libsequence.a \
$(top_builddir)/lib/sound/libsound.a \
$(top_builddir)/lib/script/libscript.a \
Expand All @@ -293,7 +294,9 @@ warzone2100_LIBS = \
$(top_builddir)/lib/exceptionhandler/libexceptionhandler.a \
$(top_builddir)/3rdparty/miniupnpc/libminiupnpc.a

warzone2100_LDADD = $(warzone2100_LIBS) $(LTLIBINTL) $(PHYSFS_LIBS) $(PNG_LIBS) $(OGGVORBIS_LIBS) $(THEORA_LIBS) $(OPENAL_LIBS) $(OPENGLC_LIBS) $(OPENGL_LIBS) $(QT4_LIBS) $(GLEW_LIBS)
warzone2100_LDADD = $(warzone2100_LIBS) $(LTLIBINTL) $(PHYSFS_LIBS) $(PNG_LIBS) $(OGGVORBIS_LIBS) \
$(THEORA_LIBS) $(OPENAL_LIBS) $(OPENGLC_LIBS) $(OPENGL_LIBS) $(QT4_LIBS) $(GLEW_LIBS) \
$(X_LIBS) $(X_EXTRA_LIBS)

if MINGW32
warzone2100_LDADD += $(top_builddir)/win32/warzone2100.o $(WIN32_LIBS)
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ int main(int argc, char *argv[])
format.setSampleBuffers(true);
format.setSamples(war_getFSAA());
}
WzMainWindow mainwindow(format);
WzMainWindow mainwindow(QSize(w, h), format);
if (!mainwindow.context()->isValid())
{
QMessageBox::critical(NULL, "Oops!", "Warzone2100 failed to create an OpenGL context. This probably means that your graphics drivers are out of date. Try updating them!");
Expand Down