search for a panel-pointer

Posted By: JoGa

search for a panel-pointer - 06/16/13 22:05

Hey

in a application i create panels during runtime. Their pointers are saved in a array like (i hope, this is right):
Code:
array_panels_d_elemente[i] = (int*)pan_temp;



If the user right-clicks on a panel, i have to check, if its a panel, which was saved in the array.
I wanted to use mouse_panel for this.

But I have some problems with the comparison . how can I check if the pointer of the mouse_panel "points" on a panel, which is saved in the array?

Code:
int i;
for(i=0;i<50;i++)
	{
		if(mouse_panel !? array_panels_d_elemente[i]) // my problems
		{
			//....
		}
	}



Could someone help me how to search for the pointer right?
Thanks laugh
Posted By: Anonymous

Re: search for a panel-pointer - 06/16/13 22:25

Code:
#define MAX_PANELS 500 // ? as many as you need

PANEL* array_panels_d_elemente[MAX_PANELS];
var totalPanels = 0;

if(totalPanels < MAX_PANELS)
{
   array_panels_d_elemente[totalPanels] = pan_create(.....);
   totalPanels += 1;
}



if ( mouse_right && mouse_panel != NULL )
{
    int i;
    for(i=0;i<50;i++)
	{
	    if(mouse_panel == array_panels_d_elemente[i])
              { 
                // panel found do stuff here //
 
                break; // stop the loop
              }            
 	} 
}




Posted By: Superku

Re: search for a panel-pointer - 06/16/13 23:27

Btw. saving a pointer in an integer variable will most likely not work. (JustSid just informed me that it is perfectly fine to use ints) You can however save them in vars, for instance as follows:

entity-skills are a var skill[100] array, thus writing
my.skill70 = ent_create(...);
and
my.skill71 = pan_create(...);
or
PANEL* pnl_tmp = pan_create(...);
my.skill71 = pnl_tmp;
is perfectly fine. You can then later retrieve the pointer by a simple cast:
((ENTITY*)my.skill70).x = 10;
or handier as
you = (ENTITY*)my.skill70;
pnl_tmp = (PANEL*)my.skill71;

The last two typecasts should not be necessary (you = my.skill70; should work, too) but I like to do it that way.
© 2024 lite-C Forums