Get possible screen resolutions from SDL library
authorunc0rr
Thu, 12 Jul 2007 14:44:41 +0000
changeset 555 0376fdcc6322
parent 554 4f83b3de17c7
child 556 49675457d76e
Get possible screen resolutions from SDL library
QTfrontend/CMakeLists.txt
QTfrontend/SDLs.cpp
QTfrontend/SDLs.h
QTfrontend/game.cpp
QTfrontend/gameuiconfig.cpp
QTfrontend/gameuiconfig.h
QTfrontend/hedgewars.pro
QTfrontend/hwconsts.h.in
QTfrontend/pages.cpp
--- a/QTfrontend/CMakeLists.txt	Thu Jul 12 14:43:34 2007 +0000
+++ b/QTfrontend/CMakeLists.txt	Thu Jul 12 14:44:41 2007 +0000
@@ -1,3 +1,4 @@
+# Configure for Qt4
 set(QT_MIN_VERSION "4.2.0")
 
 set(QT_USE_QTCORE TRUE)
@@ -10,6 +11,14 @@
 find_package(Qt4 REQUIRED)
 include(${QT_USE_FILE}) 
 
+# Configure for SDL
+find_package(SDL REQUIRED)
+
+if(SDL_INCLUDE_DIR)
+	include_directories(${SDL_INCLUDE_DIR})
+endif(SDL_INCLUDE_DIR)
+
+# Done
 include_directories(.)
 
 if(WIN32 AND NOT UNIX)
@@ -56,7 +65,8 @@
 	netudpserver.cpp
 	netudpwidget.cpp
 	chatwidget.cpp
-	binds.cpp)
+	binds.cpp
+	SDLs.cpp)
 
 if (WIN32)
 	set(hwfr_src ${hwfr_src} res/hedgewars.rc)
@@ -85,7 +95,8 @@
 	newnetclient.h
 	netudpserver.h
 	netudpwidget.h
-	chatwidget.h)
+	chatwidget.h
+	SDLs.h)
 
 set(hwfr_hdrs
 	binds.h
@@ -109,14 +120,25 @@
 	${hwfr_hdrs}
 	${hwfr_rez_src})
 	
-set(HW_LINK_LIBS ${QT_LIBRARIES})
+set(HW_LINK_LIBS 
+	${QT_LIBRARIES}
+	${SDL_LIBRARY}
+	)
 
 if(WIN32 AND NOT UNIX)
+	if(NOT SDL_LIBRARY)
+		set(HW_LINK_LIBS 
+			${HW_LINK_LIBS}
+			SDL
+			)
+	endif(NOT SDL_LIBRARY)
+
 	set(HW_LINK_LIBS 
 		${HW_LINK_LIBS}
 		ole32
 		winspool
-		uuid)
+		uuid
+		)
 endif(WIN32 AND NOT UNIX)
 
 target_link_libraries(hedgewars 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/SDLs.cpp	Thu Jul 12 14:44:41 2007 +0000
@@ -0,0 +1,52 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2007 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program 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; version 2 of the License
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include "SDLs.h"
+
+#include "SDL.h"
+
+SDLInteraction::SDLInteraction()
+{
+	SDL_Init(SDL_INIT_VIDEO);
+}
+
+SDLInteraction::~SDLInteraction()
+{
+	SDL_Quit();
+}
+
+QStringList SDLInteraction::getResolutions() const
+{
+	QStringList result;
+
+	SDL_Rect **modes;
+
+	modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
+
+	if((modes == (SDL_Rect **)0) || (modes == (SDL_Rect **)-1))
+	{
+		result << "640x480";
+	} else
+	{
+		for(int i = 0; modes[i]; ++i)
+			if ((modes[i]->w >= 640) && (modes[i]->h >= 480))
+				result << QString("%1x%2").arg(modes[i]->w).arg(modes[i]->h);
+	}
+
+	return result;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/SDLs.h	Thu Jul 12 14:44:41 2007 +0000
@@ -0,0 +1,34 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2007 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program 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; version 2 of the License
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef SDLS_H
+#define SDLS_H
+
+#include <QStringList>
+
+class SDLInteraction : public QObject
+{
+	Q_OBJECT
+
+	public:
+	SDLInteraction();
+	~SDLInteraction();
+	QStringList getResolutions() const;
+};
+
+#endif
--- a/QTfrontend/game.cpp	Thu Jul 12 14:43:34 2007 +0000
+++ b/QTfrontend/game.cpp	Thu Jul 12 14:44:41 2007 +0000
@@ -211,9 +211,10 @@
 QStringList HWGame::setArguments()
 {
 	QStringList arguments;
+	QRect resolution = config->vid_Resolution();
 	arguments << cfgdir->absolutePath();
-	arguments << resolutions[0][config->vid_Resolution()];
-	arguments << resolutions[1][config->vid_Resolution()];
+	arguments << QString::number(resolution.width());
+	arguments << QString::number(resolution.height());
 	arguments << "16"; // bpp
 	arguments << QString("%1").arg(ipc_port);
 	arguments << (config->vid_Fullscreen() ? "1" : "0");
--- a/QTfrontend/gameuiconfig.cpp	Thu Jul 12 14:43:34 2007 +0000
+++ b/QTfrontend/gameuiconfig.cpp	Thu Jul 12 14:44:41 2007 +0000
@@ -31,7 +31,8 @@
 {
 	Form = FormWidgets;
 
-	Form->ui.pageOptions->CBResolution->setCurrentIndex(value("video/resolution").toUInt());
+	int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString());
+	Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 0 : t);
 	Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool());
 
 	Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool());
@@ -58,7 +59,7 @@
 
 void GameUIConfig::SaveOptions()
 {
-	setValue("video/resolution", vid_Resolution());
+	setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText());
 	setValue("video/fullscreen", vid_Fullscreen());
 
 	setValue("audio/sound", isSoundEnabled());
@@ -72,9 +73,16 @@
 	setValue("misc/altdamage", isAltDamageEnabled());
 }
 
-int GameUIConfig::vid_Resolution()
+QRect GameUIConfig::vid_Resolution()
 {
-	return Form->ui.pageOptions->CBResolution->currentIndex();
+	QRect result(0, 0, 640, 480);
+	QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x');
+	if (wh.size() == 2)
+	{
+		result.setWidth(wh[0].toInt());
+		result.setHeight(wh[1].toInt());
+	}
+	return result;
 }
 
 bool GameUIConfig::vid_Fullscreen()
--- a/QTfrontend/gameuiconfig.h	Thu Jul 12 14:43:34 2007 +0000
+++ b/QTfrontend/gameuiconfig.h	Thu Jul 12 14:44:41 2007 +0000
@@ -21,6 +21,7 @@
 
 #include <QSettings>
 #include <QStringList>
+#include <QRect>
 
 class HWForm;
 class QSettings;
@@ -32,7 +33,7 @@
 public:
 	GameUIConfig(HWForm * FormWidgets, const QString & fileName);
 	QStringList GetTeamsList();
-	int vid_Resolution();
+	QRect vid_Resolution();
 	bool vid_Fullscreen();
 	bool isSoundEnabled();
 	bool isShowFPSEnabled();
--- a/QTfrontend/hedgewars.pro	Thu Jul 12 14:43:34 2007 +0000
+++ b/QTfrontend/hedgewars.pro	Thu Jul 12 14:44:41 2007 +0000
@@ -38,7 +38,8 @@
            newnetclient.h \
            netudpserver.h \
            netudpwidget.h \
-           chatwidget.h
+           chatwidget.h \
+           SDLs.h
            
            
 SOURCES += binds.cpp \
@@ -67,8 +68,11 @@
            newnetclient.cpp \
            netudpserver.cpp \
            netudpwidget.cpp \
-           chatwidget.cpp
+           chatwidget.cpp \
+           SDLs.cpp
 
 TRANSLATIONS += ../share/hedgewars/Data/Locale/hedgewars_ru.ts
 
 RESOURCES += hedgewars.qrc
+
+LIBS += libSDL
--- a/QTfrontend/hwconsts.h.in	Thu Jul 12 14:43:34 2007 +0000
+++ b/QTfrontend/hwconsts.h.in	Thu Jul 12 14:44:41 2007 +0000
@@ -19,12 +19,6 @@
 #include <QDir>
 #include <QString>
 
-const char resolutions[2][4][5] =
-{
-	{"640", "800", "1024", "1280"},
-	{"480", "600",  "768", "1024"}
-};
-
 extern QDir * cfgdir;
 extern QDir * datadir;
 extern QDir * bindir;
--- a/QTfrontend/pages.cpp	Thu Jul 12 14:43:34 2007 +0000
+++ b/QTfrontend/pages.cpp	Thu Jul 12 14:44:41 2007 +0000
@@ -41,6 +41,7 @@
 #include "fpsedit.h"
 #include "netudpwidget.h"
 #include "chatwidget.h"
+#include "SDLs.h"
 
 PageMain::PageMain(QWidget* parent) : QWidget(parent)
 {
@@ -372,10 +373,8 @@
 	GBAreslayout->addWidget(resolution);
 
 	CBResolution = new QComboBox(AGGroupBox);
-	CBResolution->addItem("640x480");
-	CBResolution->addItem("800x600");
-	CBResolution->addItem("1024x768");
-	CBResolution->addItem("1280x1024");
+	SDLInteraction sdli;
+	CBResolution->addItems(sdli.getResolutions());
 	GBAreslayout->addWidget(CBResolution);
 	GBAlayout->addLayout(GBAreslayout);