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

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

classfly
Just popping in
Just popping in
Posts: 17
Joined: Mon Feb 27, 2012 08:36

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

Postby classfly » Sat Mar 03, 2012 15:38

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.
Last edited by classfly on Tue Mar 27, 2012 12:20, edited 1 time in total.

classfly
Just popping in
Just popping in
Posts: 17
Joined: Mon Feb 27, 2012 08:36

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

Postby classfly » Sat Mar 03, 2012 17:52

My environment:Ogre 1.7.3 + CEGUI 0.7.5

classfly
Just popping in
Just popping in
Posts: 17
Joined: Mon Feb 27, 2012 08:36

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

Postby classfly » Sat Mar 03, 2012 18:23

I find that function onEquip() was not called as planed when i clicked on the window(StaticImage):"Root/left/slot". :(

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

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

Postby CrazyEddie » Sun Mar 04, 2012 11:47

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.

classfly
Just popping in
Just popping in
Posts: 17
Joined: Mon Feb 27, 2012 08:36

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

Postby classfly » Sun Mar 04, 2012 13:36

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.

classfly
Just popping in
Just popping in
Posts: 17
Joined: Mon Feb 27, 2012 08:36

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

Postby classfly » Mon Mar 05, 2012 05:08

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 :(

classfly
Just popping in
Just popping in
Posts: 17
Joined: Mon Feb 27, 2012 08:36

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

Postby classfly » Mon Mar 05, 2012 06:35

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.


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 11 guests