瀏覽代碼

Resolution selector will now correctly update in borderless window mode

Ivan Savenko 2 年之前
父節點
當前提交
06b6f59107

+ 34 - 5
client/windows/settings/GeneralOptionsTab.cpp

@@ -145,10 +145,6 @@ GeneralOptionsTab::GeneralOptionsTab()
 
 
 	const auto & currentResolution = settings["video"]["resolution"];
 	const auto & currentResolution = settings["video"]["resolution"];
 
 
-	std::shared_ptr<CLabel> resolutionLabel = widget<CLabel>("resolutionLabel");
-	if (resolutionLabel)
-		resolutionLabel->setText(resolutionToLabelString(currentResolution["width"].Integer(), currentResolution["height"].Integer()));
-
 	std::shared_ptr<CLabel> scalingLabel = widget<CLabel>("scalingLabel");
 	std::shared_ptr<CLabel> scalingLabel = widget<CLabel>("scalingLabel");
 	scalingLabel->setText(scalingToLabelString(currentResolution["scaling"].Integer()));
 	scalingLabel->setText(scalingToLabelString(currentResolution["scaling"].Integer()));
 
 
@@ -183,6 +179,34 @@ GeneralOptionsTab::GeneralOptionsTab()
 
 
 	std::shared_ptr<CLabel> soundVolumeLabel = widget<CLabel>("soundValueLabel");
 	std::shared_ptr<CLabel> soundVolumeLabel = widget<CLabel>("soundValueLabel");
 	soundVolumeLabel->setText(std::to_string(CCS->soundh->getVolume()) + "%");
 	soundVolumeLabel->setText(std::to_string(CCS->soundh->getVolume()) + "%");
+
+	updateResolutionSelector();
+}
+
+void GeneralOptionsTab::updateResolutionSelector()
+{
+	std::shared_ptr<CButton> resolutionButton = widget<CButton>("resolutionButton");
+	std::shared_ptr<CLabel> resolutionLabel = widget<CLabel>("resolutionLabel");
+
+	if (settings["video"]["fullscreen"].Bool() && !settings["video"]["realFullscreen"].Bool())
+	{
+		if (resolutionButton)
+			resolutionButton->disable();
+
+		if (resolutionLabel)
+			resolutionLabel->setText(resolutionToLabelString(GH.screenDimensions().x, GH.screenDimensions().y));
+	}
+	else
+	{
+		const auto & currentResolution = settings["video"]["resolution"];
+
+		if (resolutionButton)
+			resolutionButton->enable();
+
+		if (resolutionLabel)
+			resolutionLabel->setText(resolutionToLabelString(currentResolution["width"].Integer(), currentResolution["height"].Integer()));
+	}
+
 }
 }
 
 
 void GeneralOptionsTab::selectGameResolution()
 void GeneralOptionsTab::selectGameResolution()
@@ -240,14 +264,19 @@ void GeneralOptionsTab::setFullscreenMode(bool on, bool exclusive)
 
 
 	if (fullscreenExclusiveCheckbox)
 	if (fullscreenExclusiveCheckbox)
 		fullscreenExclusiveCheckbox->setSelected(on && exclusive);
 		fullscreenExclusiveCheckbox->setSelected(on && exclusive);
+
+	updateResolutionSelector();
 }
 }
 
 
 void GeneralOptionsTab::selectGameScaling()
 void GeneralOptionsTab::selectGameScaling()
 {
 {
 	supportedScaling.clear();
 	supportedScaling.clear();
 
 
+	// generate list of all possible scaling values, with 10% step
+	// also add one value over maximum, so if player can use scaling up to 123.456% he will be able to select 130%
+	// and let screen handler clamp that value to actual maximum
 	auto [minimalScaling, maximalScaling] = GH.screenHandler().getSupportedScalingRange();
 	auto [minimalScaling, maximalScaling] = GH.screenHandler().getSupportedScalingRange();
-	for (int i = 0; i <= maximalScaling; i += 10)
+	for (int i = 0; i <= maximalScaling + 10 - 1; i += 10)
 	{
 	{
 		if (i >= minimalScaling)
 		if (i >= minimalScaling)
 			supportedScaling.push_back(i);
 			supportedScaling.push_back(i);

+ 2 - 0
client/windows/settings/GeneralOptionsTab.h

@@ -31,4 +31,6 @@ private:
 
 
 public:
 public:
 	GeneralOptionsTab();
 	GeneralOptionsTab();
+
+	void updateResolutionSelector();
 };
 };

+ 10 - 0
client/windows/settings/SettingsMainWindow.cpp

@@ -156,3 +156,13 @@ void SettingsMainWindow::showAll(SDL_Surface *to)
 	CIntObject::showAll(to);
 	CIntObject::showAll(to);
 	CMessage::drawBorder(color, to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
 	CMessage::drawBorder(color, to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
 }
 }
+
+void SettingsMainWindow::onScreenResize()
+{
+	InterfaceObjectConfigurable::onScreenResize();
+
+	auto tab = std::dynamic_pointer_cast<GeneralOptionsTab>(tabContentArea->getItem());
+
+	if (tab)
+		tab->updateResolutionSelector();
+}

+ 2 - 1
client/windows/settings/SettingsMainWindow.h

@@ -41,6 +41,7 @@ private:
 public:
 public:
 	SettingsMainWindow(BattleInterface * parentBattleInterface = nullptr);
 	SettingsMainWindow(BattleInterface * parentBattleInterface = nullptr);
 
 
-	void showAll(SDL_Surface * to);
+	void showAll(SDL_Surface * to) override;
+	void onScreenResize() override;
 };
 };