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

Commit

Permalink
MachGuiSingleSelectionListBoxItem: Backdrop blitting now performed by…
Browse files Browse the repository at this point in the history
… some GuiRoot. MGSS dependency remains because of need to access global game state via startupData. Also, made confusing 2nd constructor protected and fixed some warnings.
  • Loading branch information
m-flak committed Aug 19, 2022
1 parent 4a907e4 commit db78e70
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 101 deletions.
180 changes: 98 additions & 82 deletions src/libdev/machgui/sslistit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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<GuiRoot*>(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<GuiRoot*>(pParentListBox->findRoot(this));

TEST_INVARIANT;
}
Expand All @@ -29,8 +45,8 @@ MachGuiSingleSelectionListBoxItem::~MachGuiSingleSelectionListBoxItem()
{
TEST_INVARIANT;

if ( pMyListBox_ )
pMyListBox_->removeListItem( this );
if ( pMyListBox_ )
pMyListBox_->removeListItem( this );
}

void MachGuiSingleSelectionListBoxItem::CLASS_INVARIANT
Expand All @@ -41,152 +57,152 @@ 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<void*>( const_cast<MachGuiSingleSelectionListBoxItem*>(&t) ) << " start" << std::endl;
o << "MachGuiSingleSelectionListBoxItem " << reinterpret_cast<void*>( const_cast<MachGuiSingleSelectionListBoxItem*>(&t) ) << " end" << std::endl;

return o;
}

//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<int>(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<int>(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<int>(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 *************************************************/
49 changes: 30 additions & 19 deletions src/libdev/machgui/sslistit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "base/base.hpp"
#include "stdlib/string.hpp"
#include "gui/root.hpp"
#include "gui/sslistit.hpp"

class GuiBmpFont;
Expand All @@ -24,42 +25,52 @@ 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 );

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_;
};


Expand Down

0 comments on commit db78e70

Please sign in to comment.