[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Code review



Hi!

What do you think about the following code snippet, which checks for
rectangular buttons?

typedef struct
{
  int active;
  int x; int x1;
  int y; int y1;
} Buttontyp;

Buttontyp Buttons[]={
{1,10,20,10,20},
{1,20,120,20,120},
{1,530,630,10,30},
//...
};
int nButtons=sizeof(Buttons)/sizeof(Buttontyp);

int CheckButtons()
{
  int i=0;
  // printf("nButtons: %d\n",nButtons);
  for(i=0;i<nButtons;i++)
    if ( Buttons[i].active && (mx>=Buttons[i].x) && (mx<=Buttons[i].x1) && (my>=Buttons[i].y) && (my<=Buttons[i].y1) )
      return i;
  return -1;
};

Is there a better, "right" solution?

--
~ Philipp Gühring              p.guehring@poboxes.com
~ http://www.poboxes.com/p.guehring  ICQ UIN: 6588261