From 00012888e63cff47922fc81c0f3e8ac85adbcda8 Mon Sep 17 00:00:00 2001 From: Matthew Kehrer Date: Fri, 12 Aug 2022 16:08:22 -0500 Subject: [PATCH] MachGuiScrollableText: Constructor no longer references MGSS. It may now be used with any GuiRoot --- src/libdev/machgui/scrltext.cpp | 84 ++++++++++++++++++--------------- src/libdev/machgui/scrltext.hpp | 25 +++++----- 2 files changed, 60 insertions(+), 49 deletions(-) diff --git a/src/libdev/machgui/scrltext.cpp b/src/libdev/machgui/scrltext.cpp index d97bddf62..c356b5763 100644 --- a/src/libdev/machgui/scrltext.cpp +++ b/src/libdev/machgui/scrltext.cpp @@ -13,72 +13,72 @@ #include "gui/font.hpp" #include "gui/painter.hpp" -MachGuiScrollableText::MachGuiScrollableText( MachGuiStartupScreens* pParent, const Gui::Box& box, uint stringId ) -: GuiSimpleScrollableList( pParent, box, 1000, GuiBmpFont::getFont("gui/menu/smallfnt.bmp").charHeight() + 1, 1 ), - pStartupScreens_( pParent ) +MachGuiScrollableText::MachGuiScrollableText( GuiDisplayable* pParent, const Gui::Box& box, uint stringId ) +: GuiSimpleScrollableList( pParent, box, 1000, GuiBmpFont::getFont("gui/menu/smallfnt.bmp").charHeight() + 1, 1 ) { - setText( stringId ); + pRootParent_ = static_cast(pParent->findRoot(this)); + setText( stringId ); TEST_INVARIANT; } -MachGuiScrollableText::MachGuiScrollableText( MachGuiStartupScreens* pParent, const Gui::Box& box, const string& text ) -: GuiSimpleScrollableList( pParent, box, 1000, GuiBmpFont::getFont("gui/menu/smallfnt.bmp").charHeight() + 1, 1 ), - pStartupScreens_( pParent ) +MachGuiScrollableText::MachGuiScrollableText( GuiDisplayable* pParent, const Gui::Box& box, const string& text ) +: GuiSimpleScrollableList( pParent, box, 1000, GuiBmpFont::getFont("gui/menu/smallfnt.bmp").charHeight() + 1, 1 ) { - setText( text ); + pRootParent_ = static_cast(pParent->findRoot(this)); + setText( text ); TEST_INVARIANT; } -MachGuiScrollableText::MachGuiScrollableText( MachGuiStartupScreens* pParent, const Gui::Box& box ) -: GuiSimpleScrollableList( pParent, box, 1000, GuiBmpFont::getFont("gui/menu/smallfnt.bmp").charHeight() + 1, 1 ), - pStartupScreens_( pParent ) +MachGuiScrollableText::MachGuiScrollableText(GuiDisplayable* pParent, const Gui::Box& box ) +: GuiSimpleScrollableList( pParent, box, 1000, GuiBmpFont::getFont("gui/menu/smallfnt.bmp").charHeight() + 1, 1 ) { + pRootParent_ = static_cast(pParent->findRoot(this)); TEST_INVARIANT; } -MachGuiScrollableText::MachGuiScrollableText( MachGuiStartupScreens* pParent, const Gui::Box& box, uint columnWidth, const string& text ) -: GuiSimpleScrollableList( pParent, box, columnWidth, GuiBmpFont::getFont("gui/menu/smallfnt.bmp").charHeight() + 1, 1 ), - pStartupScreens_( pParent ) +MachGuiScrollableText::MachGuiScrollableText( GuiDisplayable* pParent, const Gui::Box& box, uint columnWidth, const string& text ) +: GuiSimpleScrollableList( pParent, box, columnWidth, GuiBmpFont::getFont("gui/menu/smallfnt.bmp").charHeight() + 1, 1 ) { - setText( text ); + pRootParent_ = static_cast(pParent->findRoot(this)); + setText( text ); TEST_INVARIANT; } void MachGuiScrollableText::setText( uint stringId ) { - GuiResourceString text( stringId ); - setText( text.asString() ); + GuiResourceString text( stringId ); + setText( text.asString() ); } void MachGuiScrollableText::setText( const string& text ) { - deleteAllChildren(); + deleteAllChildren(); - strings linesOfText; + strings linesOfText; linesOfText.reserve( 64 ); - MachGuiMenuText::chopUpText( text, width(), GuiBmpFont::getFont("gui/menu/smallfnt.bmp"), &linesOfText ); + MachGuiMenuText::chopUpText( text, width(), GuiBmpFont::getFont("gui/menu/smallfnt.bmp"), &linesOfText ); - for ( strings::iterator iter = linesOfText.begin(); iter != linesOfText.end(); ++iter ) - { - string lineOfText = *iter; + for (auto iter = linesOfText.begin(); iter != linesOfText.end(); ++iter ) + { + string lineOfText = *iter; - NEIL_STREAM( lineOfText << std::endl ); + NEIL_STREAM( lineOfText << std::endl ); - if ( strncasecmp(&lineOfText.c_str()[0], "",3) == 0 ) - { - _NEW(MachGuiText(this, width(), &lineOfText.c_str()[3], "gui/menu/smalwfnt.bmp")); - } - else - { - _NEW(MachGuiText(this, width(), lineOfText)); - } - } + if ( strncasecmp(&lineOfText.c_str()[0], "",3) == 0 ) + { + _NEW(MachGuiText(this, width(), &lineOfText.c_str()[3], "gui/menu/smalwfnt.bmp")); + } + else + { + _NEW(MachGuiText(this, width(), lineOfText)); + } + } - childrenUpdated(); + childrenUpdated(); } MachGuiScrollableText::~MachGuiScrollableText() @@ -104,9 +104,19 @@ ostream& operator <<( ostream& o, const MachGuiScrollableText& t ) // virtual void MachGuiScrollableText::doDisplay() { - // Blit background to list box item - pStartupScreens_->blitBackdrop( absoluteBoundary(), - absoluteBoundary().minCorner() ); + // Blit background to list box item + auto backdrop = pRootParent_->getSharedBitmaps()->getNamedBitmap("backdrop"); + pRootParent_->getSharedBitmaps()->blitNamedBitmapFromArea( + backdrop, + absoluteBoundary(), + absoluteBoundary().minCorner(), + [](Gui::Box box) { + return Gui::Box(Gui::Coord(box.minCorner().x() - MachGuiStartupScreens::xMenuOffset(), + box.minCorner().y() - MachGuiStartupScreens::yMenuOffset()), + box.maxCorner().x() - box.minCorner().x(), + box.maxCorner().y() - box.minCorner().y() + ); + }); } /* End SCRLTEXT.CPP *************************************************/ diff --git a/src/libdev/machgui/scrltext.hpp b/src/libdev/machgui/scrltext.hpp index 36fee4c78..7e8fc53b3 100644 --- a/src/libdev/machgui/scrltext.hpp +++ b/src/libdev/machgui/scrltext.hpp @@ -14,23 +14,23 @@ #include "base/base.hpp" #include "gui/scrolist.hpp" - -class MachGuiStartupScreens; +#include "gui/root.hpp" class MachGuiScrollableText : public GuiSimpleScrollableList // Canonical form revoked { public: - MachGuiScrollableText( MachGuiStartupScreens* pParent, const Gui::Box& ); - MachGuiScrollableText( MachGuiStartupScreens* pParent, const Gui::Box&, uint stringId ); - MachGuiScrollableText( MachGuiStartupScreens* pParent, const Gui::Box&, const string& text ); - MachGuiScrollableText( MachGuiStartupScreens* pParent, const Gui::Box&, uint columnWidth, const string& text ); - virtual ~MachGuiScrollableText(); + MachGuiScrollableText(GuiDisplayable* pParent, const Gui::Box& box); + MachGuiScrollableText(GuiDisplayable* pParent, const Gui::Box& box, uint stringId ); + MachGuiScrollableText(GuiDisplayable* pParent, const Gui::Box& box, const string& text ); + MachGuiScrollableText(GuiDisplayable* pParent, const Gui::Box& box, uint columnWidth, const string& text ); + virtual ~MachGuiScrollableText(); + + void setText( uint stringId ); + void setText( const string& ); - void setText( uint stringId ); - void setText( const string& ); + virtual void doDisplay() override; - virtual void doDisplay(); void CLASS_INVARIANT; @@ -39,8 +39,9 @@ class MachGuiScrollableText : public GuiSimpleScrollableList MachGuiScrollableText( const MachGuiScrollableText& ); MachGuiScrollableText& operator =( const MachGuiScrollableText& ); - - MachGuiStartupScreens* pStartupScreens_; + + // A GuiRoot such as MachGuiStartupScreens + GuiRoot* pRootParent_; };