# HG changeset patch # User unc0rr # Date 1184251481 0 # Node ID 0376fdcc6322fc0a6ef9a7163c0fb2b2fbc7789e # Parent 4f83b3de17c7bb40908079debbb32f5ce22df7ee Get possible screen resolutions from SDL library diff -r 4f83b3de17c7 -r 0376fdcc6322 QTfrontend/CMakeLists.txt --- 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 diff -r 4f83b3de17c7 -r 0376fdcc6322 QTfrontend/SDLs.cpp --- /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 + * + * 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; +} diff -r 4f83b3de17c7 -r 0376fdcc6322 QTfrontend/SDLs.h --- /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 + * + * 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 + +class SDLInteraction : public QObject +{ + Q_OBJECT + + public: + SDLInteraction(); + ~SDLInteraction(); + QStringList getResolutions() const; +}; + +#endif diff -r 4f83b3de17c7 -r 0376fdcc6322 QTfrontend/game.cpp --- 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"); diff -r 4f83b3de17c7 -r 0376fdcc6322 QTfrontend/gameuiconfig.cpp --- 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() diff -r 4f83b3de17c7 -r 0376fdcc6322 QTfrontend/gameuiconfig.h --- 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 #include +#include 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(); diff -r 4f83b3de17c7 -r 0376fdcc6322 QTfrontend/hedgewars.pro --- 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 diff -r 4f83b3de17c7 -r 0376fdcc6322 QTfrontend/hwconsts.h.in --- 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 #include -const char resolutions[2][4][5] = -{ - {"640", "800", "1024", "1280"}, - {"480", "600", "768", "1024"} -}; - extern QDir * cfgdir; extern QDir * datadir; extern QDir * bindir; diff -r 4f83b3de17c7 -r 0376fdcc6322 QTfrontend/pages.cpp --- 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);