Panel do not center

Posted By: Elektron

Panel do not center - 03/21/10 03:55

I want a centred panel, idependently of screen ratio.
I tried this:
Code:
var panel_pos_x=screen_size.x/2-50;
	var panel_pos_y=screen_size.y/2-25;
	PANEL* splash_panel = pan_create
	("
	pos_x=panel_pos_x;
	pos_y=panel_pos_y;
	bmap=logo16.bmp;",1);
	set(splash_panel,SHOW);
	wait(-5);
	ptr_remove(* splash_panel);



But, it shows bitmap on left upper corner.

P.S. Please any moderator if it is a engine bug move this thread for proper forum.

Thanks in advance
Posted By: Walori

Re: Panel do not center - 03/21/10 08:24

The problem is that you're using global variables, right? Now for some reason (someone with more experience may tell you why) you can't define global variables to use screen_size as a value. So you have two options:

-Use local variables
-Define variable later inside of a function

Then it'll work just fine
Posted By: DJBMASTER

Re: Panel do not center - 03/21/10 10:46

It can't be a global variable, because 'screen_size' is not known at compile time, only at runtime.

Also it seems only constants can be passed to pos_x/pos_y, so that might also be a problem, although i'm not sure about Panels defined at runtime.

Finally 'ptr_remove(* splash_panel);' shouldn't compile. as 'ptr_remove' wants a pointer and '*splash_panel' is a pointer-to-a-pointer.
Posted By: Progger

Re: Panel do not center - 03/21/10 12:24

try it with brackets
var panel_pos_x=(screen_size.x/2)-50;
var panel_pos_y=(screen_size.y/2)-25;
perhaps it will work
Hope that helps
here is something out of the manual with centered Panel (:

// startup with 300x300 window resolution
function main()
{
screen_size.x = 300; screen_size.y = 300;
...}

// place panel in the center of the screen
function center_panel(PANEL* panel)
{
panel.pos_x = (screen_size.x - bmap_width(panel.bmap))/2;
panel.pos_y = (screen_size.y - bmap_height(panel.bmap))/2;
}

WFG Progger laugh

© 2024 lite-C Forums