void animate2(void) { const float step = 0.05; static int t = 0; float a,r1,r2; pgSetMapping(gc,0,0,1000,1000,PG_MAP_SQUARESCALE); /* Fade and blur */ if (!(t&3)) { pgSetColor(gc,PGCF_ALPHA | PGC_BLACK | (4<<24)); pgSetLgop(gc,PG_LGOP_ALPHA); pgRect(gc,0,0,1000,1000); pgSetLgop(gc,PG_LGOP_NONE); } pgBlur(gc,0,0,1000,1000,2); /* Draw our polar function defined above */ pgSetColor(gc, 0xFF7344); for (a=0;a<2*pi;a+=step) { r1 = radius(a,t)*300; r2 = radius(a+step,t)*300; pgLine(gc,cos(a)*r1+500,sin(a)*r1+500, cos(a+step)*r2+500,sin(a+step)*r2+500); } pgContextUpdate(gc); t++; }
/* Functions to create a VFD-style display and set it's text */ void new_vfd_label(pghandle canvas) { pgcontext gc; pghandle h = pgNewString(" "); /* Use a canvas widget to do a 'inverse VFD style' phone number display * * Code like this makes me really glad that the canvas widget is * as smart as it is about scaling and calculating preferred sizes */ gc = pgNewCanvasContext(canvas,PGFX_PERSISTENT); pgSetMapping(gc,0,0,1,1,PG_MAP_SCALE); pgSetColor(gc,0xBFEDBD); /* Pastel green */ pgRect(gc,0,0,1,1); pgSetColor(gc,0x000000); pgFrame(gc,0,0,1,1); pgSetFont(gc,pgNewFont(NULL,20,0)); pgText(gc,0,0,h); pgSetPayload(canvas,h); pgDeleteContext(gc); }
/* Small utility function to XOR a key's rectangle */ void xorKey(struct key_entry *k) { pgcontext gc; if (!k) return; gc = pgNewCanvasContext(wCanvas,PGFX_IMMEDIATE); pgSetLgop(gc,PG_LGOP_XOR); pgSetColor(gc,0xFFFFFF); pgRect(gc,k->x,k->y,k->w,k->h); pgContextUpdate(gc); pgDeleteContext(gc); }
/* * Draw the contents of the disabled keyboard * This could be filled with an image, a logo, etc. */ void drawDisabledKeyboard () { pgcontext gc = pgNewCanvasContext (wDisabled, PGFX_PERSISTENT); pgSetMapping (gc, 0, 0, 100, 100, PG_MAP_SCALE); pgSetColor (gc, 0xFFFFFF); pgRect (gc, 0, 0, 100, 100); /* ... */ pgContextUpdate (gc); pgDeleteContext (gc); }
int btnTarget(struct pgEvent *evt) { pgcontext gc; pghandle wClose,wTB; int i,x,w; pgEnterContext(); pgDialogBox("Target"); wTB = pgNewWidget(PG_WIDGET_TOOLBAR,0,0); pgSetWidget(PGDEFAULT, PG_WP_SIDE,PG_S_BOTTOM, 0); /* Just draw something fun here */ pgNewWidget(PG_WIDGET_CANVAS,0,0); gc = pgNewCanvasContext(PGDEFAULT,PGFX_PERSISTENT); pgSetMapping(gc,0,0,100,100,PG_MAP_SCALE); for (i=0;i<=4;i++) { x = i*10; w = 100-(x<<1); pgSetColor(gc,i&1 ? 0xFFFFFF : 0xFF0000); pgFEllipse(gc,x,x,w,w); pgSetColor(gc,0x000000); pgEllipse(gc,x,x,w,w); } pgContextUpdate(gc); pgDeleteContext(gc); /* A close button */ wClose = pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wTB); pgSetWidget(PGDEFAULT, PG_WP_TEXT,pgNewString("Close"), PG_WP_HOTKEY,PGKEY_RETURN, PG_WP_SIDE,PG_S_RIGHT, 0); /* Wait for a click on the canvas, then clean up */ while (pgGetEvent()->from != wClose); pgLeaveContext(); return 0; }
/* int main(int argc,char **argv) { */ void chaos_fire(pghandle widget) { pgcontext bg; /* pgInit(argc,argv); */ /* pgRegisterApp(PG_APP_NORMAL,"Burning cinder fury of crimson chaos fire",0); */ /* pgNewWidget(PG_WIDGET_CANVAS,0,0); */ bg = pgNewCanvasContext(widget,PGFX_PERSISTENT); pgSetMapping(bg,0,0,100,100,PG_MAP_SCALE); pgSetColor(bg, 0); pgRect(bg,0,0,100,100); gc = pgNewCanvasContext(widget,PGFX_IMMEDIATE); idleHandlerAdd(animate2); return; while (1) { animate2(); pgEventPoll(); } }