// Microwin driver bootstrap functions static int NX_Available () { Dprintf ("enter NX_Available\n") ; if (GrOpen () < 0) return 0 ; GrClose () ; Dprintf ("leave NX_Available\n") ; return 1 ; }
static void GrOpenWrapper(void *r) { nxOpenReq *req = r; /* store process id of client*/ curclient->processid = req->pid; GrOpen(); }
int main(int ac, char **av) { GR_EVENT event; GR_GC_ID gc; GR_WINDOW_ID pmap; GR_WINDOW_ID window; GR_WINDOW_INFO info; if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } window = nxCreateAppWindow(&ac, &av, args); gc = GrNewGC(); GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_WINDOW)); GrSetGCBackground(gc, GrGetSysColor(GR_COLOR_WINDOWTEXT)); GrSelectEvents(window, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_UPDATE | GR_EVENT_MASK_CLOSE_REQ); GrGetWindowInfo(window, &info); pmap = resize(info.width, info.height, 0); GrMapWindow(window); while (1) { GrGetNextEventTimeout(&event, 500L); switch (event.type) { case GR_EVENT_TYPE_EXPOSURE: case GR_EVENT_TYPE_TIMEOUT: draw_clock(0, 0, width, height, pmap, gc, window); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); case GR_EVENT_TYPE_UPDATE: switch (event.update.utype) { case GR_UPDATE_SIZE: pmap = resize(event.update.width, event.update.height, pmap); break; } } } return 0; }
int start(int argc, char **argv) { GR_EVENT event; nxeyes_state *state; if(GrOpen() < 0) { printf("Couldn't connect to Nano-X server\n"); return 1; } if(!(state = init())) { printf("Couldn't allocate state structure\n"); return 1; } while(!state->quit) { GrGetNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_CLOSE_REQ: state->quit = 1; break; case GR_EVENT_TYPE_MOUSE_POSITION: position_event(&event.mouse, state); break; case GR_EVENT_TYPE_BUTTON_UP: case GR_EVENT_TYPE_BUTTON_DOWN: button_event(&event.button, state); break; case GR_EVENT_TYPE_EXPOSURE: draw_eyes(state, 1); break; #if MW_FEATURE_TIMERS case GR_EVENT_TYPE_TIMER: timer_event(&event.timer, state); break; #endif default: break; } if(state->mouse_moved) { draw_eyes(state, 0); state->mouse_moved = 0; } } GrClose(); free(state); return 0; }
int main() { GR_SCREEN_INFO si; GR_FONT_INFO fi; GR_GC_INFO gi; GR_FONT fonts; int x, y; GrOpen(); GrGetScreenInfo(&si); printf("rows = %d\n", si.rows); printf("cols = %d\n", si.cols); printf("bpp = %d\n", si.bpp); printf("planes = %d\n", si.planes); printf("ncolors = %d\n", si.ncolors); printf("buttons = 0x%x\n", si.buttons); printf("modifiers = 0x%x\n", si.modifiers); printf("fonts = %d\n", si.fonts); getch(); for(fonts = 0; fonts < si.fonts; fonts++) { /* if(!GrGetFontInfo(fonts, &fi)) { */ GrGetFontInfo(fonts, &fi); if(1) { printf("\nfont = %d\n", fi.font); printf("height = %d\n", fi.height); printf("maxwidth = %d\n", fi.maxwidth); printf("baseline = %d\n", fi.baseline); printf("fixed = %s\n", fi.fixed ? "TRUE" : "FALSE"); printf("widths =\n"); for(y = 0; y != 3; y++) { for(x = 0; x != 7; x++) printf("%2d", fi.widths[x * y]); printf("\n"); getch(); } } } getch(); GrClose(); }
//------------------------------------------------------------------------------ // Function Name : init_ui_manager() // Description : //------------------------------------------------------------------------------ BOOL init_ui_manager(void) { CObject* pObject; UINT id; PRINT_FUNC_CO(); // start nano-x service if (GrOpen() < 0) { // DBGMSG(DBG_MAIN, "[Failure]\r\n--> %s: GrOpen Failed!!\r\n", __func__); return FALSE; } GrSetErrorHandler(error_handler); GrGetScreenInfo(&g_scr_info); // prepare g_font g_font = GrCreateFontEx((GR_CHAR *)FONT_PATH, 18, 18, NULL); GrSetFontAttr(g_font, (GR_TFKERNING | GR_TFANTIALIAS), 0); g_wid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, g_scr_info.cols, g_scr_info.rows, 0, BLACK, 0); if (g_wid == 0) { // DBGMSG(DBG_MAIN, "[Failure]\r\n--> %s: GrNewWindow failure\r\n", __func__); GrClose(); return FALSE; } g_gc = GrNewGC(); GrRaiseWindow(g_wid); GrMapWindow(g_wid); GrSelectEvents(g_wid, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_EXPOSURE); GrSetGCUseBackground(g_gc, FALSE); // GrSetGCUseBackground(g_gc, TRUE); GrSetGCFont(g_gc, g_font); // GrSetGCBackground(g_gc, BLACK); GrSetGCForeground(g_gc, WHITE); // BuildObject(); return TRUE; }
int main() { GR_WINDOW_ID window; GR_EVENT event; if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } window = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 20, 100, 60, 4, WHITE, BLUE); GrMapWindow(window); while(1) GrCheckNextEvent(&event); GrClose(); }
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; }
int main(int argc, char **argv) { int COLS, ROWS; if (GrOpen() == -1) exit(1); COLS = 480; ROWS = 300; load_pixmap(); g_main = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "tsdemo", GR_ROOT_WINDOW_ID, 100, 50, COLS - 120, ROWS - 60, GRAY); GrSelectEvents(g_main, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ); GrMapWindow(g_main); while (1) { GR_EVENT event; GrGetNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_EXPOSURE: g_x = 5; draw_set("GR_FILL_STIPPLE", GR_FILL_STIPPLE); draw_set("GR_FILL_OPAQUE_STIPPLE", GR_FILL_OPAQUE_STIPPLE); draw_set("GR_FILL_TILE", GR_FILL_TILE); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); } } }
int main(int argc, char **argv) { GR_WINDOW_ID wid; GR_GC_ID gc[NUMGCS]; GR_EVENT event; if(GrOpen() < 0) { fprintf(stderr, "Couldn't connect to the Nano-X server\n"); return 1; } wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "rgndemo", GR_ROOT_WINDOW_ID, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, GR_COLOR_GRAY80); GrSelectEvents(wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE); gc[0] = setup_single_rect_region(); gc[1] = setup_multi_rect_region(); gc[2] = setup_simple_poly_region(); gc[3] = setup_bitmap_region(); gc[4] = setup_complex_poly_region(); GrMapWindow(wid); while(1) { GrGetNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_EXPOSURE: redraw(wid, gc); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); return 0; default: break; } } }
void ttk_gfx_init() { if (GrOpen() < 0) { fprintf (stderr, "GrOpen() failed\n"); exit (1); } tmp_gc = GrNewGC(); GrSetGCUseBackground (tmp_gc, 0); ttk_screen->srf = GrNewWindowEx (GR_WM_PROPS_APPFRAME | GR_WM_PROPS_CAPTION | GR_WM_PROPS_CLOSEBOX, "TTK Program", GR_ROOT_WINDOW_ID, 0, 0, ttk_screen->w, ttk_screen->h, ttk_makecol (WHITE)); GrSelectEvents (ttk_screen->srf, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_KEY_UP | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_TIMER); GrMapWindow (ttk_screen->srf); gettimeofday (&tvstart, 0); }
int main(void) { GR_WINDOW_ID wid; GR_GC_ID gc; GR_EVENT event; if(GrOpen() < 0) { fprintf(stderr, "Couldn't connect to the Nano-X server\n"); return 1; } wid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, BITMAPWIDTH, BITMAPHEIGHT, 0, GR_COLOR_WHITE, 0); GrSelectEvents(wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE); gc = GrNewGC(); GrSetGCForeground(gc, GR_COLOR_BLACK); GrSetGCBackground(gc, GR_COLOR_WHITE); GrMapWindow(wid); while(1) { GrGetNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_EXPOSURE: redraw(wid, gc); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); return 0; default: break; } } }
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_BITMAP bitmap1fg[7]; /* mouse cursor */ GR_BITMAP bitmap1bg[7]; if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } GrGetScreenInfo(&si); w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 30, si.cols - 120, si.rows - 60, 1, WHITE, LTBLUE); 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); GrMapWindow(w1); gc1 = GrNewGC(); gc3 = GrNewGC(); GrSetGCForeground(gc1, GRAY); GrSetGCBackground(gc1, LTBLUE); GrSetGCFont(gc1, GrCreateFont(GR_FONT_SYSTEM_FIXED, 0, NULL)); /*GrSetGCFont(gc1, GrCreateFont(GR_FONT_OEM_FIXED, 0, NULL));*/ GrSetGCForeground(gc3, WHITE); GrSetGCBackground(gc3, BLACK); bitmap1fg[0] = MASK(_,_,X,_,X,_,_); bitmap1fg[1] = MASK(_,_,_,X,_,_,_); bitmap1fg[2] = MASK(_,_,_,X,_,_,_); bitmap1fg[3] = MASK(_,_,_,X,_,_,_); bitmap1fg[4] = MASK(_,_,_,X,_,_,_); bitmap1fg[5] = MASK(_,_,_,X,_,_,_); bitmap1fg[6] = MASK(_,_,X,_,X,_,_); bitmap1bg[0] = MASK(_,X,X,X,X,X,_); bitmap1bg[1] = MASK(_,_,X,X,X,_,_); bitmap1bg[2] = MASK(_,_,X,X,X,_,_); bitmap1bg[3] = MASK(_,_,X,X,X,_,_); bitmap1bg[4] = MASK(_,_,X,X,X,_,_); bitmap1bg[5] = MASK(_,_,X,X,X,_,_); bitmap1bg[6] = MASK(_,X,X,X,X,X,_); GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg); /*GrFillRect(GR_ROOT_WINDOW_ID, gc1, 0, 0, si.cols, si.rows);*/ GrSetGCForeground(gc1, BLACK); GrSetGCBackground(gc1, WHITE); text_init(); if (term_init() < 0) { GrClose(); exit(1); } /* we want tfd events also*/ GrRegisterInput(tfd); #if 1 GrMainLoop(HandleEvent); #else while(1) { GR_EVENT ev; GrGetNextEvent(&ev); HandleEvent(&ev); } #endif /* notreached*/ return 0; }
int main(int ac, char **av) { GR_EVENT event; /* current event */ GR_BITMAP bitmap1fg[7]; /* bitmaps for first cursor */ GR_BITMAP bitmap1bg[7]; if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } /* create window*/ w1 = GrNewWindowEx( GR_WM_PROPS_NOAUTOMOVE|GR_WM_PROPS_BORDER|GR_WM_PROPS_CAPTION| GR_WM_PROPS_CLOSEBOX, "nxclock", GR_ROOT_WINDOW_ID, 10, 10, CWIDTH, CHEIGHT, GrGetSysColor(GR_COLOR_WINDOW)); GrSelectEvents(w1, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ); gc1 = GrNewGC(); gc2 = GrNewGC(); GrSetGCForeground(gc1, GrGetSysColor(GR_COLOR_WINDOW)); GrSetGCBackground(gc1, GrGetSysColor(GR_COLOR_WINDOWTEXT)); GrSetGCForeground(gc2, GrGetSysColor(GR_COLOR_WINDOWTEXT)); GrSetGCBackground(gc2, GrGetSysColor(GR_COLOR_WINDOW)); bitmap1bg[0] = MASK(_,_,X,X,X,_,_); bitmap1bg[1] = MASK(_,X,X,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,X,X,_); bitmap1bg[6] = MASK(_,_,X,X,X,_,_); bitmap1fg[0] = MASK(_,_,_,X,_,_,_); bitmap1fg[1] = MASK(_,X,_,X,_,X,_); bitmap1fg[2] = MASK(_,_,_,X,_,_,_); bitmap1fg[3] = MASK(X,_,_,X,X,_,X); bitmap1fg[4] = MASK(_,_,_,_,_,_,_); bitmap1fg[5] = MASK(_,X,_,_,_,X,_); bitmap1fg[6] = MASK(_,_,_,X,_,_,_); GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg); GrMapWindow(w1); while (1) { GrGetNextEventTimeout(&event, 500L); switch (event.type) { case GR_EVENT_TYPE_EXPOSURE: do_exposure(&event.exposure); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); case GR_EVENT_TYPE_TIMEOUT: do_clock(); break; } } }
int main(int ac, char **av) { GR_WINDOW_ID window; GR_GC_ID gc; GR_FONT_ID fontid; int x, y, fnum; GR_REGION_ID regionid; #if CLIP_POLYGON GR_POINT points[] = { {20, 20}, {300, 20}, {300, 300}, {20, 300} }; #else GR_RECT clip_rect = { 20, 20, 300, 300 }; #endif if (GrOpen() < 0) exit(1); window = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "t1demo loadable fonts (truetype, t1lib, pcf, mgl, hzk)", GR_ROOT_WINDOW_ID, 50, 50, WIDTH, HEIGHT, BLACK); GrSelectEvents(window, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ); GrMapWindow(window); gc = GrNewGC(); GrSetGCUseBackground(gc, GR_FALSE); GrSetGCBackground(gc, BLACK); #if CLIP_POLYGON /* polygon clip region */ regionid = GrNewPolygonRegion(MWPOLY_EVENODD, 3, points); #else /* rectangle clip region */ regionid = GrNewRegion(); GrUnionRectWithRegion(regionid, &clip_rect); #endif GrSetGCRegion(gc, regionid); srand(time(0)); while (1) { GR_EVENT event; GrCheckNextEvent(&event); if (event.type == GR_EVENT_TYPE_CLOSE_REQ) { GrClose(); exit(0); } fontid = GrCreateFontEx(names[fnum=RAND(MAXFONTS)], 0, 0, NULL); GrSetFontSizeEx(fontid, RAND(80) + 1, RAND(80) + 1); GrSetFontRotation(fontid, 330); /* 33 degrees */ GrSetFontAttr(fontid, GR_TFKERNING | GR_TFANTIALIAS, 0); GrSetGCFont(gc, fontid); GrSetGCForeground(gc, rand() & 0xffffff); /*GrSetGCBackground(gc, rand() & 0xffffff); */ x = RAND(WIDTH); y = RAND(HEIGHT); #if HAVE_HZK_SUPPORT { #if HZKBIG5 /* hzk big5 unicode-16 test*/ static unsigned short buffer[] = { 0x9060, 0x898b, 0x79d1, 0x6280, 0x0061, 0x0041, 0 }; GrText(window, gc, x, y, buffer, 7, GR_TFUC16); /* hzk big5 dbcs test #1*/ x = RAND(WIDTH); y = RAND(HEIGHT); GrText(window, gc, x, y, "Microwindows,Åwªï¨Ï¥Î¤¤^¤åÂI°}¦rÅé", -1, GR_TFASCII); /* hzk big5 dbcs test #2*/ x = RAND(WIDTH); y = RAND(HEIGHT); GrText(window, gc, x, y, "£t£u£v£w£¸£¹£º", -1, GR_TFASCII); #else #if 0 /* hzk test #1*/ static char buffer[] = { 0x6c, 0x49, 0x73, 0x8b, 0x79, 0xd1, 0x62, 0x80, 0x61, 0x00, 0x41, 0x00, 0x00, 0xa1, 0x00, 0xa6, 0x6c, 0x49, 0, 0 }; /* *static unsigned short buffer[] = { 0x496c, 0x8b73, 0xd179, 0x8062, 0x0061, 0x0041, 0xa100, 0xa600, 0x496c, 0 };***/ GrText(window, gc, x, y, buffer, 9, GR_TFUC16); #endif /* HZK Metrix font test, includes Chinese and English */ x = RAND(WIDTH); y = RAND(HEIGHT); GrText(window, gc, x, y, "Microwindows,»¶ÓʹÓÃÖÐÓ¢ÎĵãÕó×ÖÌå", -1, GR_TFASCII); #endif /* HZKBIG5*/ } #elif HAVE_BIG5_SUPPORT /* encoding BIG5 test 61 B1 64 B1 64 61 */ GrText(window, gc, x, y, "\151\261\144\261\144\151", 6, MWTF_DBCS_BIG5); #elif HAVE_GB2312_SUPPORT /* encoding GB2312 test BD A1 BD A1 */ GrText(window, gc, x, y, "\275\241\275\241", 4, MWTF_DBCS_GB); #elif HAVE_EUCJP_SUPPORT /* encoding EUC_JP test A2 A1 */ GrText(window, gc, x, y, "ï¿½Þ¥ï¿½ï¿½ï¿½ï¿½í¥¦ï¿½ï¿½ï¿½ï¿½ï¿½É¥ï¿½ï¿½ï¿½ï¿½Ø¤è¤¦ï¿½ï¿½ï¿½ï¿½!", -1, MWTF_DBCS_EUCJP); #elif HAVE_JISX0213_SUPPORT /* encoding JISX0213 test A2 A1 */ GrText(window, gc, x, y, "\242\241", 2, MWTF_DBCS_JIS); #elif HAVE_KSC5601_SUPPORT /* encoding KSC5601 test B0 B0 */ GrText(window, gc, x, y, "\273\273", 2, MWTF_DBCS_EUCKR); #elif HAVE_FREETYPE_2_SUPPORT /* ASCII test */ GrText(window, gc, x, y, "Microwindows", -1, GR_TFASCII); #elif HAVE_PCF_SUPPORT /* note: large PCF fonts require XCHAR2B, this is not figured out yet for these fonts. FIXME */ if (fnum == 3) { /* japanese jiskan24*/ unsigned short text[] = { 0x213a, 0x213b, 0x2170, 0x2276, 0x2339 }; GrText(window, gc, x,y, text, 5, GR_TFUC16); } else if (fnum == 4) { /* chinese gb24st*/ unsigned short text[] = /* FIXME: why doesn't first row index correctly?*/ /*{ 0x7765, 0x7766, 0x7767, 0x777a, 0x777e };*/ { 0x2129, 0x212a, 0x212b, 0x212c, 0x212d }; GrText(window, gc, x,y, text, 5, GR_TFUC16); } else GrText(window, gc, x,y, "Microwindows", -1, GR_TFASCII); #elif HAVE_FNT_SUPPORT /* UC16 test */ if (fnum == 2 || fnum == 3) { /* japanese jiskan24, jiskan16-2000-1*/ unsigned short text[] = { 0x213a, 0x213b, 0x2170, 0x2276, 0x2339 }; GrText(window, gc, x,y, text, 5, GR_TFUC16); } else if (fnum == 4) { /* chinese gbk16-xke*/ unsigned short text[] = { 0x8144, 0x8147, 0x8148, 0xfe4e, 0xfe4f }; GrText(window, gc, x,y, text, 5, GR_TFUC16); } else GrText(window, gc, x,y, "Microwindows", -1, GR_TFASCII); #else /* ASCII test */ GrText(window, gc, x, y, "Microwindows", -1, GR_TFASCII); #endif GrFlush(); GrDestroyFont(fontid); } GrDestroyRegion(regionid); GrClose(); return 0; }
int main(int ac,char **av) { GR_WINDOW_ID w; GR_GC_ID gc; GR_FONT_ID font; GR_WINDOW_INFO wi; if (GrOpen() < 0) { GrError("Can't open graphics\n"); return 1; } //w = GrNewWindowEx(GR_WM_PROPS_APPWINDOW|GR_WM_PROPS_NOBACKGROUND, "Nano-X Demo2", //GR_ROOT_WINDOW_ID, 20, 20, 320, 240, BLACK); w = GrNewWindowEx(GR_WM_PROPS_BORDER|GR_WM_PROPS_NOBACKGROUND, "Nano-X Demo2", GR_ROOT_WINDOW_ID, 20, 20, 320, 240, BLACK); gc = GrNewGC(); //font = GrCreateFontEx("lubI24.pcf", 0, 0, NULL); font = GrCreateFontEx("helvB12.pcf.gz", 0, 0, NULL); GrSetGCFont(gc, font); 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); // pass errors through main loop GrSetErrorHandler(NULL); for (;;) { GR_EVENT event; 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); GrGetWindowInfo(w, &wi); GrError("Exposure:wi.width:%d,wi.height:%d,wi.x:%d,wi.y:%d,wi.parent:%d\n",wi.width,wi.height,wi.x,wi.y,wi.parent); break; case GR_EVENT_TYPE_BUTTON_DOWN: // FIXME unmap window is broken GrUnmapWindow(w); GrFlush(); GrMapWindow(w); //uncomment to test server error on bad syscall //GrMoveWindow(GR_ROOT_WINDOW_ID, 0, 0); GrGetWindowInfo(w, &wi); GrError("Button: wi.width:%d,wi.height:%d,wi.x:%d,wi.y:%d,wi.parent:%d\n",wi.width,wi.height,wi.x,wi.y,wi.parent); break; case GR_EVENT_TYPE_ERROR: GrError("demo2: Error (%s) ", event.error.name); GrError(nxErrorStrings[event.error.code], event.error.id); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); return 0; } } return 0; }
int main(int argc, char **argv) { int t = 1; GR_EVENT event; /* current event */ while (t < argc) { if (!strcmp("-t", argv[t])) { bTextwin = GR_TRUE; ++t; continue; } } if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } if (bTextwin) { /* create text output window for debugging*/ wt = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 20, TEXTWIN_WIDTH, TEXTWIN_HEIGHT, 5, BLACK, GREEN); GrSelectEvents(wt, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_EXPOSURE); GrMapWindow(wt); gct = GrNewGC(); GrSetGCForeground(gct, GREEN); GrGetGCTextSize(gct, "A",1, GR_TFASCII, &width, &height, &base); GrSetGCFont(gct, GrCreateFont(GR_FONT_SYSTEM_FIXED, 0, NULL)); gctb = GrNewGC(); GrSetGCForeground(gctb, BLACK); } /* create scribble input window*/ w = create_scribble(); 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_FOCUS_IN: do_focusin(&event.general); 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_CLOSE_REQ: GrClose(); exit(0); } } }
int main(int argc,char **argv) { char *imagefile = "bin/slidebmp.bmp"; if (GrOpen() < 0) { GrError("cannot open graphics\n"); exit(1); } gc1 = GrNewGC(); #if USE_IMAGE image = GrNewWindow(GR_ROOT_WINDOW_ID, 300, 0, (WIDTH_IN_TILES * tile_width), (HEIGHT_IN_TILES * tile_height), 4, BLACK, WHITE); if (argc > 1) imagefile = argv[1]; /* need to find out image size.... */ image_addr = malloc(4 * (WIDTH_IN_TILES * tile_width) * (HEIGHT_IN_TILES * tile_height)); image = GrNewPixmap((WIDTH_IN_TILES * tile_width), (HEIGHT_IN_TILES * tile_height), image_addr); GrDrawImageFromFile(image, gc1, 0, 0, GR_IMAGE_MAX_SIZE, GR_IMAGE_MAX_SIZE, imagefile, 0); #endif /* calculate size of tile area */ calc_width = 10 + (WIDTH_IN_TILES * tile_width); calc_height = 15 + 35 + (HEIGHT_IN_TILES * tile_height); #if 0 /* enforce minimum size */ if (calc_width < 240) calc_width=240; if (calc_height < 320) calc_height=320; #endif master = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, calc_width, calc_height, 1, RED, WHITE); buttons = GrNewWindow((GR_WINDOW_ID) master, 5, 5, (calc_width - 5), 35, 1, RED, RED); tiles = GrNewWindow((GR_WINDOW_ID) master, (calc_width/2) - (WIDTH_IN_TILES * tile_width /2), 45 + ((calc_height - 50)/2) - (HEIGHT_IN_TILES * tile_height /2), (WIDTH_IN_TILES * tile_width), (HEIGHT_IN_TILES * tile_height), 1, RED, RED); GrMapWindow(master); GrMapWindow(buttons); GrMapWindow(tiles); /* set random seed */ srandom((int) getpid()); RandomiseTiles(); GrSelectEvents(master, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ| GR_EVENT_MASK_KEY_DOWN); GrSelectEvents(buttons, GR_EVENT_MASK_BUTTON_DOWN); GrSelectEvents(tiles, GR_EVENT_MASK_BUTTON_DOWN); RefreshWindow(); while (GR_TRUE) { GR_EVENT event; GrGetNextEvent(&event); HandleEvents(&event); } }
/* ***********************************************************/ 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 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) { 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); } }
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 img_demo_thread(CYG_ADDRWORD data) { int err, s, client, client_len; struct sockaddr client_addr; struct sockaddr_in my_addr; struct addrinfo *ai, *addrs, hints; char buf[256], addr_buf[256]; int one = 1; fd_set in_fds, src_fds; int num, len; struct timeval tv; INIT_PER_THREAD_DATA(); printf("Image demo here\n"); #ifdef CYGPKG_FS_RAM // Stage files from JFFS2 image into RAM err = mount("", "/ramfs", "ramfs"); if (err >= 0) { do_copy_all("/", "/ramfs"); } else { pexit("Can't mount RAMfs\n"); } chdir("/ramfs"); #endif if(GrOpen() < 0) { fprintf(stderr, "Couldn't connect to Nano-X server\n"); exit(1); } // Set up as a generic server, listening on TCP/7734 #if 0 bzero(&hints, sizeof(hints)); hints.ai_family = PF_UNSPEC;b hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; if ((err = getaddrinfo(NULL, "7734", &hints, &addrs)) != EAI_NONE) { diag_printf("can't getaddrinfo(): %s\n", gai_strerror(err)); pexit("getaddrinfo"); } s = socket(ai->ai_family, ai->ai_socktype, 0); if (s < 0) { pexit("stream socket"); } if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) { pexit("setsockopt SO_REUSEADDR"); } if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) { pexit("setsockopt SO_REUSEPORT"); } if(bind(s, ai->ai_addr, ai->ai_addr->sa_len) < 0) { pexit("bind error"); } listen(s, SOMAXCONN); #else s = socket(AF_INET, SOCK_STREAM, 0); if (s < 0) { pexit("stream socket"); } if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) { pexit("setsockopt SO_REUSEADDR"); } if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) { pexit("setsockopt SO_REUSEPORT"); } memset(&my_addr, 0, sizeof(my_addr)); my_addr.sin_family = AF_INET; my_addr.sin_len = sizeof(my_addr); my_addr.sin_port = htons(7734); my_addr.sin_addr.s_addr = INADDR_ANY; if(bind(s, (struct sockaddr *) &my_addr, sizeof(my_addr)) < 0) { pexit("bind error"); } listen(s, SOMAXCONN); #endif while (true) { // Wait for a connection FD_ZERO(&src_fds); FD_SET(s, &src_fds); tv.tv_sec = 15; tv.tv_usec = 0; num = select(s+1, &src_fds, 0, 0, &tv); if (num > 0) { client_len = sizeof(client_addr); if ((client = accept(s, (struct sockaddr *)&client_addr, &client_len)) < 0) { pexit("accept"); } client_len = sizeof(client_addr); getpeername(client, &client_addr, &client_len); _inet_ntop(&client_addr, addr_buf, sizeof(addr_buf)); diag_printf("connection from %s(%d)\n", addr_buf, ntohs(_inet_port(&client_addr))); fdprintf(client, "Hello %s(%d)\n", addr_buf, ntohs(_inet_port(&client_addr))); while (true) { fdprintf(client, "// Ready\n"); tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&in_fds); FD_SET(client, &in_fds); num = select(client+1, &in_fds, 0, 0, &tv); if (num > 0) { len = read(client, buf, sizeof(buf)-1); if (len <= 0) { diag_printf("Client read error: %s\n", strerror(errno)); break; } buf[len-1] = '\0'; do_cmd(client, buf); } else if (num == 0) { fdprintf(client, "<IDLE> show_all\n"); do_show_all(client, "show_all ."); } else { perror("select"); } } close(client); diag_printf("Connection with %s closed\n", addr_buf); } else if (num == 0) { // No connection within 15 seconds do_show_all(0, "show_all ."); } else { diag_printf("select returned: %d\n", num); pexit("bad select"); } } }
int main(int argc,char **argv) { GR_EVENT event; /* current event */ struct app_info * act; int width, height; #ifdef USE_WEIRD_POINTER GR_BITMAP bitmap1fg[7]; /* bitmaps for first cursor */ GR_BITMAP bitmap1bg[7]; #endif for(act = Apps; act->app_id[0] != '\0'; act++, num_apps++); if (GrOpen() < 0) { GrError("cannot open graphics\n"); return 1; } GrGetScreenInfo(&si); signal(SIGCHLD, &reaper); gc = GrNewGC(); bgc = GrNewGC(); GrSetGCForeground(bgc, GRAY); GrSetGCFont(gc, GrCreateFontEx(GR_FONT_SYSTEM_FIXED, 0, 0, NULL)); GrGetGCTextSize(gc, "A", 1, GR_TFASCII, &fwidth, &fheight, &fbase); width = fwidth * 8 + 4; height = (fheight) * num_apps + 4; w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 5, 5, width, height, 1, WHITE, BLACK); GrSelectEvents(w1, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CHLD_UPDATE); GrMapWindow(w1); #ifdef USE_WEIRD_POINTER bitmap1bg[0] = MASK(_,_,X,X,X,_,_); bitmap1bg[1] = MASK(_,X,X,X,X,X,_); bitmap1bg[2] = MASK(_,X,X,X,X,X,_); bitmap1bg[3] = MASK(_,X,X,X,X,X,_); bitmap1bg[4] = MASK(_,X,X,X,X,X,_); bitmap1bg[5] = MASK(_,X,X,X,X,X,_); bitmap1bg[6] = MASK(X,X,X,X,X,X,X); bitmap1fg[0] = MASK(_,_,_,_,_,_,_); bitmap1fg[1] = MASK(_,_,_,X,_,_,_); bitmap1fg[2] = MASK(_,_,X,X,X,_,_); bitmap1fg[3] = MASK(_,_,X,X,X,_,_); bitmap1fg[4] = MASK(_,_,X,X,X,_,_); bitmap1fg[5] = MASK(_,_,X,X,X,_,_); bitmap1fg[6] = MASK(_,X,X,X,X,X,_); GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg); #endif GrFillRect(GR_ROOT_WINDOW_ID, bgc, 0, 0, si.cols, si.rows); GrSetGCForeground(gc, BLACK); GrSetGCBackground(gc, WHITE); while (1) { GrGetNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_EXPOSURE: do_exposure(&event.exposure); break; 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_UPDATE: do_update(&event.update); break; case GR_EVENT_TYPE_MOUSE_POSITION: do_mouse(&event.mouse); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); return 0; } } }
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 ui_loop(int argc, char **argv, const char *name) { GR_EVENT event; /* current event */ GR_IMAGE_ID id = 0; NGLXContext cx; int width, height, k; if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } width = 400; height = 300; GrSetErrorHandler(errorcatcher); w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, width, height, 4, BLACK, WHITE); GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_KEY_DOWN); GrMapWindow(w1); gc1 = GrNewGC(); GrSetGCForeground(gc1, WHITE); cx = nglXCreateContext(NULL, 0); nglXMakeCurrent(w1, cx); init(); reshape(width, height); while (1) { GrCheckNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_CLOSE_REQ: GrFreeImage(id); GrClose(); exit(0); case GR_EVENT_TYPE_EXPOSURE: break; case GR_EVENT_TYPE_KEY_DOWN: { GR_EVENT_KEYSTROKE *kp = &event.keystroke; /* XXX: nanoX special keys are totally bugged ! */ switch (kp->ch) { case 81: k = KEY_LEFT; break; case 83: k = KEY_RIGHT; break; case 82: k = KEY_UP; break; case 84: k = KEY_DOWN; break; default: k = kp->ch; break; } key(k, 0); } break; default: idle(); break; } } return 0; }
int NX_VideoInit (_THIS, SDL_PixelFormat * vformat) { GR_SCREEN_INFO si ; Dprintf ("enter NX_VideoInit\n") ; if (GrOpen () < 0) { SDL_SetError ("GrOpen() fail") ; return -1 ; } // use share memory to speed up #ifdef NANOX_SHARE_MEMORY GrReqShmCmds (0xFFFF); #endif SDL_Window = 0 ; FSwindow = 0 ; GammaRamp_R = NULL ; GammaRamp_G = NULL ; GammaRamp_B = NULL ; GrGetScreenInfo (& si) ; SDL_Visual.bpp = si.bpp ; /* Determine the current screen size */ this->info.current_w = si.cols ; this->info.current_h = si.rows ; // GetVideoMode SDL_modelist = (SDL_Rect **) SDL_malloc (sizeof (SDL_Rect *) * 2) ; if (SDL_modelist) { SDL_modelist [0] = (SDL_Rect *) SDL_malloc (sizeof(SDL_Rect)) ; if (SDL_modelist [0]) { SDL_modelist [0] -> x = 0 ; SDL_modelist [0] -> y = 0 ; SDL_modelist [0] -> w = si.cols ; SDL_modelist [0] -> h = si.rows ; } SDL_modelist [1] = NULL ; } pixel_type = si.pixtype; SDL_Visual.red_mask = si.rmask; SDL_Visual.green_mask = si.gmask; SDL_Visual.blue_mask = si.bmask; vformat -> BitsPerPixel = SDL_Visual.bpp ; if (vformat -> BitsPerPixel > 8) { vformat -> Rmask = SDL_Visual.red_mask ; vformat -> Gmask = SDL_Visual.green_mask ; vformat -> Bmask = SDL_Visual.blue_mask ; } // See if we have been passed a window to use SDL_windowid = getenv ("SDL_WINDOWID") ; // Create the fullscreen (and managed windows : no implement) create_aux_windows (this) ; Dprintf ("leave NX_VideoInit\n") ; return 0 ; }
/* 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. */ }
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); }