I redeveloped the fox pan using a struct and in the end I base if the foxpan needs to be removed by if the mother panel is removed or not. I get the same thing. Only if a handle and ptr_for_handle.
It works but when I put 100 panels with one foxpan on each and nothing else on the screen then the FPS drops to 80.
Once I get this to not be such a FPS eater I will put it in user contributions.
If it matters I use A7 latest.
The setup
create_fox_pan(0,0,0,0,mother_pans[a],bmap_create("click_button.png"),values[a]);
The header file
#ifndef fox_pan_h
#define fox_pan_h
typedef struct fox_panel {
PANEL* mother_pan;
var* *mother_panel_handle;
PANEL* click_panel;
TEXT* see_string_text;
var* adjustable_var;
var offset_x;
var offset_y;
var text_offset_x;
var text_offset_y;
} fox_panel;
//////////////////////////////
// this is used to create a fox panel and returns the fox panel as a string
//////////////////////////////
fox_panel* create_fox_pan(var pos_x,var pos_y, var text_offset_x,var text_offset_y, PANEL* mother_panel, BMAP* click_bmap,var* loc_display_var);
//////////////////////////////
// this funciton is called when the button for the fox pan is pushed letting us know we want to change the string and thus the display number
//////////////////////////////
void adjust_string_fox_pan(var button_number,PANEL* panel_pointer);
//////////////////////////////
// this keeps track of info on the mother panel and transfer it to the fox panel
//////////////////////////////
void fpan_monitor_function(fox_panel* fp, var* loc_display_var);
//////////////////////////////
// we get rid of the fox panel and everything about ti
//////////////////////////////
void destory_foxpan(fox_panel* fp);
#endif
the main file
#ifndef fox_pan_c
#define fox_pan_c
//////////////////////////////
// the fox panel allows for having editable digits on standard panels
// it works by having a mother panel, the main backboard, then creating a panel that only has a button. this button should be invsible or able to look as if it belongs on the backboard
// the function from the button will allow for editing of the text. Pressing enter will set the new number typed in. If letters are typed in it will ignore it.
// If the number is changed outside of the button's function it will be updated.
// if the panel is moved, the button panel and the text will move with it.
//////////////////////////////
//////////////////////////////
// we include our header file
//////////////////////////////
#include <general_functions\fox_pan.h>
//////////////////////////////
// this is used to create a fox panel and returns the fox panel as a string
//////////////////////////////
fox_panel* create_fox_pan(var pos_x,var pos_y, var text_offset_x,var text_offset_y, PANEL* mother_panel, BMAP* click_bmap,var* loc_display_var)
{
//////////////////////////////
// we create the fox panel pointer
//////////////////////////////
fox_panel* temp_fox_panel = malloc(sizeof(fox_panel)); // creates a new SPOT struct at runtime
memset(temp_fox_panel,0,sizeof(fox_panel)); // set the struct content to zero (it's undefined after malloc)
temp_fox_panel.offset_x = pos_x;
temp_fox_panel.offset_y = pos_y;
temp_fox_panel.mother_pan = mother_panel;
// temp_fox_panel.mother_panel_handle = handle(mother_panel);
temp_fox_panel.click_panel = pan_create("",mother_panel.layer + 1);
//////////////////////////////
// we set our position to our mother panel
//////////////////////////////
temp_fox_panel.click_panel.pos_x = mother_panel.pos_x + pos_x;
temp_fox_panel.click_panel.pos_y = mother_panel.pos_y + pos_y;
//////////////////////////////
// our bmap is our button
//////////////////////////////
pan_setbutton(temp_fox_panel.click_panel,0,0,
0,0,click_bmap,click_bmap,click_bmap,NULL,adjust_string_fox_pan,NULL,NULL);
//////////////////////////////
// we create the text and set it's string to that of the var we will display
//////////////////////////////
temp_fox_panel.see_string_text = txt_create(1,mother_panel.layer + 2);//1 higher than the butotn panel
//////////////////////////////
// 10 digits
//////////////////////////////
str_cpy((temp_fox_panel.see_string_text.pstring)[0], "#10");
//////////////////////////////
// we set our position to our mother panel
//////////////////////////////
temp_fox_panel.see_string_text.pos_x = mother_panel.pos_x + text_offset_x;
temp_fox_panel.see_string_text.pos_y = mother_panel.pos_y + text_offset_y;
temp_fox_panel.see_string_text.red = 255;
temp_fox_panel.see_string_text.blue = 0;
temp_fox_panel.see_string_text.green = 0;
temp_fox_panel.adjustable_var = loc_display_var;
//////////////////////////////
// we store the pointer to the fox panel
//////////////////////////////
temp_fox_panel.click_panel.skill_x = handle(&temp_fox_panel);
//////////////////////////////
// we make the panel and the text visible
//////////////////////////////
set(temp_fox_panel.click_panel,SHOW);
set(temp_fox_panel.see_string_text,SHOW);
//////////////////////////////
// we now make the fox panel behave with the mother panel
//////////////////////////////
fpan_monitor_function(temp_fox_panel, *loc_display_var);
//////////////////////////////
// we return our panel pointer
//////////////////////////////
return(temp_fox_panel);
}
//////////////////////////////
// this funciton is called when the button for the fox pan is pushed letting us know we want to change the string and thus the display number
//////////////////////////////
void adjust_string_fox_pan(var button_number,PANEL* panel_pointer)
{
//////////////////////////////
// we declare a string so we can use it to hold the old string
//////////////////////////////
STRING* old_string = "#3";
fox_panel* temp_fp = handle(panel_pointer.skill_x);
//////////////////////////////
// we get the pointer for the text we were using
//////////////////////////////
TEXT* temp_text = temp_fp.see_string_text;//ptr_for_handle(panel_pointer.skill_y);
//////////////////////////////
// we copy the old string in case we need to put it back
//////////////////////////////
str_cpy(old_string,(temp_text.pstring)[0]);
//////////////////////////////
// we also check to see how we ended the key
//////////////////////////////
var key = inkey((temp_text.pstring)[0]); // wait until [enter] pressed
//////////////////////////////
// we get the var for the number
//////////////////////////////
var new_number = str_to_num((temp_text.pstring)[0]); // vpi == 3.142
//////////////////////////////
// we make sure we entered a number and not a letter
//////////////////////////////
if(new_number == 0)
{
//////////////////////////////
// we copy the original string back to this one
//////////////////////////////
str_cpy((temp_text.pstring)[0],old_string);
//////////////////////////////
// get it right!
//////////////////////////////
printf("must be a number");
}
else
{
//////////////////////////////
// we changed our number so now we need to update or display number
//////////////////////////////
*temp_fp.adjustable_var = new_number;
}
}
//////////////////////////////
// this keeps track of info on the mother panel and transfer it to the fox panel
//////////////////////////////
void fpan_monitor_function(fox_panel* fp, var* loc_display_var)
{
//////////////////////////////
// we get the old value of the var
//////////////////////////////
var old_var = *loc_display_var;
//////////////////////////////
// as long as the mother panel is good we are good
//////////////////////////////
while(ptr_for_handle(handle(fp.mother_pan)))
{
//////////////////////////////
// for testing purposes
//////////////////////////////
// loc_mother_pan.pos_x = random(800);
// loc_mother_pan.pos_y = random(800);
//////////////////////////////
// we keep our position the same
//////////////////////////////
fp.click_panel.pos_x = fp.mother_pan.pos_x + fp.offset_x;
fp.click_panel.pos_y = fp.mother_pan.pos_y + fp.offset_y;
//////////////////////////////
// now the text panel
//////////////////////////////
fp.see_string_text.pos_x = fp.mother_pan.pos_x + fp.text_offset_x;
fp.see_string_text.pos_y = fp.mother_pan.pos_y + fp.text_offset_y;
//////////////////////////////
// if the mother panel is invsible then so are we
//////////////////////////////
if(is(fp.mother_pan,SHOW))
{
set(fp.click_panel,SHOW);
set(fp.see_string_text,SHOW);
}
else
{
reset(fp.click_panel,SHOW);
reset(fp.see_string_text,SHOW);
}
//////////////////////////////
// if our old var was changed then we update the string in the editble text for the fox pan
//////////////////////////////
if(old_var != *loc_display_var)
{
old_var = *loc_display_var;
str_for_num( (fp.see_string_text.pstring)[0],old_var);
}
wait(1);
}
destory_foxpan(fp);
}
//////////////////////////////
// we no longer need the fox pan so we get rid of it
//////////////////////////////
void destory_foxpan(fox_panel* fp)
{
//////////////////////////////
// we remove the text
//////////////////////////////
ptr_remove(fp.see_string_text);
fp.see_string_text = NULL;
//////////////////////////////
// we remove the panel
//////////////////////////////
ptr_remove(fp.click_panel);
fp.click_panel = NULL;
//////////////////////////////
// now we get rid of the fox panel itself
//////////////////////////////
free(fp);
}
#endif