[Scummvm-git-logs] scummvm master -> 7f0d75bbfc76fdb41c9ce0f9812114c045fb9fb0

lephilousophe noreply at scummvm.org
Tue Jul 4 19:11:56 UTC 2023


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
43bd4edcc1 GUI: Handle screen resize while displaying MessageDialog
7f0d75bbfc ANDROID: Fix cursor position in touchpad mode while rotating


Commit: 43bd4edcc15684ef4869932ec40c5bfc968f439e
    https://github.com/scummvm/scummvm/commit/43bd4edcc15684ef4869932ec40c5bfc968f439e
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-07-04T21:09:12+02:00

Commit Message:
GUI: Handle screen resize while displaying MessageDialog

Changed paths:
    gui/message.cpp
    gui/message.h


diff --git a/gui/message.cpp b/gui/message.cpp
index 6de65d1ae8f..ee798569f23 100644
--- a/gui/message.cpp
+++ b/gui/message.cpp
@@ -44,10 +44,33 @@ void MessageDialog::init(const Common::U32String &message,
 						 Graphics::TextAlign alignment,
 						 const char *url,
 						 const Common::U32String &extraMessage) {
+	// message widgets will be created in reflowLayout as needed
+	_message = message;
+	_alignment = alignment;
 	_url = url;
-
 	_extraMessage = nullptr;
 
+	// Only use bogus sizes, we do the calculation in reflowLayout
+	if (!defaultButton.empty()) {
+		// Confirm dialog
+		_buttons.push_back(new ButtonWidget(this, 0, 0, 0, 0, defaultButton, Common::U32String(), kDefaultCmd, Common::ASCII_RETURN));
+	}
+
+	int buttonHotKey = altButtons.size() == 1 ? Common::ASCII_ESCAPE : 0;
+	for (size_t i = 0, total = altButtons.size(); i < total; ++i) {
+		_buttons.push_back(new ButtonWidget(this, 0, 0, 0, 0, altButtons[i], Common::U32String(), kAltCmd + i, buttonHotKey));
+		buttonHotKey = 0;
+	}
+
+	if (!extraMessage.empty()) {
+		_extraMessage = new StaticTextWidget(this, 0, 0, 0, 0, extraMessage, Graphics::kTextAlignLeft);
+	}
+}
+
+void MessageDialog::reflowLayout() {
+	const int horizontalMargin = 10;
+	const int buttonSpacing = 10;
+
 	const int screenW = g_system->getOverlayWidth();
 	const int screenH = g_system->getOverlayHeight();
 
@@ -59,24 +82,24 @@ void MessageDialog::init(const Common::U32String &message,
 	// Using this, and accounting for the space the button(s) need, we can set
 	// the real size of the dialog
 	Common::Array<Common::U32String> lines;
-	int lineCount;
-	const int horizontalMargin = 10;
-	int maxlineWidth = g_gui.getFont().wordWrapText(message, screenW - 2 * horizontalMargin - 20, lines);
-	const int buttonCount = altButtons.size() + 1;
-	const int buttonSpacing = 10;
+	size_t lineCount;
+
+	int maxlineWidth = g_gui.getFont().wordWrapText(_message, screenW - 2 * horizontalMargin - 20, lines);
+
+	const size_t buttonCount = _buttons.size();
 	const int buttonsTotalWidth = buttonCount * buttonWidth + (buttonCount - 1) * buttonSpacing;
 
-	// Calculate the desired dialog size (maxing out at 300*180 for now)
+	// Calculate the desired dialog size
 	_w = MAX(maxlineWidth, buttonsTotalWidth) + 2 * horizontalMargin;
 
 	lineCount = lines.size();
 
 	_h = 16;
-	if (!defaultButton.empty() || !altButtons.empty())
+	if (buttonCount)
 		_h += buttonHeight + 8;
 
 	// Limit the number of lines so that the dialog still fits on the screen.
-	if (lineCount > (screenH - 20 - _h) / kLineHeight) {
+	if (lineCount > size_t((screenH - 20 - _h) / kLineHeight)) {
 		lineCount = (screenH - 20 - _h) / kLineHeight;
 	}
 	_h += lineCount * kLineHeight;
@@ -86,29 +109,34 @@ void MessageDialog::init(const Common::U32String &message,
 	_y = (screenH - _h) / 2;
 
 	// Each line is represented by one static text item.
-	for (int i = 0; i < lineCount; i++) {
-		new StaticTextWidget(this, horizontalMargin, 10 + i * kLineHeight, maxlineWidth, kLineHeight, lines[i], alignment);
+	// Update existing lines
+	size_t toUpdateLines = MIN<size_t>(lineCount, _lines.size());
+	for (size_t i = 0; i < toUpdateLines; i++) {
+		_lines[i]->setPos(horizontalMargin, 10 + i * kLineHeight);
+		_lines[i]->setSize(maxlineWidth, kLineHeight);
+		_lines[i]->setLabel(lines[i]);
 	}
-
-	// Assume defaultButton is always given
-	int buttonPos = (_w - buttonsTotalWidth) / 2;
-
-	if (!defaultButton.empty()) {
-		// Confirm dialog
-		new ButtonWidget(this, buttonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, defaultButton, Common::U32String(), kDefaultCmd, Common::ASCII_RETURN);
-		buttonPos += buttonWidth + buttonSpacing;
+	// Create missing lines
+	for (size_t i = toUpdateLines; i < lineCount; i++) {
+		_lines.push_back(new StaticTextWidget(this, horizontalMargin, 10 + i * kLineHeight, maxlineWidth, kLineHeight, lines[i], _alignment));
+	}
+	// Cleanup old useless lines
+	for (size_t i = lineCount, total = _lines.size(); i < total; i++) {
+		this->removeWidget(_lines[i]);
+		delete _lines[i];
 	}
+	_lines.resize(lineCount);
 
-	int buttonHotKey = altButtons.size() == 1 ? Common::ASCII_ESCAPE : 0;
-	for (size_t i = 0, total = altButtons.size(); i < total; ++i) {
-		new ButtonWidget(this, buttonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, altButtons[i], Common::U32String(), kAltCmd + i, buttonHotKey);
-		buttonHotKey = 0;
+	int buttonPos = (_w - buttonsTotalWidth) / 2;
+	for (size_t i = 0; i < buttonCount; ++i) {
+		_buttons[i]->setPos(buttonPos, _h - buttonHeight - 8);
+		_buttons[i]->setSize(buttonWidth, buttonHeight);
 		buttonPos += buttonWidth + buttonSpacing;
 	}
 
-	if (!extraMessage.empty()) {
-		_extraMessage = new StaticTextWidget(this, 10, _h, maxlineWidth, kLineHeight, extraMessage, Graphics::kTextAlignLeft);
-
+	if (_extraMessage) {
+		_extraMessage->setPos(10, _h);
+		_extraMessage->setSize(maxlineWidth, kLineHeight);
 		_h += kLineHeight;
 	}
 }
diff --git a/gui/message.h b/gui/message.h
index 0789b36ee72..2656fa81659 100644
--- a/gui/message.h
+++ b/gui/message.h
@@ -30,6 +30,7 @@ namespace GUI {
 
 class CommandSender;
 class StaticTextWidget;
+class ButtonWidget;
 
 enum {
 	kMessageOK = 0,
@@ -59,6 +60,8 @@ public:
 				  Graphics::TextAlign alignment = Graphics::kTextAlignCenter);
 
 	void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
+	void reflowLayout() override;
+
 private:
 	const char *_url;
 	void init(const Common::U32String &message,
@@ -69,6 +72,10 @@ private:
 			  const Common::U32String &extraMessage);
 
 protected:
+	Common::U32String _message;
+	Graphics::TextAlign _alignment;
+	Common::Array<StaticTextWidget *> _lines;
+	Common::Array<ButtonWidget *> _buttons;
 	StaticTextWidget *_extraMessage;
 };
 


Commit: 7f0d75bbfc76fdb41c9ce0f9812114c045fb9fb0
    https://github.com/scummvm/scummvm/commit/7f0d75bbfc76fdb41c9ce0f9812114c045fb9fb0
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-07-04T21:09:13+02:00

Commit Message:
ANDROID: Fix cursor position in touchpad mode while rotating

Without this, the cursor ends up in limbo and you need to scroll several
times to make it appear again.

Changed paths:
    backends/platform/android/events.cpp


diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index 95c42d45328..5e1268b26dd 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -673,6 +673,16 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
 	case JE_DOWN:
 //		LOGD("JE_DOWN");
 		_touch_pt_down = dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->getMousePosition();
+		// If the cursor was outside the area (because the screen rotated) clip it
+		// to not scroll several times to make the cursor appear in the area
+		// Do not clamp the cursor position while rotating the screen because if the user rotated by mistake
+		// rotating again will see the cursor position preserved
+		if (_touch_pt_down.x > JNI::egl_surface_width) {
+			_touch_pt_down.x = JNI::egl_surface_width;
+		}
+		if (_touch_pt_down.y > JNI::egl_surface_height) {
+			_touch_pt_down.y = JNI::egl_surface_height;
+		}
 		_touch_pt_scroll.x = -1;
 		_touch_pt_scroll.y = -1;
 		break;




More information about the Scummvm-git-logs mailing list