IGUIBox password mask

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

IGUIBox password mask

Post by elvman »

I checked out the latest irrlicht's SVN and found out, that it still does not support password masking for edit boxes. Why? Is it really so hard to implement such a feature? I allways have to modify the irrlicht's source when a new version of irrlicht comes out to have the password support. Don't really people make games where user has to enter user name and password?
The code I add to irrlicht is as follows:
IGUIEditBox.h:

Code: Select all

virtual void SetPassword(bool use, wchar_t chr = L'*') = 0;
CGUIEditBox.h:

Code: Select all

public:
	//...
	virtual void SetPassword(bool use, wchar_t chr = '*');
private:
	//...
	bool password;
	wchar_t PWChar;
CGUIEditBox.cpp:

Code: Select all

CGUIEditBox::CGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
			IGUIElement* parent, s32 id,
			const core::rect<s32>& rectangle, IOSOperator* op)
: IGUIEditBox(environment, parent, id, rectangle), MouseMarking(false),
	Border(border), OverrideColorEnabled(false), MarkBegin(0), MarkEnd(0),
	OverrideColor(video::SColor(101,255,255,255)),
	OverrideFont(0), Operator(op), CursorPos(0), ScrollPos(0), Max(0), password(false), PWChar(L'')

void CGUIEditBox::SetPassword(bool use, wchar_t chr)
{
    password = use;
    PWChar = chr;
}

void CGUIEditBox::draw()
{
	if (!IsVisible)
		return;

	bool focus = Environment->hasFocus(this);

	IGUISkin* skin = Environment->getSkin();
	if (!skin)
		return;

	irr::video::IVideoDriver* driver = Environment->getVideoDriver();

	core::rect<s32> frameRect(AbsoluteRect);

	// draw the border

	if (Border)
	{
		skin->draw3DSunkenPane(this, skin->getColor(EGDC_WINDOW),
			false, true, frameRect, &AbsoluteClippingRect);
      
		frameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X);
	}

//-----------------------------------this is added
	// draw the text
	core::stringw tmpText("");
   
	// If password is enabled then construct a string of PWchar the same length as the Text
	if(password)
	{
		u32 i;
		for(i = 0;i < Text.size();i++)tmpText += PWChar;
	}
	else tmpText = Text;
//-----------------------------------

	IGUIFont* font = OverrideFont;
	if (!OverrideFont)
	font = skin->getFont();

	if (font)
	{
		// calculate cursor pos

		core::stringw s = tmpText.subString(0,CursorPos);
		s32 charcursorpos = font->getDimension(s.c_str()).Width;

		s = tmpText.subString(0, ScrollPos); //now use the tmpText everywhere
		s32 charscrollpos = font->getDimension(s.c_str()).Width;

		core::rect<s32> rct;

		// draw mark

		if (focus && MarkBegin != MarkEnd)
		{
			rct = frameRect;

			rct.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y);
			rct.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y);

			s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
			s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;

			s = tmpText.subString(0, realmbgn);
			s32 mbegin = font->getDimension(s.c_str()).Width;

			s = tmpText.subString(realmbgn, realmend - realmbgn);
			s32 mend = font->getDimension(s.c_str()).Width;

			rct.UpperLeftCorner.X  += mbegin - charscrollpos;
			rct.LowerRightCorner.X = rct.UpperLeftCorner.X + mend;

			driver->draw2DRectangle(skin->getColor(EGDC_HIGH_LIGHT), rct, &AbsoluteClippingRect);
		}

		// draw cursor

		if (focus && (os::Timer::getTime() - BlinkStartTime) % 700 < 350)
		{
			rct = frameRect;
			rct.UpperLeftCorner.X += charcursorpos;
			rct.UpperLeftCorner.X -= charscrollpos;

			font->draw(L"_", rct,
				OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
				false, true, &AbsoluteClippingRect);
		}

		// draw Text
		if (tmpText.size())
		{
			rct = frameRect;
			rct.UpperLeftCorner.X -= charscrollpos;

			// Save the override color information.
			// Then, alter it if the edit box is disabled.
			bool prevOver = OverrideColorEnabled;
			video::SColor prevColor = OverrideColor;
			if ( !this->IsEnabled && !OverrideColorEnabled )
			{
				OverrideColorEnabled = true;
				OverrideColor = skin->getColor( EGDC_GRAY_TEXT );
			}

			if (focus && MarkBegin != MarkEnd)
			{
				// marked Text

				font->draw(tmpText.c_str(), rct,
					OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
					false, true, &AbsoluteClippingRect);

				s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
				s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;

				s = tmpText.subString(0, realmbgn);
				s32 mbegin = font->getDimension(s.c_str()).Width;

				s = tmpText.subString(realmbgn, realmend - realmbgn);

				rct.UpperLeftCorner.X += mbegin;

				font->draw(s.c_str(), rct,
					OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
					false, true, &AbsoluteClippingRect);                        
			}
			else
			{
				// normal Text
				font->draw(tmpText.c_str(), rct,
					OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
					false, true, &AbsoluteClippingRect);
			}

			// Return the override color information to its previous settings.
			OverrideColorEnabled = prevOver;
			OverrideColor = prevColor;
		}
	}
}
JPulham
Posts: 320
Joined: Sat Nov 19, 2005 12:06 pm

Post by JPulham »

pushpork
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Post by elvman »

Yes, this is the place where I got the code from JPulham. Thanks for your code!
But is it really so hard to implement it in the Irrlicht engine?
rooly
Posts: 224
Joined: Tue Oct 25, 2005 4:32 pm
Location: Louisiana, USA, backwater country
Contact:

Post by rooly »

my question is, is it really necessary to implement in the engine itself?

this is a 3d engine, afterall, not an mmorpg engine. make sure you get the priority differences straight.
When banks compete, you win.
When ISPs compete, you win.
When electronics retailers compete, you win.
When governments compete...you get drafted.
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Post by elvman »

Then why does Irrlicht have a GUI system at all? They add features like word wrapping etc. but can't add a small feature like this? I don't understand!
rooly
Posts: 224
Joined: Tue Oct 25, 2005 4:32 pm
Location: Louisiana, USA, backwater country
Contact:

Post by rooly »

well there i would have to assume because irrlicht wanted to make it easier on users. but since a password box is more of a niche usage reserved for central server games like mmo's and competition services (battle.net anyone?), it's not neccissarily a feature that should be implemented. If you go to your engine next door, you can't even guarantee to have a gui system, much less a gui system with built in text boxes, input fields, and hey, input fields with password masking.

All i'm saying is, seeing how easily you can implement it yourself in what looks like modifying only 3 files minimally, it doesn't need to be included into the general engine itself.

this is all opinion and conjecture of mine own, for the most part, and my not reflect accurately the opinions of the dev team, however my point still stands.

furthermore, for the whole
Then why does Irrlicht have a GUI system at all?
you could always go over to ogre, which doesn't have ANY gui system, and code all your own inputs and overlays and text recievers and yadda yadda whatnot...but i for one would rather the copy/paste of 10-20 lines of code necessary.
When banks compete, you win.
When ISPs compete, you win.
When electronics retailers compete, you win.
When governments compete...you get drafted.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Don't really people make games where user has to enter user name and password?
Sure they do, they just don't *finish* them :P

You can expect password editboxes before the next release, along with automatic scrollbars and a bunch of other options.
Then why does Irrlicht have a GUI system at all?
I'm toying with the idea of having the option to compile without the GUI at all, it would shave quite a bit off the DLL and make sense for embedded development.
They add features like word wrapping etc. but can't add a small feature like this? I don't understand!
I'm working for free in my spare time, for fun. Adding word wrap and text justification was challenging and fun, and I needed it for something I was playing with. Adding passwords and testing it all is boring work, so it gets shifted down my todo list quite regularly ;)
Besides, changing the way that editboxes work comes before adding bells and whistles.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Post by elvman »

Adding passwords and testing it all is boring work, so it gets shifted down my todo list quite regularly
I can do this boring work! I can write a patch for Irrlicht in a correct Irrlicht-like language, just let me do that!

P.S. What happens if I commit my changes to Irrlicht's SVN?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

you'll get access denied if you try to commit ;)

It will be at least as much work for me to check your patch as it would be to write it from scratch.
Word wrap and multi-line should be disabled when passwords are enabled, and line feeds should probably somehow be converted/removed. You shouldn't be able to copy the password using ctrl+c.

Then there's the things I want to add in the future... Like ctrl+direction for word navigation, you shouldn't be able to identify words by using ctrl+left/right. Password boxes shouldn't have context menus and scrollbars, if they are numerical then they shouldn't allow decimal places.

So I could add this right now and rearrange everything when I finish the edit box, or I could wait until it is almost complete :?

Don't worry, when the edit box is finished it will have password chars :)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Post by elvman »

Thank you bitplane!!! Can't wait for the next release of Irrlicht!
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I've been holding my breath since submitting pretty much exactly this patch to the tracker in November 2006, when I was told that the new GUI was "almost ready". :roll:
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

Meh , second thought. early mornings and im sick, apologies

:)
Last edited by FuzzYspo0N on Fri Aug 31, 2007 9:10 am, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Hey Fuzzy, did you really read the post? rogerborg did implement it, it's there for immediate use. But thanks to bitplane (and several reminders on the forum) it's now also in the library - SVN revision something.
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Post by elvman »

Yes, thanks to bitplane!
Post Reply