diff --git a/src/libdev/machgui/sslistit.cpp b/src/libdev/machgui/sslistit.cpp index 4a360d89f..5e4126377 100644 --- a/src/libdev/machgui/sslistit.cpp +++ b/src/libdev/machgui/sslistit.cpp @@ -5,6 +5,7 @@ // Definitions of non-inline non-template methods and global functions +#include "gui/sslistit.hpp" #include "machgui/sslistit.hpp" #include "machgui/sslistbx.hpp" #include "machgui/startup.hpp" @@ -13,14 +14,29 @@ #include "gui/painter.hpp" #include "machgui/internal/mgsndman.hpp" -MachGuiSingleSelectionListBoxItem::MachGuiSingleSelectionListBoxItem( MachGuiStartupScreens* pStartupScreens, MachGuiSingleSelectionListBox* pListBox, size_t width, const string& text ) -: GuiSingleSelectionListBoxItem( pListBox, width, reqHeight() ), - text_( text ), - highlighted_( false ), - pStartupScreens_( pStartupScreens ), - pMyListBox_( pListBox ) +MachGuiSingleSelectionListBoxItem::MachGuiSingleSelectionListBoxItem(MachGuiStartupScreens* pStartupScreens, MachGuiSingleSelectionListBox* pParentListBox, size_t width, const string& text ) +: GuiSingleSelectionListBoxItem(pParentListBox, width, reqHeight() ), + text_( text ), + highlighted_( false ), + pStartupScreens_( pStartupScreens ), + pMyListBox_(pParentListBox ) { - pMyListBox_->addListItem( this ); + pMyListBox_->addListItem( this ); + + pRootParent_ = static_cast(pParentListBox->findRoot(this)); + + TEST_INVARIANT; +} + +// This variant utilized by MachGuiDropDownListBoxItem to initialize it. Hence, pMyListBox_ is null. +MachGuiSingleSelectionListBoxItem::MachGuiSingleSelectionListBoxItem(MachGuiStartupScreens* pStartupScreens, GuiSingleSelectionListBox* pParentListBox, size_t width, const string& text ) +: GuiSingleSelectionListBoxItem(pParentListBox, width, reqHeight() ), + text_( text ), + highlighted_( false ), + pStartupScreens_( pStartupScreens ), + pMyListBox_( nullptr ) +{ + pRootParent_ = static_cast(pParentListBox->findRoot(this)); TEST_INVARIANT; } @@ -29,8 +45,8 @@ MachGuiSingleSelectionListBoxItem::~MachGuiSingleSelectionListBoxItem() { TEST_INVARIANT; - if ( pMyListBox_ ) - pMyListBox_->removeListItem( this ); + if ( pMyListBox_ ) + pMyListBox_->removeListItem( this ); } void MachGuiSingleSelectionListBoxItem::CLASS_INVARIANT @@ -41,8 +57,8 @@ void MachGuiSingleSelectionListBoxItem::CLASS_INVARIANT ostream& operator <<( ostream& o, const MachGuiSingleSelectionListBoxItem& t ) { - o << "MachGuiSingleSelectionListBoxItem " << (void*)&t << " start" << std::endl; - o << "MachGuiSingleSelectionListBoxItem " << (void*)&t << " end" << std::endl; + o << "MachGuiSingleSelectionListBoxItem " << reinterpret_cast( const_cast(&t) ) << " start" << std::endl; + o << "MachGuiSingleSelectionListBoxItem " << reinterpret_cast( const_cast(&t) ) << " end" << std::endl; return o; } @@ -50,143 +66,143 @@ ostream& operator <<( ostream& o, const MachGuiSingleSelectionListBoxItem& t ) //static size_t MachGuiSingleSelectionListBoxItem::reqHeight() { - size_t myReqHeight = getFont().charHeight(); + size_t myReqHeight = getFont().charHeight(); - myReqHeight += 5; + myReqHeight += 5; - return myReqHeight; + return myReqHeight; } //static GuiBmpFont MachGuiSingleSelectionListBoxItem::getFont() { - GuiBmpFont bmpFont = GuiBmpFont::getFont( SysPathName("gui/menu/smallfnt.bmp") ); + GuiBmpFont bmpFont = GuiBmpFont::getFont( SysPathName("gui/menu/smallfnt.bmp") ); - return bmpFont; + return bmpFont; } //static GuiBmpFont MachGuiSingleSelectionListBoxItem::getHighlightFont() { - GuiBmpFont bmpFont = GuiBmpFont::getFont( SysPathName("gui/menu/smaldfnt.bmp") ); + GuiBmpFont bmpFont = GuiBmpFont::getFont( SysPathName("gui/menu/smaldfnt.bmp") ); - return bmpFont; + return bmpFont; } //static GuiBmpFont MachGuiSingleSelectionListBoxItem::getUnderlineFont() { - GuiBmpFont bmpFont = GuiBmpFont::getFont( SysPathName("gui/menu/smaldfnt.bmp") ); + GuiBmpFont bmpFont = GuiBmpFont::getFont( SysPathName("gui/menu/smaldfnt.bmp") ); - bmpFont.underline( true ); + bmpFont.underline( true ); - return bmpFont; + return bmpFont; } //virtual void MachGuiSingleSelectionListBoxItem::select() { - // Play select sound - MachGuiSoundManager::instance().playSound( "gui/sounds/listclik.wav" ); + // Play select sound + MachGuiSoundManager::instance().playSound( "gui/sounds/listclik.wav" ); - changed(); + changed(); } //virtual void MachGuiSingleSelectionListBoxItem::unselect() { - changed(); + changed(); } //virtual void MachGuiSingleSelectionListBoxItem::doDisplay() { - if ( selected() ) - { - if ( pMyListBox_ and pMyListBox_->isFocusControl() ) - { - GuiPainter::instance().blit( MachGui::longYellowGlowBmp(), Gui::Box(0,0,width(),height() - 1), absoluteBoundary().minCorner() ); - } - else - { - GuiPainter::instance().blit( MachGui::longGlowBmp(), Gui::Box(0,0,width(),height() - 1), absoluteBoundary().minCorner() ); - } - - getUnderlineFont().drawText( text_, Gui::Coord( absoluteBoundary().minCorner().x() + 1, absoluteBoundary().minCorner().y() + 1 ), width() ); - } - else if ( highlighted() ) - { - if ( pMyListBox_ and pMyListBox_->isFocusControl() ) - { - GuiPainter::instance().blit( MachGui::longYellowGlowBmp(), Gui::Box(0,0,width(),height() - 1), absoluteBoundary().minCorner() ); - } - else - { - GuiPainter::instance().blit( MachGui::longGlowBmp(), Gui::Box(0,0,width(),height() - 1), absoluteBoundary().minCorner() ); - } - - getHighlightFont().drawText( text_, Gui::Coord( absoluteBoundary().minCorner().x() + 1, absoluteBoundary().minCorner().y() + 1 ), width() ); - } - else - { - // Blit background to list box item - pStartupScreens_->blitBackdrop( absoluteBoundary(), - absoluteBoundary().minCorner() ); - - // Draw list box item text - getFont().drawText( text_, Gui::Coord( absoluteBoundary().minCorner().x() + 1, absoluteBoundary().minCorner().y() + 1 ), width() ); - } + if ( selected() ) + { + if ( pMyListBox_ and pMyListBox_->isFocusControl() ) + { + GuiPainter::instance().blit( MachGui::longYellowGlowBmp(), Gui::Box(0,0,width(),height() - 1), absoluteBoundary().minCorner() ); + } + else + { + GuiPainter::instance().blit( MachGui::longGlowBmp(), Gui::Box(0,0,width(),height() - 1), absoluteBoundary().minCorner() ); + } + + getUnderlineFont().drawText( text_, Gui::Coord( absoluteBoundary().minCorner().x() + 1, absoluteBoundary().minCorner().y() + 1 ), static_cast(width()) ); + } + else if ( highlighted() ) + { + if ( pMyListBox_ and pMyListBox_->isFocusControl() ) + { + GuiPainter::instance().blit( MachGui::longYellowGlowBmp(), Gui::Box(0,0,width(),height() - 1), absoluteBoundary().minCorner() ); + } + else + { + GuiPainter::instance().blit( MachGui::longGlowBmp(), Gui::Box(0,0,width(),height() - 1), absoluteBoundary().minCorner() ); + } + + getHighlightFont().drawText( text_, Gui::Coord( absoluteBoundary().minCorner().x() + 1, absoluteBoundary().minCorner().y() + 1 ), static_cast(width()) ); + } + else + { + // 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() + ); + }); + + // Draw list box item text + getFont().drawText( text_, Gui::Coord( absoluteBoundary().minCorner().x() + 1, absoluteBoundary().minCorner().y() + 1 ), static_cast(width()) ); + } } bool MachGuiSingleSelectionListBoxItem::highlighted() const { - return highlighted_; + return highlighted_; } //virtual void MachGuiSingleSelectionListBoxItem::doHandleMouseEnterEvent( const GuiMouseEvent& /*rel*/ ) { - // Play enter sound - MachGuiSoundManager::instance().playSound( "gui/sounds/listhigh.wav" ); + // Play enter sound + MachGuiSoundManager::instance().playSound( "gui/sounds/listhigh.wav" ); - highlighted_ = true; + highlighted_ = true; - if ( not selected() ) - changed(); + if ( not selected() ) + changed(); } //virtual void MachGuiSingleSelectionListBoxItem::doHandleMouseExitEvent( const GuiMouseEvent& /*rel*/ ) { - highlighted_ = false; + highlighted_ = false; - if ( not selected() ) - changed(); + if ( not selected() ) + changed(); } const string& MachGuiSingleSelectionListBoxItem::text() const { - return text_; + return text_; } MachGuiStartupScreens* MachGuiSingleSelectionListBoxItem::startupScreens() { - return pStartupScreens_; -} - -MachGuiSingleSelectionListBoxItem::MachGuiSingleSelectionListBoxItem( MachGuiStartupScreens* pStartupScreens, GuiSingleSelectionListBox* pListBox, size_t width, const string& text ) -: GuiSingleSelectionListBoxItem( pListBox, width, reqHeight() ), - text_( text ), - highlighted_( false ), - pStartupScreens_( pStartupScreens ), - pMyListBox_( NULL ) -{ - TEST_INVARIANT; + return pStartupScreens_; } MachGuiSingleSelectionListBox* MachGuiSingleSelectionListBoxItem::myListBox() { - return pMyListBox_; + return pMyListBox_; } /* End SSLISTIT.CPP *************************************************/ diff --git a/src/libdev/machgui/sslistit.hpp b/src/libdev/machgui/sslistit.hpp index f3a78ed26..aa70ee162 100644 --- a/src/libdev/machgui/sslistit.hpp +++ b/src/libdev/machgui/sslistit.hpp @@ -14,6 +14,7 @@ #include "base/base.hpp" #include "stdlib/string.hpp" +#include "gui/root.hpp" #include "gui/sslistit.hpp" class GuiBmpFont; @@ -24,31 +25,37 @@ class MachGuiSingleSelectionListBoxItem : public GuiSingleSelectionListBoxItem // Canonical form revoked { public: - MachGuiSingleSelectionListBoxItem( MachGuiStartupScreens*, MachGuiSingleSelectionListBox* pListBox, size_t width, const string& text ); - MachGuiSingleSelectionListBoxItem( MachGuiStartupScreens*, GuiSingleSelectionListBox* pListBox, size_t width, const string& text ); + //TODO: Find a suitable abstraction for getting handle to game state ("startupData" lol) so MGSS dependency can be removed + MachGuiSingleSelectionListBoxItem(MachGuiStartupScreens* pStartupScreens, MachGuiSingleSelectionListBox* pParentListBox, size_t width, const string& text ); + ~MachGuiSingleSelectionListBoxItem(); void CLASS_INVARIANT; - static size_t reqHeight(); + static size_t reqHeight(); protected: - virtual void select(); - virtual void unselect(); + // This variant utilized by MachGuiDropDownListBoxItem to initialize it. Hence, pMyListBox_ is null + //TODO: Find a suitable abstraction for getting handle to game state ("startupData" lol) so MGSS dependency can be removed + MachGuiSingleSelectionListBoxItem(MachGuiStartupScreens* pStartupScreens, GuiSingleSelectionListBox* pParentListBox, size_t width, const string& text ); + + virtual void select() override; + virtual void unselect() override; - static GuiBmpFont getFont(); - static GuiBmpFont getUnderlineFont(); - static GuiBmpFont getHighlightFont(); + static GuiBmpFont getFont(); + static GuiBmpFont getUnderlineFont(); + static GuiBmpFont getHighlightFont(); - virtual void doDisplay(); + virtual void doDisplay() override; - bool highlighted() const; - const string& text() const; - MachGuiStartupScreens* startupScreens(); - MachGuiSingleSelectionListBox* myListBox(); + bool highlighted() const; + const string& text() const; + // TODO: Eliminate this. Subclasses in declared in ctxjoin.cpp and ctxmulti.cpp use this to join & name the MP game. + MachGuiStartupScreens* startupScreens() __attribute((deprecated)); + MachGuiSingleSelectionListBox* myListBox(); - virtual void doHandleMouseEnterEvent( const GuiMouseEvent& rel ); - virtual void doHandleMouseExitEvent( const GuiMouseEvent& rel ); + virtual void doHandleMouseEnterEvent( const GuiMouseEvent& rel ) override; + virtual void doHandleMouseExitEvent( const GuiMouseEvent& rel ) override; private: friend ostream& operator <<( ostream& o, const MachGuiSingleSelectionListBoxItem& t ); @@ -56,10 +63,14 @@ class MachGuiSingleSelectionListBoxItem : public GuiSingleSelectionListBoxItem MachGuiSingleSelectionListBoxItem( const MachGuiSingleSelectionListBoxItem& ); MachGuiSingleSelectionListBoxItem& operator =( const MachGuiSingleSelectionListBoxItem& ); - string text_; - bool highlighted_; - MachGuiStartupScreens* pStartupScreens_; - MachGuiSingleSelectionListBox* pMyListBox_; + string text_; + bool highlighted_; + // TODO: Eliminate this. Subclasses in declared in ctxjoin.cpp and ctxmulti.cpp use this to join & name the MP game. + MachGuiStartupScreens* pStartupScreens_ __attribute((deprecated)); + MachGuiSingleSelectionListBox* pMyListBox_; + + // A GuiRoot such as MachGuiStartupScreens + GuiRoot* pRootParent_; };