diff options
author | joye <joye> | 2014-03-19 19:19:22 (GMT) |
---|---|---|
committer | joye <joye> | 2014-03-19 19:19:22 (GMT) |
commit | aad4b63a80f7461314e733de4f559d94f09246e9 (patch) | |
tree | 6ad387660f0c5236398baba04731d5cb14b45a5f /src/bltGrMarkerText.C | |
parent | 35c3d137f2666241c88c83016b9e6558ba5ae47b (diff) | |
download | blt-aad4b63a80f7461314e733de4f559d94f09246e9.zip blt-aad4b63a80f7461314e733de4f559d94f09246e9.tar.gz blt-aad4b63a80f7461314e733de4f559d94f09246e9.tar.bz2 |
*** empty log message ***
Diffstat (limited to 'src/bltGrMarkerText.C')
-rw-r--r-- | src/bltGrMarkerText.C | 183 |
1 files changed, 81 insertions, 102 deletions
diff --git a/src/bltGrMarkerText.C b/src/bltGrMarkerText.C index 6060c08..224368a 100644 --- a/src/bltGrMarkerText.C +++ b/src/bltGrMarkerText.C @@ -43,9 +43,6 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_CUSTOM, "-bindtags", "bindTags", "BindTags", "Text all", -1, Tk_Offset(TextMarker, obj.tags), TK_OPTION_NULL_OK, &listObjOption, 0}, - {TK_OPTION_CUSTOM, "-coords", "coords", "Coords", - NULL, -1, Tk_Offset(TextMarker, worldPts), - TK_OPTION_NULL_OK, &coordsObjOption, 0}, {TK_OPTION_STRING, "-element", "element", "Element", NULL, -1, Tk_Offset(TextMarker, elemName), TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_SYNONYM, "-fg", NULL, NULL, NULL, -1, 0, 0, "-foreground", 0}, @@ -53,8 +50,7 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_FONT, "-font", "font", "Font", STD_FONT_NORMAL, -1, Tk_Offset(TextMarker, style.font), 0, NULL, 0}, {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground", - STD_NORMAL_FOREGROUND, -1, Tk_Offset(TextMarker, style.color), - TK_OPTION_NULL_OK, NULL, 0}, + STD_NORMAL_FOREGROUND, -1, Tk_Offset(TextMarker, style.color), 0, NULL, 0}, {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify", "left", -1, Tk_Offset(TextMarker, style.justify), 0, NULL, 0}, {TK_OPTION_BOOLEAN, "-hide", "hide", "Hide", @@ -64,10 +60,6 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_CUSTOM, "-mapy", "mapY", "MapY", "y", -1, Tk_Offset(TextMarker, axes.y), 0, &yAxisObjOption, 0}, {TK_OPTION_SYNONYM, "-outline", NULL, NULL, NULL, -1, 0, 0, "-foreground", 0}, - {TK_OPTION_PIXELS, "-padx", "padX", "PadX", - "4", -1, Tk_Offset(TextMarker, style.xPad), 0, NULL, 0}, - {TK_OPTION_PIXELS, "-pady", "padY", "PadY", - "4", -1, Tk_Offset(TextMarker, style.yPad), 0, NULL, 0}, {TK_OPTION_DOUBLE, "-rotate", "rotate", "Rotate", "0", -1, Tk_Offset(TextMarker, style.angle), 0, NULL, 0}, {TK_OPTION_STRING_TABLE, "-state", "state", "State", @@ -76,8 +68,12 @@ static Tk_OptionSpec optionSpecs[] = { NULL, -1, Tk_Offset(TextMarker, string), TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_BOOLEAN, "-under", "under", "Under", "no", -1, Tk_Offset(TextMarker, drawUnder), 0, NULL, 0}, + {TK_OPTION_DOUBLE, "-x", "x", "X", + "0", -1, Tk_Offset(TextMarker, world.x), 0, NULL, 0}, {TK_OPTION_PIXELS, "-xoffset", "xOffset", "XOffset", "0", -1, Tk_Offset(TextMarker, xOffset), 0, NULL, 0}, + {TK_OPTION_DOUBLE, "-y", "y", "Y", + "0", -1, Tk_Offset(TextMarker, world.y), 0, NULL, 0}, {TK_OPTION_PIXELS, "-yoffset", "yOffset", "YOffset", "0", -1, Tk_Offset(TextMarker, yOffset), 0, NULL, 0}, {TK_OPTION_END, NULL, NULL, NULL, NULL, -1, 0, 0, NULL, 0} @@ -110,200 +106,183 @@ Marker* Blt_CreateTextProc(Graph* graphPtr) Blt_Ts_InitStyle(tmPtr->style); tmPtr->optionTable = Tk_CreateOptionTable(graphPtr->interp, optionSpecs); - return (Marker *)tmPtr; + return (Marker*)tmPtr; } -static int ConfigureTextProc(Marker *markerPtr) +static int ConfigureTextProc(Marker* markerPtr) { Graph* graphPtr = markerPtr->obj.graphPtr; - TextMarker *tmPtr = (TextMarker *)markerPtr; - GC newGC; - XGCValues gcValues; - unsigned long gcMask; + TextMarker* tmPtr = (TextMarker*)markerPtr; tmPtr->style.angle = (float)fmod(tmPtr->style.angle, 360.0); if (tmPtr->style.angle < 0.0f) { tmPtr->style.angle += 360.0f; } - newGC = NULL; + + GC newGC = NULL; + XGCValues gcValues; + unsigned long gcMask; if (tmPtr->fillColor) { gcMask = GCForeground; gcValues.foreground = tmPtr->fillColor->pixel; newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues); } - if (tmPtr->fillGC) { + if (tmPtr->fillGC) Tk_FreeGC(graphPtr->display, tmPtr->fillGC); - } tmPtr->fillGC = newGC; markerPtr->flags |= MAP_ITEM; - if (markerPtr->drawUnder) { + if (markerPtr->drawUnder) graphPtr->flags |= CACHE_DIRTY; - } + Blt_EventuallyRedrawGraph(graphPtr); return TCL_OK; } -static void MapTextProc(Marker *markerPtr) +static void MapTextProc(Marker* markerPtr) { Graph* graphPtr = markerPtr->obj.graphPtr; - TextMarker *tmPtr = (TextMarker *)markerPtr; - Region2d extents; - Point2d anchorPt; - int i; - unsigned int w, h; - double rw, rh; + TextMarker* tmPtr = (TextMarker*)markerPtr; - tmPtr->width = tmPtr->height = 0; - if (tmPtr->string == NULL) { + if (!tmPtr->string) return; - } + + tmPtr->width =0; + tmPtr->height =0; + + unsigned int w, h; Blt_Ts_GetExtents(&tmPtr->style, tmPtr->string, &w, &h); + + double rw, rh; Blt_GetBoundingBox(w, h, tmPtr->style.angle, &rw, &rh, tmPtr->outline); tmPtr->width = ROUND(rw); tmPtr->height = ROUND(rh); - for (i = 0; i < 4; i++) { - tmPtr->outline[i].x += ROUND(rw * 0.5); - tmPtr->outline[i].y += ROUND(rh * 0.5); + for (int ii=0; ii<4; ii++) { + tmPtr->outline[ii].x += ROUND(rw * 0.5); + tmPtr->outline[ii].y += ROUND(rh * 0.5); } tmPtr->outline[4].x = tmPtr->outline[0].x; tmPtr->outline[4].y = tmPtr->outline[0].y; - anchorPt = Blt_MapPoint(markerPtr->worldPts, &markerPtr->axes); - anchorPt = Blt_AnchorPoint(anchorPt.x, anchorPt.y, (double)(tmPtr->width), - (double)(tmPtr->height), tmPtr->anchor); + + Point2d anchorPt = Blt_MapPoint(&tmPtr->world, &markerPtr->axes); + anchorPt = Blt_AnchorPoint(anchorPt.x, anchorPt.y, tmPtr->width, + tmPtr->height, tmPtr->anchor); anchorPt.x += markerPtr->xOffset; anchorPt.y += markerPtr->yOffset; - /* - * Determine the bounding box of the text and test to see if it is at - * least partially contained within the plotting area. - */ + + Region2d extents; extents.left = anchorPt.x; extents.top = anchorPt.y; extents.right = anchorPt.x + tmPtr->width - 1; extents.bottom = anchorPt.y + tmPtr->height - 1; markerPtr->clipped = Blt_BoxesDontOverlap(graphPtr, &extents); tmPtr->anchorPt = anchorPt; - } -static int PointInTextProc(Marker *markerPtr, Point2d *samplePtr) +static int PointInTextProc(Marker* markerPtr, Point2d *samplePtr) { - TextMarker *tmPtr = (TextMarker *)markerPtr; + TextMarker* tmPtr = (TextMarker*)markerPtr; - if (tmPtr->string == NULL) { + if (!tmPtr->string) return 0; - } + if (tmPtr->style.angle != 0.0f) { Point2d points[5]; - int i; - - /* - * Figure out the bounding polygon (isolateral) for the text and see - * if the point is inside of it. - */ - for (i = 0; i < 5; i++) { - points[i].x = tmPtr->outline[i].x + tmPtr->anchorPt.x; - points[i].y = tmPtr->outline[i].y + tmPtr->anchorPt.y; + + // Figure out the bounding polygon (isolateral) for the text and see + // if the point is inside of it. + for (int ii=0; ii<5; ii++) { + points[ii].x = tmPtr->outline[ii].x + tmPtr->anchorPt.x; + points[ii].y = tmPtr->outline[ii].y + tmPtr->anchorPt.y; } return Blt_PointInPolygon(samplePtr, points, 5); } + return ((samplePtr->x >= tmPtr->anchorPt.x) && (samplePtr->x < (tmPtr->anchorPt.x + tmPtr->width)) && (samplePtr->y >= tmPtr->anchorPt.y) && (samplePtr->y < (tmPtr->anchorPt.y + tmPtr->height))); } -static int RegionInTextProc(Marker *markerPtr, Region2d *extsPtr, int enclosed) +static int RegionInTextProc(Marker* markerPtr, Region2d *extsPtr, int enclosed) { - TextMarker *tmPtr = (TextMarker *)markerPtr; + TextMarker* tmPtr = (TextMarker*)markerPtr; - if (markerPtr->nWorldPts < 1) { - return FALSE; - } if (tmPtr->style.angle != 0.0f) { + // Generate the bounding polygon (isolateral) for the bitmap and see + // if the point is inside of it. Point2d points[5]; - int i; - - /* - * Generate the bounding polygon (isolateral) for the bitmap and see - * if the point is inside of it. - */ - for (i = 0; i < 4; i++) { - points[i].x = tmPtr->outline[i].x + tmPtr->anchorPt.x; - points[i].y = tmPtr->outline[i].y + tmPtr->anchorPt.y; + for (int ii=0; ii<4; ii++) { + points[ii].x = tmPtr->outline[ii].x + tmPtr->anchorPt.x; + points[ii].y = tmPtr->outline[ii].y + tmPtr->anchorPt.y; } return Blt_RegionInPolygon(extsPtr, points, 4, enclosed); } - if (enclosed) { + + if (enclosed) return ((tmPtr->anchorPt.x >= extsPtr->left) && (tmPtr->anchorPt.y >= extsPtr->top) && ((tmPtr->anchorPt.x + tmPtr->width) <= extsPtr->right) && ((tmPtr->anchorPt.y + tmPtr->height) <= extsPtr->bottom)); - } + return !((tmPtr->anchorPt.x >= extsPtr->right) || (tmPtr->anchorPt.y >= extsPtr->bottom) || ((tmPtr->anchorPt.x + tmPtr->width) <= extsPtr->left) || ((tmPtr->anchorPt.y + tmPtr->height) <= extsPtr->top)); } -static void DrawTextProc(Marker *markerPtr, Drawable drawable) +static void DrawTextProc(Marker* markerPtr, Drawable drawable) { - TextMarker *tmPtr = (TextMarker *)markerPtr; + TextMarker* tmPtr = (TextMarker*)markerPtr; Graph* graphPtr = markerPtr->obj.graphPtr; - if (tmPtr->string == NULL) { + if (!tmPtr->string) return; - } + if (tmPtr->fillGC) { + // Simulate the rotated background of the bitmap by filling a bounding + // polygon with the background color. XPoint points[4]; - int i; - - /* - * Simulate the rotated background of the bitmap by filling a bounding - * polygon with the background color. - */ - for (i = 0; i < 4; i++) { - points[i].x = (short int)(tmPtr->outline[i].x + tmPtr->anchorPt.x); - points[i].y = (short int)(tmPtr->outline[i].y + tmPtr->anchorPt.y); + for (int ii=0; ii<4; ii++) { + points[ii].x = (short int)(tmPtr->outline[ii].x + tmPtr->anchorPt.x); + points[ii].y = (short int)(tmPtr->outline[ii].y + tmPtr->anchorPt.y); } XFillPolygon(graphPtr->display, drawable, tmPtr->fillGC, points, 4, Convex, CoordModeOrigin); } - if (tmPtr->style.color) { - Blt_Ts_DrawText(graphPtr->tkwin, drawable, tmPtr->string, -1, - &tmPtr->style, (int)tmPtr->anchorPt.x, (int)tmPtr->anchorPt.y); - } + + // be sure to update style->gc, things might have changed + tmPtr->style.flags |= UPDATE_GC; + Blt_Ts_DrawText(graphPtr->tkwin, drawable, tmPtr->string, -1, + &tmPtr->style, tmPtr->anchorPt.x, tmPtr->anchorPt.y); } -static void TextToPostscriptProc(Marker *markerPtr, Blt_Ps ps) +static void TextToPostscriptProc(Marker* markerPtr, Blt_Ps ps) { - TextMarker *tmPtr = (TextMarker *)markerPtr; + TextMarker* tmPtr = (TextMarker*)markerPtr; - if (tmPtr->string == NULL) { + if (!tmPtr->string) return; - } + if (tmPtr->fillGC) { + // Simulate the rotated background of the bitmap by filling a bounding + // polygon with the background color. Point2d points[4]; - int i; - - /* - * Simulate the rotated background of the bitmap by filling a bounding - * polygon with the background color. - */ - for (i = 0; i < 4; i++) { - points[i].x = tmPtr->outline[i].x + tmPtr->anchorPt.x; - points[i].y = tmPtr->outline[i].y + tmPtr->anchorPt.y; + for (int ii=0; ii<4; ii++) { + points[ii].x = tmPtr->outline[ii].x + tmPtr->anchorPt.x; + points[ii].y = tmPtr->outline[ii].y + tmPtr->anchorPt.y; } Blt_Ps_XSetBackground(ps, tmPtr->fillColor); Blt_Ps_XFillPolygon(ps, points, 4); } + Blt_Ps_DrawText(ps, tmPtr->string, &tmPtr->style, tmPtr->anchorPt.x, tmPtr->anchorPt.y); } -static void FreeTextProc(Marker *markerPtr) +static void FreeTextProc(Marker* markerPtr) { - TextMarker *tmPtr = (TextMarker *)markerPtr; + TextMarker* tmPtr = (TextMarker*)markerPtr; Graph* graphPtr = markerPtr->obj.graphPtr; Blt_Ts_FreeStyle(graphPtr->display, &tmPtr->style); |