Page 1 of 1

[SOLVED]i create the tooltip which can show images and text

Posted: Sat Mar 03, 2012 15:38
by classfly
I want to create a tooltip which can show the images and different fonts.But here i met two problems:
1.the content of the tooltip i create cann't work as i wished
I create two staticimages(one is Root/left/slot another is Root/righttop/weapon) in my layoutfile unnamed2.layout.Root/left/slot is the child window of Root/left(StaticImage) and Root/righttop/weapon is the childwindow of Root/righttop(StaticImage).

Code: Select all

CEGUI::Window* itemWidget = MyGUI::getSingletonPtr()->getWindow("Root/left/slot");//MyGUI is a class which i create some functions on UI
itemWidget->setUserString("type","Destroyer");//to set a flag "Destroyer"
formatInvTooltip(itemWidget,mItems[0]);//std::vector<Item*> mItems;
CEGUI::Window* skillWidget = MyGUI::getSingletonPtr()->getWindow("Root/righttop/slot");
formatSkillTooltip(skillWidget,mSkills[0]);//std::vector<Skill*> mSkills;

formatInvTooltip()

Code: Select all

void Demo::formatInvTooltip(CEGUI::Window* window,Item* item)
{
    std::stringstream ssTooltip; 
    ssTooltip 
    <<"[font='SimHei-14'][colour='FF0000FF']"<<item->getName()<<std::endl 
    <<"[top-padding='5'][bottom-padding='10'][image-width='60'][image-height='90'][colour='FFFFFFFF'][image='" 
    <<item->getIconName()<<"']"<<std::endl 
    <<"------------------------"<<std::endl 
   <<"[top-padding='0'][bottom-padding='0'][font='SimHei-14'][colour='FF00FFFF']" << item->getDescription() << std::endl 
    <<"------------------------"<<std::endl 
   <<"Tech Level: " << item->getSkillLevel() << std::endl 
    <<"------------------------"<<std::endl 
    <<"Cost: "<<item->getCost()<<std::endl; 
    //
    window->setTooltipText(ssTooltip.str()); 
}

formatInvSkillTooltip

Code: Select all

void Demo::formatSkillTooltip(CEGUI::Window* window, Skill* skill) 

   std::stringstream ssTooltip; 
   ssTooltip 
   <<"[font='SimHei-14'][colour='FFFFFF00']"<<skill->getName()<<std::endl 
   <<"[top-padding='5'][bottom-padding='10'][image-width='80'][image-height='80'][colour='FFFFFFFF'][image='" 
   <<skill->getIconName()<<"']"<<std::endl 
   <<"------------------------"<<std::endl 
   <<"[top-padding='0'][bottom-padding='0'][font='SimHei-14'][colour='FF00FF00']" << skill->getDescription() << std::endl 
   <<"------------------------"<<std::endl 
   <<(CEGUI::utf8*)Ogre::UTFString(L"Your skill level is : ").asUTF8_c_str()<< skill->getLevel() << std::endl 
   <<"------------------------"<<std::endl 
   <<(CEGUI::utf8*)Ogre::UTFString(L"Mana cost of XXX Skill: ").asUTF8_c_str()<<skill->getCost()<<std::endl 
   <<"------------------------"<<std::endl 
   <<(CEGUI::utf8*)Ogre::UTFString(L"Damageļ¼š").asUTF8_c_str()<<skill->getDamage()<<std::endl; 
   // 
   window->setTooltipText((CEGUI::utf8*)ssTooltip.str().c_str()); 
}

But when i call createGUIEvents()

Code: Select all

void Demo::createGUIEvents()
{
     MyGUI::subscribeEvent("Root/left/slot",CEGUI::Window::EventMouseClick,CEGUI::Event::Subscriber(&Demo::onEquip,this));
}
bool Demo::onEquip(const CEGUI::EventArgs& args)
{
   const CEGUI::WindowEventArgs& WindowArgs = static_cast<const CEGUI::WindowEventArgs&>(args);
   if(WindowArgs.window->getUserString("type") == "Destroyer")
   {
      CEGUI::Window* invleft = MyGUI::getSingletonPtr()->getWindow("Root/left");
      invleft->removeChildWindow(WindowArgs.window);
      CEGUI::Window* invweapon = MyGUI::getSingletonPtr()->getWindow("Root/righttop/weapon");
      invweapon->getChild(0)->addChildWindow(WindowArgs.window);
      WindowArgs.window->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0), CEGUI::UDim(0, 0)));
      WindowArgs.window->setSize(CEGUI::UVector2(CEGUI::UDim(1, 0), CEGUI::UDim(1, 0)));
   }
   return true;
}

formatInvTooltip() and formatSkillTooltip() ,they are created in order to create the tooltip which i can put the image and text in it and i find when my cursor was on the staticimage window ,nothing happend :(
While in the model of debug,i find that the EventMouseClick event was not fired.Oh what a mess!!.Maybe i made a stupid mistakes again,but i really want to know where are they set.

Re: i create the tooltip which can show images and text,but.

Posted: Sat Mar 03, 2012 17:52
by classfly
My environment:Ogre 1.7.3 + CEGUI 0.7.5

Re: i create the tooltip which can show images and text,but.

Posted: Sat Mar 03, 2012 18:23
by classfly
I find that function onEquip() was not called as planed when i clicked on the window(StaticImage):"Root/left/slot". :(

Re: i create the tooltip which can show images and text,but.

Posted: Sun Mar 04, 2012 11:47
by CrazyEddie
If those container windows have other windows attached to them (like the static images), the static image will receive the mouse click, not the containing window. Depending on your needs it might be enough to set the MousePassThroughEnabled property to True on the static image(s) (of course, depending on your needs, that may not be desirable, so other solutions might be needed).

CE.

Re: i create the tooltip which can show images and text,but.

Posted: Sun Mar 04, 2012 13:36
by classfly
CrazyEddie wrote:If those container windows have other windows attached to them (like the static images), the static image will receive the mouse click, not the containing window. Depending on your needs it might be enough to set the MousePassThroughEnabled property to True on the static image(s) (of course, depending on your needs, that may not be desirable, so other solutions might be needed).

CE.

I know what you mean.By setting property MousePassThroughEnabled = true;the staticimage won't receive the mouse click but the parent window of it.And i find out one (the display of the tooltip)of the two problems .But the subscribeEvent problem is still there and unsolved.Maybe i didn't get the full understanding of what you said.I hope i can get some more help from you.

Re: i create the tooltip which can show images and text,but.

Posted: Mon Mar 05, 2012 05:08
by classfly
Here are my subscribeEvent():

Code: Select all

void MyGUI::subscribeEvent(const CEGUI::String& windowName,
                     const CEGUI::String& eventName,
                     const CEGUI::Event::Subscriber& subscriber)
{
   CEGUI::WindowManager::getSingleton().getWindow(CEGUI::String(windowName))->subscribeEvent(eventName,subscriber);
}

I put the function in my class MyGUI(Inheritated from class BaseApplication).And in my Demo.cpp ,i try to register the event by calling createGUIEvents():

Code: Select all

void Demo::createGUIEvents()
{
   MyGUI::subscribeEvent("Root/left/slot",CEGUI::Window::EventMouseClick,CEGUI::Event::Subscriber(&Demo::onEquip,this));
}

When i click staticimage "Root/left/slot",nothing happend :(

Re: i create the tooltip which can show images and text,but.

Posted: Mon Mar 05, 2012 06:35
by classfly
Thanks godness.I find the mistake now!It's the function injectMouseButtonUp().The logic in it has some problem and i have corrected it right.Now everything goes well.