Exemplo n.º 1
0
void hide_call_info(void) {
  /* Turn off the idle handler, hide everything */
  pgSetIdle(0,NULL);
  pgSetWidget(wInfoBar,PG_WP_SIZE,0,0);
  pgSetWidget(wKeypad,PG_WP_SIZE,0,0);
  pgUpdate();
}
Exemplo n.º 2
0
/* In most situations this will display an error dialog, giving
 * the option to exit or continue. If it isn't even able to make
 * a dialog box, it will print to stderr.
 */
void _pg_defaulterr(u16 errortype,const char *msg) {
  static unsigned char in_defaulterr = 0;
  char *s1,*copys1,*s2,*copys2;
		  
  /* Are we unable to make a dialog? (no connection, or we already tried) */  
  if (in_defaulterr)
    exit(errortype);

  /* Print on stderr too in case the dialog fails */
  fprintf(stderr,"*** PicoGUI ERROR (%s) : %s\n",pgErrortypeString(errortype),msg);

  /* We haven't even established a connection? (let the error print first) */
  if (!_pgsockfd)
    exit(errortype);

  /* Try a dialog box.
	* We must copy the strings because the pgGetString buffer is only valid
	* until the next picogui call */
  in_defaulterr = 1;
  s1 = pgGetString(pgGetServerRes(PGRES_STRING_PGUIERR));
  copys1 = alloca(strlen(s1)+1);
  strcpy(copys1,s1);
  s2 = pgGetString(pgGetServerRes(PGRES_STRING_PGUIERRDLG));
  copys2 = alloca(strlen(s2)+strlen(pgErrortypeString(errortype))+
		  strlen(_pg_appname)+strlen(msg)+1);
  sprintf(copys2,s2,pgErrortypeString(errortype),_pg_appname,msg);
  if (PG_MSGBTN_YES ==
      pgMessageDialog(copys1,copys2,
		      PG_MSGBTN_YES | PG_MSGBTN_NO | PG_MSGICON_ERROR))
    exit(errortype);
  pgUpdate(); /* In case this happens in a weird place, go ahead and update. */
  in_defaulterr = 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv) {
  pghandle w[40];
  pghandle app;
  int i;
  float t;
  
  pgInit(argc,argv);
  app = pgRegisterApp(PG_APP_NORMAL,"Scrollbar Fun - C",0);
  
  for (i=0;i<40;i++) {
    w[i] = pgNewWidget(PG_WIDGET_SCROLL,PG_DERIVE_INSIDE,app);
    pgSetWidget(PGDEFAULT,
		PG_WP_SIDE, PG_S_LEFT,
		0);
  }
  
  t = 0;
  while (1) {
    t += 0.04;
    for (i=0;i<40;i++)
      pgSetWidget(w[i],
		  PG_WP_VALUE, (int)(50 + 50 * sin(i*0.2+t)),
		  0);
    pgUpdate();
  }

  return 0;
}
Exemplo n.º 4
0
int main(int argc, char **argv) {
  pgInit(argc,argv);

  pgLoadTheme(pgFromFile(argv[1]));
  pgUpdate();

  getc(stdin);

  return 0;
}
Exemplo n.º 5
0
/* Prepare settings for use in updateTime */
void mungeSettings(void) {
  unsigned long t;

  /* Set clock font */
  pgSetWidget(currentClock.wClock,
	      PG_WP_FONT,currentClock.fClockFont,
	      0);
  
  /* Figure out the necessary update time */
  if (currentClock.flashColon)
    t = 500;
  else if (currentClock.enableSeconds)
    t = 1000;
  else
    t = 60000;
  pgSetIdle(t,&updateTime);

  /* Build a format string */
  currentClock.fmt1[0] = 0;              /* Start out blank */
  if (currentClock.enableWeekDay)
    strcat(currentClock.fmt1,"%a ");
  if (currentClock.enableMonth)
    strcat(currentClock.fmt1,"%b ");
  if (currentClock.enableDay)
    strcat(currentClock.fmt1,"%e ");
  if (currentClock.enable24hour)
    strcat(currentClock.fmt1,"%k");
  else
    strcat(currentClock.fmt1,"%l");
  strcat(currentClock.fmt1,":%M");
  if (currentClock.enableSeconds)        /* Careful with the colons... */
    strcat(currentClock.fmt1,":%S ");
  else
    strcat(currentClock.fmt1," ");
  if (!currentClock.enable24hour)
    strcat(currentClock.fmt1,"%p ");
  if (currentClock.enableYear)
    strcat(currentClock.fmt1,"%Y ");
  currentClock.fmt1[strlen(currentClock.fmt1)-1] = 0;  /* Chop extra space */

  /* Make secondary format string with optional colon flashing */
  strcpy(currentClock.fmt2,currentClock.fmt1);
  if (currentClock.flashColon) {
    /* Convert all colons to blanks */
    char *p = currentClock.fmt2;
    while (p = strchr(p,':'))
      *p = ' ';
  }

  /* Resize the applet if necessary */
  updateTime();
  pgUpdate();
}
Exemplo n.º 6
0
/* Adds to the end of the call's phone number */
void call_dial(struct phonecall *call, char digit) {
  char str[2] = " ";
  *str = digit;

  /* Already full? */
  if (strlen(call->number)>=MAX_PHONENUM_LEN-1)
    return;
  
  strcat(call->number,str);
  if (call==current_call) {
    set_vfd_text(wPhoneNumber,call->number);
    pgUpdate();
  }
}
Exemplo n.º 7
0
/* Update the status of the current call,
 * setting time stamps when applicable */
void set_call_status(struct phonecall *call,int status) {
  if (!call)
    return;
  call->original_status = call->status = status;

  if (!call->begin_time && status==CALL_INPROGRESS)
    call->begin_time = time(NULL);
  if (!call->end_time && status==CALL_COMPLETED)
    call->end_time = time(NULL);

  if (call==current_call) {
    pgReplaceText(wCallStatus,status_messages[call->status]);
    pgUpdate();
  }
}
Exemplo n.º 8
0
struct pgEvent *pgGetEvent(void) {

  /* Run the idle handler here too, so it still gets a chance
   * even if we're flooded with events. */
  _pg_idle();

  /* Update before waiting for the user */
  pgUpdate();

  /* Wait for a new event */
  do {
     _pg_add_request(PGREQ_WAIT,NULL,0);
     pgFlushRequests();
  } while (_pg_return.type != PG_RESPONSE_EVENT);

  return &_pg_return.e.event;
}
Exemplo n.º 9
0
/* Redraw the game board */
int evtDrawBoard(struct pgEvent *evt) {
   int x,y,i,j;
   light *p = board;

   /* Extra space on the sides or top and bottom? */
   if (evt->e.size.w < evt->e.size.h)
     bs = evt->e.size.w-4;
   else
     bs = evt->e.size.h-4;
   
   bx = (evt->e.size.w - bs)>>1;
   by = (evt->e.size.h - bs)>>1;
   lightw = bs/boardwidth;
   lighth = bs/boardheight;
   /* Get rid of remainder */
   bs = boardwidth*lightw;
   
   /* Clear the groplist, by default store color with each grop */
   pgWriteCmd(evt->from,PGCANVAS_NUKE,0);
   pgWriteCmd(evt->from,PGCANVAS_DEFAULTFLAGS,1,PG_GROPF_COLORED);
   
   /* Black game board background */
   pgWriteCmd(evt->from,PGCANVAS_GROP,6,PG_GROP_RECT,0,0,
	      evt->e.size.w,evt->e.size.h,0x000000);
   
   /* Game board frame */
   pgWriteCmd(evt->from,PGCANVAS_GROP,6,PG_GROP_FRAME,
	      bx-1,by-1,bs+3,bs+3,0x808080);

   /* Light gropnodes */
   for (j=boardheight,y=by;j;j--,y+=lighth)
     for (i=boardwidth,x=bx;i;i--,x+=lightw) {
	pgWriteCmd(evt->from,PGCANVAS_GROP,6,PG_GROP_RECT,
		   x+1,y+1,lightw-1,lighth-1,(*(p++)) ? ON_COLOR : OFF_COLOR);
     }
   
   /* Draw it */
   pgWriteCmd(evt->from,PGCANVAS_REDRAW,0);
   pgUpdate();

   return 0;
}
Exemplo n.º 10
0
/* Show and hide the call info bar */
void show_call_info(struct phonecall *call) {
  current_call = call;
  old_connect_time = -1;

  /* Display info on this call 
   *
   * FIXME: pretty-print the phone number, so the user sees "(303) 555-1234"
   *        instead of "3035551234". Make sure to look up the appropriate specs
   *        so it does local calls, long distance, 10-digit dialing,
   *        and international correctly.
   */
  set_call_status(call,call->status);
  update_call_timer();
  pgSetIdle(500,update_call_timer);
  pgSetWidget(wKeypadBtn,
	      PG_WP_ON,0,
	      0);
  set_vfd_text(wPhoneNumber,"");
  pgSetWidget(wInfoBar,
	      PG_WP_SIZE,-1,    /* Automatic sizing */
	      0);
  pgUpdate();
}
Exemplo n.º 11
0
void sysIdle(void) {
  FILE *net;
  char buf[256];
  char *p;
  float rx_bytes, tx_bytes;
  float rx_kbps, tx_kbps;
  float elapsed;
  static float max_kbps = 0, rx_bytes_old = 0, tx_bytes_old = 0;
  struct timeval now;
  static struct timeval then = {0,0};
  static int first_sample = 1;

  /* Read transmitted and received bytes from the kernel
   */
  net = fopen(NET_PROC_FILE,"r");
  while (!feof(net)) {
    fgets(buf,256,net);
    if (strstr (buf,pgGetString (pgGetWidget (wDeviceName, PG_WP_TEXT))))
      if (p = strchr(buf,':')) {
	sscanf(p+1, "%f %*f %*f %*f %*f %*f %*f %*f %f", &rx_bytes, &tx_bytes);
      }   
  }
  fclose(net);


  /* Time for the next sample?
   */

  gettimeofday(&now,NULL);
  if ( first_sample || (now.tv_sec-then.tv_sec)*1000 + 
       (now.tv_usec-then.tv_usec)/1000 >= SAMPLE_TIME ) {
    if (!first_sample) {
      
      /* Calculations
       */
      elapsed = (now.tv_sec - then.tv_sec) + (now.tv_usec - then.tv_usec)/1000000.0;
      tx_kbps = (tx_bytes - tx_bytes_old) / elapsed / 1024.0;
      rx_kbps = (rx_bytes - rx_bytes_old) / elapsed / 1024.0;
      
      if (tx_kbps > max_kbps) max_kbps = tx_kbps;
      if (rx_kbps > max_kbps) max_kbps = rx_kbps;
      
      /* Update PicoGUI display
       */
      pgSetWidget(wTX, PG_WP_VALUE, (int)( 100*tx_kbps/max_kbps ), 0);
      pgSetWidget(wRX, PG_WP_VALUE, (int)( 100*rx_kbps/max_kbps ), 0);
      
      /* display either the total or the current traffic */
      if (bDisplayTotal) {
	pgReplaceTextFmt(wRXlabel, "%.3f KB", rx_bytes/1024);
	pgReplaceTextFmt(wTXlabel, "%.3f KB", tx_bytes/1024);
      } else {
	pgReplaceTextFmt(wRXlabel, "%.4f KB/s", rx_kbps);
	pgReplaceTextFmt(wTXlabel, "%.4f KB/s", tx_kbps);
      }
    }
    then = now;
    rx_bytes_old = rx_bytes;
    tx_bytes_old = tx_bytes;
    first_sample = 0;
  }
  pgUpdate();
}
Exemplo n.º 12
0
void PG_SetCaption(_THIS, const char *title, const char *icon)
{
        if (title != NULL)
	  pgReplaceText(this->hidden->wApp, title);
	pgUpdate();
}
Exemplo n.º 13
0
SDL_Surface *PG_SetVideoMode(_THIS, SDL_Surface *current,
				int width, int height, int bpp, Uint32 flags)
{
	if ( this->hidden->bitmap ) {
	  /* Free old bitmap */
	  if (current->pixels) {
	    shmdt(current->pixels);
	    current->pixels = NULL;
	  }
	  pgDelete(this->hidden->bitmap);
	}

	/* Allocate the new pixel format for the screen */
	if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
		SDL_SetError("Couldn't allocate new pixel format for requested mode");
		return(NULL);
	}

	/* Create a new picogui bitmap */
	this->hidden->bitmap = pgCreateBitmap(width,height);
	this->hidden->shm = *pgMakeSHMBitmap(this->hidden->bitmap);
	current->pixels = shmat(shmget(this->hidden->shm.shm_key,
				       this->hidden->shm.shm_length,0),NULL,0);

	/* Reset the canvas, and draw persistent and incremental grops.
	 * Use mapping and offsets to center it.
	 */

	pgWriteCmd(this->hidden->wCanvas, PGCANVAS_NUKE, 0);

	/* 0. Set the source position during incremental rendering
	 */
	pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 5, PG_GROP_SETSRC,0,0,0,0);
	pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROPFLAGS, 1, PG_GROPF_INCREMENTAL);

	/* 1. Incremental bitmap rendering
	 */
	pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 6, PG_GROP_BITMAP,
		   0,0,0,0,this->hidden->bitmap);
	pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROPFLAGS, 1, PG_GROPF_INCREMENTAL);

	/* 2. Normal bitmap rendering
	 */
	pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 6, PG_GROP_BITMAP,
		   0,0,this->hidden->shm.width,this->hidden->shm.height,this->hidden->bitmap);
     
	/* Set up the new mode framebuffer */
	current->flags = 0;
	current->w = this->hidden->shm.width;
	current->h = this->hidden->shm.height;
	current->pitch = this->hidden->shm.pitch;

	/* Set up pixel format */
	current->format->BitsPerPixel = this->hidden->shm.bpp;
	current->format->BytesPerPixel = this->hidden->shm.bpp >> 3;
	if (this->hidden->shm.bpp & 7)
	  current->format->BytesPerPixel++;
	current->format->palette = NULL;
	current->format->Rmask = this->hidden->shm.red_mask;
	current->format->Gmask = this->hidden->shm.green_mask;
	current->format->Bmask = this->hidden->shm.blue_mask;
	current->format->Amask = this->hidden->shm.alpha_mask;
	current->format->Rshift = this->hidden->shm.red_shift;
	current->format->Gshift = this->hidden->shm.green_shift;
	current->format->Bshift = this->hidden->shm.blue_shift;
	current->format->Ashift = this->hidden->shm.alpha_shift;
	current->format->Rloss = 8 - this->hidden->shm.red_length;
	current->format->Gloss = 8 - this->hidden->shm.green_length;
	current->format->Bloss = 8 - this->hidden->shm.blue_length;
	current->format->Aloss = 8 - this->hidden->shm.alpha_length;

	/* Draw the app */
	pgUpdate();

	/* We're done */
	return(current);
}
Exemplo n.º 14
0
int main(int argc, char **argv) {
   int c;
   unsigned long i,number = 1000000;
   unsigned int gremlin = 0;
   time_t start,now,last=0,eta=0;
   struct pgmodeinfo mi;
   char spinner[] = "/-\\|";
   char stats[80];
   int cx,cy;  /* Cursor position */

   /* Init and get video mode */
   pgInit(argc,argv); 
   mi = *pgGetVideoMode();

   /* Process command line */
   while ( (c = getopt(argc,argv,"g:n:")) != -1 )
     switch (c) {
	
      case 'g':
	gremlin = atoi(optarg);
	break;
	
      case 'n':
	number = atol(optarg);
	break;
	
      default:        /* Help */
	puts("PicoGUI gremlin (pgui.sourceforge.net)\n\n"
	     "usage pgserver [-g gremlin] [-n number]\n\n"
	     "  g gremlin  : Specify a gremlin number to repeat previous results\n"
	     "               Defaults is derived from the current time\n"
	     "  n number   : Specify the number of iteratons\n"
	     "               Default is a large number\n"
	     "\n"
	     "  PicoGUI gremlin is similar to the PalmOS program of similar name.\n"
	     "  It feeds random events to the server, acting as a relentles but\n"
	     "  quite unintelligent beta tester.");
	exit(1);
     }
   
   /* Initialize to a (sometimes) predictable state */
   if (!gremlin)
     gremlin = time(NULL) & 0xFFFFF ;
   srand(gremlin);
   printf("Summoning gremlin #%lu for %lu frobs...\n",gremlin,number);

   /* Start the clock */
   start = time(NULL);

   /* The gremlin loop */
   for (i=0;i<number;i++) {
      /* Get the time and calculate the ETA */
      now = time(NULL) - start;
      if (i && now>last) {  /* Only update ETA every second to prevent round errors
			     * causing wild fluctuation */
	 eta = (number * now / i) - now;
	 last = now;
      }
      
      /* Use unbuffered output or it looks bad */
      write(1,stats,sprintf(stats,"\r %c --- #%-10lu ---"
			    " Running %02d:%02d:%02d ---"
			    " Remaining %02d:%02d:%02d ",
			    spinner[(i>>6)&3],i+1,now/3600,(now%3600)/60,
			    now%60,eta/3600,(eta%3600)/60,eta%60));

      /* Move the mouse */
      cx = rand() % mi.xres;
      cy = rand() % mi.yres;
      sendPointerInput(PG_TRIGGER_MOVE,cx,cy,0);
      pgUpdate();
      
      /* Clickski! */
      if ((rand()%100) < 80) {
	 sendPointerInput(PG_TRIGGER_DOWN,cx,cy,1);
	 pgUpdate();

	 /* Drag */
	 if ((rand()%100) < 5) {
	    cx = rand() % mi.xres;
	    cy = rand() % mi.yres;
	    sendPointerInput(PG_TRIGGER_MOVE,cx,cy,1);
	    pgUpdate();
	 }
	 
	 sendPointerInput(PG_TRIGGER_UP,cx,cy,0);
	 pgUpdate();
      }
      
      /* Some common keys */
      if ((rand()%100) < 5) {
	 sendKeyInput(PG_TRIGGER_KEYDOWN,PGKEY_y,0);
	 pgUpdate();
	 sendKeyInput(PG_TRIGGER_KEYUP,PGKEY_y,0);
	 sendKeyInput(PG_TRIGGER_CHAR,'y',0);
	 pgUpdate();
      }
      if ((rand()%100) < 2) {
	 sendKeyInput(PG_TRIGGER_KEYDOWN,PGKEY_n,0);
	 pgUpdate();
	 sendKeyInput(PG_TRIGGER_KEYUP,PGKEY_n,0);
	 sendKeyInput(PG_TRIGGER_CHAR,'n',0);
	 pgUpdate();
      }
      if ((rand()%100) < 30) {
	 sendKeyInput(PG_TRIGGER_KEYDOWN,PGKEY_TAB,0);
	 pgUpdate();
	 sendKeyInput(PG_TRIGGER_KEYUP,PGKEY_TAB,0);
	 pgUpdate();
      }
      if ((rand()%100) < 5) {
	 sendKeyInput(PG_TRIGGER_KEYDOWN,PGKEY_SPACE,0);
	 pgUpdate();
	 sendKeyInput(PG_TRIGGER_KEYUP,PGKEY_SPACE,0);
	 pgUpdate();
      }

           
      /* Wait */
      if ((rand()%100) < 20)
	 usleep(1000);
   
   }

   printf("\nDone. Remember to check for memory leaks with CTRL-ALT-M!\n");
   
   return 0;
}
Exemplo n.º 15
0
/* Update the status display with current parameters */
void updateStatus(void) {
   pgReplaceTextFmt(wStatusLabel,"L%d  Move %d",level,moves);
   pgUpdate();
}
Exemplo n.º 16
0
int main(int argc,char **argv) {
  pghandle frames[NUMFRAMES];
  char frname[FRAMENAMELEN];
  int i, d;
  pghandle wBitmap, wOk;

  pgInit(argc,argv);

  /* This is so we can clean up afterwards. This isn't necessary for this
   * simple demo, but if this code is used as part of a larger app this
   * is very important.
   */
  pgEnterContext();

  /* Load the frames into memory */
  for (i=0;i<NUMFRAMES;i++) {
    snprintf(frname,FRAMENAMELEN,FRAMENAME,i);
    frames[i] = pgNewBitmap(pgFromFile(frname));
  }

  /* Create a dialog box with an ok button and bitmap widget */
  pgDialogBox(ANIMTITLE);
  wOk = pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_BOTTOM,
	      PG_WP_TEXT,pgGetServerRes(PGRES_STRING_OK),
	      PG_WP_HOTKEY,pgThemeLookup(PGTH_O_DEFAULT,PGTH_P_HOTKEY_OK),
	      0);
  wBitmap = pgNewWidget(PG_WIDGET_LABEL,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_ALL,
	      PG_WP_TRANSPARENT,0,
	      0);

  /* Animation loop */
  i = 0;
  d = 1;
  for (;;) {
    
    /* change the frame, update the screen */
    pgSetWidget(wBitmap,
		PG_WP_BITMAP,frames[i],
		0);
    pgUpdate();
    
    /* Check whether the ok button was clicked */
    if (pgCheckEvent() && pgGetEvent()->from==wOk)
      break;

    /* Small delay between frames */
    usleep(1);

    /* Next frame, ping-pong style */
    if (i == NUMFRAMES-1)
      d = -1;
    if (!i)
      d = 1;
    i += d;
  }

  /* Clean up */
  pgLeaveContext();

  return 0;
}