1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Merge branch 'krnowak/choose-display' into develop

This commit is contained in:
AlexVinS
2016-09-04 04:06:42 +03:00
12 changed files with 129 additions and 36 deletions

View File

@@ -92,7 +92,7 @@ static po::variables_map vm;
static bool ermInteractiveMode = false; //structurize when time is right static bool ermInteractiveMode = false; //structurize when time is right
void processCommand(const std::string &message); void processCommand(const std::string &message);
static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo=true); static void setScreenRes(int w, int h, int bpp, bool fullscreen, int displayIndex, bool resetVideo=true);
void dispose(); void dispose();
void playIntro(); void playIntro();
static void mainLoop(); static void mainLoop();
@@ -407,7 +407,7 @@ int main(int argc, char** argv)
} }
} }
setScreenRes(res["width"].Float(), res["height"].Float(), video["bitsPerPixel"].Float(), video["fullscreen"].Bool()); setScreenRes(res["width"].Float(), res["height"].Float(), video["bitsPerPixel"].Float(), video["displayIndex"].Float(), video["fullscreen"].Bool());
logGlobal->infoStream() <<"\tInitializing screen: "<<pomtime.getDiff(); logGlobal->infoStream() <<"\tInitializing screen: "<<pomtime.getDiff();
} }
@@ -984,7 +984,7 @@ static void cleanupRenderer()
} }
} }
static bool recreateWindow(int w, int h, int bpp, bool fullscreen) static bool recreateWindow(int w, int h, int bpp, bool fullscreen, int displayIndex)
{ {
// VCMI will only work with 2 or 4 bytes per pixel // VCMI will only work with 2 or 4 bytes per pixel
vstd::amax(bpp, 16); vstd::amax(bpp, 16);
@@ -992,7 +992,14 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
if(bpp>16) if(bpp>16)
bpp = 32; bpp = 32;
if(!checkVideoMode(0,w,h)) if(displayIndex < 0)
{
if (mainWindow != nullptr)
displayIndex = SDL_GetWindowDisplayIndex(mainWindow);
if (displayIndex < 0)
displayIndex = 0;
}
if(!checkVideoMode(displayIndex, w, h))
{ {
logGlobal->errorStream() << "Error: SDL says that " << w << "x" << h << " resolution is not available!"; logGlobal->errorStream() << "Error: SDL says that " << w << "x" << h << " resolution is not available!";
return false; return false;
@@ -1005,12 +1012,12 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
if(fullscreen) if(fullscreen)
{ {
//in full-screen mode always use desktop resolution //in full-screen mode always use desktop resolution
mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, 0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP); mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex),SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex), 0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
} }
else else
{ {
mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, w, h, 0); mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex),SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex), w, h, 0);
} }
if(nullptr == mainWindow) if(nullptr == mainWindow)
@@ -1091,9 +1098,9 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
} }
//used only once during initialization //used only once during initialization
static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo) static void setScreenRes(int w, int h, int bpp, bool fullscreen, int displayIndex, bool resetVideo)
{ {
if(!recreateWindow(w,h,bpp,fullscreen)) if(!recreateWindow(w, h, bpp, fullscreen, displayIndex))
{ {
throw std::runtime_error("Requested screen resolution is not available\n"); throw std::runtime_error("Requested screen resolution is not available\n");
} }
@@ -1111,7 +1118,7 @@ static void fullScreenChanged()
auto w = screen->w; auto w = screen->w;
auto h = screen->h; auto h = screen->h;
if(!recreateWindow(w,h,bitsPerPixel,toFullscreen)) if(!recreateWindow(w, h, bitsPerPixel, toFullscreen, -1))
{ {
//will return false and report error if video mode is not supported //will return false and report error if video mode is not supported
return; return;

View File

@@ -45,7 +45,7 @@
"type" : "object", "type" : "object",
"additionalProperties" : false, "additionalProperties" : false,
"default": {}, "default": {},
"required" : [ "screenRes", "bitsPerPixel", "fullscreen", "spellbookAnimation","driver", "showIntro" ], "required" : [ "screenRes", "bitsPerPixel", "fullscreen", "spellbookAnimation","driver", "showIntro", "displayIndex" ],
"properties" : { "properties" : {
"screenRes" : { "screenRes" : {
"type" : "object", "type" : "object",
@@ -77,6 +77,10 @@
"type" : "string", "type" : "string",
"default" : "opengl", "default" : "opengl",
"description" : "preferred graphics backend driver name for SDL2" "description" : "preferred graphics backend driver name for SDL2"
},
"displayIndex" : {
"type" : "number",
"default" : 0
} }
} }
}, },

View File

@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8.7)
include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${ZLIB_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}) include_directories(${ZLIB_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS})
include_directories(${SDL_INCLUDE_DIR})
set(launcher_modmanager_SRCS set(launcher_modmanager_SRCS
modManager/cdownloadmanager_moc.cpp modManager/cdownloadmanager_moc.cpp
@@ -25,6 +26,7 @@ set(launcher_SRCS
mainwindow_moc.cpp mainwindow_moc.cpp
launcherdirs.cpp launcherdirs.cpp
jsonutils.cpp jsonutils.cpp
sdldisplayquery.cpp
) )
set(launcher_FORMS set(launcher_FORMS
@@ -60,10 +62,10 @@ endif()
if(MSVC) if(MSVC)
# Fix _WinMain@16 linking error # Fix _WinMain@16 linking error
target_link_libraries(vcmilauncher vcmi ${Qt5Core_QTMAIN_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES}) target_link_libraries(vcmilauncher vcmi ${Qt5Core_QTMAIN_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES} ${SDL_LIBRARY})
else() else()
# The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore # The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore
target_link_libraries(vcmilauncher vcmi ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES}) target_link_libraries(vcmilauncher vcmi ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES} ${SDL_LIBRARY})
endif() endif()
# temporary(?) disabled - generation of PCH takes too much time since cotire is trying to collect all Qt headers # temporary(?) disabled - generation of PCH takes too much time since cotire is trying to collect all Qt headers

View File

@@ -1,11 +1,13 @@
#include "StdInc.h" #include "StdInc.h"
#include "mainwindow_moc.h" #include "mainwindow_moc.h"
#include <QApplication> #include <QApplication>
#include "sdldisplayquery.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
auto displayList = getDisplays();
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w(displayList);
w.show(); w.show();
return a.exec(); return a.exec();

View File

@@ -26,7 +26,7 @@ void MainWindow::load()
settings.init(); settings.init();
} }
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(const QStringList& displayList, QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
@@ -34,6 +34,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
ui->tabListWidget->setCurrentIndex(0); ui->tabListWidget->setCurrentIndex(0);
ui->settingsView->setDisplayList(displayList);
connect(ui->tabSelectList, SIGNAL(currentRowChanged(int)), connect(ui->tabSelectList, SIGNAL(currentRowChanged(int)),
ui->tabListWidget, SLOT(setCurrentIndex(int))); ui->tabListWidget, SLOT(setCurrentIndex(int)));

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include <QMainWindow> #include <QMainWindow>
#include <QStringList>
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
@@ -14,7 +15,7 @@ class MainWindow : public QMainWindow
void load(); void load();
void startExecutable(QString name); void startExecutable(QString name);
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(const QStringList& displayList, QWidget *parent = 0);
~MainWindow(); ~MainWindow();
private slots: private slots:

View File

@@ -176,7 +176,7 @@
<number>1</number> <number>1</number>
</property> </property>
<widget class="CModListView" name="stackedWidgetPage2"/> <widget class="CModListView" name="stackedWidgetPage2"/>
<widget class="CSettingsView" name="stackedWidgetPage3"/> <widget class="CSettingsView" name="settingsView"/>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@@ -0,0 +1,32 @@
#include "sdldisplayquery.h"
#include <QString>
#include <QTextStream>
#include <SDL.h>
#include <SDL_video.h>
QStringList getDisplays()
{
if(SDL_Init(SDL_INIT_VIDEO))
return QStringList("default display");
const int displays = SDL_GetNumVideoDisplays();
QStringList list;
for (int display = 0; display < displays; ++display)
{
SDL_Rect rect;
if (SDL_GetDisplayBounds (display, &rect))
continue;
QString string;
QTextStream(&string) << display << " - " << rect.w << "x" << rect.h << " (at " << rect.x << ", " << rect.y << ")";
list << string;
}
SDL_Quit();
return list;
}

View File

@@ -0,0 +1,5 @@
#pragma once
#include <QStringList>
QStringList getDisplays();

View File

@@ -20,11 +20,25 @@ static const std::string knownEncodingsList[] = //TODO: remove hardcode
"GB2312" // basic set for Simplified Chinese. Separate from GBK to allow proper detection of H3 fonts "GB2312" // basic set for Simplified Chinese. Separate from GBK to allow proper detection of H3 fonts
}; };
void CSettingsView::setDisplayList(const QStringList& displayList)
{
if (displayList.count() < 2)
{
ui->comboBoxDisplayIndex->hide ();
ui->labelDisplayIndex->hide ();
}
else
{
ui->comboBoxDisplayIndex->clear();
ui->comboBoxDisplayIndex->addItems(displayList);
ui->comboBoxDisplayIndex->setCurrentIndex(settings["video"]["displayIndex"].Float());
}
}
void CSettingsView::loadSettings() void CSettingsView::loadSettings()
{ {
int resX = settings["video"]["screenRes"]["width"].Float(); int resX = settings["video"]["screenRes"]["width"].Float();
int resY = settings["video"]["screenRes"]["height"].Float(); int resY = settings["video"]["screenRes"]["height"].Float();
int resIndex = ui->comboBoxResolution->findText(QString("%1x%2").arg(resX).arg(resY)); int resIndex = ui->comboBoxResolution->findText(QString("%1x%2").arg(resX).arg(resY));
ui->comboBoxResolution->setCurrentIndex(resIndex); ui->comboBoxResolution->setCurrentIndex(resIndex);
@@ -92,6 +106,12 @@ void CSettingsView::on_comboBoxAutoCheck_currentIndexChanged(int index)
node->Bool() = index; node->Bool() = index;
} }
void CSettingsView::on_comboBoxDisplayIndex_currentIndexChanged(int index)
{
Settings node = settings.write["video"];
node["displayIndex"].Float() = index;
}
void CSettingsView::on_comboBoxPlayerAI_currentIndexChanged(const QString &arg1) void CSettingsView::on_comboBoxPlayerAI_currentIndexChanged(const QString &arg1)
{ {
Settings node = settings.write["server"]["playerAI"]; Settings node = settings.write["server"]["playerAI"];

View File

@@ -15,6 +15,7 @@ public:
~CSettingsView(); ~CSettingsView();
void loadSettings(); void loadSettings();
void setDisplayList(const QStringList& displayList);
private slots: private slots:
void on_comboBoxResolution_currentIndexChanged(const QString &arg1); void on_comboBoxResolution_currentIndexChanged(const QString &arg1);
@@ -43,6 +44,8 @@ private slots:
void on_comboBoxAutoCheck_currentIndexChanged(int index); void on_comboBoxAutoCheck_currentIndexChanged(int index);
void on_comboBoxDisplayIndex_currentIndexChanged(int index);
private: private:
Ui::CSettingsView *ui; Ui::CSettingsView *ui;
}; };

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>700</width> <width>714</width>
<height>420</height> <height>429</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -26,7 +26,7 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item row="9" column="1" colspan="4"> <item row="10" column="1" colspan="4">
<widget class="QLabel" name="LauncherSettings"> <widget class="QLabel" name="LauncherSettings">
<property name="font"> <property name="font">
<font> <font>
@@ -39,7 +39,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="6" colspan="4"> <item row="6" column="6" colspan="4">
<widget class="QLabel" name="labelGeneral"> <widget class="QLabel" name="labelGeneral">
<property name="font"> <property name="font">
<font> <font>
@@ -59,7 +59,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="7" colspan="3"> <item row="7" column="7" colspan="3">
<widget class="QSpinBox" name="spinBoxNetworkPort"> <widget class="QSpinBox" name="spinBoxNetworkPort">
<property name="minimum"> <property name="minimum">
<number>1024</number> <number>1024</number>
@@ -99,7 +99,7 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="5" column="1" colspan="4"> <item row="6" column="1" colspan="4">
<widget class="QLabel" name="labelAISettings"> <widget class="QLabel" name="labelAISettings">
<property name="font"> <property name="font">
<font> <font>
@@ -192,7 +192,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="13" column="1" colspan="9"> <item row="14" column="1" colspan="9">
<widget class="QPlainTextEdit" name="plainTextEditRepos"> <widget class="QPlainTextEdit" name="plainTextEditRepos">
<property name="lineWrapMode"> <property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum> <enum>QPlainTextEdit::NoWrap</enum>
@@ -222,7 +222,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="4"> <item row="8" column="4">
<widget class="QComboBox" name="comboBoxNeutralAI"> <widget class="QComboBox" name="comboBoxNeutralAI">
<item> <item>
<property name="text"> <property name="text">
@@ -250,21 +250,21 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="8" column="1">
<widget class="QLabel" name="labelNeutralAI"> <widget class="QLabel" name="labelNeutralAI">
<property name="text"> <property name="text">
<string>Neutral AI</string> <string>Neutral AI</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="6"> <item row="8" column="6">
<widget class="QLabel" name="labelEncoding"> <widget class="QLabel" name="labelEncoding">
<property name="text"> <property name="text">
<string>Heroes III character set</string> <string>Heroes III character set</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="4"> <item row="7" column="4">
<widget class="QComboBox" name="comboBoxPlayerAI"> <widget class="QComboBox" name="comboBoxPlayerAI">
<item> <item>
<property name="text"> <property name="text">
@@ -273,14 +273,14 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="7" column="1">
<widget class="QLabel" name="labelPlayerAI"> <widget class="QLabel" name="labelPlayerAI">
<property name="text"> <property name="text">
<string>Player AI</string> <string>Player AI</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="7" colspan="3"> <item row="8" column="7" colspan="3">
<widget class="QComboBox" name="comboBoxEncoding"> <widget class="QComboBox" name="comboBoxEncoding">
<item> <item>
<property name="text"> <property name="text">
@@ -309,7 +309,7 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="6" column="6"> <item row="7" column="6">
<widget class="QLabel" name="labelNetworkPort"> <widget class="QLabel" name="labelNetworkPort">
<property name="text"> <property name="text">
<string>Network port</string> <string>Network port</string>
@@ -329,7 +329,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="11" column="1" colspan="4"> <item row="12" column="1" colspan="4">
<widget class="QLabel" name="labelRepositories"> <widget class="QLabel" name="labelRepositories">
<property name="font"> <property name="font">
<font> <font>
@@ -411,7 +411,7 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="4" column="1" colspan="4"> <item row="5" column="1" colspan="4">
<spacer name="spacerSections"> <spacer name="spacerSections">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@@ -427,7 +427,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="8" column="1" colspan="4"> <item row="9" column="1" colspan="4">
<spacer name="spacerRepos"> <spacer name="spacerRepos">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@@ -472,7 +472,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="10" column="6"> <item row="11" column="6">
<widget class="QComboBox" name="comboBoxAutoCheck"> <widget class="QComboBox" name="comboBoxAutoCheck">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>1</number>
@@ -489,13 +489,29 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="10" column="1" colspan="4"> <item row="11" column="1" colspan="4">
<widget class="QLabel" name="labelAutoCheck"> <widget class="QLabel" name="labelAutoCheck">
<property name="text"> <property name="text">
<string>Check repositories on startup</string> <string>Check repositories on startup</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1">
<widget class="QLabel" name="labelDisplayIndex">
<property name="text">
<string>Display index</string>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QComboBox" name="comboBoxDisplayIndex">
<item>
<property name="text">
<string>0</string>
</property>
</item>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>