static void GrSetGCModeWrapper(void *r) { nxSetGCModeReq *req = r; GrSetGCMode(req->gcid, req->mode); }
static void idw_draw_sheet(TSheet *sheet) { GR_SIZE width, height, base; char str[50], *ap; int i; if (sheet == NULL) { sheet = game.screen->menuitems[game.select].sheet; } // draw the title pz_draw_header (sheet->title); GrGetGCTextSize(idw_gc, sheet->button, -1, GR_TFASCII, &width, &height, &base); height+=4; // (left, top, right, bottom) GrSetGCForeground(idw_gc, BLACK); GrLine(idw_wid, idw_gc, 20, 0, 20, screen_info.rows-44); GrLine(idw_wid, idw_gc, 20, screen_info.rows-44, screen_info.cols-20, screen_info.rows-44); GrLine(idw_wid, idw_gc, screen_info.cols-20, 0, screen_info.cols-20, screen_info.rows-44); GrSetGCForeground(idw_gc, WHITE); GrFillRect(idw_wid, idw_gc, 21, 0, screen_info.cols-41, screen_info.rows-44); GrSetGCForeground(idw_gc, BLACK); GrSetGCUseBackground(idw_gc, GR_FALSE); GrSetGCMode(idw_gc, GR_MODE_SET); ap = strtok(sheet->text, "\n"); for (i=0; ap != NULL; i++) { GrText(idw_wid, idw_gc, 30, 1 + ((i + 1) * height - 4), ap, -1, GR_TFASCII); ap = strtok(NULL, "\n"); } if (sheet->ammount != -1) { // print ammount sprintf(str, "Ammount: %d", game.ammount); GrText(idw_wid, idw_gc, 30, 50, str, -1, GR_TFASCII); } else { // the next time the user presses the middle button the sheet will disappear game.dismiss_sheet = 1; } // print the single menu option GrSetGCForeground(idw_gc, BLACK); GrFillRect(idw_wid, idw_gc, 21, 1 + 4 * height-4, screen_info.cols-41, height-1); GrSetGCForeground(idw_gc, WHITE); GrSetGCUseBackground(idw_gc, GR_TRUE); GrText(idw_wid, idw_gc, (screen_info.cols/2)-width+4, (5 * height - 8), sheet->button, -1, GR_TFASCII); // we're in a transaction game.in_transaction = 1; }
/* this would be much cleaner if raster ops worked properly; perhaps I just * misunderstand how they are supposed to be used */ void menu_draw_item(menu_st *menulist, int item) { if(item < 0 || item > menulist->screen_items - 1) { Dprintf("menu_draw_item::No Such Pixmap\n"); return; } /* xor the pixmap */ if(item == (menulist->sel - menulist->top_item)) { GrSetGCMode(menulist->menu_gc, GR_MODE_XOR); if (hw_version == 0 || hw_version == 0x6 || hw_version == 0xc || hw_version == 0xb) { /* make sure that the xor works properly for devices with * fbrev turned off (host, photo) */ GrSetGCForeground(menulist->menu_gc, WHITE ); } /* just xor the menu option for now */ /* eventually, draw the correct colors... */ GrFillRect(menulist->pixmaps[menulist->pixmap_pos[item]], menulist->menu_gc, 0, 0, menulist->w, menulist->height); } GrCopyArea(menulist->menu_wid, menulist->menu_gc, menulist->x, (item * menulist->height) + menulist->y, menulist->w - (menulist->scrollbar ? 8 : 0), menulist->height, menulist->pixmaps[menulist->pixmap_pos[item]], 0, 0, 0); /* un umm xor the pixmap */ if(item == (menulist->sel - menulist->top_item)) { GrFillRect(menulist->pixmaps[menulist->pixmap_pos[item]], menulist->menu_gc, 0, 0, menulist->w, menulist->height); GrSetGCMode(menulist->menu_gc, GR_MODE_SET); if (hw_version == 0 || hw_version == 0x6 || hw_version == 0xc || hw_version == 0xb) { /* reset fix for xor on certain devices (host, photo) */ GrSetGCForeground(menulist->menu_gc, BLACK); } } }
static void draw_itunes_parse(int cnt) { char str[10]; sprintf(str, "%i", cnt); GrSetGCUseBackground(currentml->gc, GR_FALSE); GrSetGCMode(currentml->gc, GR_MODE_SET); GrSetGCForeground(currentml->gc, WHITE); GrFillRect(currentml->wid, currentml->gc, 0, 3 * currentml->gr_height, currentml->screen_info.cols, currentml->gr_height); GrSetGCForeground(currentml->gc, BLACK); GrText(currentml->wid, currentml->gc, 8, 3 * currentml->gr_height - 3, str, -1, GR_TFASCII); }
int XSetSubwindowMode(Display *dpy, GC gc, int subwindow_mode) { XGCValues *vp = (XGCValues *)gc->ext_data; int mode; vp->subwindow_mode = subwindow_mode; mode = (subwindow_mode == IncludeInferiors)? GR_MODE_EXCLUDECHILDREN: 0; /* must OR in draw mode when GrSetGCMode called*/ mode |= _nxConvertROP(vp->function); GrSetGCMode(gc->gid, mode); return 1; }
int XSetFunction(Display *dpy, GC gc, int function) { XGCValues *vp = (XGCValues *)gc->ext_data; int mode = _nxConvertROP(function); vp->function = function; /* must OR in clip mode when GrSetGCMode called*/ if (vp->subwindow_mode == IncludeInferiors) mode |= GR_MODE_EXCLUDECHILDREN; GrSetGCMode(gc->gid, mode); return 1; }
static void draw_dialer() { GR_SIZE width, height, base; GrSetGCUseBackground(dialer_gc, GR_FALSE); GrSetGCForeground(dialer_gc, GR_RGB(0,0,0)); GrGetGCTextSize(dialer_gc, digitdisplay, -1, GR_TFASCII, &width, &height, &base); /* GrRect(dialer_wid, dialer_gc, CXOFF, CYOFF, CWIDTH, cbh); GrSetGCForeground(dialer_gc, GR_RGB(255,255,255)); GrFillRect(dialer_wid, dialer_gc, CXOFF+1, CYOFF+1, CWIDTH-2, cbh-2); GrSetGCForeground(dialer_gc, GR_RGB(0,0,0)); GrText(dialer_wid, dialer_gc, CXOFF+(CWIDTH-width-4), CYOFF+((cbh/2)-(height/2)), digitdisplay, -1, GR_TFASCII|GR_TFTOP); */ /* range check */ if(current_dialer_button < 0) current_dialer_button = 15; else if(current_dialer_button >= 16) current_dialer_button = 0; /* compute button sizings */ xlocal=CXOFF+((cbw+cxgap)*(current_dialer_button%4)); ylocal=CBYOFF+((cbh+cygap)*(current_dialer_button/4)); lastxlocal=CXOFF+((cbw+cxgap)*(last_bouvet_item%4)); lastylocal=CBYOFF+((cbh+cygap)*(last_bouvet_item/4)); GrSetGCForeground(dialer_gc, GR_RGB(255,255,255)); GrFillRect(dialer_wid, dialer_gc, lastxlocal+1, lastylocal+1, cbw-2, cbh-2); GrSetGCForeground(dialer_gc, GR_RGB(0,0,0)); GrGetGCTextSize(dialer_gc, dialerpad[last_bouvet_item], -1, GR_TFASCII, &width, &height, &base); GrText(dialer_wid, dialer_gc, lastxlocal+((cbw/2)-(width/2)), lastylocal+((cbh/2)-(height/2)), dialerpad[last_bouvet_item], -1, GR_TFASCII|GR_TFTOP); GrFillRect(dialer_wid, dialer_gc, xlocal, ylocal, cbw, cbh); GrSetGCForeground(dialer_gc, GR_RGB(255,255,255)); GrGetGCTextSize(dialer_gc, dialerpad[current_dialer_button], -1, GR_TFASCII, &width, &height, &base); GrText(dialer_wid, dialer_gc, xlocal+((cbw/2)-(width/2)), ylocal+((cbh/2)-(height/2)), dialerpad[current_dialer_button], -1, GR_TFASCII|GR_TFTOP); GrSetGCUseBackground(dialer_gc, GR_FALSE); GrSetGCMode(dialer_gc, GR_MODE_SET); }
void wm_container_buttondown(win *window, GR_EVENT_BUTTON *event) { struct pos_size *pos; GR_RECT r; GR_COORD cxborder = 0, cyborder = 0; GR_WINDOW_INFO info; GR_WINDOW_INFO cinfo; GR_GC_ID gc; Dprintf("wm_container_buttondown window %d\n", window->wid); if(window->active) return; GrGetWindowInfo(window->wid, &info); GrGetWindowInfo(window->clientid, &cinfo); /* calc border sizes*/ if (info.props & GR_WM_PROPS_BORDER) { cxborder = 1; cyborder = 1; } if (info.props & GR_WM_PROPS_APPFRAME) { cxborder = CXBORDER; cyborder = CYBORDER; } /* Check for close box press*/ if ((info.props & (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) == (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) { /* Get close box rect*/ r.x = info.width - CXCLOSEBOX - cxborder - 2; r.y = cyborder + 2; r.width = CXCLOSEBOX; r.height = CYCLOSEBOX; /* Check mousedn in close box*/ if (PtInRect(&r, event->x, event->y)) { /* close on button up*/ window->close = GR_TRUE; return; } } /* * Set focus to the window only if client * or the container itself is clicked. * if any of the children (of the client) * are clicked better not take the focus * away from them. They might require handling * the focus themself. * -- Amit Kulkarni */ if(window->wid==event->subwid) GrSetFocus(window->wid); /* check for corner resize */ r.x = info.width - 5; r.y = info.height - 5; r.width = 5; r.height = 5; if (PtInRect(&r,event->x, event->y) && !(info.props & GR_WM_PROPS_NORESIZE) && !(cinfo.props & GR_WM_PROPS_NORESIZE)) { #if !NO_CORNER_RESIZE struct pos_size * pos; if(!window->data) if(!(window->data = malloc(sizeof(struct pos_size)))) return; window->sizing = GR_TRUE; /* save off the width/height offset from the window manager */ GrGetWindowInfo(window->clientid,&info); pos = (struct pos_size*)window->data; pos->xoff = -info.width; pos->yoff = -info.height; GrGetWindowInfo(window->wid,&info); pos->xoff += info.width; pos->yoff += info.height; gc = GrNewGC(); GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN); GrRect(GR_ROOT_WINDOW_ID,gc,info.x, info.y, info.width, info.height); GrDestroyGC(gc); /* save this rectangle's width/height so we can erase it later */ pos->width = info.width; pos->height = info.height; pos->xorig = event->x; pos->yorig = event->y; /* * This window is being resized. * The client should have focus now. * -- Amit Kulkarni */ GrSetFocus(window->clientid); return; #endif /* !NO_CORNER_RESIZE*/ } else GrSetWindowCursor(window->wid, 0); /* if not in caption, return (FIXME, not calc'd exactly)*/ if (!(info.props & GR_WM_PROPS_CAPTION)) return; /* Get caption box rect*/ r.x = cxborder; r.y = cyborder; r.width = info.width - cxborder*2; r.height = CYCAPTION; /* Check for mousedn in caption box*/ if (!PtInRect(&r, event->x, event->y)) return; /* * Now we have a click on the caption. * So window is active. * Set focus to the client * --Amit Kulkarni */ GrSetFocus(window->clientid); /* Raise window if mouse down and allowed*/ if (!(info.props & GR_WM_PROPS_NORAISE) && !(cinfo.props & GR_WM_PROPS_NORAISE)) GrRaiseWindow(window->wid); /* Don't allow window move if NOMOVE property set*/ if ((info.props & GR_WM_PROPS_NOMOVE) || (cinfo.props & GR_WM_PROPS_NOMOVE)) return; if(!window->data) if(!(window->data = malloc(sizeof(struct pos_size)))) return; GrGetWindowInfo(window->wid,&info); pos = (struct pos_size *)window->data; pos->xoff = event->x; pos->yoff = event->y; #if OUTLINE_MOVE pos->xorig = info.x; pos->yorig = info.y; pos->width = info.width; pos->height = info.height; gc = GrNewGC(); GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN); GrRect(GR_ROOT_WINDOW_ID, gc,info.x, info.y, info.width, info.height); GrDestroyGC(gc); #endif window->active = GR_TRUE; }
void wm_container_mousemoved(win *window, GR_EVENT_MOUSE *event) { struct pos_size *pos; GR_GC_ID gc; GR_RECT r; GR_WINDOW_INFO info; Dprintf("wm_container_mousemoved window %d\n", window->wid); GrGetWindowInfo(window->wid, &info); if(window->sizing) { struct pos_size * pos = (struct pos_size*)window->data; /* erase old rectangle */ gc = GrNewGC(); GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN); GrRect(GR_ROOT_WINDOW_ID, gc, info.x, info.y, pos->width, pos->height); /* draw new one */ GrRect(GR_ROOT_WINDOW_ID,gc,info.x, info.y, event->rootx - info.x, event->rooty - info.y); GrDestroyGC(gc); /* save this new rectangle's width, height */ /* I know, this shouldn't be stored in x/y, but... */ pos->width = event->rootx - info.x; pos->height = event->rooty - info.y; return; } #if !NO_CORNER_RESIZE /* check corner resize cursor on/off*/ r.x = info.width - 5; r.y = info.height - 5; r.width = 5; r.height = 5; if (PtInRect(&r,event->x, event->y)) set_resize_cursor(window->wid); else GrSetWindowCursor(window->wid, 0); #endif if(!window->active) return; pos = (struct pos_size *)window->data; #if OUTLINE_MOVE gc = GrNewGC(); GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN); GrRect(GR_ROOT_WINDOW_ID,gc,pos->xorig, pos->yorig, pos->width, pos->height); GrRect(GR_ROOT_WINDOW_ID,gc,event->rootx - pos->xoff, event->rooty - pos->yoff, pos->width, pos->height); pos->xorig = event->rootx - pos->xoff; pos->yorig = event->rooty - pos->yoff; GrDestroyGC(gc); #else GrMoveWindow(window->wid, event->rootx - pos->xoff, event->rooty - pos->yoff); #endif }
void wm_container_buttonup(win *window, GR_EVENT_BUTTON *event) { GR_RECT r; GR_COORD cxborder = 0, cyborder = 0; GR_WINDOW_INFO info; Dprintf("wm_container_buttonup window %d\n", window->wid); GrGetWindowInfo(window->wid, &info); /* Check for close box press*/ if ((info.props & (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) == (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) { /* calc border sizes*/ if (info.props & GR_WM_PROPS_BORDER) { cxborder = 1; cyborder = 1; } if (info.props & GR_WM_PROPS_APPFRAME) { cxborder = CXBORDER; cyborder = CYBORDER; } /* Get close box rect*/ r.x = info.width - CXCLOSEBOX - cxborder - 2; r.y = cyborder + 2; r.width = CXCLOSEBOX; r.height = CYCLOSEBOX; /* Check mouseup in close box*/ if (PtInRect(&r, event->x, event->y)) { if(window->close == GR_TRUE) { /* * This sends a CLOSE_REQ event to the window. * NXLIB clients catch this and convert it * to an X11 ClientMessage with a WM_DELETE_WINDOW * atom, causing the window to close. */ GrCloseWindow(window->clientid); window->close = GR_FALSE; return; } } } window->close = GR_FALSE; if(window->active) { #if OUTLINE_MOVE struct pos_size * pos = (struct pos_size *)window->data; GR_GC_ID gc = GrNewGC(); GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN); GrRect(GR_ROOT_WINDOW_ID, gc, pos->xorig, pos->yorig, pos->width, pos->height); GrMoveWindow(window->wid, pos->xorig, pos->yorig); GrDestroyGC(gc); #endif free(window->data); window->active = GR_FALSE; window->data = 0; } if(window->sizing) { struct pos_size * pos = (struct pos_size *)window->data; GR_GC_ID gc = GrNewGC(); GR_WINDOW_INFO info; GR_SIZE w, h; GrGetWindowInfo(window->wid, &info); GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN); GrRect(GR_ROOT_WINDOW_ID, gc, info.x, info.y, pos->width, pos->height); GrDestroyGC(gc); w = info.width + (event->x - pos->xorig); h = info.height + (event->y - pos->yorig); GrResizeWindow(window->wid, w, h); GrResizeWindow(window->clientid, w - pos->xoff, h - pos->yoff); free(window->data); window->sizing = GR_FALSE; window->data = 0; } }
int main(int argc, char **argv) { GR_SCREEN_INFO si; GR_WM_PROPERTIES props; if (GrOpen() < 0) { fprintf(stderr, "Cannot open graphics\n"); exit(1); } GrReqShmCmds(65536); /* Test by Morten Rolland for shm support */ GrGetScreenInfo(&si); #ifdef __ECOS /* 240x320 screen*/ COLS = si.cols - 10; ROWS = si.rows - 40; #else COLS = si.cols - 40; ROWS = si.rows - 80; #endif mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, COLS, ROWS, 0, BLACK, BLACK); /* set title */ props.flags = GR_WM_FLAGS_TITLE | GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION; props.title = "NanoX World Map"; GrSetWMProperties(mainwid, &props); mapwidth = COLS - 2; mapheight = ROWS - 2; mapxorig = mapwidth / 2; mapyorig = mapheight / 2; selectxscale = 4; selectyscale = 3; coordx = 0; coordy = ROWS - 1; mapwid = GrNewWindow(mainwid, 1, 1, mapwidth, mapheight, #if 0 1, BLACK, WHITE); #else 1, LTGRAY, BLACK); #endif GrSelectEvents(mainwid, GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(mapwid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_POSITION | GR_EVENT_MASK_KEY_DOWN); GrMapWindow(mainwid); GrMapWindow(mapwid); mapgc = GrNewGC(); xorgc = GrNewGC(); GrSetGCMode(xorgc, GR_MODE_XOR); Longitude = ITOF(0); Latitude = ITOF(0); setzoom(ITOF(1)); while (1) checkevent(); }
int main(int argc,char **argv) { GR_COORD x; GR_COORD y; GR_SIZE width; GR_SIZE height; GR_COORD rightx; /* x coordinate for right half stuff */ GR_BOOL setsize; /* TRUE if size of board is set */ GR_BOOL setmines; /* TRUE if number of mines is set */ GR_SIZE newsize = 10; /* desired size of board */ GR_COUNT newmines = 25; /* desired number of mines */ GR_WM_PROPERTIES props; setmines = GR_FALSE; setsize = GR_FALSE; argc--; argv++; while ((argc > 0) && (**argv == '-')) { switch (argv[0][1]) { case 'm': if (argc <= 0) { fprintf(stderr, "Missing mine count\n"); exit(1); } argc--; argv++; newmines = atoi(*argv); setmines = GR_TRUE; break; case 's': if (argc <= 0) { fprintf(stderr, "Missing size\n"); exit(1); } argc--; argv++; newsize = atoi(*argv); setsize = GR_TRUE; break; default: fprintf(stderr, "Unknown option \"-%c\"\n", argv[0][1]); exit(1); } argc--; argv++; } if (argc > 0) savefile = *argv; srand(time(0)); readgame(savefile); if (setsize) { if ((newsize < MINSIZE) || (newsize > MAXSIZE)) { fprintf(stderr, "Illegal board size\n"); exit(1); } if (newsize != size) { if (steps && playing) { fprintf(stderr, "Cannot change size while game is in progress\n"); exit(1); } playing = GR_FALSE; size = newsize; if (!playing) mines = (size * size * MINEPERCENT) / 100; } } if (setmines) { if ((newmines <= 0) || ((newmines > (size * size) / 2))) { fprintf(stderr, "Illegal number of mines\n"); exit(1); } if (newmines != mines) { if (steps && playing) { fprintf(stderr, "Cannot change mines while game is in progress\n"); exit(1); } playing = GR_FALSE; mines = newmines; } } findindex(); /* * Parameters of the game have been verified. * Now open the graphics and play the game. */ if (GrOpen() < 0) { fprintf(stderr, "Cannot open graphics\n"); exit(1); } GrReqShmCmds(655360); /* Test by Morten Rolland for shm support */ GrGetScreenInfo(&si); GrGetFontInfo(0, &fi); charheight = fi.height; /* * Create the main window which will contain all the others. */ #if 0 COLS = si.cols - 40; #else COLS = si.cols; #endif ROWS = si.rows - 80; mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, COLS, ROWS, 0, BLACK, WHITE); /* set title */ props.flags = GR_WM_FLAGS_TITLE | GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_APPFRAME | GR_WM_PROPS_CAPTION; props.title = "Land Mine"; GrSetWMProperties(mainwid, &props); /* * Create the board window which lies at the left side. * Make the board square, and as large as possible while still * leaving room to the right side for statistics and buttons. */ width = COLS - RIGHTSIDE - (si.xdpcm * RIGHTGAP / 10) - BOARDBORDER * 2; height = (((long) width) * si.ydpcm) / si.xdpcm; if (height > ROWS /* - y * 2*/) { height = ROWS - BOARDBORDER * 2; width = (((long) height) * si.xdpcm) / si.ydpcm; } xp = width / size; yp = height / size; width = xp * size - 1; height = yp * size - 1; x = BOARDBORDER; y = (ROWS - height) / 2; rightx = x + width + (si.xdpcm * RIGHTGAP / 10); boardwid = GrNewWindow(mainwid, x, y, width, height, BOARDBORDER, BLUE, WHITE); /* * Create the buttons. */ x = rightx; y = (si.ydpcm * BOARDGAP / 10); quitwid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT, 1, RED, WHITE); y += (si.ydpcm * BUTTONGAP / 10); savewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT, 1, GREEN, WHITE); y += (si.ydpcm * BUTTONGAP / 10); newgamewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT, 1, GREEN, WHITE); /* * Create the statistics window. */ x = rightx; y += (si.ydpcm * STATUSGAP / 10); width = COLS - x; height = ROWS - y; statwid = GrNewWindow(mainwid, x, y, width, height, 0, 0, 0); statwidth = width; statheight = height; /* * Create the GC for drawing the board. */ boardgc = GrNewGC(); cleargc = GrNewGC(); delaygc = GrNewGC(); redgc = GrNewGC(); greengc = GrNewGC(); statgc = GrNewGC(); blackgc = GrNewGC(); buttongc = GrNewGC(); xorgc = GrNewGC(); GrSetGCBackground(boardgc, BLUE); GrSetGCForeground(cleargc, BLUE); GrSetGCForeground(redgc, RED); GrSetGCForeground(greengc, GREEN); GrSetGCForeground(statgc, GRAY); GrSetGCForeground(delaygc, BLACK); GrSetGCForeground(blackgc, BLACK); GrSetGCMode(delaygc, GR_MODE_XOR); GrSetGCMode(xorgc, GR_MODE_XOR); GrSetGCUseBackground(boardgc, GR_FALSE); GrSetGCUseBackground(buttongc, GR_FALSE); GrSelectEvents(mainwid, GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(boardwid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN); GrSelectEvents(statwid, GR_EVENT_MASK_EXPOSURE); GrSelectEvents(quitwid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrSelectEvents(newgamewid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrSelectEvents(savewid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); setcursor(); GrMapWindow(mainwid); GrMapWindow(boardwid); GrMapWindow(statwid); GrMapWindow(quitwid); GrMapWindow(savewid); GrMapWindow(newgamewid); if (!playing) newgame(); while (GR_TRUE) { GR_EVENT event; GrGetNextEvent(&event); handleevent(&event); } }
void menu_draw_timer(menu_st *menulist) { char *c = strdup(">"); int colors[] = {CS_ARROW0, CS_ARROW1, CS_ARROW2, CS_ARROW3, CS_ARROW3, CS_ARROW2, CS_ARROW1, CS_ARROW0}; if(menulist->items[menulist->sel].op & CFLASH) { menulist->items[menulist->sel].op ^= CFLASH; menu_clear_pixmap(menulist, menulist->sel - menulist->top_item); menu_retext_pixmap(menulist, menulist->sel - menulist->top_item, &menulist->items[menulist->sel]); menu_handle_timer(menulist, 0); free(c); return; } if(menulist->items[menulist->sel].text_width > menulist->w - (8 + (menulist->scrollbar ? 8 : 0))) { int item, diff, move; item = menulist->sel - menulist->top_item; diff = (menulist->items[menulist->sel].text_width + 8) - (menulist->w - (8 + (menulist->scrollbar ? 8 : 0))); menulist->timer_step++; move = (!((menulist->timer_step / diff) % 2) ? (menulist->timer_step % diff) : (diff - (menulist->timer_step % diff))); if (menulist->timer == INT_MAX - 1) menulist->timer = 0; /* xor the pixmap */ GrSetGCMode(menulist->menu_gc, GR_MODE_XOR); if (hw_version == 0 || hw_version == 0x6 || hw_version == 0xc || hw_version == 0xb) { /* make sure that the xor works properly for devices with * fbrev turned off (host, photo) */ GrSetGCForeground(menulist->menu_gc, WHITE); } GrFillRect(menulist->pixmaps[menulist->pixmap_pos[item]], menulist->menu_gc, move, 0, menulist->w, menulist->height); GrCopyArea(menulist->menu_wid, menulist->menu_gc, menulist->x, (item * menulist->height) + menulist->y, menulist->w - (menulist->scrollbar ? 8 : 0), menulist->height, menulist->pixmaps[menulist->pixmap_pos[item]], move, 0, 0); /* un umm xor the pixmap */ GrFillRect(menulist->pixmaps[menulist->pixmap_pos[item]], menulist->menu_gc, move, 0, menulist->w, menulist->height); GrSetGCMode(menulist->menu_gc, GR_MODE_SET); if (hw_version == 0 || hw_version == 0x6 || hw_version == 0xc || hw_version == 0xb) { /* reset fix for xor on certain devices (host, photo) */ GrSetGCForeground(menulist->menu_gc, BLACK); } free(c); return; } GrSetGCUseBackground(menulist->menu_gc, GR_FALSE); /* cycle through colors */ if (menulist->timer_step < 0 || menulist->timer_step >= 12) menulist->timer_step = 0; GrSetGCForeground(menulist->menu_gc, appearance_get_color(colors[menulist->timer_step < 8 ? menulist->timer_step : 7])); menulist->timer_step++; /* executable instead */ if(EXECUTE_MENU & menulist->items[menulist->sel].op) *c = 'x'; /* double; with a 1px offset for bold */ GrText(menulist->menu_wid, menulist->menu_gc, menulist->x + (menulist->w - 8) - 6, menulist->height * (menulist->sel - menulist->top_item) + menulist->y + 2, c, -1, GR_TFASCII | GR_TFTOP); GrText(menulist->menu_wid, menulist->menu_gc, menulist->x + (menulist->w - 8) - 7, menulist->height * (menulist->sel - menulist->top_item) + menulist->y + 2, c, -1, GR_TFASCII | GR_TFTOP); GrSetGCForeground(menulist->menu_gc, BLACK); GrSetGCUseBackground(menulist->menu_gc, GR_TRUE); free(c); }
int main() { #ifdef TEST_FOR_X Display *display; Window window; GC gc; XGCValues gcValues; Colormap colormap; Pixmap src_pixmap; unsigned long fgColor, bgColor; int screenNum; XPoint points[NUM_POINTS]; #else GR_WINDOW_ID window; GR_WINDOW_ID src_pixmap; unsigned char* src_pixmap_buf[320*240*2]; GR_GC_ID gc; GR_POINT points[NUM_POINTS]; #endif int c, c1, count=4500; int x, y, x1, y1, x2, y2; #ifdef TEST_FOR_X if(!(display=XOpenDisplay(""))) { printf("Cannot connect to X.\n"); } screenNum = DefaultScreen(display); colormap = DefaultColormap(display, screenNum); bgColor = BlackPixel(display, screenNum); fgColor = WhitePixel(display, screenNum); window = XCreateSimpleWindow(display, RootWindow(display, screenNum), 0, 0 , 639, 479, 0, fgColor, bgColor); src_pixmap = XCreatePixmap(display, window, 320, 240, 16); XMapRaised(display, window); gcValues.background = bgColor; gcValues.foreground = fgColor; gcValues.line_width = 1; gcValues.line_style = LineSolid; gcValues.fill_style = FillSolid; gcValues.fill_rule = WindingRule; gcValues.arc_mode = ArcPieSlice; gc = XCreateGC(display, window, GCForeground | GCBackground | GCLineWidth | GCLineStyle | GCFillStyle, &gcValues); #else GrOpen(); window = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, 639, 479, 0, BLACK, BLUE); src_pixmap = GrNewPixmap(640, 480, src_pixmap_buf); GrMapWindow(window); gc = GrNewGC(); GrSetGCForeground(gc, WHITE); GrSetGCBackground(gc, BLACK); GrSetGCMode(gc, GR_MODE_COPY); #endif // Horizontal Line //////////////////////////////////////////////// printf("Horizontal Line(XDrawLine)\n"); start_timer(); for(c=0; c<count*20; c++) { y1=random()%480; #ifdef TEST_FOR_X XDrawLine(display, window, gc, 0, y1, 639, y1); XFlush(display); #else GrLine(window, gc, 0, y1, 639, y1); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // Vertical Line ///////////////////////////////////////////////// printf("Vertical Line(XDrawLine)\n"); start_timer(); for(c=0; c<count*19; c++) { x1=random()%640; #ifdef TEST_FOR_X XDrawLine(display, window, gc, x1, 0, x1, 479); XFlush(display); #else GrLine(window, gc, x1, 0, x1, 479); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // General Line ///////////////////////////////////////////////// printf("General Line(XDrawLine)\n"); start_timer(); for(c=0; c<count*22; c++) { x1 = random()%640; x2 = random()%640; y1 = random()%480; y2 = random()%480; #ifdef TEST_FOR_X XDrawLine(display, window, gc, x1, y1, x2, y2); XFlush(display); #else GrLine(window, gc, x1, y1, x2, y2); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // Point ////////////////////////////////////////////////// printf("XPoint\n"); start_timer(); for(c=0; c<count*25; c++) { x1 = random()%640; y1 = random()%480; #ifdef TEST_FOR_X XDrawPoint(display, window, gc, x1, y1); XFlush(display); #else GrPoint(window, gc, x1, y1); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // Rectangle ////////////////////////////////////////////////// printf("XRectangle\n"); start_timer(); for(c=0; c<count*20; c++) { x1=random()%639; y1=random()%479; x2=random()%(639-x1)+1; y2=random()%(479-y1)+1; #ifdef TEST_FOR_X XDrawRectangle(display, window, gc, x1, y1, x2, y2); XFlush(display); #else GrRect(window, gc, x1, y1, x2, y2); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // FillRectangle ////////////////////////////////////////////////// printf("XFillRectangle\n"); start_timer(); for(c=0; c<count*18; c++) { x1=random()%639; y1=random()%479; x2=random()%(639-x1)+1; y2=random()%(479-y1)+1; #ifdef TEST_FOR_X XFillRectangle(display, window, gc, x1, y1, x2, y2); XFlush(display); #else GrFillRect(window, gc, x1, y1, x2, y2); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // FillPolygon ////////////////////////////////////////////////// printf("XFillPolygon\n"); start_timer(); for(c=0; c<count; c++) { for(c1=0; c1<NUM_POINTS; c1++) { points[c1].x = random()%640; points[c1].y = random()%480; } #ifdef TEST_FOR_X XFillPolygon(display, window, gc, points, NUM_POINTS, 0, 0); XFlush(display); #else GrFillPoly(window, gc, NUM_POINTS, points); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // CopyArea ///////////////////////////////////////////////// printf("XCopyArea\n"); start_timer(); for(c=0; c<count*5; c++) { x1=random()%320; y1=random()%240; x2=random()%319+1; y2=random()%239+1; #ifdef TEST_FOR_X XCopyArea(display, src_pixmap, window, gc, 0, 0, x2, y2, x1, y1); XFlush(display); #else GrCopyArea(window, gc, x1, y1, x2 ,y2, src_pixmap, 0, 0, 0); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XDestroyWindow(display, window); #else GrClose(); #endif }
int main(int argc,char **argv) { GR_EVENT event; /* current event */ GR_BITMAP bitmap1fg[7]; /* bitmaps for first cursor */ GR_BITMAP bitmap1bg[7]; GR_BITMAP bitmap2fg[7]; /* bitmaps for second cursor */ GR_BITMAP bitmap2bg[7]; if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } GrReqShmCmds(655360); GrGetScreenInfo(&si); COLS = si.cols - 40; ROWS = si.rows - 80; /* print error, but don't exit*/ GrSetErrorHandler(errorcatcher); w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 100, 50, COLS - 120, ROWS - 60, 1, BROWN, WHITE); w2 = GrNewWindow(GR_ROOT_WINDOW_ID, 6, 6, W2_WIDTH, W2_HEIGHT, 2, GREEN, WHITE); w3 = GrNewWindow(GR_ROOT_WINDOW_ID, 250, 30, 80, 100, 1, LTGRAY, GREEN); w4 = GrNewWindow(GR_ROOT_WINDOW_ID, 350, 20, 200, 150, 5, BLACK, WHITE); w5 = GrNewWindow(GR_ROOT_WINDOW_ID, 11, 143, 209, 100, 1, BLUE, GREEN); GrSelectEvents(w1, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | GR_EVENT_MASK_CLOSE_REQ); /* must select down and up for w2 to get implicit grab when * running window manager, otherwise the wm-created parent * window will get the grab, and we won't get the button up... */ GrSelectEvents(w2, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(w3, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(w4, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_POSITION | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(w5, GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_CLOSE_REQ); GrMapWindow(w1); GrMapWindow(w2); GrMapWindow(w3); GrMapWindow(w4); GrMapWindow(w5); gc1 = GrNewGC(); gc2 = GrNewGC(); gc3 = GrNewGC(); gc4 = GrNewGC(); GrSetGCForeground(gc1, RED); GrSetGCBackground(gc1, BROWN); GrSetGCForeground(gc2, MAGENTA); GrSetGCMode(gc4, GR_MODE_XOR); bitmap1fg[0] = MASK(_,_,_,X,_,_,_); bitmap1fg[1] = MASK(_,_,_,X,_,_,_); bitmap1fg[2] = MASK(_,_,_,X,_,_,_); bitmap1fg[3] = MASK(X,X,X,X,X,X,X); bitmap1fg[4] = MASK(_,_,_,X,_,_,_); bitmap1fg[5] = MASK(_,_,_,X,_,_,_); bitmap1fg[6] = MASK(_,_,_,X,_,_,_); bitmap1bg[0] = MASK(_,_,X,X,X,_,_); bitmap1bg[1] = MASK(_,_,X,X,X,_,_); bitmap1bg[2] = MASK(X,X,X,X,X,X,X); bitmap1bg[3] = MASK(X,X,X,X,X,X,X); bitmap1bg[4] = MASK(X,X,X,X,X,X,X); bitmap1bg[5] = MASK(_,_,X,X,X,_,_); bitmap1bg[6] = MASK(_,_,X,X,X,_,_); bitmap2fg[0] = MASK(_,_,X,X,X,_,_); bitmap2fg[1] = MASK(_,X,_,_,_,X,_); bitmap2fg[2] = MASK(X,_,_,_,_,_,X); bitmap2fg[3] = MASK(X,_,_,_,_,_,X); bitmap2fg[4] = MASK(_,X,_,_,_,X,_); bitmap2fg[5] = MASK(_,_,X,X,X,_,_); bitmap2bg[0] = MASK(_,_,X,X,X,_,_); bitmap2bg[1] = MASK(_,X,X,X,X,X,_); bitmap2bg[2] = MASK(X,X,X,X,X,X,X); bitmap2bg[3] = MASK(X,X,X,X,X,X,X); bitmap2bg[4] = MASK(_,X,X,X,X,X,_); bitmap2bg[5] = MASK(_,_,X,X,X,_,_); GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg); GrSetCursor(w2, 7, 7, 3, 3, WHITE, BLACK, bitmap2fg, bitmap2bg); while (1) { GrCheckNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_BUTTON_DOWN: do_buttondown(&event.button); break; case GR_EVENT_TYPE_BUTTON_UP: do_buttonup(&event.button); break; case GR_EVENT_TYPE_MOUSE_POSITION: case GR_EVENT_TYPE_MOUSE_MOTION: do_motion(&event.mouse); break; case GR_EVENT_TYPE_KEY_DOWN: do_keystroke(&event.keystroke); break; case GR_EVENT_TYPE_EXPOSURE: do_exposure(&event.exposure); break; case GR_EVENT_TYPE_FOCUS_IN: do_focusin(&event.general); break; case GR_EVENT_TYPE_FOCUS_OUT: do_focusout(&event.general); break; case GR_EVENT_TYPE_MOUSE_ENTER: do_enter(&event.general); break; case GR_EVENT_TYPE_MOUSE_EXIT: do_exit(&event.general); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); case GR_EVENT_TYPE_NONE: do_idle(); break; } } }
int main(int argc,char **argv) { GR_EVENT event; /* current event */ GR_BITMAP bitmap1fg[7]; /* bitmaps for first cursor */ GR_BITMAP bitmap1bg[7]; GR_BITMAP bitmap2fg[7]; /* bitmaps for second cursor */ GR_BITMAP bitmap2bg[7]; if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } GrGetScreenInfo(&si); w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 100, 50, si.cols - 120, si.rows - 60, 1, BROWN, WHITE); w2 = GrNewWindow(GR_ROOT_WINDOW_ID, 6, 6, W2_WIDTH, W2_HEIGHT, 2, GREEN, WHITE); w3 = GrNewWindow(GR_ROOT_WINDOW_ID, 250, 30, 80, 100, 1, LTGRAY, GREEN); w4 = GrNewWindow(GR_ROOT_WINDOW_ID, 350, 20, 200, 150, 5, BLACK, WHITE); w5 = GrNewWindow(GR_ROOT_WINDOW_ID, 11, 143, 209, 100, 1, BLUE, GREEN); p1 = GrNewPixmap(200,200,0); GrSelectEvents(w1, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(w2, GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(w3, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(w4, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_POSITION | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(w5, GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_CLOSE_REQ); GrMapWindow(w1); GrMapWindow(w2); GrMapWindow(w3); GrMapWindow(w4); GrMapWindow(w5); gc1 = GrNewGC(); gc2 = GrNewGC(); gc3 = GrNewGC(); gc4 = GrNewGC(); GrSetGCForeground(gc1, RED); GrSetGCBackground(gc1, BROWN); GrSetGCForeground(gc2, MAGENTA); GrSetGCMode(gc4, GR_MODE_XOR); bitmap1fg[0] = MASK(_,_,_,X,_,_,_); bitmap1fg[1] = MASK(_,_,_,X,_,_,_); bitmap1fg[2] = MASK(_,_,_,X,_,_,_); bitmap1fg[3] = MASK(X,X,X,X,X,X,X); bitmap1fg[4] = MASK(_,_,_,X,_,_,_); bitmap1fg[5] = MASK(_,_,_,X,_,_,_); bitmap1fg[6] = MASK(_,_,_,X,_,_,_); bitmap1bg[0] = MASK(_,_,X,X,X,_,_); bitmap1bg[1] = MASK(_,_,X,X,X,_,_); bitmap1bg[2] = MASK(X,X,X,X,X,X,X); bitmap1bg[3] = MASK(X,X,X,X,X,X,X); bitmap1bg[4] = MASK(X,X,X,X,X,X,X); bitmap1bg[5] = MASK(_,_,X,X,X,_,_); bitmap1bg[6] = MASK(_,_,X,X,X,_,_); bitmap2fg[0] = MASK(_,_,X,X,X,_,_); bitmap2fg[1] = MASK(_,X,_,_,_,X,_); bitmap2fg[2] = MASK(X,_,_,_,_,_,X); bitmap2fg[3] = MASK(X,_,_,_,_,_,X); bitmap2fg[4] = MASK(_,X,_,_,_,X,_); bitmap2fg[5] = MASK(_,_,X,X,X,_,_); bitmap2bg[0] = MASK(_,_,X,X,X,_,_); bitmap2bg[1] = MASK(_,X,X,X,X,X,_); bitmap2bg[2] = MASK(X,X,X,X,X,X,X); bitmap2bg[3] = MASK(X,X,X,X,X,X,X); bitmap2bg[4] = MASK(_,X,X,X,X,X,_); bitmap2bg[5] = MASK(_,_,X,X,X,_,_); GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg); GrSetCursor(w2, 7, 6, 3, 3, WHITE, BLACK, bitmap2fg, bitmap2bg); GrRect(GR_ROOT_WINDOW_ID, gc1, 0, 0, si.cols, si.rows); while (1) { GrGetNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_BUTTON_DOWN: do_buttondown(&event.button); break; case GR_EVENT_TYPE_BUTTON_UP: do_buttonup(&event.button); break; case GR_EVENT_TYPE_MOUSE_POSITION: case GR_EVENT_TYPE_MOUSE_MOTION: do_motion(&event.mouse); break; case GR_EVENT_TYPE_KEY_DOWN: do_keystroke(&event.keystroke); break; case GR_EVENT_TYPE_EXPOSURE: do_exposure(&event.exposure); break; case GR_EVENT_TYPE_FOCUS_IN: do_focusin(&event.general); break; case GR_EVENT_TYPE_FOCUS_OUT: do_focusout(&event.general); break; case GR_EVENT_TYPE_MOUSE_ENTER: do_enter(&event.general); break; case GR_EVENT_TYPE_MOUSE_EXIT: do_exit(&event.general); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); case GR_EVENT_TYPE_NONE: do_idle(); break; } } }