[Solved] std::string to UTFString

Jekteir

30-07-2007 01:17:53

Do you have a function or know of simple code that converts std::strings (which are the same as Ogre::Strings in my case) to the UTFString format that is required for TextBox's addCharacter()? I am using OIS, and checking all unbuffered characters before writing string characters from them, and adding them to my textbox. Have you favoured UTFString instead of String because String didn't support enough characters?

Code to convert a single character would be fine.


Jek

Jekteir

30-07-2007 01:48:56

OK, well, I've tried using this code to convert a character from std::string to UTFString:

loadSaveTxt->addCharacter(Ogre::UTFString::UTFString(newChar).getChar(1));

It may have worked -- I'm not sure. I can now add characters, and the cursor moves along the textbox as I do -- but the characters are not visible. The textbox has the standard GUI background material(s). I also tried doing this beforehand to make sure it wasn't a text color issue:

loadFileTextBox->setTextColor(Ogre::ColourValue(1,1,1,1));

No dice. I know that this may not matter in the next version of QuickGUI anyway, but if you know what's up... : )

Jek

Jekteir

30-07-2007 01:52:22

Turns out I just needed to play a little more. The working code is:

loadSaveTxt->addCharacter(Ogre::UTFString::UTFString(newChar).getChar(0));

Jekteir

30-07-2007 02:06:04

OK, so now I'm trying to send QuickGUI a backspace! I tried \b as my std::string (which should compile to the backspace escape ascii key...possibly), but that just sort of mini-tabbed forward in my textbox after conversion to utf character.

I looked at

http://www.ogre3d.org/phpBB2addons/view ... hp?p=26850

but couldn't see anything helpful.

Being able to get the character in ASCII from OIS without translating myself (as I am now) might solve the problem. Right now I'm doing:


if (checkKeyDownNew(OIS::KC_SLASH))
{
return "/";
}
if (checkKeyDownNew(OIS::KC_BACKSLASH))
{
return "\\";
}
if (checkKeyDownNew(OIS::KC_BACK))
{
return "\b";
}


etc...

There must be a way to do this from a keycode in OIS without manual translation -- right?

Jekteir

30-07-2007 02:10:58

OK, tried:

return mKeyboard->getAsString(OIS::KC_BACK);

This worked OK from the OIS side, but QuickGUI printed Bs. This is when I remembered that I should be using a QuickGUI character delete function for this anyway ;)

Jekteir

30-07-2007 03:05:51

It's rather particular to my situation, but in case anyone finds this useful...


std::string newChar = mInputMgr->checkAllCharsNew(); // custom function added to InputManager, returns only characters which are down for the first time, i.e. have not been held down; returns them in string form

if (newChar == "BACK" || (mInputMgr->checkKeyDown(OIS::KC_BACK) && lastBackkey < timeCurrentFrame-70))
{
loadSaveTxt->backSpace();
lastBackkey = timeCurrentFrame;
}
else if (newChar == "DEL" || (mInputMgr->checkKeyDown(OIS::KC_DELETE) && lastDelkey < timeCurrentFrame-70))
{
loadSaveTxt->deleteCharacter();
lastDelkey = timeCurrentFrame;
}
else if (newChar == "RIGHT" || (mInputMgr->checkKeyDown(OIS::KC_RIGHT) && lastRightkey < timeCurrentFrame-70))
{
lastRightkey = timeCurrentFrame;
if (loadSaveTxt->getTextWidget()->getCursorIndex() < loadSaveTxt->getText().length())
loadSaveTxt->getTextWidget()->incrementCursorIndex();
}
else if (newChar == "LEFT" || (mInputMgr->checkKeyDown(OIS::KC_LEFT) && lastLeftkey < timeCurrentFrame-70))
{
lastLeftkey = timeCurrentFrame;
if (loadSaveTxt->getTextWidget()->getCursorIndex() > 0)
loadSaveTxt->getTextWidget()->decrementCursorIndex();
}
else if (newChar != "")
{
loadSaveTxt->addCharacter(Ogre::UTFString::UTFString(newChar).getChar(0));
}