StaticImage use

RT

08-12-2008 08:03:05

Hi all,

I'm looking at using MyGUI for a project and so far have been finding it very effective. I have run into one issue, though, and that's figuring out the workings of a StaticImage through the Layout Editor.

I've got an image in my GUI directory, and I've created and saved a GUI there in which there's a StaticImage component which references that image. When I entered the image's filename into the StaticImage, however, it gave me an error that no such Image_Texture exists. When I load the GUI with this component already inside it gives me the same error.

I've had a poke around and found that in the Layour Editor's own layout a StaticImage is used. The code created by the LayourEditor seems to mirror that working code, so I'm pretty sure my problem lies elsewhere. I'm thinking that I've got to load the image as an Image_Texture before I apply it, but can't find where to do that.

If I replace the name of my own image file with the one included with the Layout Editor it loads fine. I've tried using the full path name to the file, no luck. I've also tried using the names of loaded Ogre materials (as the wiki mentions that this is what StaticImages are for) and that didn't seem to work either.

Any pointers?

Thanks for any help.

Altren

08-12-2008 13:29:00

Well, in StiticImage you can set texture by file name (file need to be in Ogre resources paths) or by name of texture that loaded in Ogre manually (for example by RTT). You don't need to preload it. Something like:
MyGUI::StaticImagePtr image = mGUI->createWidget<MyGUI::StaticImage>("StaticImage", MyGUI::IntCoord(MyGUI::IntPoint(), mGUI->getViewSize()), MyGUI::Align::Stretch, "Back");
image->setImageTexture("wallpaper.jpg");

RT

09-12-2008 02:48:17

I haven't tried making them in code directly as I need other people to be able to make GUIs with the LayoutEditor.

Strange thing is that while the Layout Editor complains that the Image_Texture doesn't exist, if I save the layout and then load it in my application the image shows up fine. So whatever's up it just seems to be in the Layout Editor.

So am I doing something wrong with the Layout Editor? Your layout that came with it seems to work, so I must be missing something.

Altren

09-12-2008 20:23:49

Well, if you creating StaticImage with yours file this file not in LayoutEditor resources and LE will say that it can't find picture and it's ok. If you want to see correct warnings add path to your pictures to resources.cfg.

RT

10-12-2008 12:19:08

The Layout Editor and my application are both using the same resources.cfg file, so they should all be referencing the same paths. I'll double check that though...

RT

12-12-2008 00:01:44

Sorry about the delay. :-)

LayoutEditor and my application are definitely using the same resource config file. Not even a copy, they're running from the same folder so it's the same physical file and the same physical resource set.

Anything else I could be missing?

casio

22-12-2008 11:37:56

Sorry about the delay. :-)

LayoutEditor and my application are definitely using the same resource config file. Not even a copy, they're running from the same folder so it's the same physical file and the same physical resource set.

Anything else I could be missing?


Hi RT,

I'm having the exact same problem with layout editor. I need the artist to be able to use layouteditor to add StaticImages, The editor lets you place the outline for the staticimage but won't show an image if you type it into the texture box.

I can find the staticimage and change it's texture in code, but like you I need the image to show up when the layout loads.

I now have layouteditor.exe in my games directory and definately using the same resources.

I've just stepped through the layouteditor source and it only loads textures in that are mentioned in interface.layout widgets. It doesn't load textures in from the resource path. So putting your picture in the same location as wallpaperEditor.jpg wont work.

casio

22-12-2008 13:16:29

Well, if you creating StaticImage with yours file this file not in LayoutEditor resources and LE will say that it can't find picture and it's ok. If you want to see correct warnings add path to your pictures to resources.cfg.

Fixed it! Sorry I don't know how to submit code changes to your mygui project so here is my fix that seems to work fine.

bool EditorWidgets::tryToApplyProperty(MyGUI::WidgetPtr _widget, std::string _key, std::string _value, bool _test)
{
try{
if (_key == "Image_Texture")
{
if ( false == Ogre::TextureManager::getSingleton().resourceExists(_value) )
{
Ogre::TextureManager & manager = Ogre::TextureManager::getSingleton();
if (false == manager.resourceExists(_value))
manager.load(_value, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if ( false == Ogre::TextureManager::getSingleton().resourceExists(_value) )
{
MyGUI::Message::_createMessage("Warning", "No such " + _key + ": '" + _value + "'. This value will be saved.", "", "LayoutEditor_Overlapped", true, null, MyGUI::Message::IconWarning | MyGUI::Message::Ok);
return true;
}
}
}
if (_test ||
(("Message_Modal" != _key) && ("Window_AutoAlpha" != _key) && ("Window_Snap" != _key) && ("Widget_NeedMouse" != _key)))
MyGUI::WidgetManager::getInstance().parse(_widget, _key, _value);
Ogre::Root::getSingleton().renderOneFrame();
}
catch(MyGUI::MyGUIException & e)
{
MyGUI::Message::_createMessage("Warning", "Can't apply '" + _key + "'property" + ": " + e.getDescription(), ". This value will be saved.", "LayoutEditor_Overlapped", true, null, MyGUI::Message::IconWarning | MyGUI::Message::Ok);
}
catch(Ogre::Exception & )
{
MyGUI::Message::_createMessage("Warning", "No such " + _key + ": '" + _value + "'. This value will be saved.", "", "LayoutEditor_Overlapped", true, null, MyGUI::Message::IconWarning | MyGUI::Message::Ok);
}// for incorrect meshes or textures
catch(...)
{
MyGUI::Message::_createMessage("Error", "Can't apply '" + _key + "'property.", "", "LayoutEditor_Overlapped", true, null, MyGUI::Message::IconWarning | MyGUI::Message::Ok);
return false;
}
return true;
}


Essentially, When the texture is not found in the loaded resources it loads it via the manager. Then does the check again. If the image really is missing from the resource path you will still get the error.

Someone will need to add the fix to the source as like I said I've no idea how.

Altren

22-12-2008 15:38:31

Wait a second, you use code from MyGUI 2.2 RC1, right? If yes then you should checkout new code from svn. We changed check for texture and files is resources :oops:

casio

22-12-2008 20:06:51

Wait a second, you use code from MyGUI 2.2 RC1, right? If yes then you should checkout new code from svn. We changed check for texture and files is resources :oops:

Thanks Altren, yes it's 2.2 RC1, I checked out the latest sources but I had trouble building it so went back to 2.2 RC1.

Altren

22-12-2008 20:16:44

What's problem with building? If you still have it we'll fix it.

casio

23-12-2008 00:07:11

What's problem with building? If you still have it we'll fix it.

I will have another go building the svn source and let you know later.

Excellent GUI by the way.

casio

23-12-2008 13:06:36

What's problem with building? If you still have it we'll fix it.

Hi Altren, I've just re built the latest svn and it all built ok. The problem wasn't the build but the integration into my project. A lot had changed and I had a few errors integrating the new lib. It's all fixed now.

Altren

23-12-2008 14:26:59

Great.

RT

04-01-2009 23:03:01

Ok, I'm getting back to my project now. I'll grab the latest source myself.