Jump to content

Gui screen position


photo

Recommended Posts

hi,

 

I want to know if it's possible to have the screen position of an widget.

 

I try getPosition but if i don't set before the position i 0x0

I try with the parent of parent of parent position but doesn't work two.

 

An example :

 

 

WidgetHBox hbox;

WidgetVBox vbox;

WidgetSprite sprite;

WidgetButton button;

WidgetButton button2;

 

/*

*/

 

int init() {

Gui gui = engine.getGui();

 

hbox = new WidgetHBox(gui);

 

vbox = new WidgetVBox(gui);

 

sprite = new WidgetSprite(gui,"");

sprite.setWidth(200);

sprite.setHeight(200);

 

button = new WidgetButton(gui,"B1");

button2 = new WidgetButton(gui,"B2");

 

gui.addChild(hbox,GUI_ALIGN_CENTER);

hbox.addChild(sprite,GUI_ALIGN_BACKGROUND);

hbox.addChild(vbox,GUI_ALIGN_OVERLAP);

vbox.addChild(button,GUI_ALIGN_OVERLAP|GUI_ALIGN_LEFT);

vbox.addChild(button2,GUI_ALIGN_OVERLAP|GUI_ALIGN_RIGHT);

 

 

return 1;

}

/*

*/

 

int shutdown() {

log.message("SHUTDOWN\n");

return 1;

}

/*

*/

 

int update() {

 

counter++;

 

if (counter == 1){

hbox.arrange();

log.message("hbox : %d x %d\n",hbox.getPositionX(),hbox.getPositionY());

log.message("sprite : %d x %d\n",sprite.getPositionX(),sprite.getPositionY());

log.message("vbox : %d x %d\n",vbox.getPositionX(),vbox.getPositionY());

log.message("Button : %d x %d\n",button.getPositionX(),button.getPositionY());

log.message("Button2 : %d x %d\n",button2.getPositionX(),button2.getPositionY());

}

 

return 1;

}

 

if someone have an idea.

Link to comment

Widgets with overlap flag (that are are drawn after and atop of all other GUI widgets) cannot return their position unless you directly set it.

 

As for non-overlapping widgets, you can get their position in the same frame after calling arrange(). It forces to recalculate widget size according to new data set in this update(). Without calling arrange() you can get position only in the next frame, because one cannot get access to the updated data on GUI layout until it is actually calculated for the current frame (which is the very last stage, after everything else is executed).

Link to comment
×
×
  • Create New...