In one message you noted that you are C n00b. Is C++ totally out of the question, do you think? Because reading this thread is like listening to someone drawing their nails across a blackboard. An object (sic) like a button just begs - no, screams - to be implemented in the OO paradigm. I may have stated that already. Implementing it would be an absolute breeze, at the same time cleaning the code which has the risk of becoming a bit messy soon.
Maybe something like this (just something so you get the idea):
class button {
private:
uint8_t x,y,w,h; //coordinates and dimensions
bool visible;
//other stuff you need
char caption[11];
show();
hide();
public:
button();
button(uint8_t xpos, ypos, width, height, char *cap); // either this or the next one, depends how dynamic you want (dare) to be
init(uint8_t xpos, ypos, width, height, char *cap); // you want this for statically constructed buttons
move(uint8_t dx, dy);
moveto(uint8_t nx, ny);
rename(char *newcap);
}
button::button() { // not really needed because this happens anyway
x=y=h=w=0;
visible = false;
caption[0] = 0;
}
button::button(uint8_t xpos, ypos, width, height, char *cap) {
x=xpos;
y=ypos;
w=width;
h=height;
visible = false;
strlcpy(&caption, cap, sizeof(caption));
show();
}
button::init(uint8_t xpos, ypos, width, height, char *cap) {
x=xpos;
y=ypos;
w=width;
h=height;
visible = false;
strlcpy(&caption, cap, sizeof(caption));
show();
}
button::show() {
// do what needs to be done to draw the button
visible = true;
}
button::hide{
// overwrite the button with the background
visible = false;
button::move(uint8_t dx, dy) {
hide();
x+=dx;
y+=dy;
show();
}
button::moveto(uint8_t dx, dy) {
hide();
x=nx;
y=ny;
show();
}
button::rename(char *newcap) {
hide();
strlcpy(&caption, newcap, sizeof(caption));
show();
}
- - - - - - -
#define NUM_BUTTONS 32;
button my_buttons[NUM_BUTTONS];
...
for (i=0; i < NUM_BUTTONS; i++) {
my_buttons.init(some_x, some_y, some_h, some_w, some_cap_p);
}
my_buttons[random_index].rename("newcaption");
//done