variable panels?

Posted By: Nicholas

variable panels? - 09/06/11 03:36

I am working on a keymap with bitmaps I need shown.
I am currently using panels with a =SHOW and &=~SHOW (to hide) command. I'd like to shorten it using C, but am not quite good enough to do it on my own.

this is what I have over and over again:
Code:
//button variable array. 
if(buttonz[1] ==1)  {pb_x.flags =SHOW;}
if(buttonz[1] ==0)  {pb_x.flags &=~SHOW;}



what I'd like to be able to do is use something like this:
Code:
if(buttonz[i] ==1)  {panel[i].flags =SHOW;}
if(buttonz[i] ==0)  {panel[i].flags &=~SHOW;}
i++;



I have found some examples I can use as a for(i) command, but I don't know how to do it with the panels, I really don't need it to be a panel, just a bitmap is what I need (with specific coordinates of course).
any help would be nice
:-)
Posted By: Superku

Re: variable panels? - 09/06/11 04:23

Quote:
I have found some examples I can use as a for(i) command, but I don't know how to do it with the panels

This gives you an array of panels:

// global declaration:
PANEL* my_panel_array[10];
...
// create them once:
for(i = 0; i < 10; i++) my_panel_array[i] = pan_create("",1);

Now you can access every panel and assign different bitmaps, positions and so on, f.i. my_panel_array[4].bmap = cookie_bmp;


Quote:
I really don't need it to be a panel, just a bitmap is what I need (with specific coordinates of course).

Have a look at draw_quad, you can draw bitmaps without the need for panels anywhere on the screen.
Posted By: Nicholas

Re: variable panels? - 09/06/11 15:02

Thanks, that helps quite a bit. Unfortunately it still means I have to define each bitmap accordingly. I have seen use of parameters in the title so would I be able to do something like this:

PANEL* my_panel_array[10](bitmap)
{bitmap1=bit_alpha; pos_x=456;pos_y=125;
bitmap2=bit_beta; pos_x=111;pos_y=222;}

then use
my_panel_array[4](4).flags=SHOW; //the array number and parameter number is ok to always have to be the same, but I'd have to be able to tell whats what inside the panel and have multiple bmps and positions defined

This way I could have just one panel array defined with all the bitmaps and locations predefined and just use the code to show or hide it.

If not, I'll still have to have all that code to define the bitmap and coordinates anyway. If I have to do it that way, I'll stick with the draw_quads and save myself from needing those panels at all since they only show in a while loop anyway.

thanks
Posted By: Superku

Re: variable panels? - 09/06/11 15:45

I don't understand your post, sorry, but it seems to me as if you are looking for a bitmap array?
Imagine you have mybitmapname1.tga,mybitmapname2.tga,... Then you can easily create an array of bitmaps:

BMAP* bmp_array[10];
STRING* str_bitmap = "";
...
for(i = 0; i < 10; i++)
{
str_printf(str_bitmap,"mybitmapname%d.tga",(int)i); //untested, should work though
bmp_array[i] = bmap_create(str_bitmap);
}

Now you can draw the bitmaps in a for loop:
draw_quad(bmp_array[i], at position bitmap_position[i], ...);
where bitmap_position is an array of VECTORs.
Posted By: Nicholas

Re: variable panels? - 09/06/11 17:38

Excellent.
you forgot the "var i;", but the rest works great. Now I can setup a function to call whenever I need it to show.

function drawz(i,x,y,z)
{
draw_quad(bmp_array[i], vector(x,y,z),NULL,NULL,NULL,NULL,100,NULL);
}


thanks for the help. to shorten it more I was going to do something like this, but it's not working

var vec1[6]={20,30,40,50,60,70};
var vec2[6]={20,30,40,50,60,70};
var vec3[6]={20,30,40,50,60,70};

while(1){
for(i = 0; i < 4; i++)
{
if(buttonz[i]==1){drawz[i], vec1[i], vec2[i], vec3[i];}
}
wait(1);}

basically checking if the variable buttonz is set to 1 then executes the command. but it keeps saying subscript requires array or pointer type.

any ideas?
thanks again
Posted By: Superku

Re: variable panels? - 09/06/11 17:53

Quote:
you forgot the "var i;"

I didn't forget anything, I've just assumed you're clever enough to figure that out on your own.
Posted By: Nicholas

Re: variable panels? - 09/06/11 19:23

lol, I assumed that was it, and I obviously did figure it out ;-)
I just like having it in the post in case anyone else needing code like this doesn't think of it.
thanks for the help and I think I figured out my other issue with the xyz. I'll have to check when I get home
© 2024 lite-C Forums