Page 1 of 3

[Closed/Unconstructive] setPosition does not work

Posted: Tue Aug 12, 2014 06:26
by codeMonkey
hello everyone , today i write my first cegui program,but in my program the function "setPostion" seem to be not in effect,here is my code:

Code: Select all

using namespace CEGUI;
   SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
   System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");
   WindowManager& winMgr = WindowManager::getSingleton();
   DefaultWindow* d_root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root");
   Font& defaultFont = FontManager::getSingleton().createFromFile("DejaVuSans-10.font");
   System::getSingleton().getDefaultGUIContext().setDefaultFont(&defaultFont);
   System::getSingleton().getDefaultGUIContext().setRootWindow(d_root);
   FrameWindow* wnd = (FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "DemoWindow");
   d_root->addChild(wnd);
   wnd->setPosition(UVector2(cegui_reldim(0.25f),cegui_reldim(0.25f)));
   wnd->setSize(USize(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
   wnd->setMaxSize(USize(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
   wnd->setMinSize(USize(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
   wnd->setText("Hello World!");

I want to render in the center,but it is on the top-left corner of the display,who can tell why?

Re: setPosition does not work

Posted: Tue Aug 12, 2014 06:40
by Ident

Re: setPosition does not work

Posted: Tue Aug 12, 2014 06:54
by codeMonkey
Ident wrote:http://static.cegui.org.uk/docs/0.8.4/classCEGUI_1_1Element.html#a583c97a5d79e2189538705ef532cf5a6

can you tell how to set the setHorizontalAlignment ? parent window or child window or others?

Re: setPosition does not work

Posted: Tue Aug 12, 2014 07:01
by Ident
The window you want to align. So the "child window" as you refer to it.

I recommend you to download CEED and play with a layout in order to learn how positioning works.

Re: setPosition does not work

Posted: Tue Aug 12, 2014 07:12
by codeMonkey

Code: Select all

wnd->setHorizontalAlignment(HA_CENTRE);

it seems to be not in effect

Re: setPosition does not work

Posted: Tue Aug 12, 2014 07:42
by Ident
There is no question about this function having an effect. It definitely does.

I can't help you because you do not give us enough information.

Re: setPosition does not work

Posted: Tue Aug 12, 2014 07:55
by codeMonkey

Code: Select all

FrameWindow* wnd = (FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "DemoWindow");
   d_root->addChild(wnd);
   wnd->setHorizontalAlignment(HA_LEFT);
   wnd->setVerticalAlignment(VA_TOP);
   wnd->setPosition(UVector2(cegui_reldim(0.25f),cegui_reldim(0.25f)));
   wnd->setSize(USize(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
   wnd->setMaxSize(USize(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
   wnd->setMinSize(USize(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
   wnd->setText("Hello World!");

I write like this ,but the window deos not change, I don't where i am wrong

Re: setPosition does not work

Posted: Tue Aug 12, 2014 08:17
by Ident
And you tried HA_CENTRE instead of HA_LEFT?

Well, looking at the code the position would be at 1/4th of the width and the size is half of the width. So the window will be centered if you got HA_LEFT chosen wont it?

Re: setPosition does not work

Posted: Tue Aug 12, 2014 08:23
by codeMonkey
I did , still not in effect, wnd is still on the top-left corner of the display

Re: setPosition does not work

Posted: Tue Aug 12, 2014 08:24
by Ident
Thats impossible because the position set to neither the very left nor the very top. Screenshot and CEGUI log please.

Re: setPosition does not work

Posted: Tue Aug 12, 2014 08:34
by codeMonkey
I don't know how to upload the image ,so I give you a network disk link http://pan.baidu.com/s/1gdgRk23

Re: setPosition does not work

Posted: Tue Aug 12, 2014 08:44
by Ident
What happens if you set the position to

Code: Select all

   wnd->setPosition(UVector2(cegui_reldim(0.0f),cegui_reldim(0.0f)));

and also what happens if you set it to

Code: Select all

wnd->setPosition(UVector2(cegui_reldim(1.0f),cegui_reldim(1.0f)));

Re: setPosition does not work

Posted: Tue Aug 12, 2014 09:03
by codeMonkey
still on the corner ,all the code I referenced hand not set the aligment, but there window seemed to be on the center

Re: setPosition does not work

Posted: Tue Aug 12, 2014 09:18
by Ident
I dont understand what you are saying.

Did you even recompile your project after making changes to your code?

Re: setPosition does not work

Posted: Tue Aug 12, 2014 10:03
by codeMonkey
sorry , my english is pool , I mean to say that my window is still in the corner , did not change