From 49caaf77a1aa5f2668a1b21cc2722fb536558929 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 21 Jun 2016 14:36:21 +0600 Subject: GUI: Add ScrollContainer --- gui/widgets/scrollcontainer.cpp | 236 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 gui/widgets/scrollcontainer.cpp (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp new file mode 100644 index 0000000000..c8dae8357a --- /dev/null +++ b/gui/widgets/scrollcontainer.cpp @@ -0,0 +1,236 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/util.h" +#include "gui/widgets/scrollcontainer.h" +#include "gui/gui-manager.h" + +#include "gui/ThemeEval.h" + +namespace GUI { + +ScrollContainerWidget::ScrollContainerWidget(GuiObject *boss, int x, int y, int w, int h) + : Widget(boss, x, y, w, h) { + init(); +} + +ScrollContainerWidget::ScrollContainerWidget(GuiObject *boss, const Common::String &name) + : Widget(boss, name) { + init(); +} + +void ScrollContainerWidget::init() { + setFlags(WIDGET_ENABLED); + _type = kScrollContainerWidget; + _verticalScroll = nullptr; + _verticalScroll = new ScrollBarWidget(this, _w-16, 0, 16, _h); + _verticalScroll->setTarget(this); + //_navRight = new ButtonWidget(this, x + _butW + 2, y, _butW, _butH, ">", 0, kCmdRight); + _scrolledX = 0; + _scrolledY = 0; + _limitH = 140; + _clippingArea = Common::Rect(0, 0, _w, _h); + recalc(); +} + +void ScrollContainerWidget::recalc() { + _verticalScroll->_numEntries = _h; + _verticalScroll->_currentPos = _scrolledY; + _verticalScroll->_entriesPerPage = _limitH; + _verticalScroll->setPos(_w - 16, _scrolledY); + _verticalScroll->setSize(16, _limitH); + debug("%d %d", _boss->getHeight(), _h); +} + + +ScrollContainerWidget::~ScrollContainerWidget() { + _firstWidget = 0; + //delete _navRight; +} + +int16 ScrollContainerWidget::getChildX() const { + return getAbsX() - _scrolledX;// +_tabHeight; +} + +int16 ScrollContainerWidget::getChildY() const { + return getAbsY() - _scrolledY;// +_tabHeight; +} + +uint16 ScrollContainerWidget::getWidth() const { + return (_boss ? _boss->getWidth() : _w); +} + +uint16 ScrollContainerWidget::getHeight() const { + return _limitH; +} + +void ScrollContainerWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { + Widget::handleCommand(sender, cmd, data); + switch (cmd) { + case kSetPositionCmd: + _scrolledY = _verticalScroll->_currentPos; + recalc(); + draw(); + break; + /* + case kCmdLeft: + if (_firstVisibleTab) { + _firstVisibleTab--; + draw(); + } + break; + + case kCmdRight: + if (_firstVisibleTab + _w / _tabWidth < (int)_tabs.size()) { + _firstVisibleTab++; + draw(); + } + break; + */ + } +} + +void ScrollContainerWidget::handleMouseDown(int x, int y, int button, int clickCount) { + /* + assert(y < _tabHeight); + + // Determine which tab was clicked + int tabID = -1; + if (x >= 0 && (x % _tabWidth) < _tabWidth) { + tabID = x / _tabWidth; + if (tabID >= (int)_tabs.size()) + tabID = -1; + } + + // If a tab was clicked, switch to that pane + if (tabID >= 0 && tabID + _firstVisibleTab < (int)_tabs.size()) { + setActiveTab(tabID + _firstVisibleTab); + } + */ +} + +bool ScrollContainerWidget::handleKeyDown(Common::KeyState state) { + /* + if (state.hasFlags(Common::KBD_SHIFT) && state.keycode == Common::KEYCODE_TAB) + adjustTabs(kTabBackwards); + else if (state.keycode == Common::KEYCODE_TAB) + adjustTabs(kTabForwards); + */ + return Widget::handleKeyDown(state); +} + +void ScrollContainerWidget::reflowLayout() { + _clippingArea = Common::Rect(0, 0, _w, _h); + recalc(); + Widget::reflowLayout(); + + /* + for (uint i = 0; i < _tabs.size(); ++i) { + Widget *w = _tabs[i].firstWidget; + while (w) { + w->reflowLayout(); + w = w->next(); + } + } + + _tabHeight = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Height"); + _tabWidth = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Width"); + _titleVPad = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Padding.Top"); + + if (_tabWidth == 0) { + _tabWidth = 40; +#ifdef __DS__ + } + if (true) { +#endif + int maxWidth = _w / _tabs.size(); + + for (uint i = 0; i < _tabs.size(); ++i) { + // Determine the new tab width + int newWidth = g_gui.getStringWidth(_tabs[i].title) + 2 * 3; + if (_tabWidth < newWidth) + _tabWidth = newWidth; + if (_tabWidth > maxWidth) + _tabWidth = maxWidth; + } + } + + _butRP = g_gui.xmlEval()->getVar("Globals.TabWidget.NavButton.PaddingRight", 0); + _butTP = g_gui.xmlEval()->getVar("Globals.TabWidget.NavButton.Padding.Top", 0); + _butW = g_gui.xmlEval()->getVar("GlobalsTabWidget.NavButton.Width", 10); + _butH = g_gui.xmlEval()->getVar("Globals.TabWidget.NavButton.Height", 10); + + int x = _w - _butRP - _butW * 2 - 2; + int y = _butTP - _tabHeight; + _navLeft->resize(x, y, _butW, _butH); + _navRight->resize(x + _butW + 2, y, _butW, _butH); + */ +} + +void ScrollContainerWidget::drawWidget() { + /* + Common::Array tabs; + for (int i = _firstVisibleTab; i < (int)_tabs.size(); ++i) { + tabs.push_back(_tabs[i].title); + } + g_gui.theme()->drawDialogBackground(Common::Rect(_x + _bodyLP, _y + _bodyTP, _x+_w-_bodyRP, _y+_h-_bodyBP), _bodyBackgroundType); + */ + g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x + _w, _y + getHeight()), ThemeEngine::kDialogBackgroundDefault); + //g_gui.theme()->addDirtyRect(Common::Rect(_x, _y, _x + _w, _y + getHeight())); + /* + g_gui.theme()->drawTab(Common::Rect(_x, _y, _x+_w, _y+_h), _tabHeight, _tabWidth, tabs, _activeTab - _firstVisibleTab, 0, _titleVPad); + */ +} + +void ScrollContainerWidget::draw() { + Widget::draw(); + /* + if (_tabWidth * _tabs.size() > _w) { + _navLeft->draw(); + _navRight->draw(); + } + */ +} + +Widget *ScrollContainerWidget::findWidget(int x, int y) { + /* + if (y < _tabHeight) { + if (_tabWidth * _tabs.size() > _w) { + if (y >= _butTP && y < _butTP + _butH) { + if (x >= _w - _butRP - _butW * 2 - 2 && x < _w - _butRP - _butW - 2) + return _navLeft; + if (x >= _w - _butRP - _butW && x < _w - _butRP) + return _navRight; + } + } + + // Click was in the tab area + return this; + } else { + // Iterate over all child widgets and find the one which was clicked + return Widget::findWidgetInChain(_firstWidget, x, y - _tabHeight); + } + */ + return Widget::findWidgetInChain(_firstWidget, x + _scrolledX, y + _scrolledY); +} + +} // End of namespace GUI -- cgit v1.2.3 From 9bf2d65dd24f217a7462da823ff30c43a7110e29 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 21 Jun 2016 14:46:09 +0600 Subject: GUI: Cleanup in ScrollContainer --- gui/widgets/scrollcontainer.cpp | 137 +--------------------------------------- 1 file changed, 3 insertions(+), 134 deletions(-) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index c8dae8357a..7fde9a6198 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -41,10 +41,8 @@ ScrollContainerWidget::ScrollContainerWidget(GuiObject *boss, const Common::Stri void ScrollContainerWidget::init() { setFlags(WIDGET_ENABLED); _type = kScrollContainerWidget; - _verticalScroll = nullptr; _verticalScroll = new ScrollBarWidget(this, _w-16, 0, 16, _h); _verticalScroll->setTarget(this); - //_navRight = new ButtonWidget(this, x + _butW + 2, y, _butW, _butH, ">", 0, kCmdRight); _scrolledX = 0; _scrolledY = 0; _limitH = 140; @@ -58,21 +56,17 @@ void ScrollContainerWidget::recalc() { _verticalScroll->_entriesPerPage = _limitH; _verticalScroll->setPos(_w - 16, _scrolledY); _verticalScroll->setSize(16, _limitH); - debug("%d %d", _boss->getHeight(), _h); } -ScrollContainerWidget::~ScrollContainerWidget() { - _firstWidget = 0; - //delete _navRight; -} +ScrollContainerWidget::~ScrollContainerWidget() {} int16 ScrollContainerWidget::getChildX() const { - return getAbsX() - _scrolledX;// +_tabHeight; + return getAbsX() - _scrolledX; } int16 ScrollContainerWidget::getChildY() const { - return getAbsY() - _scrolledY;// +_tabHeight; + return getAbsY() - _scrolledY; } uint16 ScrollContainerWidget::getWidth() const { @@ -91,145 +85,20 @@ void ScrollContainerWidget::handleCommand(CommandSender *sender, uint32 cmd, uin recalc(); draw(); break; - /* - case kCmdLeft: - if (_firstVisibleTab) { - _firstVisibleTab--; - draw(); - } - break; - - case kCmdRight: - if (_firstVisibleTab + _w / _tabWidth < (int)_tabs.size()) { - _firstVisibleTab++; - draw(); - } - break; - */ } } -void ScrollContainerWidget::handleMouseDown(int x, int y, int button, int clickCount) { - /* - assert(y < _tabHeight); - - // Determine which tab was clicked - int tabID = -1; - if (x >= 0 && (x % _tabWidth) < _tabWidth) { - tabID = x / _tabWidth; - if (tabID >= (int)_tabs.size()) - tabID = -1; - } - - // If a tab was clicked, switch to that pane - if (tabID >= 0 && tabID + _firstVisibleTab < (int)_tabs.size()) { - setActiveTab(tabID + _firstVisibleTab); - } - */ -} - -bool ScrollContainerWidget::handleKeyDown(Common::KeyState state) { - /* - if (state.hasFlags(Common::KBD_SHIFT) && state.keycode == Common::KEYCODE_TAB) - adjustTabs(kTabBackwards); - else if (state.keycode == Common::KEYCODE_TAB) - adjustTabs(kTabForwards); - */ - return Widget::handleKeyDown(state); -} - void ScrollContainerWidget::reflowLayout() { _clippingArea = Common::Rect(0, 0, _w, _h); recalc(); Widget::reflowLayout(); - - /* - for (uint i = 0; i < _tabs.size(); ++i) { - Widget *w = _tabs[i].firstWidget; - while (w) { - w->reflowLayout(); - w = w->next(); - } - } - - _tabHeight = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Height"); - _tabWidth = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Width"); - _titleVPad = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Padding.Top"); - - if (_tabWidth == 0) { - _tabWidth = 40; -#ifdef __DS__ - } - if (true) { -#endif - int maxWidth = _w / _tabs.size(); - - for (uint i = 0; i < _tabs.size(); ++i) { - // Determine the new tab width - int newWidth = g_gui.getStringWidth(_tabs[i].title) + 2 * 3; - if (_tabWidth < newWidth) - _tabWidth = newWidth; - if (_tabWidth > maxWidth) - _tabWidth = maxWidth; - } - } - - _butRP = g_gui.xmlEval()->getVar("Globals.TabWidget.NavButton.PaddingRight", 0); - _butTP = g_gui.xmlEval()->getVar("Globals.TabWidget.NavButton.Padding.Top", 0); - _butW = g_gui.xmlEval()->getVar("GlobalsTabWidget.NavButton.Width", 10); - _butH = g_gui.xmlEval()->getVar("Globals.TabWidget.NavButton.Height", 10); - - int x = _w - _butRP - _butW * 2 - 2; - int y = _butTP - _tabHeight; - _navLeft->resize(x, y, _butW, _butH); - _navRight->resize(x + _butW + 2, y, _butW, _butH); - */ } void ScrollContainerWidget::drawWidget() { - /* - Common::Array tabs; - for (int i = _firstVisibleTab; i < (int)_tabs.size(); ++i) { - tabs.push_back(_tabs[i].title); - } - g_gui.theme()->drawDialogBackground(Common::Rect(_x + _bodyLP, _y + _bodyTP, _x+_w-_bodyRP, _y+_h-_bodyBP), _bodyBackgroundType); - */ g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x + _w, _y + getHeight()), ThemeEngine::kDialogBackgroundDefault); - //g_gui.theme()->addDirtyRect(Common::Rect(_x, _y, _x + _w, _y + getHeight())); - /* - g_gui.theme()->drawTab(Common::Rect(_x, _y, _x+_w, _y+_h), _tabHeight, _tabWidth, tabs, _activeTab - _firstVisibleTab, 0, _titleVPad); - */ -} - -void ScrollContainerWidget::draw() { - Widget::draw(); - /* - if (_tabWidth * _tabs.size() > _w) { - _navLeft->draw(); - _navRight->draw(); - } - */ } Widget *ScrollContainerWidget::findWidget(int x, int y) { - /* - if (y < _tabHeight) { - if (_tabWidth * _tabs.size() > _w) { - if (y >= _butTP && y < _butTP + _butH) { - if (x >= _w - _butRP - _butW * 2 - 2 && x < _w - _butRP - _butW - 2) - return _navLeft; - if (x >= _w - _butRP - _butW && x < _w - _butRP) - return _navRight; - } - } - - // Click was in the tab area - return this; - } else { - // Iterate over all child widgets and find the one which was clicked - return Widget::findWidgetInChain(_firstWidget, x, y - _tabHeight); - } - */ return Widget::findWidgetInChain(_firstWidget, x + _scrolledX, y + _scrolledY); } -- cgit v1.2.3 From 34af71a8ef81db5fb4ee6d502df77a8c15540266 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 21 Jun 2016 14:51:50 +0600 Subject: GUI: Remove _clippingArea from ScrollContainer --- gui/widgets/scrollcontainer.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index 7fde9a6198..8b9341f575 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -46,7 +46,6 @@ void ScrollContainerWidget::init() { _scrolledX = 0; _scrolledY = 0; _limitH = 140; - _clippingArea = Common::Rect(0, 0, _w, _h); recalc(); } @@ -89,7 +88,6 @@ void ScrollContainerWidget::handleCommand(CommandSender *sender, uint32 cmd, uin } void ScrollContainerWidget::reflowLayout() { - _clippingArea = Common::Rect(0, 0, _w, _h); recalc(); Widget::reflowLayout(); } -- cgit v1.2.3 From 8f2d35b0b89c4b8912df96ec3c403e00c85c5875 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 22 Jun 2016 14:29:02 +0600 Subject: GUI: drawRoundedSquareClip() --- gui/widgets/scrollcontainer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index 8b9341f575..5e112b476f 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -50,7 +50,7 @@ void ScrollContainerWidget::init() { } void ScrollContainerWidget::recalc() { - _verticalScroll->_numEntries = _h; + _verticalScroll->_numEntries = _h + 40; _verticalScroll->_currentPos = _scrolledY; _verticalScroll->_entriesPerPage = _limitH; _verticalScroll->setPos(_w - 16, _scrolledY); -- cgit v1.2.3 From b946ef8598b96631057beffddbf35b627fa25b8d Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 22 Jun 2016 15:21:35 +0600 Subject: GUI: Make ScrollContainerWidget hide children --- gui/widgets/scrollcontainer.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index 5e112b476f..f2fb21302c 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -81,7 +81,7 @@ void ScrollContainerWidget::handleCommand(CommandSender *sender, uint32 cmd, uin switch (cmd) { case kSetPositionCmd: _scrolledY = _verticalScroll->_currentPos; - recalc(); + reflowLayout(); draw(); break; } @@ -90,6 +90,16 @@ void ScrollContainerWidget::handleCommand(CommandSender *sender, uint32 cmd, uin void ScrollContainerWidget::reflowLayout() { recalc(); Widget::reflowLayout(); + Widget *ptr = _firstWidget; + while (ptr) { + int y = ptr->getAbsY() - getChildY(); + int h = ptr->getHeight(); + bool visible = true; + if (y + h - _scrolledY < 0) visible = false; + if (y - _scrolledY > _limitH) visible = false; + ptr->setVisible(visible); + ptr = ptr->next(); + } } void ScrollContainerWidget::drawWidget() { -- cgit v1.2.3 From 31e528c070d14baf62dc1e8570075425a2efbb42 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 22 Jun 2016 17:29:01 +0600 Subject: GUI: Make ScrollContainerWidget do full redraw --- gui/widgets/scrollcontainer.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index f2fb21302c..fffa451ad9 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -83,6 +83,7 @@ void ScrollContainerWidget::handleCommand(CommandSender *sender, uint32 cmd, uin _scrolledY = _verticalScroll->_currentPos; reflowLayout(); draw(); + g_gui.doFullRedraw(); break; } } -- cgit v1.2.3 From 9c1eab6415729b1c5edf362f0792cde250a382ab Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 22 Jun 2016 17:59:46 +0600 Subject: GUI: Fix ScrollContainerWidget look a bit --- gui/widgets/scrollcontainer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index fffa451ad9..d27c9df0c0 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -53,8 +53,8 @@ void ScrollContainerWidget::recalc() { _verticalScroll->_numEntries = _h + 40; _verticalScroll->_currentPos = _scrolledY; _verticalScroll->_entriesPerPage = _limitH; - _verticalScroll->setPos(_w - 16, _scrolledY); - _verticalScroll->setSize(16, _limitH); + _verticalScroll->setPos(_w - 16, _scrolledY+1); + _verticalScroll->setSize(16, _limitH -2); } @@ -104,7 +104,7 @@ void ScrollContainerWidget::reflowLayout() { } void ScrollContainerWidget::drawWidget() { - g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x + _w, _y + getHeight()), ThemeEngine::kDialogBackgroundDefault); + g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x + _w, _y + getHeight() - 1), ThemeEngine::kDialogBackgroundDefault); } Widget *ScrollContainerWidget::findWidget(int x, int y) { -- cgit v1.2.3 From ac25acbccc384eaf1a4e5169da1da3e475b97c83 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 22 Jun 2016 18:44:47 +0600 Subject: GUI: Update ScrollContainerWidget --- gui/widgets/scrollcontainer.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index d27c9df0c0..b975c42112 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -50,11 +50,32 @@ void ScrollContainerWidget::init() { } void ScrollContainerWidget::recalc() { - _verticalScroll->_numEntries = _h + 40; + int scrollbarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0); + + //calculate _limitH - available height (boss's height - boss's "offset") + int d = _boss->getChildY() - _boss->getAbsY(); + _limitH = _boss->getHeight() - d; + + //calculate virtual height + const int spacing = g_gui.xmlEval()->getVar("Global.Font.Height", 16); //on the bottom + int h = 0; + int min = spacing, max = 0; + Widget *ptr = _firstWidget; + while (ptr) { + if (ptr != _verticalScroll) { + int y = ptr->getAbsY() - getChildY(); + min = MIN(min, y - spacing); + max = MAX(max, y + ptr->getHeight() + spacing); + } + ptr = ptr->next(); + } + h = max - min; + + _verticalScroll->_numEntries = h; _verticalScroll->_currentPos = _scrolledY; _verticalScroll->_entriesPerPage = _limitH; - _verticalScroll->setPos(_w - 16, _scrolledY+1); - _verticalScroll->setSize(16, _limitH -2); + _verticalScroll->setPos(_w - scrollbarWidth, _scrolledY+1); + _verticalScroll->setSize(scrollbarWidth, _limitH -2); } @@ -69,7 +90,7 @@ int16 ScrollContainerWidget::getChildY() const { } uint16 ScrollContainerWidget::getWidth() const { - return (_boss ? _boss->getWidth() : _w); + return _w - _verticalScroll->getWidth(); } uint16 ScrollContainerWidget::getHeight() const { @@ -89,8 +110,8 @@ void ScrollContainerWidget::handleCommand(CommandSender *sender, uint32 cmd, uin } void ScrollContainerWidget::reflowLayout() { - recalc(); Widget::reflowLayout(); + recalc(); Widget *ptr = _firstWidget; while (ptr) { int y = ptr->getAbsY() - getChildY(); @@ -108,6 +129,8 @@ void ScrollContainerWidget::drawWidget() { } Widget *ScrollContainerWidget::findWidget(int x, int y) { + if (x >= _w - _verticalScroll->getWidth()) + return _verticalScroll; return Widget::findWidgetInChain(_firstWidget, x + _scrolledX, y + _scrolledY); } -- cgit v1.2.3 From 40fa9b4de3f719ad11ceb665a724712ccbcb7376 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 23 Jun 2016 12:52:38 +0600 Subject: GUI: Fix ScrollContainerWidget's reflowLayout() --- gui/widgets/scrollcontainer.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index b975c42112..fdb02f8be2 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -111,8 +111,19 @@ void ScrollContainerWidget::handleCommand(CommandSender *sender, uint32 cmd, uin void ScrollContainerWidget::reflowLayout() { Widget::reflowLayout(); - recalc(); + + //reflow layout of inner widgets Widget *ptr = _firstWidget; + while (ptr) { + ptr->reflowLayout(); + ptr = ptr->next(); + } + + //recalculate height + recalc(); + + //hide those widgets which are out of visible area + ptr = _firstWidget; while (ptr) { int y = ptr->getAbsY() - getChildY(); int h = ptr->getHeight(); -- cgit v1.2.3 From 421f9826c8ad403d76b6f40bf1aa4c7c0ec7e676 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 23 Jun 2016 17:50:38 +0600 Subject: GUI: Hide scrollbar in ScrollContainerWidget when needed --- gui/widgets/scrollcontainer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index fdb02f8be2..1173b08279 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -90,7 +90,7 @@ int16 ScrollContainerWidget::getChildY() const { } uint16 ScrollContainerWidget::getWidth() const { - return _w - _verticalScroll->getWidth(); + return _w - (_verticalScroll->isVisible() ? _verticalScroll->getWidth() : 0); } uint16 ScrollContainerWidget::getHeight() const { @@ -133,6 +133,8 @@ void ScrollContainerWidget::reflowLayout() { ptr->setVisible(visible); ptr = ptr->next(); } + + _verticalScroll->setVisible(_verticalScroll->_numEntries > _limitH); //show when there is something to scroll } void ScrollContainerWidget::drawWidget() { @@ -140,7 +142,7 @@ void ScrollContainerWidget::drawWidget() { } Widget *ScrollContainerWidget::findWidget(int x, int y) { - if (x >= _w - _verticalScroll->getWidth()) + if (_verticalScroll->isVisible() && x >= _w - _verticalScroll->getWidth()) return _verticalScroll; return Widget::findWidgetInChain(_firstWidget, x + _scrolledX, y + _scrolledY); } -- cgit v1.2.3 From 0ae4409138f828ee7eb0241db44f43d68cec85d8 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Fri, 24 Jun 2016 23:26:25 +0600 Subject: GUI: Add ThemeLayoutTabWidget --- gui/widgets/scrollcontainer.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index 1173b08279..eca0279c55 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -51,10 +51,7 @@ void ScrollContainerWidget::init() { void ScrollContainerWidget::recalc() { int scrollbarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0); - - //calculate _limitH - available height (boss's height - boss's "offset") - int d = _boss->getChildY() - _boss->getAbsY(); - _limitH = _boss->getHeight() - d; + _limitH = _h; //calculate virtual height const int spacing = g_gui.xmlEval()->getVar("Global.Font.Height", 16); //on the bottom -- cgit v1.2.3 From 3d636617d0781bdd477551a87f6b9fc60e0a4a1f Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Fri, 1 Jul 2016 14:25:05 +0600 Subject: GUI: Use clipping everywhere --- gui/widgets/scrollcontainer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index eca0279c55..8b68b0fc0b 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -135,7 +135,7 @@ void ScrollContainerWidget::reflowLayout() { } void ScrollContainerWidget::drawWidget() { - g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x + _w, _y + getHeight() - 1), ThemeEngine::kDialogBackgroundDefault); + g_gui.theme()->drawDialogBackgroundClip(Common::Rect(_x, _y, _x + _w, _y + getHeight() - 1), getBossClipRect(), ThemeEngine::kDialogBackgroundDefault); } Widget *ScrollContainerWidget::findWidget(int x, int y) { -- cgit v1.2.3 From cea58cc61c12206f41b64ba0094655dcd84b57af Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Sat, 2 Jul 2016 13:26:05 +0600 Subject: JANITORIAL: Remove trailing spaces --- gui/widgets/scrollcontainer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gui/widgets/scrollcontainer.cpp') diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index 8b68b0fc0b..1b38478c11 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -95,7 +95,7 @@ uint16 ScrollContainerWidget::getHeight() const { } void ScrollContainerWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { - Widget::handleCommand(sender, cmd, data); + Widget::handleCommand(sender, cmd, data); switch (cmd) { case kSetPositionCmd: _scrolledY = _verticalScroll->_currentPos; @@ -103,7 +103,7 @@ void ScrollContainerWidget::handleCommand(CommandSender *sender, uint32 cmd, uin draw(); g_gui.doFullRedraw(); break; - } + } } void ScrollContainerWidget::reflowLayout() { -- cgit v1.2.3