示例#1
0
文件: g_error.c 项目: UIKit0/picogui
void guru(const char *fmt, ...) {
  struct font_descriptor *df=NULL;
  char msgbuf[512];  /* Cruftee! */
  char *p,*pline;
  char c;
  va_list ap;
  struct pgquad screenclip;
  static int semaphore = 0;
   
  if (!vid) return;
  if (semaphore) {
    fprintf(stderr, "GURU re-entered!\n");
    return;
  }
  semaphore++;

  /* Format and print message */
  va_start(ap,fmt);
  vsnprintf(msgbuf,512,fmt,ap);
  va_end(ap);
  
  if (!disable_output) {

    /* Setup */
    VID(rect) (VID(window_debug)(),0,0,vid->lxres,vid->lyres,VID(color_pgtohwr)(0),
	       PG_LGOP_NONE);
    rdhandle((void**)&df,PG_TYPE_FONTDESC,-1,res[PGRES_DEFAULT_FONT]);
    screenclip.x1 = screenclip.y1 = 0;
    screenclip.x2 = vid->lxres-1;
    screenclip.y2 = vid->lyres-1;
    
#ifdef CONFIG_FORMAT_XBM
    /* Icon (if this fails, no big deal) */
    {
      hwrbitmap icon;
      if (!iserror(VID(bitmap_loadxbm) (&icon,deadcomp_bits,
					deadcomp_width,deadcomp_height,
					VID(color_pgtohwr) (0xFFFF80),
					VID(color_pgtohwr) (0x000000)))) {
	VID(blit) (VID(window_debug)(),5,5,deadcomp_width,deadcomp_height,
		   icon,0,0,PG_LGOP_NONE);
	VID(bitmap_free) (icon);
      }
    }
#else
    /* To appease the below code */
# define deadcomp_width 0
#endif
  
    df->lib->draw_string(df,VID(window_debug)(),xy_to_pair(10+deadcomp_width,5),
			 VID(color_pgtohwr)(0xFFFFFF),pgstring_tmpwrap(msgbuf),
			 &screenclip,PG_LGOP_NONE,0);
    VID(update) (VID(window_debug)(),0,0,vid->lxres,vid->lyres);    
  }
  
#ifdef CONFIG_STDERR_GURU
  /* Mirror the message on stderr, prefix each line with "GURU:  " */
  for (c=1,pline=msgbuf;c;pline=p+1) {
    for (p=pline;*p && *p!='\n';p++);
    c=*p; *p=0;
    fprintf(stderr,"GURU:  %s\n",pline); 
  }
#endif
    
  semaphore--;
}
示例#2
0
g_error debug_bitmaps(const void **pobj, void *extra) {
  struct debug_bitmaps_data *data = (struct debug_bitmaps_data *) extra;
  hwrbitmap bmp = (hwrbitmap) *pobj;
  s16 w,h;
  int has_alpha, i;
  struct font_descriptor *df=NULL;
  struct pgquad screenclip;
  struct font_metrics m;
  hwrbitmap debugwin;
  s16 lxres,lyres;
  VID(bitmap_getsize)(VID(window_debug)(), &lxres, &lyres);

  screenclip.x1 = screenclip.y1 = 0;
  screenclip.x2 = lxres-1;
  screenclip.y2 = lyres-1;
  rdhandle((void**)&df,PG_TYPE_FONTDESC,-1,res[PGRES_DEFAULT_FONT]);
  df->lib->getmetrics(df,&m);

  VID(bitmap_getsize) (bmp,&w,&h);
  if (data->db_x+10+w>lxres) {
    data->db_x = 0;
    data->db_y += data->db_h+8;
    data->db_h = 0;
  }
  if (h>data->db_h)
    data->db_h = h;
   
  if (data->db_y+45+h>lyres) {
    df->lib->draw_string(df,VID(window_debug)(),xy_to_pair(10,lyres-m.charcell.h*3),
			 VID(color_pgtohwr) (0xFFFF00),
			 pgstring_tmpwrap("Too many bitmaps for this screen.\n"
					  "Change video mode and try again"),
			 &screenclip,PG_LGOP_NONE,0);

    return mkerror(PG_ERRT_INTERNAL,0);  /* Dummy error to get us to abort */
  }
   
  VID(rect) (VID(window_debug)(),data->db_x+3,data->db_y+38,w+4,h+4,
	     VID(color_pgtohwr)(0xFFFFFF),PG_LGOP_NONE);
  VID(rect) (VID(window_debug)(),data->db_x+4,data->db_y+39,w+2,h+2,
	     VID(color_pgtohwr)(0x000000),PG_LGOP_NONE);

  has_alpha = w && h && (VID(getpixel)(bmp,0,0) & PGCF_ALPHA);
     
  /* If we have an alpha channel, draw a interlacy background so we can see the alpha */
  if (has_alpha) {
    for (i=0;i<h;i++)
      VID(slab) (VID(window_debug)(), data->db_x+5, data->db_y+40+i, w,
		 VID(color_pgtohwr)(i&1 ? 0xFFFFFF : 0xCCCCCC), PG_LGOP_NONE);

    df->lib->draw_string(df,VID(window_debug)(),xy_to_pair(data->db_x+5,data->db_y+40),
			 VID(color_pgtohwr)(0x000000),
			 pgstring_tmpwrap("Alpha"), &screenclip, PG_LGOP_NONE,0);
  }

  VID(blit) (VID(window_debug)(),data->db_x+5,data->db_y+40,w,h,bmp,0,0,
	     has_alpha ? PG_LGOP_ALPHA : PG_LGOP_NONE);

  data->db_x += w+8;
  return success;
}