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

Commit

Permalink
MachGuiSingleLineEditBox: Now agnostic to MGSS. Also fixed some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
m-flak committed Aug 19, 2022
1 parent bd16582 commit 4a907e4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 43 deletions.
63 changes: 36 additions & 27 deletions src/libdev/machgui/editbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
unsigned char pPromptText1[] = { 87, 244, 105, 128, 48, 182, 149, 151, 72, 203, 222, 59, 150, 19, 218, 139, 154, 243, 40, 190, 242, 54, 243, 50, 98, 159, 84, 250, 37, 136, 151, 150, 0 };
unsigned char pPromptText8[] = { 4, 212, 167, 27, 173, 11, 155, 126, 58, 37, 114, 151, 128 };

MachGuiSingleLineEditBox::MachGuiSingleLineEditBox( MachGuiStartupScreens* pStartupScreens, const Gui::Box& box, const GuiBmpFont& font )
: GuiSingleLineEditBox( pStartupScreens, box, font ),
pStartupScreens_( pStartupScreens ),
clearTextOnNextChar_( false ),
ignoreSpaceAtBeginning_( true )
MachGuiSingleLineEditBox::MachGuiSingleLineEditBox(GuiDisplayable* pParent, const Gui::Box& box, const GuiBmpFont& font )
: GuiSingleLineEditBox(pParent, box, font ),
clearTextOnNextChar_( false ),
ignoreSpaceAtBeginning_( true )
{

pRootParent_ = static_cast<GuiRoot*>(pParent->findRoot(this));
TEST_INVARIANT;
}

Expand All @@ -32,8 +31,18 @@ MachGuiSingleLineEditBox::~MachGuiSingleLineEditBox()
//virtual
void MachGuiSingleLineEditBox::drawBackground()
{
pStartupScreens_->blitBackdrop( absoluteBoundary(),
absoluteBoundary().minCorner() );
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()
);
});
}

void MachGuiSingleLineEditBox::CLASS_INVARIANT
Expand All @@ -44,44 +53,44 @@ void MachGuiSingleLineEditBox::CLASS_INVARIANT
ostream& operator <<( ostream& o, const MachGuiSingleLineEditBox& t )
{

o << "MachGuiSingleLineEditBox " << (void*)&t << " start" << std::endl;
o << "MachGuiSingleLineEditBox " << (void*)&t << " end" << std::endl;
o << "MachGuiSingleLineEditBox " << reinterpret_cast<void*>( const_cast<MachGuiSingleLineEditBox*>(&t) ) << " start" << std::endl;
o << "MachGuiSingleLineEditBox " << reinterpret_cast<void*>( const_cast<MachGuiSingleLineEditBox*>(&t) ) << " end" << std::endl;

return o;
}

//virtual
bool MachGuiSingleLineEditBox::doHandleCharEvent( const GuiCharEvent& e )
{
DEBUG_STREAM( DIAG_NEIL, "MachGuiSingleLineEditBox::doHandleCharEvent " << e.getChar() << " " << (int)e.getChar() << std::endl );

if ( ignoreSpaceAtBeginning_ and leftText() == "" and e.getChar() == ' ' )
{
return true;
}
if ( clearTextOnNextChar_ )
{
text( "" );
clearTextOnNextChar_ = false;
}

return GuiSingleLineEditBox::doHandleCharEvent( e );
DEBUG_STREAM( DIAG_NEIL, "MachGuiSingleLineEditBox::doHandleCharEvent " << e.getChar() << " " << static_cast<int>(e.getChar()) << std::endl );

if ( ignoreSpaceAtBeginning_ and leftText().empty() and e.getChar() == ' ' )
{
return true;
}

if ( clearTextOnNextChar_ )
{
text( "" );
clearTextOnNextChar_ = false;
}

return GuiSingleLineEditBox::doHandleCharEvent( e );
}

void MachGuiSingleLineEditBox::clearTextOnNextChar( bool newVal )
{
clearTextOnNextChar_ = newVal;
clearTextOnNextChar_ = newVal;
}

bool MachGuiSingleLineEditBox::clearTextOnNextChar() const
{
return clearTextOnNextChar_;
return clearTextOnNextChar_;
}

void MachGuiSingleLineEditBox::ignoreSpaceAtBeginning( bool ignore )
{
ignoreSpaceAtBeginning_ = ignore;
ignoreSpaceAtBeginning_ = ignore;
}


Expand Down
33 changes: 17 additions & 16 deletions src/libdev/machgui/editbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,33 @@
MachGuiSingleLineEditBox
Constructs a GuiDisplayable that displays text on a single line as it is
typed in by the user. Note that you must call GuiManager::instance().setCharFocus( this ) in
order for this EditBox to get character messages ( WM_CHAR ).
typed in by the user. Note that you must call GuiManager::instance().setCharFocus( this ) in
order for this EditBox to get character messages ( WM_CHAR ).
*/

#ifndef _MACHGUI_EDITBOX_HPP
#define _MACHGUI_EDITBOX_HPP

#include "base/base.hpp"
#include "gui/root.hpp"
#include "gui/editbox.hpp"

class MachGuiStartupScreens;

class MachGuiSingleLineEditBox : public GuiSingleLineEditBox
{
public:
MachGuiSingleLineEditBox( MachGuiStartupScreens* pStartupScreens, const Gui::Box& box, const GuiBmpFont& font );
virtual ~MachGuiSingleLineEditBox();
MachGuiSingleLineEditBox(GuiDisplayable* pParent, const Gui::Box& box, const GuiBmpFont& font );
virtual ~MachGuiSingleLineEditBox();

void clearTextOnNextChar( bool );
bool clearTextOnNextChar() const;
void clearTextOnNextChar( bool );
bool clearTextOnNextChar() const;

// Do/Don't allow space characters to be entered at beginning of edit box.
void ignoreSpaceAtBeginning( bool );
// Do/Don't allow space characters to be entered at beginning of edit box.
void ignoreSpaceAtBeginning( bool );

protected:
virtual void drawBackground();
virtual bool doHandleCharEvent( const GuiCharEvent& e );
virtual void drawBackground() override;
virtual bool doHandleCharEvent( const GuiCharEvent& e ) override;

private:
void CLASS_INVARIANT;

Expand All @@ -43,9 +42,11 @@ class MachGuiSingleLineEditBox : public GuiSingleLineEditBox
MachGuiSingleLineEditBox( const MachGuiSingleLineEditBox& );
MachGuiSingleLineEditBox& operator =( const MachGuiSingleLineEditBox& );

MachGuiStartupScreens* pStartupScreens_;
bool clearTextOnNextChar_;
bool ignoreSpaceAtBeginning_;
bool clearTextOnNextChar_;
bool ignoreSpaceAtBeginning_;

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


Expand Down

0 comments on commit 4a907e4

Please sign in to comment.