From d655ee1c6f7b2ba85fa62752bb7d76ec0b530c03 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 26 Mar 2023 14:19:28 +0200 Subject: [PATCH] GUI: Added close button to the TextViewer dialog --- gui/textviewer.cpp | 33 ++++++++++++++++++++++++++------- gui/textviewer.h | 2 +- po/POTFILES | 1 + 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/gui/textviewer.cpp b/gui/textviewer.cpp index c3a7b386c1b..30e54c17a98 100644 --- a/gui/textviewer.cpp +++ b/gui/textviewer.cpp @@ -21,6 +21,7 @@ #include "common/file.h" #include "common/tokenizer.h" +#include "common/translation.h" #include "graphics/font.h" #include "graphics/fontman.h" @@ -45,10 +46,12 @@ TextViewerDialog::TextViewerDialog(Common::String fname) _lineHeight = _font->getFontHeight() + 2; // Add scrollbar - _scrollbarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0); - _scrollBar = new ScrollBarWidget(this, _w - _scrollbarWidth - 1, 0, _scrollbarWidth, _h); + _scrollBar = new ScrollBarWidget(this, 0, 0, 1, 1); _scrollBar->setTarget(this); + // I18N: Close dialog button + _closeButton = new ButtonWidget(this, 0, 0, 1, 1, _("Close"), Common::U32String(), kCloseCmd); + _currentPos = 0; _scrollLine = _linesPerPage - 1; @@ -107,12 +110,25 @@ void TextViewerDialog::reflowLayout() { _padX = _w * kPadX; _padY = _h * kPadY; - // Calculate depending values - _lineWidth = (_w - _scrollbarWidth - _padX * 2) / _charWidth; - _linesPerPage = (_h - _padY * 2) / _lineHeight; + int16 bW = g_gui.xmlEval()->getVar("Globals.Button.Width", 0); + int16 bH = g_gui.xmlEval()->getVar("Globals.Button.Height", 0); + int16 padR = g_gui.xmlEval()->getVar("Globals.Padding.Right", 5); + int16 padB = g_gui.xmlEval()->getVar("Globals.Padding.Bottom", 5); + int16 scrollbarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0); - _scrollBar->setPos(_w - _scrollbarWidth - 1, 0); - _scrollBar->setSize(_scrollbarWidth, _h); + int16 buttonOffset = bH + padB; + + _closeButton->setPos(_w - bW - padR, _h - buttonOffset); + _closeButton->setSize(bW, bH); + + // Calculate depending values + _lineWidth = (_w - scrollbarWidth - _padX * 2) / _charWidth; + _linesPerPage = (_h - _padY * 2 - buttonOffset) / _lineHeight; + + warning("Lines: %d", _linesPerPage); + + _scrollBar->setPos(_w - scrollbarWidth - 1, 0); + _scrollBar->setSize(scrollbarWidth, _h - buttonOffset); } void TextViewerDialog::open() { @@ -167,6 +183,9 @@ void TextViewerDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 d drawDialog(kDrawLayerForeground); break; + case kCloseCmd: + close(); + break; default: return; } diff --git a/gui/textviewer.h b/gui/textviewer.h index d12acee8099..250c1a82e1b 100644 --- a/gui/textviewer.h +++ b/gui/textviewer.h @@ -42,7 +42,6 @@ private: int _currentPos; int _scrollLine; - int _scrollbarWidth; int _charWidth; int _lineHeight; int _padX, _padY; @@ -50,6 +49,7 @@ private: Common::StringArray _linesArray; ScrollBarWidget *_scrollBar; + ButtonWidget *_closeButton; Common::String _fname; const Graphics::Font *_font = nullptr; diff --git a/po/POTFILES b/po/POTFILES index e6deb0d17f5..8d877da3faf 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -20,6 +20,7 @@ gui/recorderdialog.cpp gui/remotebrowser.cpp gui/saveload-dialog.cpp gui/shaderbrowser-dialog.cpp +gui/textviewer.cpp gui/themebrowser.cpp gui/ThemeEngine.cpp gui/unknown-game-dialog.cpp