/* 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 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(); } }
/* 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; }
int main(int argc, char** argv) { pgcolor color; struct pgmodeinfo mi; int i; pghandle ttl_box; /* init PicoGUI client */ pgInit(argc,argv); pgRegisterApp(PG_APP_NORMAL, argv[0], 0); /* create the title */ ttl_box = pgNewWidget(PG_WIDGET_BOX,0,0); ttl_text = pgNewWidget(PG_WIDGET_LABEL, PG_DERIVE_INSIDE, ttl_box); pgSetWidget (PGDEFAULT, PG_WP_TEXT, pgNewString("wclock"), 0); pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, ttl_box); pgSetWidget (PGDEFAULT, PG_WP_SIDE, PG_S_RIGHT, PG_WP_TEXT, pgNewString("?"), PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN, 0); pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &btn_handler, (void*)btnid_set); pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, ttl_box); pgSetWidget (PGDEFAULT, PG_WP_SIDE, PG_S_LEFT, PG_WP_TEXT, pgNewString(">"), PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN, 0); pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &btn_handler, (void*)btnid_right); pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, ttl_box); pgSetWidget (PGDEFAULT, PG_WP_SIDE, PG_S_LEFT, PG_WP_TEXT, pgNewString("<"), PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN, 0); pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &btn_handler, (void*)btnid_left); /* create the main context */ main_window = pgNewWidget(PG_WIDGET_CANVAS, PG_DERIVE_AFTER, ttl_box); pgBind(PGDEFAULT, PGBIND_ANY, &canvas_handler, NULL); /* init time zones */ init_zones(); /* activate mouse move, keyboard and focus events */ pgSetWidget(main_window, PG_WP_TRIGGERMASK, pgGetWidget(main_window, PG_WP_TRIGGERMASK) | PG_TRIGGER_MOVE | PG_TRIGGER_CHAR | PG_TRIGGER_KEYDOWN | PG_TRIGGER_KEYUP /* | PG_TRIGGER_ACTIVATE | PG_TRIGGER_DEACTIVATE */, 0); mi = *pgGetVideoMode(); width = mi.lxres; height = mi.lyres; /* Make a backbuffer bitmap */ world_bitmap = create_world_bitmap(); width = get_world_width(); height = get_world_height(); /* Set the clipping rectangle */ pgWriteCmd(main_window, PGCANVAS_GROP, 5, PG_GROP_SETCLIP, 0, 0, width, height + TIMEBAR_HEIGHT); /* Set to be always rendered */ pgWriteCmd(main_window, PGCANVAS_GROPFLAGS, 1, PG_GROPF_UNIVERSAL); /* Create contexts for the canvas itself and the back-buffer */ gfx_context = pgNewCanvasContext(main_window, PGFX_IMMEDIATE ); /* run all */ DPRINTF(">>> entering loop\n"); pgEventLoop(); return 0; }