Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
MachGuiScrollableText: Constructor no longer references MGSS. It may …
Browse files Browse the repository at this point in the history
…now be used with any GuiRoot
  • Loading branch information
m-flak committed Aug 12, 2022
1 parent db72417 commit 0001288
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 49 deletions.
84 changes: 47 additions & 37 deletions src/libdev/machgui/scrltext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GuiRoot*>(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<GuiRoot*>(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<GuiRoot*>(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<GuiRoot*>(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], "<w>",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], "<w>",3) == 0 )
{
_NEW(MachGuiText(this, width(), &lineOfText.c_str()[3], "gui/menu/smalwfnt.bmp"));
}
else
{
_NEW(MachGuiText(this, width(), lineOfText));
}
}

childrenUpdated();
childrenUpdated();
}

MachGuiScrollableText::~MachGuiScrollableText()
Expand All @@ -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 *************************************************/
25 changes: 13 additions & 12 deletions src/libdev/machgui/scrltext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -39,8 +39,9 @@ class MachGuiScrollableText : public GuiSimpleScrollableList

MachGuiScrollableText( const MachGuiScrollableText& );
MachGuiScrollableText& operator =( const MachGuiScrollableText& );

MachGuiStartupScreens* pStartupScreens_;

// A GuiRoot such as MachGuiStartupScreens
GuiRoot* pRootParent_;
};


Expand Down

0 comments on commit 0001288

Please sign in to comment.