void topbar_mousemoved(win *window, GR_EVENT_MOUSE *event) { struct position *pos; GR_WM_PROPERTIES props; Dprintf("topbar_mousemoved window %d\n", window->wid); if(!window->active) return; pos = (struct position *) window->data; /* turn off background erase draw while moving*/ GrGetWMProperties(window->pid, &props); if (props.title) free(props.title); props.flags = GR_WM_FLAGS_PROPS; props.props |= GR_WM_PROPS_NOBACKGROUND; GrSetWMProperties(window->pid, &props); GrMoveWindow(window->pid, event->rootx - pos->x, event->rooty - pos->y); props.props &= ~GR_WM_PROPS_NOBACKGROUND; GrSetWMProperties(window->pid, &props); }
static void create_aux_windows (_THIS) { GR_WM_PROPERTIES props ; Dprintf ("enter create_aux_windows\n") ; // Don't create any extra windows if we are being managed if (SDL_windowid) { FSwindow = 0 ; return ; } if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) { GrDestroyWindow (FSwindow) ; } FSwindow = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, BLACK, BLACK) ; props.flags = GR_WM_FLAGS_PROPS ; props.props = GR_WM_PROPS_NODECORATE ; GrSetWMProperties (FSwindow, & props) ; GrSelectEvents (FSwindow, (GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE | GR_EVENT_MASK_CLOSE_REQ)) ; Dprintf ("leave create_aux_windows\n") ; }
void wm_init(void) { GR_WM_PROPERTIES props; win window; static int init = 0; if(!init) { init = 1; /* add root window*/ window.wid = GR_ROOT_WINDOW_ID; window.pid = GR_ROOT_WINDOW_ID; window.type = WINDOW_TYPE_ROOT; window.clientid = 1; window.sizing = GR_FALSE; window.active = 0; window.data = NULL; wm_add_window(&window); GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_CHLD_UPDATE); /* Set new root window background color*/ props.flags = GR_WM_FLAGS_BACKGROUND; props.background = GrGetSysColor(GR_COLOR_DESKTOP); GrSetWMProperties(GR_ROOT_WINDOW_ID, &props); } }
void XSetWMName(Display * display, Window w, XTextProperty * name) { GR_WM_PROPERTIES props; if (!name || !name->value) return; props.flags = GR_WM_FLAGS_TITLE; props.title = name->value; GrSetWMProperties(w, &props); }
static void GrSetWMPropertiesWrapper(void *r) { nxSetWMPropertiesReq *req = r; GR_WM_PROPERTIES *props = GetReqData(req); if(GetReqVarLen(req) - sizeof(GR_WM_PROPERTIES)) props->title = (GR_CHAR *)props + sizeof(GR_WM_PROPERTIES); else props->title = NULL; GrSetWMProperties(req->windowid, props); }
nxeyes_state *init(void) { nxeyes_state *state; GR_REGION_ID rid1, rid2; GR_SCREEN_INFO si; GR_WM_PROPERTIES props; if(!(state = malloc(sizeof(nxeyes_state)))) return NULL; state->oldx = state->oldy = state->x = state->y = 0; state->button_down = state->eyes_closed = state->quit = 0; state->olx = state->orx = EYEMASK_WIDTH / 2; state->oly = state->ory = EYEMASK_HEIGHT / 2; GrGetScreenInfo(&si); state->mousex = si.xpos; state->mousey = si.ypos; state->mouse_moved = 1; state->gc = GrNewGC(); GrSetGCForeground(state->gc, GR_COLOR_WHITE); GrSetGCBackground(state->gc, GR_COLOR_BLACK); state->wid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, (EYEFG_HEIGHT * 2) + EYE_SPACING, EYEFG_HEIGHT, 0, GR_COLOR_WHITE, 0); rid1 = GrNewBitmapRegion(eyemask_bits, EYEMASK_WIDTH, EYEMASK_HEIGHT); rid2 = GrNewBitmapRegion(eyemask_bits, EYEMASK_WIDTH, EYEMASK_HEIGHT); GrOffsetRegion(rid2, EYEMASK_WIDTH + EYE_SPACING, 0); GrUnionRegion(rid1, rid1, rid2); GrSetWindowRegion(state->wid, rid1, GR_WINDOW_BOUNDING_MASK); GrDestroyRegion(rid1); GrDestroyRegion(rid2); props.flags = GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_NODECORATE; GrSetWMProperties(state->wid, &props); GrSelectEvents(state->wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_MOUSE_POSITION | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_TIMER); GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_MOUSE_POSITION); GrMapWindow(state->wid); srand(123); #if MW_FEATURE_TIMERS start_blink_timer(state); #endif return state; }
CRJinkeScreen( int width, int height ) : CRGUIScreenBase( width, height, true ) { if( GrOpen() < 0 ) { fprintf(stderr, "Couldn't connect to Nano-X server\n"); return; } GR_WM_PROPERTIES props; //GR_SCREEN_INFO si; //GrGetScreenInfo(&si); _wid = GrNewWindow(GR_ROOT_WINDOW_ID,VIEWER_WINDOW_X,VIEWER_WINDOW_Y, VIEWER_WINDOW_WIDTH,VIEWER_WINDOW_HEIGHT, 0, GR_COLOR_WHITE, 0); _gc = GrNewGC(); GrSetGCForeground(_gc, GR_COLOR_BLACK); GrSetGCBackground(_gc, GR_COLOR_WHITE); GrSelectEvents(_wid, GR_EVENT_MASK_BUTTON_DOWN | \ GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_POSITION |\ GR_EVENT_MASK_EXPOSURE |GR_EVENT_MASK_KEY_UP|\ GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_CLOSE_REQ); //Set Windows style props.flags = GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_NODECORATE; GrSetWMProperties(_wid, &props); //#ifndef USE_OLD_NANOX GrMapWindow(_wid); GrSetFocus(_wid); //#endif _canvas = LVRef<LVDrawBuf>( new LVGrayDrawBuf( _width, _height, GRAY_BACKBUFFER_BITS ) ); _front = LVRef<LVDrawBuf>( new LVGrayDrawBuf( _width, _height, GRAY_BACKBUFFER_BITS ) ); _canvas->Clear(0xFFFFFF); //_front->Clear(0xFFFFFF); _front->Clear(0x000000); instance = this; }
static void _nxDelPropData(struct window_props *prop) { /* delete XA_WM_TRANSIENT_FOR data*/ if ((prop->property == XA_WM_TRANSIENT_FOR) && prop->data) { Window prop_window = *((Window*)prop->data); GR_WM_PROPERTIES props; GrGetWMProperties(prop_window, &props); if (props.title) free(props.title); props.flags = GR_WM_FLAGS_PROPS; props.props &= ~(GR_WM_PROPS_NORAISE | GR_WM_PROPS_NOMOVE | GR_WM_PROPS_NOFOCUS); GrSetWMProperties(prop_window, &props); GrSetFocus(prop_window); } if (prop->data) Xfree(prop->data); Xfree(prop); }
void set_window_background_colour(char *buf, int lineno) { GR_WM_PROPERTIES props; char *p = buf, *pp; while(isspace(*p)) p++; if(!*p) { GrError("Premature end of line on line %d of config " "file\n", lineno); return; } pp = p; while(*p && (!isspace(*p))) p++; *p = 0; /* FIXME: Pick out a wider selection of named colours, and perhaps add * support for specifying a hex triplet. */ if(!strcmp(pp, "BLACK")) props.background = GR_COLOR_BLACK; else if(!strcmp(pp, "WHITE")) props.background = GR_COLOR_WHITE; else if(!strcmp(pp, "RED")) props.background = GR_COLOR_RED; else if(!strcmp(pp, "GREEN")) props.background = GR_COLOR_GREEN; else if(!strcmp(pp, "BLUE")) props.background = GR_COLOR_BLUE; else if(!strcmp(pp, "CYAN")) props.background = GR_COLOR_CYAN; else if(!strcmp(pp, "MAGENTA")) props.background = GR_COLOR_MAGENTA; else if(!strcmp(pp, "YELLOW")) props.background = GR_COLOR_YELLOW; else if(!strcmp(pp, "BROWN")) props.background = GR_COLOR_BROWN; else if(!strcmp(pp, "GRAY")) props.background = GR_COLOR_GRAY; else { GrError("Invalid colour \"%s\" on line %d of config " "file\n", pp, lineno); return; } props.flags = GR_WM_FLAGS_BACKGROUND; GrSetWMProperties(GR_ROOT_WINDOW_ID, &props); }
/* ***********************************************************/ int main(int argc, char* argv[]) { GR_EVENT event; GR_WM_PROPERTIES props; int computer_side; char s[256]; int i; BOOL found; char temp[50]; if (GrOpen() < 0) { fprintf(stderr, "tuxchess: cannot open graphics\n"); exit(1); } load_images(); master = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, BM_WIDTH, BM_HEIGHT, 0, WHITE, WHITE); board = GrNewWindow((GR_WINDOW_ID) master, 0, 0, 394, 394, 0, WHITE, WHITE); text = GrNewWindow((GR_WINDOW_ID) master, 0, 393, 394, 20, 0, BLACK, BLACK); GrSelectEvents(master, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE; props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION | GR_WM_PROPS_CLOSEBOX; props.title = TITLE; GrSetWMProperties(master, &props); /* eliminate white background*/ props.flags = GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_NOBACKGROUND; GrSetWMProperties(board, &props); GrMapWindow(master); GrMapWindow(board); GrMapWindow(text); gc = GrNewGC(); text_gc = GrNewGC(); init(); gen(); max_time = 1 << 25; max_depth = 4; if (argc > 1) computer_side = side; /* computer plays white */ else { computer_side = EMPTY; /* human plays white */ gprintf("Make a move..."); } for (;;) { if (side == computer_side) { /* think about the move and make it */ think(0); if (!pv[0][0].u) { gprintf("No legal moves"); computer_side = EMPTY; continue; } sprintf(temp,"Computer's move: %s\n", move_str(pv[0][0].b)); gprintf(temp); makemove(pv[0][0].b); ply = 0; gen(); print_board(); print_result(); continue; } GrGetNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); /* no return*/ case GR_EVENT_TYPE_EXPOSURE: print_board(); gprintf(NULL); break; case GR_EVENT_TYPE_BUTTON_DOWN: mouse_hit(event.button.x, event.button.y); break; } if (to != 999) { /* loop through the moves to see if it's legal */ found = FALSE; for (i = 0; i < first_move[1]; ++i) if (gen_dat[i].m.b.from == from && gen_dat[i].m.b.to == to) { found = TRUE; /* get the promotion piece right */ if (gen_dat[i].m.b.bits & 32) switch (s[4]) { case 'N': break; case 'B': i += 1; break; case 'R': i += 2; break; default: i += 3; break; } break; } /* if */ if (!found || !makemove(gen_dat[i].m.b)) gprintf("Illegal move.\n"); else { ply = 0; gen(); print_board(); print_result(); computer_side = side; to = 999; } } /* if to != 999 */ } /* for (;;) */ return(0); /* never reached */ }
int main(int argc, char **argv) { GR_EVENT event; /* current event */ if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } GrReqShmCmds(65536); /* shared mem is suposed to be faster */ w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, WIDTH, HEIGHT, 4, WHITE, BLACK); GrSelectEvents(w1, 0xffffffffl); /* all events :) */ w2 = GrNewWindow(w1, 10, 10, WIDTH / 4, HEIGHT / 4, 4, WHITE, BLACK); GrSelectEvents(w2, 0xffffffffl); /* all events :) */ { GR_WM_PROPERTIES props; props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE; props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION | \ GR_WM_PROPS_CAPTION | GR_WM_PROPS_CLOSEBOX; props.title = "nano-X Events"; GrSetWMProperties(w1, &props); } GrMapWindow(w1); GrMapWindow(w2); gc1 = GrNewGC(); GrSetGCForeground(gc1, BLACK); GrSetGCBackground(gc1, WHITE); #ifdef ALT_CURSOR { GR_BITMAP bitmap1fg[7]; /* bitmaps for cursor */ GR_BITMAP bitmap1bg[7]; bitmap1bg[0] = MASK(X,X,X,X,X,X,X); bitmap1bg[1] = MASK(_,X,X,X,X,X,_); bitmap1bg[2] = MASK(_,_,X,X,X,_,_); bitmap1bg[3] = MASK(_,_,_,X,_,_,_); bitmap1bg[4] = MASK(_,_,X,X,X,_,_); bitmap1bg[5] = MASK(_,X,X,X,X,X,_); bitmap1bg[6] = MASK(X,X,X,X,X,X,X); bitmap1fg[0] = MASK(X,X,X,X,X,X,X); bitmap1fg[1] = MASK(_,X,X,X,X,X,_); bitmap1fg[2] = MASK(_,_,X,X,X,_,_); bitmap1fg[3] = MASK(_,_,_,X,_,_,_); bitmap1fg[4] = MASK(_,_,X,X,X,_,_); bitmap1fg[5] = MASK(_,X,X,X,X,X,_); bitmap1fg[6] = MASK(X,X,X,X,X,X,X); GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg); } #endif for (;;) { GrGetNextEvent(&event); printf("%s (0x%x)\n", \ lookupEvent(event.type), event.type); switch(event.type) { case GR_EVENT_TYPE_EXPOSURE: { printf("\twid = %d\n", event.exposure.wid); printf("\t(X, Y) = (%d, %d)\n", \ event.exposure.x, event.exposure.y); printf("\twidth = %d, height = %d\n", \ event.exposure.width, event.exposure.height); } break; case GR_EVENT_TYPE_BUTTON_DOWN: case GR_EVENT_TYPE_BUTTON_UP: { printf("\twid = %d\n", event.button.wid); printf("\tsub-window id = %d\n", event.button.subwid); printf("\troot window (X, Y) coordinates = (%d, %d)\n", \ event.button.rootx, event.button.rooty); printf("\t(X, Y) = (%d, %d)\n", \ event.button.x, event.button.y); printf("\tbuttons: %04X, ", event.button.buttons); printf("changed buttons: %04X\n", event.button.changebuttons); printf("\tmodifiers: %04X\n", event.button.modifiers); } break; case GR_EVENT_TYPE_MOUSE_ENTER: case GR_EVENT_TYPE_MOUSE_EXIT: case GR_EVENT_TYPE_MOUSE_MOTION: case GR_EVENT_TYPE_MOUSE_POSITION: { printf("\twid = %d\n", event.mouse.wid); printf("\tsub-window id = %d\n", event.mouse.subwid); printf("\troot window (X, Y) coordinates = (%d, %d)\n", \ event.mouse.rootx, event.mouse.rooty); printf("\t(X, Y) = (%d, %d)\n", \ event.mouse.x, event.mouse.y); printf("\tbuttons: %04X\n", event.mouse.buttons); printf("\tmodifiers: %04X\n", event.mouse.modifiers); } break; case GR_EVENT_TYPE_KEY_DOWN: case GR_EVENT_TYPE_KEY_UP: { printf("\twid = %d\n", event.keystroke.wid); printf("\tsub-window id = %d\n", event.keystroke.subwid); printf("\troot window (X, Y) coordinates = (%d, %d)\n", \ event.keystroke.rootx, event.keystroke.rooty); printf("\t(X, Y) = (%d, %d)\n", \ event.keystroke.x, event.keystroke.y); printf("\tbuttons: %04X\n", event.keystroke.buttons); printf("\tmodifiers: %04X\n", event.keystroke.modifiers); printf("\tUnicode-16 keyvalue: %d, ASCII: %d\n", \ (int)event.keystroke.ch, event.keystroke.ch); printf("\tscancode: %02X\n", (int)event.keystroke.scancode); } break; case GR_EVENT_TYPE_FOCUS_IN: printf("\twid = %d\n", event.general.wid); printf("\told focus = %d\n", event.general.otherid); break; case GR_EVENT_TYPE_FOCUS_OUT: printf("\twid = %d\n", event.general.wid); printf("\tnew focus = %d\n", event.general.otherid); break; case GR_EVENT_TYPE_UPDATE: case GR_EVENT_TYPE_CHLD_UPDATE: { printf("\twid = %d\n", event.update.wid); printf("\tsub-window id = %d\n", event.update.subwid); printf("\t(X, Y) = (%d, %d)\n", \ event.update.x, event.update.y); printf("\twidth = %d, height = %d\n", \ event.update.width, event.update.height); { GR_UPDATE_TYPE u = event.update.utype; const char* p; p = (u > NR_UPDATES)? \ "<unknown>": \ update_types[u].name; printf("\tupdate_type: %s (%d)\n", p, u); } } break; case GR_EVENT_TYPE_TIMEOUT: printf("\ttimeout?\n"); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); /* no return*/ } } return 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(); }
void initialise(lstate *state) { GR_SCREEN_INFO si; GR_IMAGE_ID back_image; GR_IMAGE_INFO imageinfo; int rows = 1, columns = 1, width, height, x = 0, y = 0; GR_WM_PROPERTIES props; litem *i; if(GrOpen() < 0) { GrError("Couldn't connect to Nano-X server\n"); exit(4); } state->window_background_mode = 0; state->window_background_image = NULL; sspid = -1; read_config(state); GrGetScreenInfo(&si); if(si.rows > si.cols) { rows = state->numlitems; while((((rows / columns) + rows % columns) * ITEM_HEIGHT) > si.rows) { columns++; } if((columns * ITEM_WIDTH) > si.cols) goto toomany; rows = (rows / columns) + (rows % columns); width = columns * ITEM_WIDTH + 1 + columns; height = rows * ITEM_HEIGHT + 1 + rows; } else { columns = state->numlitems; while((((columns / rows) + (columns % rows)) * ITEM_WIDTH) > si.cols) { rows++; } if((rows * ITEM_HEIGHT) > si.rows) goto toomany; columns = (columns / rows) + (columns % rows); width = columns * ITEM_WIDTH + 1 + columns; height = (rows * ITEM_HEIGHT) + 1 + rows; y = si.rows - (rows * ITEM_HEIGHT) - 1 - rows; } state->gc = GrNewGC(); GrSetGCForeground(state->gc, ITEM_TEXT_COLOUR); GrSetGCBackground(state->gc, ITEM_BACKGROUND_COLOUR); if(state->window_background_image) { if(!(back_image = GrLoadImageFromFile( state->window_background_image, 0))) { GrError("Couldn't load background image\n"); } else { GrGetImageInfo(back_image, &imageinfo); if(!(state->background_pixmap = GrNewPixmap( imageinfo.width, imageinfo.height, NULL))) { GrError("Couldn't allocate pixmap " "for background image\n"); } else { GrDrawImageToFit(state->background_pixmap, state->gc, 0, 0, imageinfo.width, imageinfo.height, back_image); GrFreeImage(back_image); GrSetBackgroundPixmap(GR_ROOT_WINDOW_ID, state->background_pixmap, state->window_background_mode); GrClearWindow(GR_ROOT_WINDOW_ID, GR_TRUE); } } } if(state->ssitems) GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_SCREENSAVER); state->main_window = GrNewWindow(GR_ROOT_WINDOW_ID, 0, y, width, height, 0, ITEM_BACKGROUND_COLOUR, 0); GrSelectEvents(state->main_window, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_TIMER); props.flags = GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_NOMOVE | GR_WM_PROPS_NODECORATE | GR_WM_PROPS_NOAUTOMOVE | GR_WM_PROPS_NOAUTORESIZE; GrSetWMProperties(state->main_window, &props); i = state->lastlitem; y = 0; while(i) { i->wid = GrNewWindow(state->main_window, (x * ITEM_WIDTH) + x + 1, (y * ITEM_HEIGHT) + y + 1, ITEM_WIDTH, ITEM_HEIGHT, 1, ITEM_BACKGROUND_COLOUR, ITEM_BORDER_COLOUR); GrSelectEvents(i->wid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrMapWindow(i->wid); i = i->prev; if(++x == columns) { x = 0; y++; } } GrMapWindow(state->main_window); signal(SIGCHLD, &reaper); do_startups(state); return; toomany: GrError("Too many items to fit on screen\n"); exit(6); }
/* Initialise the game and return the state structure or NULL on failure: */ nbstate *init(int argc, char *argv[]) { GR_PROP *prop; nbstate *state; GR_SCREEN_INFO si; GR_BITMAP cursor = 0; GR_WM_PROPERTIES props; /* Try to connect to the Nano-X server: */ if(GrOpen() < 1) { fprintf(stderr, "Couldn't connect to Nano-X server\n"); return NULL; } /* Check that the server was built with alpha blending support * (necessary for the alpha blended sprites and special effects): */ GrGetScreenInfo(&si); if(!si.alphablend) { fprintf(stderr, "Error: Nano-X server was built without alpha " "blending support\nSet ALPHABLENDING = 1 in " "include/device.h, rebuild, and try again.\n"); return NULL; } /* Allocate the state structure and initialise it with defaults: */ if(!(state = malloc(sizeof(nbstate)))) return NULL; setup_default_state(state); /* Try to parse the command line arguments: */ if(parse_cmd_args(state, argc, argv)) { free(state); return NULL; } /* Try to load the game file: */ if(load_game_file(state)) { free(state); return NULL; } /* Load the high score file: */ load_hiscore(state); /* Calculate the canvas size: */ state->canvaswidth = state->width * state->brickwidth; state->canvasheight = state->scores.h + state->ball.s->h + (2 * BALLS_BORDER) + (state->height * state->brickheight) + 3 * state->brickheight + state->batheight; /* Place the bat in the centre of the window: */ state->batx = state->canvaswidth / 2; /* Create various pixmaps and alpha channels: */ state->scores.p = GrNewPixmap(state->canvaswidth, state->scores.h, NULL); state->scores.a = GrNewAlpha(state->canvaswidth, state->scores.h); state->canvas = GrNewPixmap(state->canvaswidth, state->canvasheight, NULL); /* The new and old canvasses are only used when screen fading is * enabled: */ if(state->faderate) { state->newcanvas = GrNewPixmap(state->canvaswidth, state->canvasheight, NULL); state->oldcanvas = GrNewPixmap(state->canvaswidth, state->canvasheight, NULL); } state->brickalpha = GrNewAlpha(state->brickwidth, state->brickheight); /* Start off with the canvas completely black: */ GrSetGCForeground(state->gc, GR_COLOR_BLACK); GrFillRect(state->canvas, state->gc, 0, 0, state->canvaswidth, state->canvasheight); /* If there is a window manager running, place the window off the * screen and let the window manager move it where it wants (avoids * flicker if we were to draw the window on screen before the window * manager moved it somewhere else): */ if(GrGetWindowProperty(GR_ROOT_WINDOW_ID, "WINDOW_MANAGER", &prop)) { free(prop); state->winx = GR_OFF_SCREEN; } /* Create the output window: */ state->wid = GrNewWindow(GR_ROOT_WINDOW_ID, state->winx, 0, state->canvaswidth, state->canvasheight, 0, 0, 0); /* Set the window title: */ props.flags = GR_WM_FLAGS_TITLE; props.title = "NanoBreaker"; GrSetWMProperties(state->wid, &props); /* Make the cursor over the output window be invisible: */ GrSetCursor(state->wid, 1, 1, 1, 1, 0, 0, &cursor, &cursor); /* Select the events we want to receive for the output window: */ GrSelectEvents(state->wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | GR_EVENT_MASK_UPDATE | GR_EVENT_MASK_TIMER); /* Select for mouse position events on the root window so we can move * the bat even when the pointer strays outside the window (which it * often does because the cursor is invisible you don't know exactly * where it is): */ GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_MOUSE_POSITION); /* Map the output window (make it visible): */ GrMapWindow(state->wid); /* Create the one second periodic timer that is used to decrement the * power-up and power-down timers: */ state->tid = GrCreateTimer(state->wid, 1000, GR_TRUE); /* Reset the game: */ reset_game(state); return state; /* Return the newly allocated state structure. */ }
// Set the window manager decorations according to the // given wxWidgets style bool wxSetWMDecorations(Window w, long style) { #if wxUSE_NANOX GR_WM_PROPERTIES wmProp; wmProp.flags = 0; wmProp.props = 0; if (style & wxRESIZE_BORDER) { wmProp.props |= GR_WM_PROPS_APPFRAME ; wmProp.flags |= GR_WM_FLAGS_PROPS ; } if (style & wxCLOSE_BOX) { wmProp.props |= GR_WM_PROPS_CLOSEBOX ; wmProp.flags |= GR_WM_FLAGS_PROPS ; } if ((style & wxCAPTION) || (style & wxTINY_CAPTION)) { wmProp.props |= GR_WM_PROPS_CAPTION ; wmProp.flags |= GR_WM_FLAGS_PROPS ; // The default dialog style doesn't include any kind // of border, which is a bit odd. Anyway, inclusion // of a caption surely implies a border. style |= wxRESIZE_BORDER; } if (style & wxRESIZE_BORDER) { wmProp.props |= GR_WM_PROPS_APPFRAME ; wmProp.flags |= GR_WM_FLAGS_PROPS ; } if (style & wxSIMPLE_BORDER) { wmProp.props |= GR_WM_PROPS_BORDER ; wmProp.flags |= GR_WM_FLAGS_PROPS ; } if (style & wxMINIMIZE_BOX) { } if (style & wxMAXIMIZE_BOX) { wmProp.props |= GR_WM_PROPS_MAXIMIZE ; wmProp.flags |= GR_WM_FLAGS_PROPS ; } if ( !(style & wxBORDER) && !(style & wxRESIZE_BORDER) ) { wmProp.props |= GR_WM_PROPS_NODECORATE ; wmProp.flags |= GR_WM_FLAGS_PROPS ; } GrSetWMProperties(w, & wmProp); #else Atom mwm_wm_hints = XInternAtom(wxGlobalDisplay(),"_MOTIF_WM_HINTS", False); if (mwm_wm_hints == 0) return false; MwmHints hints; hints.flags = MWM_HINTS_DECORATIONS | MWM_HINTS_FUNCTIONS; hints.decorations = 0; hints.functions = 0; if ((style & wxSIMPLE_BORDER) || (style & wxNO_BORDER)) { // leave zeros } else { hints.decorations = MWM_DECOR_BORDER; hints.functions = MWM_FUNC_MOVE; if ((style & wxCAPTION) != 0) hints.decorations |= MWM_DECOR_TITLE; if ((style & wxSYSTEM_MENU) != 0) hints.decorations |= MWM_DECOR_MENU; if ((style & wxCLOSE_BOX) != 0) hints.functions |= MWM_FUNC_CLOSE; if ((style & wxMINIMIZE_BOX) != 0) { hints.functions |= MWM_FUNC_MINIMIZE; hints.decorations |= MWM_DECOR_MINIMIZE; } if ((style & wxMAXIMIZE_BOX) != 0) { hints.functions |= MWM_FUNC_MAXIMIZE; hints.decorations |= MWM_DECOR_MAXIMIZE; } if ((style & wxRESIZE_BORDER) != 0) { hints.functions |= MWM_FUNC_RESIZE; hints.decorations |= MWM_DECOR_RESIZEH; } } XChangeProperty(wxGlobalDisplay(), w, mwm_wm_hints, mwm_wm_hints, 32, PropModeReplace, (unsigned char *) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS); #endif return true; }
int main() { int fd = open(bri_name, O_WRONLY); if ( fd < 0) { perror(bri_name); return 1; } char buff[10]; int notquit = 1, val= read_val(bri_name), max = read_val("/sys/class/backlight/s3c/max_brightness"); if ( max <= 0) return 1; GR_WINDOW_ID wid; /* window id */ GR_GC_ID gc; /* graphics context id */ GR_EVENT event; /* current event */ GR_SCREEN_INFO si; /* screen information */ if (GrOpen() < 0) { fprintf(stderr, "Cannot open graphics\n"); return 1; } GrGetScreenInfo(&si); printf("R=%d C=%d\n", si.rows, si.cols); wid = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 50, max, HEIGHT, 1, BLACK, WHITE); GR_WM_PROPERTIES props; props.title = "Nx Light"; props.flags = GR_WM_FLAGS_TITLE; GrSetWMProperties( wid, &props); GrSelectEvents(wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_BUTTON_DOWN ); GrMapWindow(wid); gc = GrNewGC(); while (notquit) { GrGetNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_MOUSE_MOTION: if ( !((GR_EVENT_MOUSE *)&event)->buttons ) break; if ( (event.mouse.x > 0) && (event.mouse.x < max)) { snprintf(buff, 9, "%d\n", val = event.mouse.x); write( fd, buff, strlen(buff)); } GrSetGCForeground(gc, WHITE); GrFillRect(wid, gc, 0, 0, val, HEIGHT); GrSetGCForeground(gc, BLACK); GrFillRect(wid, gc, val, 0, max+1, HEIGHT); break; case GR_EVENT_TYPE_EXPOSURE: if (event.exposure.wid == wid) GrSetGCForeground(gc, WHITE); GrFillRect(wid, gc, 0, 0, val, HEIGHT); GrSetGCForeground(gc, BLACK); GrFillRect(wid, gc, val, 0, max+1, HEIGHT); break; case GR_EVENT_TYPE_CLOSE_REQ: notquit = 0; } } close(fd); return 0; }
int main(int argc, char *argv[]) #endif { GR_EVENT event; GR_WM_PROPERTIES props; win window; if(GrOpen() < 0) { fprintf(stderr, "Couldn't connect to Nano-X server!\n"); exit(1); } /* pass errors through main loop, don't exit*/ GrSetErrorHandler(NULL); GrGetScreenInfo(&si); /* add root window*/ window.wid = GR_ROOT_WINDOW_ID; window.pid = GR_ROOT_WINDOW_ID; window.type = WINDOW_TYPE_ROOT; window.clientid = 1; window.sizing = GR_FALSE; window.active = 0; window.data = NULL; add_window(&window); GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_CHLD_UPDATE); /* Set new root window background color*/ props.flags = GR_WM_FLAGS_BACKGROUND; props.background = GrGetSysColor(GR_COLOR_DESKTOP); GrSetWMProperties(GR_ROOT_WINDOW_ID, &props); while(1) { GrGetNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_ERROR: printf("nanowm: error %d\n", event.error.code); break; case GR_EVENT_TYPE_EXPOSURE: do_exposure(&event.exposure); break; case GR_EVENT_TYPE_BUTTON_DOWN: do_button_down(&event.button); break; case GR_EVENT_TYPE_BUTTON_UP: do_button_up(&event.button); break; case GR_EVENT_TYPE_MOUSE_ENTER: do_mouse_enter(&event.general); break; case GR_EVENT_TYPE_MOUSE_EXIT: do_mouse_exit(&event.general); break; case GR_EVENT_TYPE_MOUSE_POSITION: do_mouse_moved(&event.mouse); break; case GR_EVENT_TYPE_KEY_DOWN: do_key_down(&event.keystroke); break; case GR_EVENT_TYPE_KEY_UP: do_key_up(&event.keystroke); break; case GR_EVENT_TYPE_FOCUS_IN: do_focus_in(&event.general); break; case GR_EVENT_TYPE_CHLD_UPDATE: do_update(&event.update); break; default: fprintf(stderr, "Got unexpected event %d\n", event.type); break; } } GrClose(); }
void init_game(nstate *state) { GR_WM_PROPERTIES props; if(GrOpen() < 0) { fprintf(stderr, "Couldn't connect to Nano-X server\n"); exit(1); } state->main_window = GrNewWindow(GR_ROOT_WINDOW_ID, MAIN_WINDOW_X_POSITION, MAIN_WINDOW_Y_POSITION, MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT, 0, MAIN_WINDOW_BACKGROUND_COLOUR, 0); /* set title */ props.flags = GR_WM_FLAGS_TITLE | GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION; props.title = "Nano-Tetris"; GrSetWMProperties(state->main_window, &props); GrSelectEvents(state->main_window, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_TIMEOUT); state->score_window = GrNewWindow(state->main_window, SCORE_WINDOW_X_POSITION, SCORE_WINDOW_Y_POSITION, SCORE_WINDOW_WIDTH, SCORE_WINDOW_HEIGHT, 0, SCORE_WINDOW_BACKGROUND_COLOUR, 0); GrSelectEvents(state->score_window, GR_EVENT_MASK_EXPOSURE); GrMapWindow(state->score_window); state->scoregcf = GrNewGC(); GrSetGCForeground(state->scoregcf, SCORE_WINDOW_FOREGROUND_COLOUR); GrSetGCBackground(state->scoregcf, SCORE_WINDOW_BACKGROUND_COLOUR); state->scoregcb = GrNewGC(); GrSetGCForeground(state->scoregcb, SCORE_WINDOW_BACKGROUND_COLOUR); state->next_shape_window = GrNewWindow(state->main_window, NEXT_SHAPE_WINDOW_X_POSITION, NEXT_SHAPE_WINDOW_Y_POSITION, NEXT_SHAPE_WINDOW_WIDTH, NEXT_SHAPE_WINDOW_HEIGHT, 0, NEXT_SHAPE_WINDOW_BACKGROUND_COLOUR, 0); GrSelectEvents(state->next_shape_window, GR_EVENT_MASK_EXPOSURE); GrMapWindow(state->next_shape_window); state->nextshapegcf = GrNewGC(); state->nextshapegcb = GrNewGC(); GrSetGCForeground(state->nextshapegcb, NEXT_SHAPE_WINDOW_BACKGROUND_COLOUR); state->new_game_button = GrNewWindow(state->main_window, NEW_GAME_BUTTON_X_POSITION, NEW_GAME_BUTTON_Y_POSITION, NEW_GAME_BUTTON_WIDTH, NEW_GAME_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->new_game_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrMapWindow(state->new_game_button); state->buttongcf = GrNewGC(); GrSetGCForeground(state->buttongcf, BUTTON_FOREGROUND_COLOUR); GrSetGCBackground(state->buttongcf, BUTTON_BACKGROUND_COLOUR); state->buttongcb = GrNewGC(); GrSetGCForeground(state->buttongcb, BUTTON_BACKGROUND_COLOUR); state->pause_continue_button = GrNewWindow(state->main_window, PAUSE_CONTINUE_BUTTON_X_POSITION, PAUSE_CONTINUE_BUTTON_Y_POSITION, PAUSE_CONTINUE_BUTTON_WIDTH, PAUSE_CONTINUE_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->pause_continue_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->anticlockwise_button = GrNewWindow(state->main_window, ANTICLOCKWISE_BUTTON_X_POSITION, ANTICLOCKWISE_BUTTON_Y_POSITION, ANTICLOCKWISE_BUTTON_WIDTH, ANTICLOCKWISE_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->anticlockwise_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->clockwise_button = GrNewWindow(state->main_window, CLOCKWISE_BUTTON_X_POSITION, CLOCKWISE_BUTTON_Y_POSITION, CLOCKWISE_BUTTON_WIDTH, CLOCKWISE_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->clockwise_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->left_button = GrNewWindow(state->main_window, LEFT_BUTTON_X_POSITION, LEFT_BUTTON_Y_POSITION, LEFT_BUTTON_WIDTH, LEFT_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->left_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->right_button = GrNewWindow(state->main_window, RIGHT_BUTTON_X_POSITION, RIGHT_BUTTON_Y_POSITION, RIGHT_BUTTON_WIDTH, RIGHT_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->right_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->drop_button = GrNewWindow(state->main_window, DROP_BUTTON_X_POSITION, DROP_BUTTON_Y_POSITION, DROP_BUTTON_WIDTH, DROP_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->drop_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->well_window = GrNewWindow(state->main_window, WELL_WINDOW_X_POSITION, WELL_WINDOW_Y_POSITION, WELL_WINDOW_WIDTH, WELL_WINDOW_HEIGHT, 0, WELL_WINDOW_BACKGROUND_COLOUR, 0); GrSelectEvents(state->well_window, GR_EVENT_MASK_EXPOSURE); GrMapWindow(state->well_window); state->wellgc = GrNewGC(); GrMapWindow(state->main_window); state->state = STATE_STOPPED; state->score = 0; read_hiscore(state); state->level = 0; state->running_buttons_mapped = 0; srandom(time(0)); choose_new_shape(state); new_game(state); }
int XChangeProperty(Display * display, Window w, Atom property, Atom type, int format, int mode, _Xconst unsigned char *data, int nelements) { struct windows *win = NULL; struct window_props *prop = NULL; Window prop_window; int hash = w % SZHASHTABLE; GR_WM_PROPERTIES props; if (!nelements || data == NULL) { DPRINTF("XChangeProperty called with NULL data [Atom:%lx,m:%x,d:%lx]\n", type, mode, (long)data); return 1; } DPRINTF("XChangeProperty called [Atom:%lx, mode:%x, data:%lx]\n", type, mode, (long)data); win = window_list[hash]; if (!win) { win = window_list[hash] = // (struct windows *) Xcalloc(sizeof(struct windows), 1); (struct windows *) Xcalloc(1, sizeof(struct windows)); } else { struct windows *t; for (t=win; ; t=t->next) { if (t->w == w) { win = t; break; } if (!t->next) break; } if (!win) { win = t->next = //(struct windows *) Xcalloc(sizeof(struct windows), 1); (struct windows *) Xcalloc(1, sizeof(struct windows)); } } win->w = w; if (!win->properties) { prop = win->properties = //(struct window_props *) Xcalloc(sizeof(struct window_props), 1); (struct window_props *) Xcalloc(1, sizeof(struct window_props)); } else { struct window_props *t; for (t=win->properties; ; t=t->next) { if (t->property == property) { prop = t; break; } if (!t->next) break; } if (!prop) { prop = t->next = //(struct window_props *) Xcalloc(sizeof(struct window_props), 1); (struct window_props *) Xcalloc(1, sizeof(struct window_props)); } } DPRINTF("XChangeProperty: win:%x prop:%x\n", (int)w, (int)prop); switch (mode) { case PropModeAppend: // 2 case PropModePrepend: // 1 if (prop->data) { int f8 = prop->format / 8; char *p; int bytes; //DPRINTF("XChangeProperty: %d,%d\n", format, bytes); if (type != prop->type || format != prop->format) return 0; bytes = (prop->nelements + nelements) * f8; p = (char *)Xmalloc(bytes+1); /* alloc + 1 for string '\0'*/ p[bytes] = '\0'; if (mode == PropModeAppend) { memcpy(p, prop->data, prop->nelements * f8); memcpy(p + (prop->nelements * f8), data, (nelements * f8)); } else { memcpy(p, data, nelements * f8); memcpy(p + (nelements * f8), prop->data, (prop->nelements * f8)); } Xfree(prop->data); prop->data = (unsigned char *)p; prop->nelements += nelements; prop->bytes = bytes; break; } /* Fall through */ case PropModeReplace: // 0 if (prop->data) Xfree(prop->data); if (format<0 || format/8 > 4) { DPRINTF("XChangeProperty: format[%d]\n", format); format = 8; } prop->bytes = nelements * (format / 8); prop->data = (unsigned char *) Xmalloc(prop->bytes+1); /* +1 for string '\0'*/ prop->data[prop->bytes] = '\0'; //DPRINTF("XChangeProperty: [%x,%d,%x]\n", prop,nelements,prop->bytes); memcpy(prop->data, data, prop->bytes); prop->property = property; prop->type = type; prop->format = format; prop->nelements = nelements; break; } switch (property) { case XA_WM_TRANSIENT_FOR: prop_window = *((Window *)data); GrGetWMProperties(prop_window, &props); if (props.title) free(props.title); props.flags = GR_WM_FLAGS_PROPS; props.props |= (GR_WM_PROPS_NORAISE | GR_WM_PROPS_NOMOVE | GR_WM_PROPS_NOFOCUS); GrSetWMProperties(prop_window, &props); break; case XA_WM_NAME: props.flags = GR_WM_FLAGS_TITLE; props.title = (char *)prop->data; GrSetWMProperties(w, &props); break; default: break; } return 1; }
int main(int ac,char **av) { GR_WINDOW_ID w, w2; GR_GC_ID gc; GR_EVENT event; GR_WM_PROPERTIES props; if (GrOpen() < 0) { printf("Can't open graphics\n"); exit(1); } /* pass errors through main loop*/ GrSetErrorHandler(NULL); #define WIDTH 320 #define HEIGHT 240 w = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 20, WIDTH, HEIGHT, 0, GREEN, BLACK); w2 = GrNewWindow(w, 20, 20, 40, 40, 0, WHITE, BLACK); props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE; props.props = GR_WM_PROPS_NOBACKGROUND; props.title = "Nano-X Demo2"; GrSetWMProperties(w, &props); gc = GrNewGC(); GrSelectEvents(w, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP); GrMapWindow(w); GrSetFocus(w); /* serious bug here: when wm running, w2 is mapped anyway!!*/ /*GrMapWindow(w2);*/ for (;;) { /*GR_EVENT_KEYSTROKE *kev;*/ GrGetNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_EXPOSURE: GrSetGCForeground(gc,GrGetSysColor(GR_COLOR_APPWINDOW)); GrFillRect(w, gc, event.exposure.x, event.exposure.y, event.exposure.width, event.exposure.height); GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_APPTEXT)); GrSetGCUseBackground(gc, GR_FALSE); GrText(w, gc, 10, 30, "Hello World", -1, GR_TFASCII); GrRect(w, gc, 5, 5, 300, 60); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); break; case GR_EVENT_TYPE_ERROR: printf("\7demo2: Error (%s) ", event.error.name); printf(nxErrorStrings[event.error.code],event.error.id); break; #if 0 case GR_EVENT_TYPE_BUTTON_DOWN: /* test server error on bad syscall*/ GrMapWindow(w2); GrMoveWindow(GR_ROOT_WINDOW_ID, 0, 0); { GR_SCREEN_INFO sinfo; GrGetScreenInfo(&sinfo); } break; #endif #if 0 case GR_EVENT_TYPE_KEY_DOWN: kev = (GR_EVENT_KEYSTROKE *)&event; printf("DOWN %d (%04x) %04x\n", kev->ch, kev->ch, kev->modifiers); break; case GR_EVENT_TYPE_KEY_UP: kev = (GR_EVENT_KEYSTROKE *)&event; printf("UP %d (%04x) %04x\n", kev->ch, kev->ch, kev->modifiers); break; #endif } } GrClose(); return 0; }
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 ecos_nx_init(CYG_ADDRWORD data) { GR_SCREEN_INFO si; /* window information */ GR_FONT_INFO fi; /* font information */ GR_WINDOW_ID mainwid; /* main window id */ GR_WM_PROPERTIES props; GR_GC_ID gct = 0; #if 0 NWIDGET *w; NBUTTON *b; NTEXTFIELD *t; #endif cyg_thread_delay(50); INIT_PER_THREAD_DATA(); test_file_io(); if(GrOpen() < 0) { fprintf(stderr, "Couldn't connect to Nano-X server\n"); exit(1); } #if (defined CYGPKG_HAL_ARM_SA11X0_IPAQ) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS) GrSetPortraitMode(MWPORTRAIT_RIGHT); #endif GrGetScreenInfo(&si); GrGetFontInfo(0, &fi); #if 1 mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, si.cols, si.rows, 0, RED, WHITE); props.flags = GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_BORDER; GrSetWMProperties(mainwid, &props); GrMapWindow(mainwid); GrFlush(); cyg_thread_delay(50); gct = GrNewGC(); GrSetGCForeground(gct, WHITE); #ifdef CYGPKG_IO_FILEIO { struct stat stat_data; if (0 == stat("/redhat.logo", &stat_data)) { GrDrawImageFromFile(mainwid, gct, 0, 0, si.cols, si.rows, "/redhat.logo", 0); } } #endif #if (defined CYGPKG_HAL_ARM) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS) // Touch sensitive screen calibration, only relevant on some // platforms. GrSetGCFont(gct, GrCreateFont(GR_FONT_GUI_VAR, 0, NULL)); GrText(mainwid, gct, 80, 350, "Tap all 4 corners", 17, GR_TFTOP); GrFlush(); printf("Tap all four corners\n"); cyg_thread_delay(10*100); #endif #else n_init_button_class(); n_init_textfield_class(); w = NEW_NOBJECT(widget); n_widget_init(w, 0); n_widget_resize(w, si.cols - 10, si.rows - 30); n_widget_background(w, "/redhat.logo"); n_widget_show(w); b = NEW_NOBJECT(button); n_button_init(b, w, "Close"); n_button_onclick(b, do_close); n_widget_resize(b, 40, 20); n_widget_move(b,180,260); n_widget_show(b); t = NEW_NOBJECT(textfield); n_textfield_init(t,w,"Tap all 4 corners"); n_widget_move(t,45,220); n_widget_resize(t,120,20); n_widget_show(t); t = NEW_NOBJECT(textfield); n_textfield_init(t,w,"Then press close"); n_widget_move(t,45,250); n_widget_resize(t,120,20); n_widget_show(t); while (!closed) { n_handle_event(); } n_widget_hide(w); n_object_cleanup(w); #endif GrClose(); }