/* 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); }
/* 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); }
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; }