void set_vfd_text(pghandle vfd,const char *text) { /* Use the lower level canvas commands to change the VFD's text. * The display's previous text is stored as its payload so we can * delete it, and we set the new text by changing the text gropnode's * parameter */ pghandle h; pgDelete(pgGetPayload(vfd)); h = pgNewString(text); pgWriteCmd(vfd,PGCANVAS_SETGROP,1,h); pgWriteCmd(vfd,PGCANVAS_REDRAW,0); pgSetPayload(vfd,h); }
/* Little internal helper function for the message dialog */ void dlgbtn(pghandle tb,u32 payload,int textproperty, int iconproperty,int key) { pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,tb); pgSetWidget(PGDEFAULT, PG_WP_TEXT,pgGetServerRes(textproperty), PG_WP_SIDE,PG_S_RIGHT, PG_WP_HOTKEY,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,key), PG_WP_IMAGE,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG, iconproperty), PG_WP_BITMASK,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG, iconproperty+1), 0); pgSetPayload(PGDEFAULT,payload); }
/* This creates a menu from an array of string handles. * Same return values as pgMenuFromString above. * * Important note: pgMenuFromArray expects that a new * context will be entered before the * string handles are created */ int pgMenuFromArray(pghandle *items,int numitems) { int i; pghandle returnHandle; returnHandle = pgNewPopupAt(PG_POPUP_ATEVENT,PG_POPUP_ATEVENT,0,0); for (i=0;i<numitems;i++) { printf("Menu Item => %d\n", pgNewWidget(PG_WIDGET_MENUITEM,0,0)); pgSetWidget(PGDEFAULT, PG_WP_TEXT,items[i], 0); pgSetPayload(PGDEFAULT,i+1); } /* Return event */ return pgGetPayload(pgGetEvent()->from); }
/* 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); }
/* There are many ways to create a menu in PicoGUI * (at the lowest level, using pgNewPopupAt and the menuitem widget) * * This creates a static popup menu from a "|"-separated list of * menu items, and returns the number (starting with 1) of the chosen * item, or 0 for cancel. */ int pgMenuFromString(char *items) { char *p; pghandle str; int ret; int i; if (!items || !*items) return 0; /* Create the menu popup in its own context */ pgEnterContext(); pgNewPopupAt(PG_POPUP_ATEVENT,PG_POPUP_ATEVENT,0,0); i=0; do { /* Do a little fancy stuff to make the string handle. * This is like pgNewString but we get to specify the * length instead of having strlen() do it for us. */ if (!(p = strchr(items,'|'))) p = items + strlen(items); _pg_add_request(PGREQ_MKSTRING,(void *) items,p-items); items = p+1; pgFlushRequests(); str = _pg_return.e.retdata; /* Create each menu item */ pgNewWidget(PG_WIDGET_MENUITEM,0,0); pgSetWidget(PGDEFAULT, PG_WP_TEXT,str, 0); pgSetPayload(PGDEFAULT,++i); } while (*p); /* Run the menu */ ret = pgGetPayload(pgGetEvent()->from); pgLeaveContext(); return ret; }
/* widget: the parent widget to derive inside * directory: the directory into which search for themes */ void themebar(pghandle widget, char* directory, int* themecontext) { struct dirent *dent; int i,l; DIR *d; char buf[80]; pghandle box; THEME_DIRECTORY=directory; if (! (d = opendir(THEME_DIRECTORY))) { eerror("directory not found"); exit(1); } /* simple & dirty */ /* pageContext = pagecontext; */ /* themeContext = themecontext; */ box = pgNewWidget(PG_WIDGET_SCROLLBOX, PG_DERIVE_AFTER, widget); pgSetWidget(PGDEFAULT, PG_WP_SIDE, PG_S_ALL, /* PG_WP_TRANSPARENT, 1, */ 0); /* Make handles */ rewinddir(d); i = 0; while ((dent = readdir(d))) { l = strlen(dent->d_name); if (l<4) continue; if (strcmp(dent->d_name+l-3,".th")) continue; buf[0] = 0; /* dent->d_name[l-3] = 0; */ if (idx == LENGHT) { eerror("max array lenght reached in themebar.c: too many themes."); break; } array[idx].dir = pgNewString(directory); array[idx].fname = pgNewString(dent->d_name); array[idx].active = 0; /* Add item */ pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, box); pgSetWidget(PGDEFAULT, /* PG_WP_EXTDEVENTS, pgGetWidget(PGDEFAULT, PG_WP_EXTDEVENTS) & ~PG_EXEV_EXCLUSIVE, */ /* PG_WP_EXTDEVENTS, PG_EXEV_TOGGLE, */ PG_WP_TEXT, array[idx].fname, PG_WP_SIDE, PG_S_BOTTOM, 0); pgSetPayload(PGDEFAULT, idx); idx++; pgBind(PGDEFAULT,PG_WE_ACTIVATE,evtChangeTheme, themecontext); } closedir(d); pgSubUpdate(widget); return; }