static void drawbutton(gl_button *bt) { Int32 lw = getlwidth(); Int32 cl = getcolor(); Int32 oriwin = winget(); int cfg, bg; winset(bt->win); linewidth(1); locate_button(bt); cfg = *(bt->state)?bt->bg:bt->fg; bg = *(bt->state)?((bt->type == BUTTON)?bt->fg:bt->active_c):bt->bg; color(bg); rectf(bt->x, bt->y, bt->x + bt->width, bt->y + bt->height); color(bt->fg); rect (bt->x, bt->y, bt->x + bt->width, bt->y + bt->height); if (bt->label != NULL) { color(cfg); cmov2(bt->x, bt->y + 0.05 * bt->height); charstr(bt->label); } winset(oriwin); color(cl); linewidth(lw); sleep(0); }
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(); }
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(); }
static void drawslider(gl_slider *sl) { Int32 lw = getlwidth(); Int32 cl = getcolor(); Int32 oriwin = winget(); long co; int i; Screencoord x, y; Int32 xo, yo; winset(sl->win); linewidth(1); update_slider_value(sl); locate_slider(sl); if (sl->txbg == -1) { /* first time, get bg color */ cmov2(sl->x + sl->len + sl->thick, sl->y); getcpos(&x, &y); getorigin(&xo, &yo); x -= xo; y -= yo; i = lrectread(x, y, x, y, &co); sl->txbg = co; #ifdef DEBUG printf("textbg = %d, bytes = %d x %d (soll %g) y %d (soll %g)\n", co,i,x,sl->x + sl->len + sl->thick, y,sl->y); #endif } color(sl->bg); rectf(sl->x, sl->y, sl->x+sl->thick+sl->len, sl->y+sl->height); color(sl->fg); rect (sl->x, sl->y, sl->x+sl->thick+sl->len, sl->y+sl->height); rectf(sl->x + sl->len * (sl->value - sl->min)/(sl->max - sl->min), sl->y, sl->x + sl->len * (sl->value - sl->min)/(sl->max - sl->min) + sl->thick, sl->y + sl->height); if (sl->buf != NULL) { color(sl->txbg); cmov2(sl->x + sl->len + sl->thick, sl->y); charstr(sl->buf); color(sl->fg); sprintf(sl->buf + 1, sl->format, sl->value); cmov2(sl->x + sl->len + sl->thick, sl->y); charstr(sl->buf); } winset(oriwin); color(cl); linewidth(lw); sleep(0); }
gl_slider *create_gl_slider(double x, double y, double len, double height, double thick, int fg, int bg, double min, double max, double step, double initvalue, double *valuep, char *format, void (*callback)(gl_slider *, double)) { gl_slider *newslider; if ((newslider = (gl_slider *)malloc(sizeof(gl_slider))) == NULL) return(NULL); if (firstslider == NULL) { /* initialization */ check_vers(); qdevice(LEFTMOUSE); tie(LEFTMOUSE, MOUSEX, MOUSEY); firstslider = actslider = newslider; } actslider->nextp = newslider; actslider = newslider; actslider->nextp = NULL; actslider->win = winget(); actslider->x = x; actslider->y = y; actslider->len = len; actslider->height = height; actslider->thick = thick; actslider->fg = fg; actslider->bg = bg; actslider->txbg = -1; actslider->min = min; actslider->max = max; actslider->step = step; actslider->value = initvalue; actslider->valuep = valuep; if (valuep != NULL) *valuep = initvalue; actslider->format = format; if (actslider->format != NULL) { actslider->buf = (char *)malloc(strlen(format) + 51); *(actslider->buf) = ' '; *(actslider->buf + 1) = 0; } actslider->callback = callback; drawslider(actslider); return(actslider); }
/**************************** BUTTONS ********************************/ gl_button *create_gl_button(double x, double y, double width, double height, int fg, int bg, int active_c, int *state, int type, char *label, void (*callback)(gl_button *, int)) { gl_button *newbutton; if ((newbutton = (gl_button *)malloc(sizeof(gl_button))) == NULL) return(NULL); if (firstbutton == NULL) { /* initialization */ check_vers(); qdevice(LEFTMOUSE); tie(LEFTMOUSE, MOUSEX, MOUSEY); firstbutton = actbutton = newbutton; } actbutton->nextp = newbutton; actbutton = newbutton; actbutton->nextp = NULL; actbutton->win = winget(); actbutton->x = x; actbutton->y = y; actbutton->width = width; actbutton->height = height; actbutton->fg = fg; actbutton->bg = bg; actbutton->active_c = active_c; actbutton->type = type; actbutton->changed = FALSE; if (state != NULL) actbutton->state = state; else { if ((actbutton->state = (int *)malloc(sizeof(int))) == NULL) return(NULL); *(actbutton->state) = 0; } if (label != NULL) { if ((actbutton->label = (char *)malloc(strlen(label) + 2)) != NULL) { *(actbutton->label) = ' '; strcpy(actbutton->label + 1, label); } } else actbutton->label = NULL; actbutton->callback = callback; drawbutton(actbutton); return(actbutton); }
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); }
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); } }