IGUIMenu bug when changing a submenu item.

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

IGUIMenu bug when changing a submenu item.

Post by christianclavet »

Hi, If this can be confirmed...

I'm using Irrlicht 1.7.2 official release.

Created a menu and added items, then I'm using this command to change the text of the item. (A viewport class I'm working on)

Code: Select all

viewportdescription->setItemText(0,L"[Perspective view]");
Once this has been done, the class is doing a recalculate and the problem seem to come from there. The calculated lenght of the text is wrong. So when I use this on a menu item, the submenu background is reducing at each call. It even clip the text at some point.

After seeing this I used the class externally, Once I commented out the command recalculateSize(); from the method setItemText method, this behavior stopped. (It's not good as it's not recalculating when it's changed, it's doesnt extend either.)

So I think the problem would came from the recalculateSize() method, but I did not find it yet. Look like the command

Code: Select all

Items[i].Dim = font->getDimension(Items[i].Text.c_str());
is returning a wrong value, but I don't understand why. It seem only to affect the wide value, the height seem ok.
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IGUIMenu bug when changing a submenu item.

Post by CuteAlien »

Ok, just so I get the problem before I start writing an example to reproduce this. The basic problem is that IGUIContextMenu::setItemText does shrink the visible part of the menu on each call?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: IGUIMenu bug when changing a submenu item.

Post by christianclavet »

Hi, CuteAlien!
Thanks for checking this!

The background box & the clip box get skrinked horizontally. I did not see it shrink vertically. The rendering of text is not affected except that it's getting clipped after a lots of calls to this has been made (it reduce each time IGUIContextMenu::setItemText is invoked). This apply only to the submenu drawing.

Here in what circumstance I discovered the problem (if it really a problem...):
The way I'm using this is for creating a "view select" menu, where you have the "mainmenu" having the text describing the current view, and when clicking on it, you can select an alternative view from the "submenu" (perspective, left, right, front) AND it change the "main" menu description for the name of the currently selected view (Same way we do in 3DS Max, Lightwave, etc.) with the current viewport camera rendering.

Since a new release of IRRlicht should appear in some months, I thought it's should be a good idea to report this now and be sure it's not a bug. Is there a kind of "updateAbsolutePosition()" I should do when I'm modifying "live" (runtime) a menu item text? Perhaps I have to do this?

For my current project, it's not a real problem, first, this is for my hobby project (First King editor), the calculation after doing the IGUIContextMenu::setItemText has been disabled temporary, and I added to the GUI, new features, as removing the background with the setDrawBackground() method, added also the setOverrideFont() and setOverrideColor() methods (same method names as in IGUIStaticText) to the code. The IRRlicht code is so well written, it was really simple to implement this. Now I can define this for each menu/submenu independantly and it is now really more flexible for me for almost any kind of menus I would like to create.

EDIT: Here are screenshots that describe the problem:
Here is the new menu I'm making (The view and + are the main menu items)
Image

Here at application startup:
Image
Here after changing the view a couple of times (notice the submenu background as been reducted):
Image
The box seem to stop shrinking when reaching that size.

If I find the problem with the calculation of width, I could post the whole component on the code snippet (or could propose it to the IRRext). I find it strange that the calculation is done properly before runtime, and when I use the setItemText() at runtime suddenly the clip box reduce horizontally...
Last edited by christianclavet on Thu Aug 18, 2011 7:05 pm, edited 2 times in total.
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IGUIMenu bug when changing a submenu item.

Post by CuteAlien »

Ok, thanks for clarification. It'll take a few days until I get to this (still fighting with editbox right now) but I'll check it out.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: IGUIMenu bug when changing a submenu item.

Post by christianclavet »

I may have found a fix, but I really don't think it is efficient. We might see a little slowdown on very slow platforms (I don't see any slowdown, but I'm running it on a fast pc)
I forced a submenu recalculation in the drawing loop of the submenu. It look like the recalculation when it's called on the method (IGUIContextMenu::setItemText), recalculate the current submenu, but then the other submenus seem to need a recalculation also :

in CGUIContextMenu.cpp, in the CGUIContextMenu::draw() method, I added this line:
recalculateSize();

Now each time I change the text item (IGUIContextMenu::setItemText), I don't see the submenu background being shrinked.
EDIT-UPDATE: I had the same problem when doing my code editor gui example, but it fixed itself because I used the setItemText() on all of the menu items (switching the whole menu from english to french. If I use the command, I need to do it on the whole menu not a single item, and it would work)
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IGUIMenu bug when changing a submenu item.

Post by CuteAlien »

Sorry, took a little more than a few days to get to this bug. Unfortunately I can't reproduce it so far.

My test:

Code: Select all

 
#include <irrlicht.h>
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
 
class MyEventReceiver : public IEventReceiver
{
public:
    MyEventReceiver() : Device(0), Environment(0), ContextMenu(0) { }
    
    void ShowContextMenu(irr::s32 x, irr::s32 y, bool keepOpen)
    {
        if ( ContextMenu )
        {
//          ContextMenu->setRelativePosition(irr::core::position2di(x,y));
            ContextMenu->setVisible(true);
            static bool flip = false;
            if ( flip )
            {
                ContextMenu->setItemText(0, L"[Perspective view] too large?");
//              ContextMenu->getSubMenu(0)->setItemText(0, L"another test");
            }
            else
            {
                ContextMenu->setItemText(0, L"short");
//              ContextMenu->getSubMenu(0)->setItemText(0, L"woof");
            }
            flip = !flip;
        }
        else
        {
            core::rect<s32> rect(x, y, x+50, y+50);
            ContextMenu = Environment->addContextMenu (rect);
            ContextMenu->setCloseHandling(ECMC_HIDE);
            ContextMenu->addItem(L"top1", -1, true, true);
            ContextMenu->addItem(L"no sub", -1, true, false);
            IGUIContextMenu* submenu = ContextMenu->getSubMenu(0);
            if ( submenu )
            {
                submenu->addItem(L"item1", -1);
                submenu->addItem(L"item2", -1);
            }
        }
    };
 
    virtual bool OnEvent(const SEvent& event)
    {
        if (event.EventType == EET_MOUSE_INPUT_EVENT )
        {
            if ( event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP )
            {
                ShowContextMenu(event.MouseInput.X, event.MouseInput.Y, false);
                return true;
            }
        }
        return false;
    }
 
    IrrlichtDevice * Device;
    gui::IGUIEnvironment* Environment;
    gui::IGUIContextMenu* ContextMenu;
};
 
 
int main()
{
    video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
    IrrlichtDevice * device = createDevice(driverType, core::dimension2d<u32>(640, 480));
    if (device == 0)
        return 1; // could not create selected driver.
    video::IVideoDriver * driver = device->getVideoDriver();
 
    MyEventReceiver receiver;
    receiver.Device = device;
    receiver.Environment = device->getGUIEnvironment();
    device->setEventReceiver(&receiver);
    
    while(device->run() )
    {
        if (device->isWindowActive())
        {
            driver->beginScene(true, true, SColor(0,200,200,200));
    
            receiver.Environment->drawAll();
        
            driver->endScene();
        }
    }
 
    device->drop();
 
    return 0;
}
 
I tried around several variations of the test above, but no matter what I tried the sub-menu always had the correct size. So unless you can show me what's missing there I fear I can't fix anything.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply