[Scummvm-git-logs] scummvm master -> a46913545f5a24fcb32e6b793a86a9b010b6fd8e

sev- noreply at scummvm.org
Wed Apr 24 22:57:07 UTC 2024


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

Summary:
a46913545f GUI: Keep caret visible in editable widgets while moving it


Commit: a46913545f5a24fcb32e6b793a86a9b010b6fd8e
    https://github.com/scummvm/scummvm/commit/a46913545f5a24fcb32e6b793a86a9b010b6fd8e
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2024-04-25T00:57:04+02:00

Commit Message:
GUI: Keep caret visible in editable widgets while moving it

This was actually the intention all along. But if a redraw of the widget
itself was triggered at the same time, it would draw over the caret,
effectively erasing it. To get around this, the caret is now also drawn
as part of the widget, when necessary.

Changed paths:
    gui/widgets/editable.cpp
    gui/widgets/editable.h
    gui/widgets/edittext.cpp
    gui/widgets/list.cpp


diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp
index e15649d012d..0a0251861f3 100644
--- a/gui/widgets/editable.cpp
+++ b/gui/widgets/editable.cpp
@@ -69,6 +69,12 @@ void EditableWidget::init() {
 EditableWidget::~EditableWidget() {
 }
 
+void EditableWidget::drawWidget() {
+	if (_caretVisible) {
+		drawCaret(false, true);
+	}
+}
+
 void EditableWidget::reflowLayout() {
 	Widget::reflowLayout();
 
@@ -526,13 +532,24 @@ int EditableWidget::getSelectionCarretOffset() const {
 	return g_gui.getStringWidth(substr, _font) - _editScrollOffset;
 }
 
-void EditableWidget::drawCaret(bool erase) {
+  void EditableWidget::drawCaret(bool erase, bool useRelativeCoordinates) {
 	// Only draw if item is visible
 	if (!isVisible() || !_boss->isVisible())
 		return;
 
 	Common::Rect editRect = getEditRect();
 
+	int xOff;
+	int yOff;
+
+	if (useRelativeCoordinates) {
+		xOff = getRelX();
+		yOff = getRelY();
+	} else {
+		xOff = getAbsX();
+		yOff = getAbsY();
+	}
+
 	int x = editRect.left;
 	int y = editRect.top;
 
@@ -554,10 +571,10 @@ void EditableWidget::drawCaret(bool erase) {
 		return;
 
 	if (g_gui.useRTL())
-		x += g_system->getOverlayWidth() - _w - getAbsX() + g_gui.getOverlayOffset();
+		x += g_system->getOverlayWidth() - _w - xOff + g_gui.getOverlayOffset();
 	else
-		x += getAbsX();
-	y += getAbsY();
+		x += xOff;
+	y += yOff;
 
 	g_gui.theme()->drawCaret(Common::Rect(x, y, x + 1, y + editRect.height()), erase);
 
diff --git a/gui/widgets/editable.h b/gui/widgets/editable.h
index acf16493229..0375f5d9b6e 100644
--- a/gui/widgets/editable.h
+++ b/gui/widgets/editable.h
@@ -91,6 +91,8 @@ public:
 	void setSelectionOffset(int newOffset);
 
 protected:
+	void drawWidget() override;
+
 	virtual void startEditMode() = 0;
 	virtual void endEditMode() = 0;
 	virtual void abortEditMode() = 0;
@@ -102,7 +104,7 @@ protected:
 	virtual Common::Rect getEditRect() const = 0;
 	virtual int getCaretOffset() const;
 	virtual int getSelectionCarretOffset() const;
-	void drawCaret(bool erase);
+	void drawCaret(bool erase, bool useRelativeCoordinates = false);
 	bool adjustOffset();
 	void makeCaretVisible();
 
diff --git a/gui/widgets/edittext.cpp b/gui/widgets/edittext.cpp
index e150e3a1792..45ce306e899 100644
--- a/gui/widgets/edittext.cpp
+++ b/gui/widgets/edittext.cpp
@@ -122,6 +122,8 @@ void EditTextWidget::drawWidget() {
 		                        -_editScrollOffset, false, _font, ThemeEngine::kFontColorNormal, true, 
 		                        _textDrawableArea);
 	}
+
+	EditableWidget::drawWidget();
 }
 
 Common::Rect EditTextWidget::getEditRect() const {
diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp
index a30f37e5987..deda99f4163 100644
--- a/gui/widgets/list.cpp
+++ b/gui/widgets/list.cpp
@@ -613,6 +613,8 @@ void ListWidget::drawWidget() {
 			g_gui.theme()->drawText(r2, buffer, _state, _drawAlign, inverted, _leftPadding, true);
 		}
 	}
+
+	EditableWidget::drawWidget();
 }
 
 Common::Rect ListWidget::getEditRect() const {




More information about the Scummvm-git-logs mailing list