static int SD_Call(GGadget *g, GEvent *e) { if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { char *fn; unichar_t *insert; fn = gwwv_open_filename(_("Call Script"), NULL, "*",NULL); if ( fn==NULL ) return(true); insert = malloc((strlen(fn)+10)*sizeof(unichar_t)); *insert = '"'; utf82u_strcpy(insert+1,fn); uc_strcat(insert,"\"()"); GTextFieldReplace(GWidgetGetControl(GGadgetGetWindow(g),CID_Script),insert); free(insert); free(fn); } return( true ); }
static int RulerText(CharView *cv, unichar_t *ubuf, int line) { char buf[80]; double len; double dx, dy; Spline *s; double t; BasePoint slope; real xoff = cv->info.x-cv->p.cx, yoff = cv->info.y-cv->p.cy; buf[0] = '\0'; switch ( line ) { case 0: { real len = sqrt(xoff*xoff+yoff*yoff); if ( cv->autonomous_ruler_w ) { xoff = last_ruler_offset[0].x; yoff = last_ruler_offset[0].y; } if ( !cv->autonomous_ruler_w && !cv->p.pressed ) /* Give current location accurately */ sprintf( buf, "%f,%f", (double) cv->info.x, (double) cv->info.y); else sprintf( buf, "%f %.0f° (%f,%f)", (double) len, atan2(yoff,xoff)*180/3.1415926535897932, (double) xoff,(double) yoff); break; } case 1: if ( cv->p.pressed ) { if ( cv->p.spline!=NULL || (cv->p.sp!=NULL && ((cv->p.sp->next==NULL && cv->p.sp->prev!=NULL) || (cv->p.sp->prev==NULL && cv->p.sp->next!=NULL) || (cv->p.sp->next!=NULL && cv->p.sp->prev!=NULL && BpColinear(!cv->p.sp->noprevcp ? &cv->p.sp->prevcp : &cv->p.sp->prev->from->me, &cv->p.sp->me, !cv->p.sp->nonextcp ? &cv->p.sp->nextcp : &cv->p.sp->next->to->me))) ) ) { Spline *spline; double t; if ( cv->p.spline!=NULL ) { spline = cv->p.spline; t = cv->p.t; } else if ( cv->p.sp->next == NULL ) { spline = cv->p.sp->prev; t = 1; } else { spline = cv->p.sp->next; t = 0; } slope.x = (3*spline->splines[0].a*t + 2*spline->splines[0].b)*t + spline->splines[0].c; slope.y = (3*spline->splines[1].a*t + 2*spline->splines[1].b)*t + spline->splines[1].c; len = sqrt(slope.x*slope.x + slope.y*slope.y); if ( len!=0 ) { slope.x /= len; slope.y /= len; sprintf( buf, _("Normal Distance: %.2f Along Spline: %.2f"), fabs(slope.y*xoff - slope.x*yoff), slope.x*xoff + slope.y*yoff ); } } } else if ( cv->dv!=NULL || cv->b.gridfit!=NULL ) { double scalex = (cv->b.sc->parent->ascent+cv->b.sc->parent->descent)/(rint(cv->ft_pointsizex*cv->ft_dpi/72.0)); double scaley = (cv->b.sc->parent->ascent+cv->b.sc->parent->descent)/(rint(cv->ft_pointsizey*cv->ft_dpi/72.0)); sprintf( buf, "%.2f,%.2f", (double) (cv->info.x/scalex), (double) (cv->info.y/scaley)); } else if ( cv->p.spline!=NULL ) { s = cv->p.spline; t = cv->p.t; sprintf( buf, _("Near (%f,%f)"), (double) (((s->splines[0].a*t+s->splines[0].b)*t+s->splines[0].c)*t+s->splines[0].d), (double) (((s->splines[1].a*t+s->splines[1].b)*t+s->splines[1].c)*t+s->splines[1].d) ); } else if ( cv->p.sp!=NULL ) { sprintf( buf, _("Near (%f,%f)"),(double) cv->p.sp->me.x,(double) cv->p.sp->me.y ); } else return( false ); break; case 2: if ( cv->p.pressed ) { if ( cv->p.sp!=NULL && cv->info_sp!=NULL && ((cv->p.sp->next!=NULL && cv->p.sp->next->to==cv->info_sp) || (cv->p.sp->prev!=NULL && cv->p.sp->prev->from==cv->info_sp)) ) { if ( cv->p.sp->next!=NULL && cv->p.sp->next->to==cv->info_sp ) len = SplineLength(cv->p.sp->next); else len = SplineLength(cv->p.sp->prev); } else if ( cv->p.spline == cv->info_spline && cv->info_spline!=NULL ) len = SplineLengthRange(cv->info_spline,cv->p.t,cv->info_t); else if ( cv->p.sp!=NULL && cv->info_spline!=NULL && cv->p.sp->next == cv->info_spline ) len = SplineLengthRange(cv->info_spline,0,cv->info_t); else if ( cv->p.sp!=NULL && cv->info_spline!=NULL && cv->p.sp->prev == cv->info_spline ) len = SplineLengthRange(cv->info_spline,cv->info_t,1); else if ( cv->info_sp!=NULL && cv->p.spline!=NULL && cv->info_sp->next == cv->p.spline ) len = SplineLengthRange(cv->p.spline,0,cv->p.t); else if ( cv->info_sp!=NULL && cv->p.spline!=NULL && cv->info_sp->prev == cv->p.spline ) len = SplineLengthRange(cv->p.spline,cv->p.t,1); else return( false ); if ( len>1 ) sprintf( buf, _("Spline Length=%.1f"), len); else sprintf( buf, _("Spline Length=%g"), len); } else if ( cv->p.spline!=NULL ) { s = cv->p.spline; t = cv->p.t; dx = (3*s->splines[0].a*t+2*s->splines[0].b)*t+s->splines[0].c; dy = (3*s->splines[1].a*t+2*s->splines[1].b)*t+s->splines[1].c; SlopeToBuf(buf,"",dx,dy); } else if ( cv->p.sp!=NULL ) { if ( cv->p.sp->nonextcp ) strcpy(buf,_("No Next Control Point")); else sprintf(buf,_("Next CP: (%f,%f)"), (double) cv->p.sp->nextcp.x, (double) cv->p.sp->nextcp.y); } else return( false ); break; case 3: if ( cv->p.pressed ) return( false ); else if ( cv->p.spline!=NULL ) { CurveToBuf(buf,cv,cv->p.spline,cv->p.t); } else if ( cv->p.sp!=NULL && cv->p.sp->next!=NULL ) { s = cv->p.sp->next; dx = s->splines[0].c; dy = s->splines[1].c; SlopeToBuf(buf,_(" Next"),dx,dy); } else if ( cv->p.sp!=NULL ) { if ( cv->p.sp->noprevcp ) strcpy(buf,_("No Previous Control Point")); else sprintf(buf,_("Prev CP: (%f,%f)"), (double) cv->p.sp->prevcp.x, (double) cv->p.sp->prevcp.y); } else return( false ); break; case 4: if ( cv->p.spline!=NULL ) return( false ); else if ( cv->p.sp->next!=NULL ) { CurveToBuf(buf,cv,cv->p.sp->next,0); } else if ( cv->p.sp->prev!=NULL ) { s = cv->p.sp->prev; dx = (3*s->splines[0].a*1+2*s->splines[0].b)*1+s->splines[0].c; dy = (3*s->splines[1].a*1+2*s->splines[1].b)*1+s->splines[1].c; SlopeToBuf(buf,_(" Prev"),dx,dy); } else return( false ); break; case 5: if ( cv->p.sp->next!=NULL ) { if ( cv->p.sp->noprevcp ) strcpy(buf,_("No Previous Control Point")); else sprintf(buf,_("Prev CP: (%f,%f)"), (double) cv->p.sp->prevcp.x, (double) cv->p.sp->prevcp.y); } else { CurveToBuf(buf,cv,cv->p.sp->prev,1); } break; case 6: if ( cv->p.sp->next!=NULL && cv->p.sp->prev!=NULL ) { s = cv->p.sp->prev; dx = (3*s->splines[0].a*1+2*s->splines[0].b)*1+s->splines[0].c; dy = (3*s->splines[1].a*1+2*s->splines[1].b)*1+s->splines[1].c; SlopeToBuf(buf,_(" Prev"),dx,dy); } else return( false ); break; case 7: if ( cv->p.sp->next!=NULL && cv->p.sp->prev!=NULL ) { CurveToBuf(buf,cv,cv->p.sp->prev,1); } else return( false ); break; default: return( false ); } utf82u_strcpy(ubuf,buf); return( true ); }