void rubberRectZoid (void *v, int device, int mouseDown) { static WmjAct backAct; pWmj cW = (pWmj)v; WmjAct *Ap = (device == LEFTMOUSE ? cW->lefMouse : cW->midMouse); /* Tetra *trp = Ap->data; */ flt zX = cW->zX, zY = cW->zY; long bxA, byA, nxA, nyA, oxA,oyA, wx,ww,wy,wh; long widA = winget(); if (! mouseDown) return; getorigin(&wx,&wy); getsize( &ww,&wh); ww -= 1; wh -= 1; oxA = bxA = (getvaluator(MOUSEX) - wx); oyA = byA = (getvaluator(MOUSEY) - wy); cursoff(); drawmode(OVERDRAW); while(getbutton(device)) { nxA = getvaluator(MOUSEX) - wx; if (nxA < 0) nxA = 0; else if (nxA > ww) nxA = ww; nyA = getvaluator(MOUSEY) - wy; if (nyA < 0) nyA = 0; else if (nyA > wh) nyA = wh; if (nxA != oxA || nyA != oyA) { winset(widA); color(BLACK); /* black erases */ sboxi(bxA,byA,oxA,oyA); color(RED); /* set color of new circle */ sboxi(bxA,byA,nxA,nyA); oxA = nxA, oyA = nyA; } } color(BLACK); sboxi(bxA,byA,oxA,oyA); drawmode(NORMALDRAW); cpack(FcGRN); sboxi(bxA,byA,nxA,nyA); if (bxA > nxA) nxA = bxA, bxA = oxA; if (byA > nyA) nyA = byA, byA = oyA; wrn("rubberRectZ B4 showSub: %4d %4d %4d %4d zX:%.2f zY:%.2f",bxA,byA,nxA,nyA, zX, zY); backAct = *Ap; backAct.func = &testChain; cW->next = showSub(cW, bxA/zX,byA/zY,nxA/zX,nyA/zY,"subA",zX*2.0,zY*2.0,5); cW->next->lefMouse = &backAct; cW->next->prev = cW; winset(widA); curson(); }
void backTrack (void *v, int device, int mouseDown) { pWmj cW = (pWmj)v, pW = cW->prev; /* WmjAct *Ap = (device == LEFTMOUSE ? cW->lefMouse : cW->midMouse); */ pDmj cD = &cW->D; long bxA, byA, nxA, nyA, oxA,oyA, wx,ww,wy,wh; long widA = winget(); if (! mouseDown) return; getorigin(&wx,&wy); getsize( &ww,&wh); ww -= 1; wh -= 1; oxA = bxA = (getvaluator(MOUSEX) - wx); oyA = byA = (getvaluator(MOUSEY) - wy); cursoff(); drawmode(OVERDRAW); while(getbutton(device)) { nxA = getvaluator(MOUSEX) - wx; if (nxA < 0) nxA = 0; else if (nxA > ww) nxA = ww; nyA = getvaluator(MOUSEY) - wy; if (nyA < 0) nyA = 0; else if (nyA > wh) nyA = wh; if (nxA != oxA || nyA != oyA) { /* winset(widA); */ color(BLACK); /* black erases */ sboxi(bxA,byA,oxA,oyA); /* NB: sbox is faster than rect, but less flex */ color(RED); /* set color of new circle */ sboxi(bxA,byA,nxA,nyA); oxA = nxA, oyA = nyA; } } color(BLACK); sboxi(bxA,byA,oxA,oyA); drawmode(NORMALDRAW); cpack(FcGRN); sboxi(bxA,byA,nxA,nyA); if (pW) { pDmj pD = &pW->D; flt pzX = pW->zX, zX = pzX/cW->zX; flt pzY = pW->zY, zY = pzY/cW->zY; long L = cD->l*pzX, B = cD->b*pzY; wrn("bT: id: %d pD->lb: %3d %3d zXY: %.1f %.1f", pW->id, pD->l, pD->b, zX, zY); wrn("bT: id: %d cD->lb: %3d %3d czXY: %.1f %.1f", cW->id, cD->l, cD->b,cW->zX,cW->zY); winset(pW->id); drawmode(OVERDRAW); color(YELLOW); sboxi(L + bxA*zX, B + byA*zY, L + oxA*zX, B + oyA*zY); drawmode(NORMALDRAW); } winset(widA); curson(); }
int update_widgets(short val) { gl_slider *sl = firstslider; gl_button *bt = firstbutton; Int16 x, y; int flag = FALSE, sliderchange = FALSE; #ifdef DEBUG printf("update_widgets called with val = %d\n", (int)val); if (qtest()) { int dev; dev = qread(&x); printf("update_widgets: qtest() for x is true. dev = %d, val = %d\n", dev, (int)x); } else { x = getvaluator(MOUSEX); printf("update_widgets: qtest() for x is FALSE!. x = %d\n", (int)x); } if (qtest()) { int dev; dev = qread(&y); printf("update_widgets: qtest() for y is true. dev = %d, val = %d\n", dev, (int)y); } else { y = getvaluator(MOUSEY); printf("update_widgets: qtest() for y is FALSE!. y = %d\n", (int)y); } #else if (qtest()) qread(&x); else x = getvaluator(MOUSEX); if (qtest()) qread(&y); else y = getvaluator(MOUSEY); #endif if (val == 0) return(FALSE); while (sl != NULL && !flag) { switch (updateslider(x, y, sl)) { case -1: sliderchange = TRUE; break; case FALSE: flag = FALSE; break; default: flag = TRUE; break; } sl = sl->nextp; } while (bt != NULL && !flag) { flag = updatebutton(x, y, bt); bt = bt->nextp; } return(flag||sliderchange); }
static int updatebutton(int x, int y, gl_button *bt) { Int32 xo, yo; Int16 xx, yy; Int32 oriwin = winget(); int oldstate; #ifdef DEBUG printf("updatebutton: button with label %s - ", bt->label); #endif winset(bt->win); locate_button(bt); getorigin(&xo, &yo); x -= xo; y -= yo; if (x < bt->scx0 || y > bt->scy0 || x > bt->scx1 || y < bt->scy1) { winset(oriwin); bt->changed = FALSE; #ifdef DEBUG printf("x = %d y = %d, btscx0 = %d btscx1 = %d btscy0 = %d btscy1 = %d\n", x, y, bt->scx0, bt->scx1, bt->scy0, bt->scy1); puts("click not inside - return(FALSE)"); #endif return(FALSE); } oldstate = *(bt->state); *(bt->state) = (bt->type == BUTTON)?TRUE:!oldstate; drawbutton(bt); while (qread(&xx) != LEFTMOUSE); /* wait for LEFTMOUSE release */ if (qtest()) qread(&xx); else { xx = getvaluator(MOUSEX); fprintf(stderr, "updatebutton: This should not happen, tie() seems to fail.\n"); } if (qtest()) qread(&yy); else { yy = getvaluator(MOUSEY); fprintf(stderr, "updatebutton: This should not happen, tie() seems to fail.\n"); } getorigin(&xo, &yo); x = xx - xo; y = yy - yo; if (!(bt->changed = !( x < bt->scx0 || y > bt->scy0 || x > bt->scx1 || y < bt->scy1 ) )) *(bt->state) = oldstate; if (bt->type == BUTTON) { *(bt->state) = FALSE; usleep(50000); } drawbutton(bt); if (oriwin != bt->win) winset(oriwin); if (bt->callback != NULL && bt->changed) { bt->callback(bt, *(bt->state)); } #ifdef DEBUG printf("return(%s)\n", bt->changed?"true":"false"); #endif return(bt->changed); }
int getmousey() { return getvaluator(MOUSEY)-yorg; }
static int updateslider(int x, int y, gl_slider *sl) { Int32 xo, yo; Int16 xx, yy; double orival; Int32 oriwin = winget(); int dev; orival = sl->value; update_slider_value(sl); winset(sl->win); getorigin(&xo, &yo); x -= xo; y -= yo; #ifdef DEBUG printf("updateslider: slider label %s - ", sl->buf); #endif locate_slider(sl); if (x < sl->scx0 || y > sl->scy0 || x > sl->scx1 + sl->sc_thick || y < sl->scy1) { winset(oriwin); if (orival != sl->value) { /* This is used when the click is not for this slider, but update_slider_value() has changed the value... */ if (sl->callback != NULL) sl->callback(sl, sl->value); #ifdef DEBUG puts("return(-1)"); #endif return(-1); } else { #ifdef DEBUG puts("return(FALSE)"); #endif return(FALSE); } } while (qtest() == 0 || (dev = qread(&xx)) != LEFTMOUSE) { /* getorigin(&xo, &yo); */ setslider(getvaluator(MOUSEX) - xo, sl); usleep(100000); } #ifdef DEBUG printf("updateslider: got an event, dev = %d val = %d\n", dev, (int)xx); if (qtest()) { int dev; dev = qread(&xx); printf("updateslider: qtest() for x is true. dev = %d, val = %d\n", dev, (int)xx); } else { xx = getvaluator(MOUSEX); printf("updateslider: qtest() for x is FALSE!. x = %d\n", (int)xx); } if (qtest()) { int dev; dev = qread(&yy); printf("updateslider: qtest() for y is true. dev = %d, val = %d\n", dev, (int)yy); } else { yy = getvaluator(MOUSEY); printf("updateslider: qtest() for y is FALSE!. y = %d\n", (int)yy); } setslider((int)(xx-xo), sl); #else if (qtest()) qread(&xx); if (qtest()) { qread(&yy); setslider((int)(xx-xo), sl); } else fprintf(stderr, "updateslider: This should not happen, tie() seems to fail.\n"); #endif winset(oriwin); if (sl->value != orival) { if (sl->callback != NULL) sl->callback(sl, sl->value); return(TRUE); #ifdef DEBUG puts("return(TRUE)"); #endif } else { #ifdef DEBUG puts("return(FALSE)"); #endif return(FALSE); } }
float fgetmousey() { return ((float)getvaluator(MOUSEY)-yorg)/(float)ysize; }
int getmousex() { return getvaluator(MOUSEX)-xorg; }
/* * winlib routines follow * */ float fgetmousex() { return ((float)getvaluator(MOUSEX)-xorg)/(float)xsize; }
main() { char *p; float tdir = TRANS; float scal = 1.0 + SCAL; int but, nplanes; int x, y, i, n; short val; int bf = 1; int fill = 1; prefsize(500L, 500L); vinit("mswin"); winopen("lcube"); unqdevice(INPUTCHANGE); qdevice(SKEY); qdevice(XKEY); qdevice(YKEY); qdevice(ZKEY); qdevice(EQUALKEY); qdevice(MINUSKEY); qdevice(ESCKEY); qdevice(QKEY); qdevice(FKEY); qdevice(BKEY); /* * Wait for REDRAW event ... */ while (qread(&val) != REDRAW) ; window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0); lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0); if ((nplanes = getplanes()) == 1) makecubes(0); makecubes(1); backface(1); doublebuffer(); gconfig(); /* * Doublebuffer does a backbuffer(TRUE).... */ while(1) { x = 500 - (int)getvaluator(MOUSEX); y = 500 - (int)getvaluator(MOUSEY); x *= 3; y *= 3; pushmatrix(); rotate(x, 'y'); rotate(y, 'x'); color(BLACK); clear(); callobj((Object)3); if (nplanes == 1) callobj((Object)2); popmatrix(); swapbuffers(); if (qtest()) { but = qread(&val); but = qread(&val); /* swallow up event */ switch (but) { case SKEY: scale(scal, scal, scal); break; case XKEY: translate(tdir, 0.0, 0.0); break; case YKEY: translate(0.0, tdir, 0.0); break; case ZKEY: translate(0.0, 0.0, tdir); break; case MINUSKEY: tdir = -tdir; if (scal < 1.0) scal = 1.0 + SCAL; else scal = 1.0 - SCAL; break; case EQUALKEY: tdir = TRANS; break; case BKEY: bf = !bf; backface(bf); break; case FKEY: fill = !fill; if (fill) polymode(PYM_FILL); else polymode(PYM_LINE); break; case ESCKEY: case QKEY: gexit(); exit(0); default: ; } } } }
main() { int i, itest, dobackface, dofill, dodouble; char buf[100]; float H; short idata; int xr, yr; vinit("mswin"); winopen("piston"); /* * Wait for REDRAW event ... */ while (qread(&idata) != REDRAW) ; doublebuffer(); gconfig(); unqdevice(INPUTCHANGE); qdevice(QKEY); qdevice(FKEY); qdevice(BKEY); qdevice(ESCKEY); qdevice(REDRAW); makecyl(); polymode(PYM_FILL); backface(1); /* * set up a perspective projection with a field of view of * 40.0 degrees, aspect ratio of 1.0, near clipping plane 0.1, * and the far clipping plane at 1000.0. */ perspective(400, 1.5, 0.1, 600.0); lookat(0.0, -6.0, 4., 0.0, 0.0, 0.0, 0); /* * here we loop back here adnaseum until someone hits a key */ xr = yr = 0; while(1) { for (i = 0; i < 360; i += 5) { color(BLACK); clear(); color(RED); H = 1.0 + cos(2.0 * 3.14159265*i / 180.0); yr = 500 - (int)getvaluator(MOUSEY); xr = 500 - (int)getvaluator(MOUSEX); yr = 500 - (int)getvaluator(MOUSEY); xr *= 3; yr *= 3; pushmatrix(); rotate(xr, 'x'); rotate(yr, 'y'); piston(H); popmatrix(); if (dodouble) swapbuffers(); if (qtest()) { itest = qread(&idata); itest = qread(&idata); /* Zap Up event */ if (itest == BKEY) { dobackface = !dobackface; backface(dobackface); } else if (itest == FKEY) { dofill = !dofill; if (dofill) polymode(PYM_FILL); else polymode(PYM_LINE); } else if(itest == QKEY || itest == ESCKEY) { gexit(); exit(0); } } } } }
/* * a routine to demonstrate using locator. */ main() { int i, bt, act, nchars; short data; Scoord x, y, sx, sy; Screencoord minx, maxx, miny, maxy; ginit(); color(BLACK); clear(); color(BLUE); getviewport(&minx, &maxx, &miny, &maxy); ortho2((Coord)minx, (Coord)maxx, (Coord)miny, (Coord)maxy); /* * draw some axes */ move2s((Scoord)minx, (Scoord)((maxy - miny) / 2)); draw2s((Scoord)maxx, (Scoord)((maxy - miny) / 2)); move2s((Scoord)((maxx - minx) / 2), (Scoord)miny); draw2s((Scoord)((maxx - minx) / 2), (Scoord)maxy); color(GREEN); /* * enable the left and middle mouse buttons */ unqdevice(INPUTCHANGE); qdevice(LEFTMOUSE); qdevice(MIDDLEMOUSE); /* * Wait for REDRAW event ... */ while (qread(&data) != REDRAW) ; act = 0; /* * getvaluator tells us the valuator's value. In * this case it's the X and Y positions of the mouse. * Note: these come back to us in screen coordinates. */ while((bt = qread(&data)) != MIDDLEMOUSE) { sx = getvaluator(MOUSEX); sy = getvaluator(MOUSEY); if (bt == -1) { gexit(); printf("No locator device found\n"); exit(0); } else { if (act) { act = 0; move2s(sx, sy); draw2s(x, y); } else { act = 1; x = sx; y = sy; } } (void)qread(&data); /* swallow the up event */ } gexit(); }