Clearing a Stringw

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
rtr_18
Posts: 60
Joined: Thu Jun 10, 2010 8:35 am
Location: Programmer

Clearing a Stringw

Post by rtr_18 »

Hi!
I'm drawing a wide char string(irr::core::stringw) using
IGUIFont::draw(). I'm drawing a particular string while mouse hovering an image(by doing hit test). I'm drawing a different string while the mouse is away from the image. My normal string(Mouse away string) is overlapping with my mouse over string. How to clear the mouse over string?
Mani2010
Posts: 107
Joined: Sat Jan 16, 2010 4:35 pm
Location: London,UK
Contact:

Post by Mani2010 »

post your code, it seems a simple fix
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

IGUIFont::draw() draws directly to viewport, so the drawn string will be cleared only when you beginScene(...with clearing color buffer...) again.

All should be fine if you do it in next way:

Code: Select all

driver->beginScene();

....

if (mouseHoversTheImage)
   s = "OVER";
else
   s = "AWAY";

font->draw(s);

....
driver->endScene();
so you redraw necessary text every frame.
rtr_18
Posts: 60
Joined: Thu Jun 10, 2010 8:35 am
Location: Programmer

Post by rtr_18 »

Hi!
I'm using this code inside the gameloop.

Code: Select all

for(int i = 0; i < levels; i++)
{
  MousePtr = device->getCursorControl()->getPosition();  
  if(circleImage[i]->getRelativePosition().isPointInside(MousePtr))
 {
   GetString(i);
  }
  else
    GetString(curLevel);
}
  pManager->getFont()->draw(testStr.c_str(),recti(20,20,100,60),RED,true);
"testStr" is a private variable in my class and assigned value in the function GetString(int). If use the above code as u suggested mouse hover string is not drawn(only current level string is always drawn). If I draw the string in both if and else sections(i.e placing last line of code in both the sections), Mouse hover and current level strings are overlapping.
How to resolve this problem?
Mani2010
Posts: 107
Joined: Sat Jan 16, 2010 4:35 pm
Location: London,UK
Contact:

Post by Mani2010 »

Would be interested in seeing you GetString function, i think something strange may be happening in there. But that wouldn't explain the overlap.

I don't think this has anything to do with Irrlicht.

Here is one solution.

Code: Select all


bool bDrawHoverString = false;
MousePtr = device->getCursorControl()->getPosition();  
for(int i = 0; i < levels; i++) 
{ 
    if(circleImage[i]->getRelativePosition().isPointInside(MousePtr)) 
    { 
       bDrawHoverString = true;
       break;
     } 
} 

if( bDrawHoverString )
{
//  set the string here
testStr = "We are hovering";
 }
else
{
//  set the string here
testStr = "We are NOT hovering";
}
 pManager->getFont()->draw(testStr.c_str(),recti(20,20,100,60),RED,true); 


Post Reply