/* Specify static text (C string). */ void VG_TextString(VG_Text *vt, const char *s) { VG_Lock(VGNODE(vt)->vg); if (s != NULL) { Strlcpy(vt->text, s, sizeof(vt->text)); } else { vt->text[0] = '\0'; } VG_Unlock(VGNODE(vt)->vg); }
/* Specify static text (format string). */ void VG_TextPrintf(VG_Text *vt, const char *fmt, ...) { va_list ap; VG_Lock(VGNODE(vt)->vg); if (fmt != NULL) { va_start(ap, fmt); Vsnprintf(vt->text, sizeof(vt->text), fmt, ap); va_end(ap); } else { vt->text[0] = '\0'; } VG_Unlock(VGNODE(vt)->vg); }
static void Draw(void *p, VG_View *vv) { VG_Circle *vc = p; VG_Vector vCenter = VG_Pos(vc->p); int x, y, r; VG_GetViewCoords(vv, vCenter, &x, &y); r = (int)(vc->r*vv->scale); AG_DrawCircle(vv, x, y, r, VG_MapColorRGB(VGNODE(vc)->color)); }
static int MouseMotion(void *p, VG_Vector vPos, VG_Vector vRel, int b) { VG_TextTool *t = p; VG_View *vv = VGTOOL(t)->vgv; VG_Point *pEx; VG_Vector pos; float theta, rad; if (t->vtIns != NULL) { pEx = t->vtIns->p1; pos = VG_Pos(pEx); theta = VG_Atan2(vPos.y - pos.y, vPos.x - pos.x); rad = VG_Hypot(vPos.x - pos.x, vPos.y - pos.y); if ((pEx = VG_NearestPoint(vv, vPos, t->vtIns->p2))) { VG_Status(vv, _("End baseline at Point%u"), (Uint)VGNODE(pEx)->handle); } else { VG_Status(vv, _("End baseline at %.2f,%.2f " "(%.2f|%.2f\xc2\xb0)"), vPos.x, vPos.y, rad, VG_Degrees(theta)); } VG_SetPosition(t->vtIns->p2, vPos); } else { if ((pEx = VG_NearestPoint(vv, vPos, NULL))) { VG_Status(vv, _("Start baseline at Point%u"), (Uint)VGNODE(pEx)->handle); } else { VG_Status(vv, _("Start baseline at %.2f,%.2f"), vPos.x, vPos.y); } } return (0); }
static void RenderText(VG_Text *vt, char *sIn, VG_View *vv) { char sSubst[VG_TEXT_MAX], *s; VG_Vector v1, v2, vMid; int x, y; int su; if (vt->vsObj != NULL) { AG_VariableSubst(vt->vsObj, sIn, sSubst, sizeof(sSubst)); s = sSubst; } else { s = sIn; } AG_PushTextState(); if (vt->fontFace[0] != '\0' && ((agGUI && vt->fontSize != (int)agDefaultFont->spec.size) || (agGUI && vt->fontFlags != agDefaultFont->flags))) { AG_TextFontLookup(vt->fontFace, vt->fontSize, vt->fontFlags); } AG_TextColor(VG_MapColorRGB(VGNODE(vt)->color)); v1 = VG_Pos(vt->p1); v2 = VG_Pos(vt->p2); vMid.x = v1.x + (v2.x - v1.x)/2.0f; vMid.y = v1.y + (v2.y - v1.y)/2.0f; VG_GetViewCoords(vv, vMid, &x, &y); if ((su = AG_TextCacheGet(vv->tCache, s)) != -1) { VG_DrawSurface(vv, x, y, VG_Degrees(VG_Atan2(v1.y-v2.y, v1.x-v2.x)), su); } AG_PopTextState(); }