int intern initbios( void ) { short int *bufptr; int i; if( UIData == NULL ) { UIData = &ui_data; } UIData->colour = M_VGA; UIData->screen.origin = malloc( UIData->width * UIData->height * sizeof( PIXEL ) ); bufptr = (short int *)UIData->screen.origin; for( i = 0; i < UIData->width * UIData->height; i++ ) { *bufptr = 0x720; bufptr++; } UIData->screen.increment = UIData->width; uiinitcursor(); initkeyboard(); UIData->mouse_acc_delay = 250; UIData->mouse_rpt_delay = 100; UIData->mouse_clk_delay = 250; UIData->tick_delay = 500; UIData->mouse_speed = 8; return( TRUE ); }
bool intern initbios( void ) /**************************/ { bool initialized; initialized = false; if( initmonitor() ) { UIData->desqview = 0; UIData->f10menus = true; if( UIData->colour == M_MONO ) { UIData->screen.origin = MK_FP( _B000h, 0 ); } else { UIData->screen.origin = MK_FP( _B800h, 0 ); } UIData->screen.increment = UIData->width; uiinitcursor(); initkeyboard(); UIData->mouse_acc_delay = 5; /* ticks */ UIData->mouse_rpt_delay = 1; /* ticks */ UIData->mouse_clk_delay = 5; /* ticks */ UIData->tick_delay = 9; /* ticks */ initialized = true; } return( initialized ); }
int main(void) { int XMax,YMax; Getborder(&XMax,&YMax); srand((unsigned int)time(0)); RP r={0,0}; RP *rp=&r; SNode *sp=NULL; Initheadtail(&sp); Randpoint(rp,sp,XMax,YMax); initscr(); initkeyboard(); //---------------------- int ch=0; while(ch!='q') { ch=0; if(kbhit()) ch=readch(); // printf("%c\n",ch); // read(0,&ch,1); switch(ch){ case 'w': sp->direction=N; break; case 's': sp->direction=S; break; case 'a': sp->direction=W; break; case 'd': sp->direction=E; break; } // printw("%d\n",sp->direction); switch(Checkhead(sp,rp)){ case -1: goto END; case 0: break; case 1: Eatpoint(&sp,rp,XMax,YMax); break; } Freshsanke(&sp); Convertborder(sp,XMax,YMax); Printscr(sp); Printpoint(r); refresh(); clear(); usleep(100000); } //---------------------- END:closekeyboard(); endwin(); Freenode(sp); return 0; }
static int td_init( void ) /************************/ { int rows, cols; const char *tmp; if( UIData == NULL ) { UIData = &ui_data; } if( !td_initconsole() ) return( FALSE ); if( !initmonitor() ) return( FALSE ); if( TCAP_MONOCHROME ) { UIData->colour = M_TERMINFO_MONO; } UIData->no_blowup = TRUE; tmp = getenv( "TIOPTIMIZE" ); if( tmp != NULL ) OptimizeTerminfo = ( stricmp( tmp, "no" ) != 0 ); // Figure out the number of columns to use cols = 0; tmp = getenv( "COLUMNS" ); if( tmp != NULL ) cols = strtoul( tmp, NULL, 0 ); // Figure out the number of rows to use rows = 0; tmp = getenv( "LINES" ); if( tmp != NULL ) rows = strtoul( tmp, NULL, 0 ); // Set up screen buffer if( !setupscrnbuff( rows, cols ) ) return( FALSE ); uiinitcursor(); if( !initkeyboard() ) return( FALSE ); UIData->mouse_acc_delay = 277; UIData->mouse_rpt_delay = 100; UIData->mouse_clk_delay = 277; UIData->tick_delay = 500; UIData->f10menus = true; //find point at which repeat chars code becomes efficient ti_find_cutoff(); ti_refresh( 1 ); return( TRUE ); }
void threadmain(int argc, char **argv) { char *p; int lfd; p = "300x40@100,100"; ARGBEGIN{ case 'W': p = ARGF(); break; case 't': textmode = 1; break; case 'k': nokill = 1; break; default: usage(); }ARGEND; if(argc != 1) usage(); winsize = p; title = argv[0]; lfd = dup(0, -1); Binit(&b, lfd, OREAD); rbar = Rect(0, 0, 60, 1); if (!textmode){ if(initdraw(0, nil, "bar") < 0) sysfatal("initdraw: %r"); initcolor(); if((mc = initmouse(nil, screen)) == nil) sysfatal("initmouse: %r"); if((kc = initkeyboard(nil)) == nil) sysfatal("initkeyboard: %r"); display->locking = 1; threadcreate(resizethread, nil, STACK); threadcreate(keyboardthread, nil, STACK); threadcreate(mousethread, nil, STACK); resize(); unlockdisplay(display); } proccreate(updateproc, nil, STACK); }
/*--------------------------------------------------------- Function: * Description: Initialize the INPUT SYSTEM. Prepare all available inputs and fill in device structures. ---------------------------------------------------------*/ void initinputs(int input) { ndevices = 0; // Dummy input device. device[ndevices].locked = 0; device[ndevices].name = "None"; device[ndevices].getmotion = getnone; ndevices++; keyboard = joypad = mouse = 0; // KEYBOARD. if (input & R_INPUT_KEYBOARD) { initkeyboard(); if (keyboard) { device[ndevices].locked = 0; device[ndevices].name = "Keyboard"; device[ndevices].getmotion = getkeyboard; ndevices++; } } // JOYPAD. if (input & R_INPUT_JOYPAD) { initjoypad(); if (joypad) { device[ndevices].locked = 0; device[ndevices].name = "Joypad"; device[ndevices].getmotion = getjoypad; ndevices++; } } // MOUSE. if (input & R_INPUT_MOUSE) { initmouse(); if (mouse) { device[ndevices].locked = 0; device[ndevices].name = "Mouse"; device[ndevices].getmotion = getmouse; ndevices++; } } }
int intern initbios( void ) /*************************/ { int initialized; // unsigned offset; #ifdef __386__ void __far16 *ptrLVB; void *ptr; #else unsigned long ptrLVB; #endif unsigned short SizeOfLVB; initialized = FALSE; if( initmonitor() ) { VioGetBuf( (PULONG) &ptrLVB, (PUSHORT) &SizeOfLVB, 0); // offset = SCREEN_OFFSET; AFS 08-feb-91 #ifdef __386__ ptr = ptrLVB; UIData->screen.origin = ptr; #else UIData->screen.origin = (LP_PIXEL)ptrLVB; #endif UIData->screen.increment = UIData->width; uiinitcursor(); initkeyboard(); if( _osmode == DOS_MODE ) { UIData->mouse_acc_delay = 5; /* ticks */ UIData->mouse_rpt_delay = 1; /* ticks */ UIData->mouse_clk_delay = 5; /* ticks */ UIData->tick_delay = 9; /* ticks */ UIData->mouse_speed = 8; /* mickeys to ticks ratio */ } else { UIData->mouse_acc_delay = 250; UIData->mouse_rpt_delay = 100; UIData->mouse_clk_delay = 250; UIData->tick_delay = 500; UIData->mouse_speed = 8; /* mickeys to ticks ratio */ } initialized = TRUE; } return( initialized ); }
void setup_mlx(t_player *player) { t_env e; e.player = player; e.mlx = mlx_init(); e.win = mlx_new_window(e.mlx, WIDTH, HEIGHT, "RTv1"); //texture_load(&e); //load_sprites(&e); initkeyboard(&e); e.bpp = 0; e.size_line = 0; e.endian = 0; mlx_hook(e.win, 2, 1, key_press_hook, &e); mlx_hook(e.win, 3, 1, key_release_hook, &e); mlx_expose_hook(e.win, expose_hook, &e); mlx_loop_hook(e.mlx, &get_loop_hook, &e); mlx_loop(e.mlx); }
static int td_init( void ) /************************/ { if (UIData == NULL) { UIData = &ui_data; } if( !td_initconsole() ) return( FALSE ); if (!initmonitor()) return (FALSE); if (!setupscrnbuff(0,0)) return (FALSE); uiinitcursor(); initkeyboard(); UIData->mouse_acc_delay = 277; UIData->mouse_rpt_delay = 55; UIData->mouse_clk_delay = 277; UIData->tick_delay = 500; UIData->f10menus = TRUE; td_refresh(1); return (TRUE); }
int intern initbios( void ) /*******************/ { int initialized = FALSE; int i; if( initmonitor() ) { UIData->screen.origin = (LPPIXEL) uimalloc( UIData->width * UIData->height * sizeof( PIXEL ) ); for( i = 0 ; i < UIData->width * UIData->height ; ++i ){ UIData->screen.origin[i].ch = ' '; UIData->screen.origin[i].attr = 7; } /* end for */ UIData->screen.increment = UIData->width; uiinitcursor(); initkeyboard(); /* No mouse support in NetWare! */ UIData->mouse_acc_delay = 0; UIData->mouse_rpt_delay = 0; UIData->mouse_clk_delay = 0; UIData->mouse_speed = 0; /* A 500 millisecond tick delay is pretty reasonable. */ UIData->tick_delay = uiclockdelay( 500 ); initialized = TRUE; } /* end if */ return( initialized ); } /* end initbios */
static int cd_init( void ) /************************/ { int initialized; initialized = false; if( UIData == NULL ) { UIData = &ui_data; } if( !initmonitor() ) return( false ); if( !setupscrnbuff() ) return( false ); uiinitcursor(); initkeyboard(); UIData->mouse_acc_delay = 277; UIData->mouse_rpt_delay = 100; UIData->mouse_clk_delay = 277; UIData->tick_delay = 500; UIData->f10menus = true; return( true ); }
void threadmain(int argc, char *argv[]) { int i; char *p, *loadfile; Column *c; int ncol; Display *d; rfork(RFENVG|RFNAMEG); ncol = -1; loadfile = nil; ARGBEGIN{ case 'D': {extern int _threaddebuglevel; _threaddebuglevel = ~0; } break; case 'a': globalautoindent = TRUE; break; case 'b': bartflag = TRUE; break; case 'c': p = ARGF(); if(p == nil) goto Usage; ncol = atoi(p); if(ncol <= 0) goto Usage; break; case 'f': fontnames[0] = ARGF(); if(fontnames[0] == nil) goto Usage; break; case 'F': fontnames[1] = ARGF(); if(fontnames[1] == nil) goto Usage; break; case 'l': loadfile = ARGF(); if(loadfile == nil) goto Usage; break; case 'm': mtpt = ARGF(); if(mtpt == nil) goto Usage; break; case 'r': swapscrollbuttons = TRUE; break; case 'W': winsize = ARGF(); if(winsize == nil) goto Usage; break; default: Usage: fprint(2, "usage: acme -a -c ncol -f fontname -F fixedwidthfontname -l loadfile -W winsize\n"); threadexitsall("usage"); }ARGEND fontnames[0] = estrdup(fontnames[0]); fontnames[1] = estrdup(fontnames[1]); quotefmtinstall(); fmtinstall('t', timefmt); cputype = getenv("cputype"); objtype = getenv("objtype"); home = getenv("HOME"); acmeshell = getenv("acmeshell"); if(acmeshell && *acmeshell == '\0') acmeshell = nil; p = getenv("tabstop"); if(p != nil){ maxtab = strtoul(p, nil, 0); free(p); } if(maxtab == 0) maxtab = 4; if(loadfile) rowloadfonts(loadfile); putenv("font", fontnames[0]); snarffd = open("/dev/snarf", OREAD|OCEXEC); /* if(cputype){ sprint(buf, "/acme/bin/%s", cputype); bind(buf, "/bin", MBEFORE); } bind("/acme/bin", "/bin", MBEFORE); */ getwd(wdir, sizeof wdir); /* if(geninitdraw(nil, derror, fontnames[0], "acme", nil, Refnone) < 0){ fprint(2, "acme: can't open display: %r\n"); threadexitsall("geninitdraw"); } */ if(initdraw(derror, fontnames[0], "acme") < 0){ fprint(2, "acme: can't open display: %r\n"); threadexitsall("initdraw"); } d = display; font = d->defaultfont; /*assert(font); */ reffont.f = font; reffonts[0] = &reffont; incref(&reffont.ref); /* one to hold up 'font' variable */ incref(&reffont.ref); /* one to hold up reffonts[0] */ fontcache = emalloc(sizeof(Reffont*)); nfontcache = 1; fontcache[0] = &reffont; iconinit(); timerinit(); rxinit(); cwait = threadwaitchan(); ccommand = chancreate(sizeof(Command**), 0); ckill = chancreate(sizeof(Rune*), 0); cxfidalloc = chancreate(sizeof(Xfid*), 0); cxfidfree = chancreate(sizeof(Xfid*), 0); cnewwindow = chancreate(sizeof(Channel*), 0); cerr = chancreate(sizeof(char*), 0); cedit = chancreate(sizeof(int), 0); cexit = chancreate(sizeof(int), 0); cwarn = chancreate(sizeof(void*), 1); if(cwait==nil || ccommand==nil || ckill==nil || cxfidalloc==nil || cxfidfree==nil || cerr==nil || cexit==nil || cwarn==nil){ fprint(2, "acme: can't create initial channels: %r\n"); threadexitsall("channels"); } chansetname(ccommand, "ccommand"); chansetname(ckill, "ckill"); chansetname(cxfidalloc, "cxfidalloc"); chansetname(cxfidfree, "cxfidfree"); chansetname(cnewwindow, "cnewwindow"); chansetname(cerr, "cerr"); chansetname(cedit, "cedit"); chansetname(cexit, "cexit"); chansetname(cwarn, "cwarn"); mousectl = initmouse(nil, screen); if(mousectl == nil){ fprint(2, "acme: can't initialize mouse: %r\n"); threadexitsall("mouse"); } mouse = &mousectl->m; keyboardctl = initkeyboard(nil); if(keyboardctl == nil){ fprint(2, "acme: can't initialize keyboard: %r\n"); threadexitsall("keyboard"); } mainpid = getpid(); startplumbing(); /* plumbeditfd = plumbopen("edit", OREAD|OCEXEC); if(plumbeditfd < 0) fprint(2, "acme: can't initialize plumber: %r\n"); else{ cplumb = chancreate(sizeof(Plumbmsg*), 0); threadcreate(plumbproc, nil, STACK); } plumbsendfd = plumbopen("send", OWRITE|OCEXEC); */ fsysinit(); #define WPERCOL 8 disk = diskinit(); if(!loadfile || !rowload(&row, loadfile, TRUE)){ rowinit(&row, screen->clipr); if(ncol < 0){ if(argc == 0) ncol = 2; else{ ncol = (argc+(WPERCOL-1))/WPERCOL; if(ncol < 2) ncol = 2; } } if(ncol == 0) ncol = 2; for(i=0; i<ncol; i++){ c = rowadd(&row, nil, -1); if(c==nil && i==0) error("initializing columns"); } c = row.col[row.ncol-1]; if(argc == 0) readfile(c, wdir); else for(i=0; i<argc; i++){ p = utfrrune(argv[i], '/'); if((p!=nil && strcmp(p, "/guide")==0) || i/WPERCOL>=row.ncol) readfile(c, argv[i]); else readfile(row.col[i/WPERCOL], argv[i]); } } flushimage(display, 1); acmeerrorinit(); threadcreate(keyboardthread, nil, STACK); threadcreate(mousethread, nil, STACK); threadcreate(waitthread, nil, STACK); threadcreate(xfidallocthread, nil, STACK); threadcreate(newwindowthread, nil, STACK); /* threadcreate(shutdownthread, nil, STACK); */ threadnotify(shutdown, 1); recvul(cexit); killprocs(); threadexitsall(nil); }
void threadmain(int argc, char *argv[]) { int i, j, k, l; Image *dark; ramp = 0; fmt = "index %3d r %3lud g %3lud b %3lud 0x%.8luX "; ARGBEGIN{ default: goto Usage; case 'D': chattydrawclient = 1; break; case 'x': fmt = "index %2luX r %3luX g %3luX b %3luX 0x%.8luX "; break; case 'r': ramp = 1; break; }ARGEND if(argc){ Usage: fprint(2, "Usage: %s [-rx]\n", argv0); threadexitsall("usage"); } if(initdraw(0, nil, "colors") < 0) sysfatal("initdraw failed: %r"); mousectl = initmouse(nil, display->image); if(mousectl == nil) sysfatal("initmouse: %r"); keyboardctl = initkeyboard(nil); if(keyboardctl == nil) sysfatal("initkeyboard: %r"); for(i=0; i<256; i++){ if(ramp){ if(screen->chan == CMAP8){ /* dither the fine grey */ j = i-(i%17); dark = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (grey(j)<<8)+0xFF); color[i] = allocimage(display, Rect(0,0,4,4), screen->chan, 1, (grey(j+17)<<8)+0xFF); for(j=0; j<16; j++){ k = j%4; l = j/4; if(dither[j] > (i%17)) draw(color[i], Rect(k, l, k+1, l+1), dark, nil, ZP); } freeimage(dark); }else color[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (grey(i)<<8)+0xFF); }else color[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (cmap2rgb(i)<<8)+0xFF); if(color[i] == nil) sysfatal("can't allocate image: %r"); } threadcreate(mousethread, nil, STACK); threadcreate(keyboardthread, nil, STACK); threadcreate(resizethread, nil, STACK); }
void threadmain(int argc, char *argv[]) { Column *c; char buf[256]; int i, ncol; rfork(RFENVG|RFNAMEG); ncol = 1; ARGBEGIN{ case 'c': ncol = atoi(EARGF(usage())); if(ncol <= 0) usage(); break; case 'm': webmountpt = EARGF(usage()); break; case 'p': procstderr++; break; case 't': charset = EARGF(usage()); break; default: usage(); break; }ARGEND snprint(buf, sizeof(buf), "%s/ctl", webmountpt); webctlfd = open(buf, ORDWR); if(webctlfd < 0) sysfatal("can't initialize webfs: %r"); snarffd = open("/dev/snarf", OREAD|OCEXEC); if(initdraw(derror, fontnames[0], "abaco") < 0) sysfatal("can't open display: %r"); memimageinit(); iconinit(); timerinit(); initfontpaths(); cexit = chancreate(sizeof(int), 0); crefresh = chancreate(sizeof(Page *), 0); if(cexit==nil || crefresh==nil) sysfatal("can't create initial channels: %r"); mousectl = initmouse(nil, screen); if(mousectl == nil) sysfatal("can't initialize mouse: %r"); mouse = mousectl; keyboardctl = initkeyboard(nil); if(keyboardctl == nil) sysfatal("can't initialize keyboard: %r"); mainpid = getpid(); plumbwebfd = plumbopen("web", OREAD|OCEXEC); if(plumbwebfd >= 0){ cplumb = chancreate(sizeof(Plumbmsg*), 0); proccreate(plumbproc, nil, STACK); } plumbsendfd = plumbopen("send", OWRITE|OCEXEC); rowinit(&row, screen->clipr); for(i=0; i<ncol; i++){ c = rowadd(&row, nil, -1); if(c==nil && i==0) error("initializing columns"); } c = row.col[row.ncol-1]; for(i=0; i<argc; i++) if(i/WPERCOL >= row.ncol) readpage(c, argv[i]); else readpage(row.col[i/WPERCOL], argv[i]); flushimage(display, 1); threadcreate(keyboardthread, nil, STACK); threadcreate(mousethread, nil, STACK); threadnotify(shutdown, 1); recvul(cexit); threadexitsall(nil); }
int ioInit(void) { mousectl = initmouse(NULL, screen); keyboardctl = initkeyboard(NULL); ctlkeyboard(keyboardctl, "rawon"); return 0; }
void threadmain(int argc, char *argv[]) { int i; char *p, *loadfile; char buf[256]; Column *c; int ncol; Display *d; static void *arg[1]; rfork(RFENVG|RFNAMEG); ncol = -1; loadfile = nil; ARGBEGIN{ case 'a': globalautoindent = TRUE; break; case 'b': bartflag = TRUE; break; case 'c': p = ARGF(); if(p == nil) goto Usage; ncol = atoi(p); if(ncol <= 0) goto Usage; break; case 'f': fontnames[0] = ARGF(); if(fontnames[0] == nil) goto Usage; break; case 'F': fontnames[1] = ARGF(); if(fontnames[1] == nil) goto Usage; break; case 'l': loadfile = ARGF(); if(loadfile == nil) goto Usage; break; default: Usage: fprint(2, "usage: acme [-ab] [-c ncol] [-f font] [-F fixedfont] [-l loadfile | file...]\n"); exits("usage"); }ARGEND if(fontnames[0] == nil) fontnames[0] = getenv("font"); if(fontnames[0] == nil) fontnames[0] = "/lib/font/bit/vga/unicode.font"; if(access(fontnames[0], 0) < 0){ fprint(2, "acme: can't access %s: %r\n", fontnames[0]); exits("font open"); } if(fontnames[1] == nil) fontnames[1] = fontnames[0]; fontnames[0] = estrdup(fontnames[0]); fontnames[1] = estrdup(fontnames[1]); quotefmtinstall(); cputype = getenv("cputype"); objtype = getenv("objtype"); home = getenv("home"); p = getenv("tabstop"); if(p != nil){ maxtab = strtoul(p, nil, 0); free(p); } if(maxtab == 0) maxtab = 4; if(loadfile) rowloadfonts(loadfile); putenv("font", fontnames[0]); snarffd = open("/dev/snarf", OREAD|OCEXEC); if(cputype){ sprint(buf, "/acme/bin/%s", cputype); bind(buf, "/bin", MBEFORE); } bind("/acme/bin", "/bin", MBEFORE); getwd(wdir, sizeof wdir); if(geninitdraw(nil, derror, fontnames[0], "acme", nil, Refnone) < 0){ fprint(2, "acme: can't open display: %r\n"); exits("geninitdraw"); } d = display; font = d->defaultfont; reffont.f = font; reffonts[0] = &reffont; incref(&reffont); /* one to hold up 'font' variable */ incref(&reffont); /* one to hold up reffonts[0] */ fontcache = emalloc(sizeof(Reffont*)); nfontcache = 1; fontcache[0] = &reffont; iconinit(); timerinit(); rxinit(); cwait = threadwaitchan(); ccommand = chancreate(sizeof(Command**), 0); ckill = chancreate(sizeof(Rune*), 0); cxfidalloc = chancreate(sizeof(Xfid*), 0); cxfidfree = chancreate(sizeof(Xfid*), 0); cnewwindow = chancreate(sizeof(Channel*), 0); cerr = chancreate(sizeof(char*), 0); cedit = chancreate(sizeof(int), 0); cexit = chancreate(sizeof(int), 0); cwarn = chancreate(sizeof(void*), 1); if(cwait==nil || ccommand==nil || ckill==nil || cxfidalloc==nil || cxfidfree==nil || cerr==nil || cexit==nil || cwarn==nil){ fprint(2, "acme: can't create initial channels: %r\n"); threadexitsall("channels"); } mousectl = initmouse(nil, screen); if(mousectl == nil){ fprint(2, "acme: can't initialize mouse: %r\n"); threadexitsall("mouse"); } mouse = mousectl; keyboardctl = initkeyboard(nil); if(keyboardctl == nil){ fprint(2, "acme: can't initialize keyboard: %r\n"); threadexitsall("keyboard"); } mainpid = getpid(); plumbeditfd = plumbopen("edit", OREAD|OCEXEC); if(plumbeditfd >= 0){ cplumb = chancreate(sizeof(Plumbmsg*), 0); proccreate(plumbproc, nil, STACK); } plumbsendfd = plumbopen("send", OWRITE|OCEXEC); fsysinit(); #define WPERCOL 8 disk = diskinit(); if(!loadfile || !rowload(&row, loadfile, TRUE)){ rowinit(&row, screen->clipr); if(ncol < 0){ if(argc == 0) ncol = 2; else{ ncol = (argc+(WPERCOL-1))/WPERCOL; if(ncol < 2) ncol = 2; } } if(ncol == 0) ncol = 2; for(i=0; i<ncol; i++){ c = rowadd(&row, nil, -1); if(c==nil && i==0) error("initializing columns"); } c = row.col[row.ncol-1]; if(argc == 0) readfile(c, wdir); else for(i=0; i<argc; i++){ p = utfrrune(argv[i], '/'); if((p!=nil && strcmp(p, "/guide")==0) || i/WPERCOL>=row.ncol) readfile(c, argv[i]); else readfile(row.col[i/WPERCOL], argv[i]); } } flushimage(display, 1); acmeerrorinit(); threadcreate(keyboardthread, nil, STACK); threadcreate(mousethread, nil, STACK); threadcreate(waitthread, nil, STACK); threadcreate(xfidallocthread, nil, STACK); threadcreate(newwindowthread, nil, STACK); threadnotify(shutdown, 1); recvul(cexit); killprocs(); threadexitsall(nil); }
void intern kbdspawnend( void ) { initkeyboard(); }
int main(void) { int count = 0; int G_pressed = 0, R_pressed = 1; char vstring[10], wstring[10]; double x1_old, y1_old; double x2_old, y2_old; double x1_new, y1_new; double x2_new, y2_new; double vx, vy, wx, wy; double v, w; posvel pv; x1_old = 100.0; y1_old = 100.0; vx = 10.0; vy = 5.0; x2_old = 250.0; y2_old = 250.0; wx = -8.0; wy = 4.0; v = sqrt(pow(wx,2)+pow(wy,2)); w = sqrt(pow(vx,2)+pow(vy,2)); /* open the graphics window */ initwindow(XWINDOW, YWINDOW); /* allow mouse operations */ initmouse(); /* allow keyboard operations */ initkeyboard(); /* create an event queue */ create_event_queue(); /* register display, mouse and keyboard as event sources */ reg_display_events(); reg_mouse_events(); reg_keyboard_events(); /* initialize the font */ initfont(); outtextxy(4,5,"To quit press left mouse button or close graphics window"); outtextxy(4,15,"To pause press right mouse button"); outtextxy(4,25,"To change ball speed use arrow keys (up/down = red, left/right = blue)"); outtextxy(4,35,"To make the red ball green press G or g "); do { if (check_if_event()) { /* wait for event */ wait_for_event(); if (event_close_display()) break; else if (event_mouse_button_down()) { if (event_mouse_left_button_down()) break; else if (event_mouse_right_button_down()) wait_for_event(); } else if (event_key_down()) { /* change speed of first ball */ if(event_key_up_arrow()) { vx = 1.25*vx; vy = 1.25*vy; } else if(event_key_down_arrow()) { vx = 0.75*vx; vy = 0.75*vy; } else if(event_key_left_arrow()) { wx = 0.75*wx; wy = 0.75*wy; } else if(event_key_right_arrow()) { wx = 1.25*wx; wy = 1.25*wy; } if (event_key('G')) { G_pressed = 1; R_pressed = 0; } else if (event_key('R')) { R_pressed = 1; G_pressed = 0; } } } v = sqrt(pow(wx,2)+pow(wy,2)); w = sqrt(pow(vx,2)+pow(vy,2)); /* calculate new ball positions */ x1_new = x1_old + vx*TICK; y1_new = y1_old + vy*TICK; x2_new = x2_old + wx*TICK; y2_new = y2_old + wy*TICK; /* handle what to do if balls hit boundaries */ pv = hit_boundary(x1_new, vx, 1); x1_new = pv.pos; vx = pv.vel; pv = hit_boundary(x2_new, wx, 1); x2_new = pv.pos; wx = pv.vel; pv = hit_boundary(y1_new, vy, 0); y1_new = pv.pos; vy = pv.vel; pv = hit_boundary(y2_new, wy, 0); y2_new = pv.pos; wy = pv.vel; /* draw balls on screen buffer in new positions */ filled_circle(x1_new, y1_new, RADIUS , BLUE); if (G_pressed) filled_circle(x2_new, y2_new, RADIUS , GREEN); else if (R_pressed) filled_circle(x2_new, y2_new, RADIUS , RED); /* make the balls visible on the screen display and remove the balls in the previous positions */ sprintf(vstring, "%4.2lf", v); sprintf(wstring, "%4.2lf", w); setcolor(RED); outtextxy(VEL_TEXT_X,VEL_TEXT_Y,"v = "); /* clear area for numeric output */ filled_rectangle(VEL_TEXT_X+40, VEL_TEXT_Y-10, VEL_TEXT_X+100, VEL_TEXT_Y+20, BLACK); outtextxy(VEL_TEXT_X+60,VEL_TEXT_Y,vstring); setcolor(BLUE); outtextxy(VEL_TEXT_X+120,VEL_TEXT_Y,"w = "); /* clear area for numeric output */ filled_rectangle(VEL_TEXT_X+160, VEL_TEXT_Y-10, VEL_TEXT_X+220, VEL_TEXT_Y+20, BLACK); outtextxy(VEL_TEXT_X+180,VEL_TEXT_Y,wstring); update_display(); /* remove the balls in the previous positions on the screen buffer */ filled_circle(x1_old, y1_old, RADIUS , BLACK); filled_circle(x2_old, y2_old, RADIUS , BLACK); /* update the old positions */ x1_old = x1_new; y1_old = y1_new; x2_old = x2_new; y2_old = y2_new; count++; pausefor(8); /* wait 8 miliseconds */ } while (count < MAXCOUNT); /* close the mouse */ closemouse(); /* remove the display */ closegraph(); return 0; }