示例#1
0
int btnColor(struct pgEvent *evt) {
  static pgcolor c = 0x224466;

  if (pgColorPicker(&c,"Select a Color"))
    pgMessageDialogFmt("Color",0,"You selected:\n0x%06X",c);

  return 0;
}
示例#2
0
/* Applications menu
 * This whole thing's a kludge, I will write
 * something better (using custom menus) soon
 */
int btnAppMenu(struct pgEvent *evt) {
  pghandle *items;
  struct dirent *dent;
  int i,l;
  DIR *d;

  d = opendir("demos");

  /* FIXME : Count the items and allocate the array */
  items = alloca(sizeof(pghandle) * 40);
  
  /* Enter a new context before making the handles */
  pgEnterContext();

  /* Make handles */
  rewinddir(d);
  i = 0;
  while (dent = readdir(d)) {
    /* Skip all but applications */
    l = strlen(dent->d_name);
    if (l<4) continue;
    if (strcmp(dent->d_name+l-4,".app")) continue;

    /* Strip extension */
    dent->d_name[l-4] = 0;

    /* Add item */
    items[i++] = pgNewString(dent->d_name);
  }

  /* Run it */
  i = pgMenuFromArray(items,i);

  /* Result? */
  if (i) {
    char buf[80];  /* FIXME: Buffer overflow 'sploit waiting to happen! */
    strcpy(buf,"demos/");
    strcat(buf,pgGetString(items[i-1]));
    strcat(buf,".app");
    if (!vfork()) {
      execlp(buf,buf,NULL);
      pgMessageDialogFmt("Error",0,"There was an error starting the\nfollowing program:\n%s",buf);
      exit(1);
    }
  }

  /* Free the server memory and destroy our menu */
  pgLeaveContext();

  closedir(d);

  return 0;
}
示例#3
0
int btnConfirm(struct pgEvent *evt) {
  int i;

  i = pgMessageDialog("Really???",
		      "You just clicked a button.\n"
		      "Are you sure you want\n"
		      "to initiate nuclear fusion?",
		      PG_MSGBTN_YES | PG_MSGBTN_NO);
  
  if (i == PG_MSGBTN_YES)
    pgMessageDialogFmt("Boom!",0,
		       "You have only %d\n"
		       "hours until critical mass",
		       time(NULL));
  return 0;
}
示例#4
0
文件: blackout.c 项目: UIKit0/picogui
/* Clickski! */
int evtMouseDown(struct pgEvent *evt) {
   int lx,ly;
   light *p;
   int i;
   
   /* What light was it in? */
   lx = (evt->e.pntr.x - bx) / lightw;
   ly = (evt->e.pntr.y - by) / lighth;

   if (evt->e.pntr.x < bx || lx >= boardwidth ||
       evt->e.pntr.y < by || ly >= boardwidth)
     return 0;

   invertLight(lx,ly);
   invertLight(lx-1,ly);
   invertLight(lx+1,ly);
   invertLight(lx,ly-1);
   invertLight(lx,ly+1);
   SOLUTION(lx,ly) ^= 1;
   
   /* Update the screen */
   pgWriteCmd(evt->from,PGCANVAS_INCREMENTAL,0);
   moves++;
   updateStatus();

   /* A win condition? */
   for (i=boardsize,p=board;i;i--,p++)
     if (*p)
       return 0; /* Nope. */
   
   /* Yep! */
   pgMessageDialogFmt("Blackout!",0,
		      "You completed level %d!\n\n"
		      "Moves: %d",level,moves);
   startLevel(level+1);
   
   return 0;
}
示例#5
0
文件: blackout.c 项目: UIKit0/picogui
void menuRestartLevel(void) {
   if (pgMessageDialogFmt("Scratching Head",
			  PG_MSGBTN_YES | PG_MSGBTN_NO,
			  "Try level %d again?",level) == PG_MSGBTN_YES)
     startLevel(level);
}