Widget alignment question

AndiNo

21-08-2009 12:11:05

Hi! Now that MyGUI works for me I tried to implement some kind of crosshair for my game. I wanted to use a StaticImage that should be centered in the middle of the screen.
My code:
MyGUI::OgrePlatform *mPlatform = new MyGUI::OgrePlatform();
mPlatform->initialise(mWindow); // mWindow is Ogre::RenderWindow* where you want to render MyGUI
mGUI = new MyGUI::Gui();
mGUI->initialise();

// load layout
MyGUI::LayoutManager::getInstance().load("SMR.layout");

My layout file:
<?xml version="1.0" encoding="UTF-8"?>

<MyGUI type="Layout">
<Widget type="Widget" skin="Default" position="0 0 100 100" align="Center" layer="Back">
<Widget type="StaticImage" skin="StaticImage" position_real="0 0 0.28 0.28" align="Center" layer="Back" name="crosshair">
<Property key="Image_Texture" value="crosshair.png"/>
</Widget>
</Widget>

<Widget type="StaticImage" skin="StaticImage" position_real="0 0 0.3 0.3" align="Center" layer="Back" name="crosshair2">
<Property key="Image_Texture" value="crosshair.png"/>
</Widget>
</MyGUI>


The problem is the widgets don't get centered. Only when I resize the Ogre window they get aligned correctly. Is there any update function which I have to call after loading a layout file?
And second: As you can see I create one StaticImage in another widget so that the scaling isn't affected by the 4:3 screen resolution. After resizing the window the parent widget is centered, but the crosshair image is NOT centered within its parent widget. How can I do this?
I'm using MyGUI SVN 2162.

Gohla

22-08-2009 11:20:48

To let MyGUI re-align all widgets you can call:

MyGUI::Gui::windowResized(Ogre::RenderWindow* rw);

AndiNo

22-08-2009 12:48:47

Thanks, I got the idea :) Although the function you mentioned was in OgreRenderManager and was private. But I did it this way:
Viewport *port = mWindow->getViewport(0);
mGUI->resizeWindow( MyGUI::IntSize(port->getActualWidth(), port->getActualHeight()) );

However this is not how it is supposed to be right? It should align without any other function calls I guess...
And my second problem remains, as you can see here: (same layout as above)
The cross should be centered within its parent window...

AndiNo

23-08-2009 14:06:43

I looked further into this problem and tested widget alignment with the old LayoutEditor 1.2 with old MyGUI and Ogre1.4.1, then with the LayoutEditor and MyGUI from SVN2162 and Ogre 1.6.3. And in my program of course - and with DirectX and OpenGL. But alignment doesn't seem to work anywhere, no matter which option I choose. It seems that the whole alignment code is broken, although I guess that's wrong. Doesn't anyone else have this problem? I mean neither stretching nor centering or anything works, that just can't be :x
edit: I just found out that centering works at least in one case: In the LayoutEditor I created a panel with alignment "center" and created a child panel inside it with align "center", too. If I call the resizeWindow function the parent panel gets centered, but the child panel doesn't. Then if I move the parent the child gets centered in it. I'm confused. Why doesn't this work on its own?

AndiNo

24-08-2009 23:38:18

I still have made no progress at this. However today I've seen that hiding the mouse pointer doesn't seem to work. It worked in the old layout editor version (1.2), but now the function mGUI->setVisiblePointer(false); seems to have no effect. If anyone comes up with a good idea (not only for the pointer) I will be thankful, otherwise I think I will have a look at QuickGUI these days.
Or maybe someone who uses MyGUI could show that these things work (if they do) ?

Gohla

25-08-2009 10:26:11

Just setting align to center won't work I think, you must also actually center the crosshair, change the layout code like this and see if it works:


<MyGUI type="Layout">
<Widget type="Widget" skin="Default" position="0 0 100 100" align="Center" layer="Back">
<Widget type="StaticImage" skin="StaticImage" position_real="0.5 0.5 0.28 0.28" align="Center" layer="Back" name="crosshair">
<Property key="Image_Texture" value="crosshair.png"/>
</Widget>
</Widget>
</MyGUI>

AndiNo

25-08-2009 11:14:41

Thanks for your replies, you seem to be the only one with any idea ;)
I tried what you said before, see how it looks:

It doesn't get centered, MyGUI puts the topleft position of the image in the center. That's the normal "positioning" but not centering. I guess I'll just have a look at QuickGUI then...

xypher

21-07-2010 23:22:34

I realize this topic is half a year old, but why wouldn't you just subtract half of the image width and height from the left and top values of the widget?

AndiNo

22-07-2010 13:16:54

It's because I don't want to call any code in C++, I just wanted it to run from the layout files. From my point of view centering is some of the least things a GUI system should be able to do. Anyway, I had changed to QuickGUI after this and just recently changed again to CEGUI.