From e8752647d6547dfbbe39ec22f1643e4782c6358b Mon Sep 17 00:00:00 2001 From: joye Date: Fri, 28 Mar 2014 14:33:16 +0000 Subject: *** empty log message *** --- bltGrMarkerBitmap.C | 131 ++++++++++-------------- bltGrMarkerBitmap.h | 4 + configure | 1 - configure.in | 1 - src/bltGrMarker.C | 14 +-- src/bltGrMarker.h | 8 +- src/bltGrMarkerLine.C | 156 ++++++++++++---------------- src/bltGrMarkerLine.h | 4 + src/bltGrMarkerPolygon.C | 257 ++++++++++++++++++++--------------------------- src/bltGrMarkerPolygon.h | 4 + src/bltGrMarkerText.C | 139 ++++++++++++------------- src/bltGrMarkerText.h | 4 + 12 files changed, 320 insertions(+), 403 deletions(-) diff --git a/bltGrMarkerBitmap.C b/bltGrMarkerBitmap.C index f016e7b..6dc46c2 100644 --- a/bltGrMarkerBitmap.C +++ b/bltGrMarkerBitmap.C @@ -81,17 +81,8 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_END, NULL, NULL, NULL, NULL, -1, 0, 0, NULL, 0} }; -static MarkerMapProc MapBitmapProc; -static MarkerPointProc PointInBitmapProc; -static MarkerPostscriptProc BitmapToPostscriptProc; -static MarkerRegionProc RegionInBitmapProc; - static MarkerClass bitmapMarkerClass = { optionSpecs, - MapBitmapProc, - PointInBitmapProc, - RegionInBitmapProc, - BitmapToPostscriptProc, }; BitmapMarker::BitmapMarker(Graph* graphPtr, const char* name) @@ -189,41 +180,40 @@ void BitmapMarker::draw(Drawable drawable) width, height, anchorPt.x, anchorPt.y, 1); } -static void MapBitmapProc(Marker* markerPtr) +void BitmapMarker::map() { - BitmapMarker* bmPtr = (BitmapMarker*)markerPtr; - BitmapMarkerOptions* ops = (BitmapMarkerOptions*)bmPtr->ops; - Graph* graphPtr = markerPtr->obj.graphPtr; + Graph* graphPtr = obj.graphPtr; + BitmapMarkerOptions* opp = (BitmapMarkerOptions*)ops; - if (ops->bitmap == None) + if (opp->bitmap == None) return; - if (!ops->worldPts || (ops->worldPts->num < 1)) + if (!opp->worldPts || (opp->worldPts->num < 1)) return; - int width, height; - Tk_SizeOfBitmap(graphPtr->display, ops->bitmap, &width, &height); + int lwidth; + int lheight; + Tk_SizeOfBitmap(graphPtr->display, opp->bitmap, &lwidth, &lheight); - Point2d anchorPt = - Blt_MapPoint(ops->worldPts->points, &ops->axes); - anchorPt = Blt_AnchorPoint(anchorPt.x, anchorPt.y, width, height, - ops->anchor); - anchorPt.x += ops->xOffset; - anchorPt.y += ops->yOffset; + Point2d lanchorPt = Blt_MapPoint(opp->worldPts->points, &opp->axes); + lanchorPt = + Blt_AnchorPoint(lanchorPt.x, lanchorPt.y, lwidth, lheight, opp->anchor); + lanchorPt.x += opp->xOffset; + lanchorPt.y += opp->yOffset; Region2d extents; - extents.left = anchorPt.x; - extents.top = anchorPt.y; - extents.right = anchorPt.x + width - 1; - extents.bottom = anchorPt.y + height - 1; - markerPtr->clipped = Blt_BoxesDontOverlap(graphPtr, &extents); + extents.left = lanchorPt.x; + extents.top = lanchorPt.y; + extents.right = lanchorPt.x + lwidth - 1; + extents.bottom = lanchorPt.y + lheight - 1; + clipped = Blt_BoxesDontOverlap(graphPtr, &extents); - if (markerPtr->clipped) + if (clipped) return; - bmPtr->width = width; - bmPtr->height = height; - bmPtr->anchorPt = anchorPt; + width = lwidth; + height = lheight; + anchorPt = lanchorPt; // Compute a polygon to represent the background area of the bitmap. // This is needed for print a background in PostScript. @@ -240,72 +230,61 @@ static void MapBitmapProc(Marker* markerPtr) polygon[ii].y = (polygon[ii].y) + ty; } Blt_GraphExtents(graphPtr, &extents); - int nn = Blt_PolyRectClip(&extents, polygon, 4, bmPtr->outline); + int nn = Blt_PolyRectClip(&extents, polygon, 4, outline); if (nn < 3) { - memcpy(&bmPtr->outline, polygon, sizeof(Point2d) * 4); - bmPtr->nOutlinePts = 4; + memcpy(&outline, polygon, sizeof(Point2d) * 4); + nOutlinePts = 4; } else - bmPtr->nOutlinePts = nn; + nOutlinePts = nn; } -static int PointInBitmapProc(Marker* markerPtr, Point2d *samplePtr) +int BitmapMarker::pointIn(Point2d *samplePtr) { - BitmapMarker* bmPtr = (BitmapMarker*)markerPtr; - BitmapMarkerOptions* ops = (BitmapMarkerOptions*)bmPtr->ops; + BitmapMarkerOptions* opp = (BitmapMarkerOptions*)ops; - if (ops->bitmap == None) + if (opp->bitmap == None) return 0; - return ((samplePtr->x >= bmPtr->anchorPt.x) && - (samplePtr->x < (bmPtr->anchorPt.x + bmPtr->width)) && - (samplePtr->y >= bmPtr->anchorPt.y) && - (samplePtr->y < (bmPtr->anchorPt.y + bmPtr->height))); + return ((samplePtr->x >= anchorPt.x) && + (samplePtr->x < (anchorPt.x + width)) && + (samplePtr->y >= anchorPt.y) && + (samplePtr->y < (anchorPt.y + height))); } -static int RegionInBitmapProc(Marker* markerPtr, Region2d *extsPtr, - int enclosed) +int BitmapMarker::regionIn(Region2d *extsPtr, int enclosed) { - BitmapMarker* bmPtr = (BitmapMarker*)markerPtr; - if (enclosed) { - return ((bmPtr->anchorPt.x >= extsPtr->left) && - (bmPtr->anchorPt.y >= extsPtr->top) && - ((bmPtr->anchorPt.x + bmPtr->width) <= extsPtr->right) && - ((bmPtr->anchorPt.y + bmPtr->height) <= extsPtr->bottom)); + return ((anchorPt.x >= extsPtr->left) && + (anchorPt.y >= extsPtr->top) && + ((anchorPt.x + width) <= extsPtr->right) && + ((anchorPt.y + height) <= extsPtr->bottom)); } - return !((bmPtr->anchorPt.x >= extsPtr->right) || - (bmPtr->anchorPt.y >= extsPtr->bottom) || - ((bmPtr->anchorPt.x + bmPtr->width) <= extsPtr->left) || - ((bmPtr->anchorPt.y + bmPtr->height) <= extsPtr->top)); + return !((anchorPt.x >= extsPtr->right) || + (anchorPt.y >= extsPtr->bottom) || + ((anchorPt.x + width) <= extsPtr->left) || + ((anchorPt.y + height) <= extsPtr->top)); } -static void BitmapToPostscriptProc(Marker* markerPtr, Blt_Ps ps) +void BitmapMarker::postscript(Blt_Ps ps) { - Graph* graphPtr = markerPtr->obj.graphPtr; - BitmapMarker* bmPtr = (BitmapMarker*)markerPtr; - BitmapMarkerOptions* ops = (BitmapMarkerOptions*)bmPtr->ops; + Graph* graphPtr = obj.graphPtr; + BitmapMarkerOptions* opp = (BitmapMarkerOptions*)ops; - if ((ops->bitmap == None) || (bmPtr->width < 1) || (bmPtr->height < 1)) + if ((opp->bitmap == None) || (width < 1) || (height < 1)) return; - if (ops->fillColor) { - Blt_Ps_XSetBackground(ps, ops->fillColor); - Blt_Ps_XFillPolygon(ps, bmPtr->outline, 4); + if (opp->fillColor) { + Blt_Ps_XSetBackground(ps, opp->fillColor); + Blt_Ps_XFillPolygon(ps, outline, 4); } - Blt_Ps_XSetForeground(ps, ops->outlineColor); + Blt_Ps_XSetForeground(ps, opp->outlineColor); - Blt_Ps_Format(ps, - " gsave\n %g %g translate\n %d %d scale\n", - bmPtr->anchorPt.x, bmPtr->anchorPt.y + bmPtr->height, - bmPtr->width, -bmPtr->height); + Blt_Ps_Format(ps, " gsave\n %g %g translate\n %d %d scale\n", + anchorPt.x, anchorPt.y + height, width, -height); Blt_Ps_Format(ps, " %d %d true [%d 0 0 %d 0 %d] {", - bmPtr->width, bmPtr->height, bmPtr->width, - -bmPtr->height, bmPtr->height); - Blt_Ps_XSetBitmapData(ps, graphPtr->display, ops->bitmap, - bmPtr->width, bmPtr->height); - Blt_Ps_VarAppend(ps, - " } imagemask\n", - "grestore\n", (char*)NULL); + width, height, width, -height, height); + Blt_Ps_XSetBitmapData(ps, graphPtr->display, opp->bitmap, width, height); + Blt_Ps_VarAppend(ps, " } imagemask\n", "grestore\n", (char*)NULL); } diff --git a/bltGrMarkerBitmap.h b/bltGrMarkerBitmap.h index dc8dedb..7f56f4f 100644 --- a/bltGrMarkerBitmap.h +++ b/bltGrMarkerBitmap.h @@ -64,6 +64,10 @@ class BitmapMarker : public Marker { private: int configure(); void draw(Drawable); + void map(); + int pointIn(Point2d*); + int regionIn(Region2d*, int); + void postscript(Blt_Ps); public: BitmapMarker(Graph*, const char*); diff --git a/configure b/configure index d3389d7..d8fed61 100755 --- a/configure +++ b/configure @@ -5540,7 +5540,6 @@ done bltGrMarkerLine.C bltGrMarkerPolygon.C bltGrMarkerText.C - bltGrMarkerWindow.C bltGrMisc.C bltGrPen.C bltGrPs.C diff --git a/configure.in b/configure.in index 16edbcc..7b550dc 100755 --- a/configure.in +++ b/configure.in @@ -85,7 +85,6 @@ TEA_ADD_SOURCES([ bltGrMarkerLine.C bltGrMarkerPolygon.C bltGrMarkerText.C - bltGrMarkerWindow.C bltGrMisc.C bltGrPen.C bltGrPs.C diff --git a/src/bltGrMarker.C b/src/bltGrMarker.C index a7596ca..b527f48 100644 --- a/src/bltGrMarker.C +++ b/src/bltGrMarker.C @@ -42,7 +42,6 @@ extern "C" { #include "bltGrMarkerLine.h" #include "bltGrMarkerPolygon.h" #include "bltGrMarkerText.h" -#include "bltGrMarkerWindow.h" using namespace Blt; @@ -306,8 +305,6 @@ static int CreateMarker(Graph* graphPtr, Tcl_Interp* interp, markerPtr = new PolygonMarker(graphPtr, name); else if (!strcmp(type, "text")) markerPtr = new TextMarker(graphPtr, name); - else if (!strcmp(type, "window")) - markerPtr = new WindowMarker(graphPtr, name); else { Tcl_AppendResult(interp, "unknown marker type ", type, NULL); return TCL_ERROR; @@ -531,7 +528,7 @@ static int FindOp(Graph* graphPtr, Tcl_Interp* interp, if (IsElementHidden(markerPtr)) continue; - if ((*markerPtr->classPtr->regionProc)(markerPtr, &extents, enclosed)) { + if (markerPtr->regionIn(&extents, enclosed)) { Tcl_Obj* objPtr = Tcl_GetObjResult(interp); Tcl_SetStringObj(objPtr, markerPtr->obj.name, -1); return TCL_OK; @@ -782,9 +779,6 @@ void Blt_MarkersToPostScript(Graph* graphPtr, Blt_Ps ps, int under) link; link = Blt_Chain_PrevLink(link)) { Marker* markerPtr = (Marker*)Blt_Chain_GetValue(link); MarkerOptions* ops = (MarkerOptions*)markerPtr->ops; - if (markerPtr->classPtr->postscriptProc == NULL) - continue; - if (ops->drawUnder != under) continue; @@ -796,7 +790,7 @@ void Blt_MarkersToPostScript(Graph* graphPtr, Blt_Ps ps, int under) Blt_Ps_VarAppend(ps, "\n% Marker \"", markerPtr->obj.name, "\" is a ", markerPtr->obj.className, ".\n", (char*)NULL); - (*markerPtr->classPtr->postscriptProc) (markerPtr, ps); + markerPtr->postscript(ps); } } @@ -840,7 +834,7 @@ void Blt_MapMarkers(Graph* graphPtr) continue; if ((graphPtr->flags & MAP_ALL) || (markerPtr->flags & MAP_ITEM)) { - (*markerPtr->classPtr->mapProc) (markerPtr); + markerPtr->map(); markerPtr->flags &= ~MAP_ITEM; } } @@ -881,7 +875,7 @@ void* Blt_NearestMarker(Graph* graphPtr, int x, int y, int under) continue; if ((ops->drawUnder == under) && (ops->state == BLT_STATE_NORMAL)) - if ((*markerPtr->classPtr->pointProc) (markerPtr, &point)) + if (markerPtr->pointIn(&point)) return markerPtr; } return NULL; diff --git a/src/bltGrMarker.h b/src/bltGrMarker.h index a0a957f..159418c 100644 --- a/src/bltGrMarker.h +++ b/src/bltGrMarker.h @@ -45,10 +45,6 @@ typedef int (MarkerRegionProc)(Marker* markerPtr, Region2d *extsPtr, int enclose typedef struct { Tk_OptionSpec *optionSpecs; - MarkerMapProc *mapProc; - MarkerPointProc *pointProc; - MarkerRegionProc *regionProc; - MarkerPostscriptProc *postscriptProc; } MarkerClass; typedef struct { @@ -88,6 +84,10 @@ typedef struct { virtual int configure() =0; virtual void draw(Drawable) =0; + virtual void map() =0; + virtual int pointIn(Point2d*) =0; + virtual int regionIn(Region2d*, int) =0; + virtual void postscript(Blt_Ps) =0; }; }; diff --git a/src/bltGrMarkerLine.C b/src/bltGrMarkerLine.C index d540813..5544b92 100644 --- a/src/bltGrMarkerLine.C +++ b/src/bltGrMarkerLine.C @@ -87,17 +87,8 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_END, NULL, NULL, NULL, NULL, -1, 0, 0, NULL, 0} }; -static MarkerMapProc MapLineProc; -static MarkerPointProc PointInLineProc; -static MarkerPostscriptProc LineToPostscriptProc; -static MarkerRegionProc RegionInLineProc; - static MarkerClass lineMarkerClass = { optionSpecs, - MapLineProc, - PointInLineProc, - RegionInLineProc, - LineToPostscriptProc, }; LineMarker::LineMarker(Graph* graphPtr, const char* name) @@ -174,7 +165,7 @@ int LineMarker::configure() gc = newGC; if (opp->xorr) { if (drawable != None) { - MapLineProc(this); + map(); draw(drawable); } return TCL_OK; @@ -195,28 +186,71 @@ void LineMarker::draw(Drawable drawable) } } -static int PointInLineProc(Marker* markerPtr, Point2d *samplePtr) +void LineMarker::map() { - LineMarker *lmPtr = (LineMarker*)markerPtr; + Graph* graphPtr = obj.graphPtr; + LineMarkerOptions* opp = (LineMarkerOptions*)ops; - return Blt_PointInSegments(samplePtr, lmPtr->segments, lmPtr->nSegments, - (double)markerPtr->obj.graphPtr->search.halo); + nSegments = 0; + if (segments) + free(segments); + + if (!opp->worldPts || (opp->worldPts->num < 2)) + return; + + Region2d extents; + Blt_GraphExtents(graphPtr, &extents); + + // Allow twice the number of world coordinates. The line will represented + // as series of line segments, not one continous polyline. This is + // because clipping against the plot area may chop the line into several + // disconnected segments. + Segment2d* lsegments = (Segment2d*)malloc(opp->worldPts->num * sizeof(Segment2d)); + Point2d* srcPtr = opp->worldPts->points; + Point2d p = Blt_MapPoint(srcPtr, &opp->axes); + p.x += opp->xOffset; + p.y += opp->yOffset; + + Segment2d* segPtr = lsegments; + Point2d* pend; + for (srcPtr++, pend = opp->worldPts->points + opp->worldPts->num; + srcPtr < pend; srcPtr++) { + Point2d next = Blt_MapPoint(srcPtr, &opp->axes); + next.x += opp->xOffset; + next.y += opp->yOffset; + Point2d q = next; + + if (Blt_LineRectClip(&extents, &p, &q)) { + segPtr->p = p; + segPtr->q = q; + segPtr++; + } + p = next; + } + nSegments = segPtr - lsegments; + segments = lsegments; + clipped = (nSegments == 0); } -static int RegionInLineProc(Marker* markerPtr, Region2d *extsPtr, int enclosed) +int LineMarker::pointIn(Point2d *samplePtr) { - LineMarker *lmPtr = (LineMarker*)markerPtr; - LineMarkerOptions* ops = (LineMarkerOptions*)lmPtr->ops; + return Blt_PointInSegments(samplePtr, segments, nSegments, + (double)obj.graphPtr->search.halo); +} - if (!ops->worldPts || ops->worldPts->num < 2) +int LineMarker::regionIn(Region2d *extsPtr, int enclosed) +{ + LineMarkerOptions* opp = (LineMarkerOptions*)ops; + + if (!opp->worldPts || opp->worldPts->num < 2) return FALSE; if (enclosed) { Point2d *pp, *pend; - for (pp = ops->worldPts->points, pend = pp + ops->worldPts->num; + for (pp = opp->worldPts->points, pend = pp + opp->worldPts->num; pp < pend; pp++) { - Point2d p = Blt_MapPoint(pp, &ops->axes); + Point2d p = Blt_MapPoint(pp, &opp->axes); if ((p.x < extsPtr->left) && (p.x > extsPtr->right) && (p.y < extsPtr->top) && (p.y > extsPtr->bottom)) { return FALSE; @@ -227,10 +261,10 @@ static int RegionInLineProc(Marker* markerPtr, Region2d *extsPtr, int enclosed) else { Point2d *pp, *pend; int count = 0; - for (pp = ops->worldPts->points, pend = pp + (ops->worldPts->num - 1); + for (pp = opp->worldPts->points, pend = pp + (opp->worldPts->num - 1); pp < pend; pp++) { - Point2d p = Blt_MapPoint(pp, &ops->axes); - Point2d q = Blt_MapPoint(pp + 1, &ops->axes); + Point2d p = Blt_MapPoint(pp, &opp->axes); + Point2d q = Blt_MapPoint(pp + 1, &opp->axes); if (Blt_LineRectClip(extsPtr, &p, &q)) count++; } @@ -239,81 +273,25 @@ static int RegionInLineProc(Marker* markerPtr, Region2d *extsPtr, int enclosed) } } -static void LineToPostscriptProc(Marker* markerPtr, Blt_Ps ps) +void LineMarker::postscript(Blt_Ps ps) { - LineMarker *lmPtr = (LineMarker*)markerPtr; - LineMarkerOptions* ops = (LineMarkerOptions*)lmPtr->ops; - - if (lmPtr->nSegments > 0) { - Blt_Ps_XSetLineAttributes(ps, ops->outlineColor, - ops->lineWidth, - &ops->dashes, - ops->capStyle, - ops->joinStyle); - if ((LineIsDashed(ops->dashes)) && (ops->fillColor)) { + LineMarkerOptions* opp = (LineMarkerOptions*)ops; + + if (nSegments > 0) { + Blt_Ps_XSetLineAttributes(ps, opp->outlineColor, opp->lineWidth, + &opp->dashes, opp->capStyle, opp->joinStyle); + if ((LineIsDashed(opp->dashes)) && (opp->fillColor)) { Blt_Ps_Append(ps, "/DashesProc {\n gsave\n "); - Blt_Ps_XSetBackground(ps, ops->fillColor); + Blt_Ps_XSetBackground(ps, opp->fillColor); Blt_Ps_Append(ps, " "); Blt_Ps_XSetDashes(ps, (Blt_Dashes*)NULL); - Blt_Ps_VarAppend(ps, - "stroke\n", - " grestore\n", - "} def\n", (char*)NULL); + Blt_Ps_VarAppend(ps, "stroke\n", " grestore\n", "} def\n", (char*)NULL); } else Blt_Ps_Append(ps, "/DashesProc {} def\n"); - Blt_Ps_Draw2DSegments(ps, lmPtr->segments, lmPtr->nSegments); + Blt_Ps_Draw2DSegments(ps, segments, nSegments); } } -static void MapLineProc(Marker* markerPtr) -{ - Graph* graphPtr = markerPtr->obj.graphPtr; - LineMarker *lmPtr = (LineMarker*)markerPtr; - LineMarkerOptions* ops = (LineMarkerOptions*)lmPtr->ops; - - lmPtr->nSegments = 0; - if (lmPtr->segments) - free(lmPtr->segments); - - if (!ops->worldPts || (ops->worldPts->num < 2)) - return; - - Region2d extents; - Blt_GraphExtents(graphPtr, &extents); - - /* - * Allow twice the number of world coordinates. The line will represented - * as series of line segments, not one continous polyline. This is - * because clipping against the plot area may chop the line into several - * disconnected segments. - */ - Segment2d* segments = - (Segment2d*)malloc(ops->worldPts->num * sizeof(Segment2d)); - Point2d* srcPtr = ops->worldPts->points; - Point2d p = Blt_MapPoint(srcPtr, &ops->axes); - p.x += ops->xOffset; - p.y += ops->yOffset; - - Segment2d* segPtr = segments; - Point2d* pend; - for (srcPtr++, pend = ops->worldPts->points + ops->worldPts->num; - srcPtr < pend; srcPtr++) { - Point2d next = Blt_MapPoint(srcPtr, &ops->axes); - next.x += ops->xOffset; - next.y += ops->yOffset; - Point2d q = next; - - if (Blt_LineRectClip(&extents, &p, &q)) { - segPtr->p = p; - segPtr->q = q; - segPtr++; - } - p = next; - } - lmPtr->nSegments = segPtr - segments; - lmPtr->segments = segments; - lmPtr->clipped = (lmPtr->nSegments == 0); -} diff --git a/src/bltGrMarkerLine.h b/src/bltGrMarkerLine.h index 0e8d1b0..dd18191 100644 --- a/src/bltGrMarkerLine.h +++ b/src/bltGrMarkerLine.h @@ -64,6 +64,10 @@ class LineMarker : public Marker { private: int configure(); void draw(Drawable); + void map(); + int pointIn(Point2d*); + int regionIn(Region2d*, int); + void postscript(Blt_Ps); public: LineMarker(Graph*, const char*); diff --git a/src/bltGrMarkerPolygon.C b/src/bltGrMarkerPolygon.C index 3a41615..ea81cdc 100644 --- a/src/bltGrMarkerPolygon.C +++ b/src/bltGrMarkerPolygon.C @@ -95,17 +95,8 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_END, NULL, NULL, NULL, NULL, -1, 0, 0, NULL, 0} }; -static MarkerMapProc MapPolygonProc; -static MarkerPointProc PointInPolygonProc; -static MarkerPostscriptProc PolygonToPostscriptProc; -static MarkerRegionProc RegionInPolygonProc; - static MarkerClass polygonMarkerClass = { optionSpecs, - MapPolygonProc, - PointInPolygonProc, - RegionInPolygonProc, - PolygonToPostscriptProc, }; PolygonMarker::PolygonMarker(Graph* graphPtr, const char* name) @@ -219,7 +210,7 @@ int PolygonMarker::configure() if ((gcMask == 0) && !(graphPtr->flags & RESET_AXES) && (opp->xorr)) { if (drawable != None) { - MapPolygonProc(this); + map(); draw(drawable); } return TCL_OK; @@ -260,157 +251,65 @@ void PolygonMarker::draw(Drawable drawable) } } -static int PointInPolygonProc(Marker* markerPtr, Point2d *samplePtr) +void PolygonMarker::map() { - PolygonMarker *pmPtr = (PolygonMarker *)markerPtr; - PolygonMarkerOptions* ops = (PolygonMarkerOptions*)pmPtr->ops; - - if (ops->worldPts && - (ops->worldPts->num >= 3) && - (pmPtr->screenPts)) - return Blt_PointInPolygon(samplePtr, pmPtr->screenPts, - ops->worldPts->num + 1); - - return FALSE; -} - -static int RegionInPolygonProc(Marker* markerPtr, Region2d *extsPtr, - int enclosed) -{ - PolygonMarker *pmPtr = (PolygonMarker *)markerPtr; - PolygonMarkerOptions* ops = (PolygonMarkerOptions*)pmPtr->ops; - - if (ops->worldPts && - (ops->worldPts->num >= 3) && - (pmPtr->screenPts)) - return Blt_RegionInPolygon(extsPtr, pmPtr->screenPts, - ops->worldPts->num, enclosed); - - return FALSE; -} - -static void PolygonToPostscriptProc(Marker* markerPtr, Blt_Ps ps) -{ - Graph* graphPtr = markerPtr->obj.graphPtr; - PolygonMarker *pmPtr = (PolygonMarker *)markerPtr; - PolygonMarkerOptions* ops = (PolygonMarkerOptions*)pmPtr->ops; - - if (ops->fill) { - - /* - * Options: fg bg - * Draw outline only. - * x Draw solid or stipple. - * x x Draw solid or stipple. - */ - - /* Create a path to use for both the polygon and its outline. */ - Blt_Ps_Polyline(ps, pmPtr->fillPts, pmPtr->nFillPts); + Graph* graphPtr = obj.graphPtr; + PolygonMarkerOptions* opp = (PolygonMarkerOptions*)ops; - /* If the background fill color was specified, draw the polygon in a - * solid fashion with that color. */ - if (ops->fillBg) { - /* Draw the solid background as the background layer of the opaque - * stipple */ - Blt_Ps_XSetBackground(ps, ops->fillBg); - /* Retain the path. We'll need it for the foreground layer. */ - Blt_Ps_Append(ps, "gsave fill grestore\n"); - } - Blt_Ps_XSetForeground(ps, ops->fill); - if (ops->stipple != None) { - /* Draw the stipple in the foreground color. */ - Blt_Ps_XSetStipple(ps, graphPtr->display, ops->stipple); - } else { - Blt_Ps_Append(ps, "fill\n"); - } + if (outlinePts) { + free(outlinePts); + outlinePts = NULL; + nOutlinePts = 0; } - /* Draw the outline in the foreground color. */ - if ((ops->lineWidth > 0) && (ops->outline)) { - - /* Set up the line attributes. */ - Blt_Ps_XSetLineAttributes(ps, ops->outline, - ops->lineWidth, - &ops->dashes, - ops->capStyle, - ops->joinStyle); - - /* - * Define on-the-fly a PostScript macro "DashesProc" that will be - * executed for each call to the Polygon drawing routine. If the line - * isn't dashed, simply make this an empty definition. - */ - if ((ops->outlineBg) && (LineIsDashed(ops->dashes))) { - Blt_Ps_Append(ps, "/DashesProc {\ngsave\n "); - Blt_Ps_XSetBackground(ps, ops->outlineBg); - Blt_Ps_Append(ps, " "); - Blt_Ps_XSetDashes(ps, (Blt_Dashes *)NULL); - Blt_Ps_Append(ps, "stroke\n grestore\n} def\n"); - } else { - Blt_Ps_Append(ps, "/DashesProc {} def\n"); - } - Blt_Ps_Draw2DSegments(ps, pmPtr->outlinePts, pmPtr->nOutlinePts); + if (fillPts) { + free(fillPts); + fillPts = NULL; + nFillPts = 0; } -} -static void MapPolygonProc(Marker* markerPtr) -{ - Graph* graphPtr = markerPtr->obj.graphPtr; - PolygonMarker *pmPtr = (PolygonMarker *)markerPtr; - PolygonMarkerOptions* ops = (PolygonMarkerOptions*)pmPtr->ops; - - if (pmPtr->outlinePts) { - free(pmPtr->outlinePts); - pmPtr->outlinePts = NULL; - pmPtr->nOutlinePts = 0; - } - if (pmPtr->fillPts) { - free(pmPtr->fillPts); - pmPtr->fillPts = NULL; - pmPtr->nFillPts = 0; - } - if (pmPtr->screenPts) { - free(pmPtr->screenPts); - pmPtr->screenPts = NULL; + if (screenPts) { + free(screenPts); + screenPts = NULL; } - if (!ops->worldPts || ops->worldPts->num < 3) + + if (!opp->worldPts || opp->worldPts->num < 3) return; - /* - * Allocate and fill a temporary array to hold the screen coordinates of - * the polygon. - */ - int nScreenPts = ops->worldPts->num + 1; - Point2d* screenPts = (Point2d*)malloc((nScreenPts + 1) * sizeof(Point2d)); + // Allocate and fill a temporary array to hold the screen coordinates of + // the polygon. + + int nScreenPts = opp->worldPts->num + 1; + Point2d* lscreenPts = (Point2d*)malloc((nScreenPts + 1) * sizeof(Point2d)); { Point2d *sp, *dp, *send; - dp = screenPts; - for (sp = ops->worldPts->points, send = sp + ops->worldPts->num; + dp = lscreenPts; + for (sp = opp->worldPts->points, send = sp + opp->worldPts->num; sp < send; sp++) { - *dp = Blt_MapPoint(sp, &ops->axes); - dp->x += ops->xOffset; - dp->y += ops->yOffset; + *dp = Blt_MapPoint(sp, &opp->axes); + dp->x += opp->xOffset; + dp->y += opp->yOffset; dp++; } - *dp = screenPts[0]; + *dp = lscreenPts[0]; } Region2d extents; Blt_GraphExtents(graphPtr, &extents); - pmPtr->clipped = TRUE; - if (ops->fill) { - Point2d* fillPts = (Point2d*)malloc(sizeof(Point2d) * nScreenPts * 3); + clipped = TRUE; + if (opp->fill) { + Point2d* lfillPts = (Point2d*)malloc(sizeof(Point2d) * nScreenPts * 3); int n = - Blt_PolyRectClip(&extents, screenPts, ops->worldPts->num,fillPts); + Blt_PolyRectClip(&extents, lscreenPts, opp->worldPts->num,lfillPts); if (n < 3) - free(fillPts); + free(lfillPts); else { - pmPtr->nFillPts = n; - pmPtr->fillPts = fillPts; - pmPtr->clipped = FALSE; + nFillPts = n; + fillPts = lfillPts; + clipped = FALSE; } } - if ((ops->outline) && (ops->lineWidth > 0)) { + if ((opp->outline) && (opp->lineWidth > 0)) { Segment2d *segPtr; Point2d *sp, *send; @@ -418,26 +317,90 @@ static void MapPolygonProc(Marker* markerPtr) * Generate line segments representing the polygon outline. The * resulting outline may or may not be closed from viewport clipping. */ - Segment2d* outlinePts = (Segment2d*)malloc(nScreenPts * sizeof(Segment2d)); - if (!outlinePts) + Segment2d* loutlinePts = (Segment2d*)malloc(nScreenPts * sizeof(Segment2d)); + if (!loutlinePts) return; // Note that this assumes that the point array contains an extra point // that closes the polygon. - segPtr = outlinePts; - for (sp = screenPts, send = sp + (nScreenPts - 1); sp < send; sp++) { + segPtr = loutlinePts; + for (sp = lscreenPts, send = sp + (nScreenPts - 1); sp < send; sp++) { segPtr->p = sp[0]; segPtr->q = sp[1]; if (Blt_LineRectClip(&extents, &segPtr->p, &segPtr->q)) { segPtr++; } } - pmPtr->nOutlinePts = segPtr - outlinePts; - pmPtr->outlinePts = outlinePts; - if (pmPtr->nOutlinePts > 0) { - pmPtr->clipped = FALSE; + nOutlinePts = segPtr - loutlinePts; + outlinePts = loutlinePts; + if (nOutlinePts > 0) { + clipped = FALSE; + } + } + + screenPts = lscreenPts; +} + +int PolygonMarker::pointIn(Point2d *samplePtr) +{ + PolygonMarkerOptions* opp = (PolygonMarkerOptions*)ops; + + if (opp->worldPts && + (opp->worldPts->num >= 3) && + (screenPts)) + return Blt_PointInPolygon(samplePtr, screenPts, + opp->worldPts->num + 1); + + return FALSE; +} + +int PolygonMarker::regionIn(Region2d *extsPtr, int enclosed) +{ + PolygonMarkerOptions* opp = (PolygonMarkerOptions*)ops; + + if (opp->worldPts && + (opp->worldPts->num >= 3) && + (screenPts)) + return Blt_RegionInPolygon(extsPtr, screenPts, + opp->worldPts->num, enclosed); + + return FALSE; +} + +void PolygonMarker::postscript(Blt_Ps ps) +{ + Graph* graphPtr = obj.graphPtr; + PolygonMarkerOptions* opp = (PolygonMarkerOptions*)ops; + + if (opp->fill) { + Blt_Ps_Polyline(ps, fillPts, nFillPts); + if (opp->fillBg) { + Blt_Ps_XSetBackground(ps, opp->fillBg); + Blt_Ps_Append(ps, "gsave fill grestore\n"); + } + Blt_Ps_XSetForeground(ps, opp->fill); + if (opp->stipple != None) { + Blt_Ps_XSetStipple(ps, graphPtr->display, opp->stipple); + } else { + Blt_Ps_Append(ps, "fill\n"); + } + } + + if ((opp->lineWidth > 0) && (opp->outline)) { + + Blt_Ps_XSetLineAttributes(ps, opp->outline, opp->lineWidth, &opp->dashes, + opp->capStyle, opp->joinStyle); + + if ((opp->outlineBg) && (LineIsDashed(opp->dashes))) { + Blt_Ps_Append(ps, "/DashesProc {\ngsave\n "); + Blt_Ps_XSetBackground(ps, opp->outlineBg); + Blt_Ps_Append(ps, " "); + Blt_Ps_XSetDashes(ps, (Blt_Dashes *)NULL); + Blt_Ps_Append(ps, "stroke\n grestore\n} def\n"); + } else { + Blt_Ps_Append(ps, "/DashesProc {} def\n"); } + Blt_Ps_Draw2DSegments(ps, outlinePts, nOutlinePts); } - pmPtr->screenPts = screenPts; } diff --git a/src/bltGrMarkerPolygon.h b/src/bltGrMarkerPolygon.h index 96ab2c5..f9bd6f4 100644 --- a/src/bltGrMarkerPolygon.h +++ b/src/bltGrMarkerPolygon.h @@ -71,6 +71,10 @@ class PolygonMarker : public Marker { private: int configure(); void draw(Drawable); + void map(); + int pointIn(Point2d*); + int regionIn(Region2d*, int); + void postscript(Blt_Ps); public: PolygonMarker(Graph*, const char*); diff --git a/src/bltGrMarkerText.C b/src/bltGrMarkerText.C index 648566a..0a93b1a 100644 --- a/src/bltGrMarkerText.C +++ b/src/bltGrMarkerText.C @@ -85,17 +85,8 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_END, NULL, NULL, NULL, NULL, -1, 0, 0, NULL, 0} }; -static MarkerMapProc MapTextProc; -static MarkerPointProc PointInTextProc; -static MarkerPostscriptProc TextToPostscriptProc; -static MarkerRegionProc RegionInTextProc; - static MarkerClass textMarkerClass = { optionSpecs, - MapTextProc, - PointInTextProc, - RegionInTextProc, - TextToPostscriptProc, }; TextMarker::TextMarker(Graph* graphPtr, const char* name) @@ -172,125 +163,123 @@ void TextMarker::draw(Drawable drawable) &opp->style, anchorPt.x, anchorPt.y); } -static void MapTextProc(Marker* markerPtr) +void TextMarker::map() { - Graph* graphPtr = markerPtr->obj.graphPtr; - TextMarker* tmPtr = (TextMarker*)markerPtr; - TextMarkerOptions* ops = (TextMarkerOptions*)tmPtr->ops; + Graph* graphPtr = obj.graphPtr; + TextMarkerOptions* opp = (TextMarkerOptions*)ops; - if (!ops->string) + if (!opp->string) return; - if (!ops->worldPts || (ops->worldPts->num < 1)) + if (!opp->worldPts || (opp->worldPts->num < 1)) return; - tmPtr->width =0; - tmPtr->height =0; + width =0; + height =0; - unsigned int w, h; - Blt_Ts_GetExtents(&ops->style, ops->string, &w, &h); + unsigned int w; + unsigned int h; + Blt_Ts_GetExtents(&opp->style, opp->string, &w, &h); - double rw, rh; - Blt_GetBoundingBox(w, h, ops->style.angle, &rw, &rh, tmPtr->outline); - tmPtr->width = ROUND(rw); - tmPtr->height = ROUND(rh); + double rw; + double rh; + Blt_GetBoundingBox(w, h, opp->style.angle, &rw, &rh, outline); + width = ROUND(rw); + height = ROUND(rh); for (int ii=0; ii<4; ii++) { - tmPtr->outline[ii].x += ROUND(rw * 0.5); - tmPtr->outline[ii].y += ROUND(rh * 0.5); + outline[ii].x += ROUND(rw * 0.5); + outline[ii].y += ROUND(rh * 0.5); } - tmPtr->outline[4].x = tmPtr->outline[0].x; - tmPtr->outline[4].y = tmPtr->outline[0].y; + outline[4].x = outline[0].x; + outline[4].y = outline[0].y; - Point2d anchorPt = - Blt_MapPoint(ops->worldPts->points, &ops->axes); - anchorPt = Blt_AnchorPoint(anchorPt.x, anchorPt.y, tmPtr->width, - tmPtr->height, ops->anchor); - anchorPt.x += ops->xOffset; - anchorPt.y += ops->yOffset; + Point2d lanchorPtr = + Blt_MapPoint(opp->worldPts->points, &opp->axes); + lanchorPtr = Blt_AnchorPoint(lanchorPtr.x, lanchorPtr.y, width, + height, opp->anchor); + lanchorPtr.x += opp->xOffset; + lanchorPtr.y += opp->yOffset; 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; + extents.left = lanchorPtr.x; + extents.top = lanchorPtr.y; + extents.right = lanchorPtr.x + width - 1; + extents.bottom = lanchorPtr.y + height - 1; + clipped = Blt_BoxesDontOverlap(graphPtr, &extents); + + anchorPt = lanchorPtr; } -static int PointInTextProc(Marker* markerPtr, Point2d *samplePtr) +int TextMarker::pointIn(Point2d *samplePtr) { - TextMarker* tmPtr = (TextMarker*)markerPtr; - TextMarkerOptions* ops = (TextMarkerOptions*)tmPtr->ops; + TextMarkerOptions* opp = (TextMarkerOptions*)ops; - if (!ops->string) + if (!opp->string) return 0; - if (ops->style.angle != 0.0f) { + if (opp->style.angle != 0.0f) { Point2d points[5]; // 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; + points[ii].x = outline[ii].x + anchorPt.x; + points[ii].y = outline[ii].y + 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))); + return ((samplePtr->x >= anchorPt.x) && + (samplePtr->x < (anchorPt.x + width)) && + (samplePtr->y >= anchorPt.y) && + (samplePtr->y < (anchorPt.y + height))); } -static int RegionInTextProc(Marker* markerPtr, Region2d *extsPtr, int enclosed) +int TextMarker::regionIn(Region2d *extsPtr, int enclosed) { - TextMarker* tmPtr = (TextMarker*)markerPtr; - TextMarkerOptions* ops = (TextMarkerOptions*)tmPtr->ops; + TextMarkerOptions* opp = (TextMarkerOptions*)ops; - if (ops->style.angle != 0.0f) { + if (opp->style.angle != 0.0f) { // Generate the bounding polygon (isolateral) for the bitmap and see // if the point is inside of it. Point2d points[5]; 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; + points[ii].x = outline[ii].x + anchorPt.x; + points[ii].y = outline[ii].y + anchorPt.y; } return Blt_RegionInPolygon(extsPtr, points, 4, 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)); + return ((anchorPt.x >= extsPtr->left) && + (anchorPt.y >= extsPtr->top) && + ((anchorPt.x + width) <= extsPtr->right) && + ((anchorPt.y + height) <= extsPtr->bottom)); + + return !((anchorPt.x >= extsPtr->right) || + (anchorPt.y >= extsPtr->bottom) || + ((anchorPt.x + width) <= extsPtr->left) || + ((anchorPt.y + height) <= extsPtr->top)); } -static void TextToPostscriptProc(Marker* markerPtr, Blt_Ps ps) +void TextMarker::postscript(Blt_Ps ps) { - TextMarker* tmPtr = (TextMarker*)markerPtr; - TextMarkerOptions* ops = (TextMarkerOptions*)tmPtr->ops; + TextMarkerOptions* opp = (TextMarkerOptions*)ops; - if (!ops->string) + if (!opp->string) return; - if (tmPtr->fillGC) { + if (fillGC) { // Simulate the rotated background of the bitmap by filling a bounding // polygon with the background color. Point2d points[4]; 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; + points[ii].x = outline[ii].x + anchorPt.x; + points[ii].y = outline[ii].y + anchorPt.y; } - Blt_Ps_XSetBackground(ps, ops->fillColor); + Blt_Ps_XSetBackground(ps, opp->fillColor); Blt_Ps_XFillPolygon(ps, points, 4); } - Blt_Ps_DrawText(ps, ops->string, &ops->style, - tmPtr->anchorPt.x, tmPtr->anchorPt.y); + Blt_Ps_DrawText(ps, opp->string, &opp->style, anchorPt.x, anchorPt.y); } diff --git a/src/bltGrMarkerText.h b/src/bltGrMarkerText.h index 9d8d1f3..979518e 100644 --- a/src/bltGrMarkerText.h +++ b/src/bltGrMarkerText.h @@ -62,6 +62,10 @@ class TextMarker : public Marker { private: int configure(); void draw(Drawable); + void map(); + int pointIn(Point2d*); + int regionIn(Region2d*, int); + void postscript(Blt_Ps); public: TextMarker(Graph*, const char*); -- cgit v0.12