diff options
author | joye <joye> | 2014-05-06 18:26:57 (GMT) |
---|---|---|
committer | joye <joye> | 2014-05-06 18:26:57 (GMT) |
commit | 358d5a4ebed94c9b7aa2e879c4d7234f227a99ae (patch) | |
tree | d36a3f77cc7b4a9acd7d70c270317b4c44a28f48 /src | |
parent | 16a5c9af45ae9e810e8eebaa4e1663ea64d8c255 (diff) | |
download | blt-358d5a4ebed94c9b7aa2e879c4d7234f227a99ae.zip blt-358d5a4ebed94c9b7aa2e879c4d7234f227a99ae.tar.gz blt-358d5a4ebed94c9b7aa2e879c4d7234f227a99ae.tar.bz2 |
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r-- | src/bltGrAxis.C | 148 | ||||
-rw-r--r-- | src/bltGrAxis.h | 2 | ||||
-rw-r--r-- | src/bltGrElemBar.C | 85 | ||||
-rw-r--r-- | src/bltGrElemBar.h | 1 | ||||
-rw-r--r-- | src/bltGrElemLine.C | 88 | ||||
-rw-r--r-- | src/bltGrLegd.C | 61 | ||||
-rw-r--r-- | src/bltGrLegd.h | 8 | ||||
-rw-r--r-- | src/bltGrMarkerText.C | 27 | ||||
-rw-r--r-- | src/bltGrMarkerText.h | 2 | ||||
-rw-r--r-- | src/bltGrMisc.h | 5 | ||||
-rw-r--r-- | src/bltGrPSOutput.C | 10 | ||||
-rw-r--r-- | src/bltGrPSOutput.h | 3 | ||||
-rw-r--r-- | src/bltGrPen.C | 3 | ||||
-rw-r--r-- | src/bltGrPen.h | 2 | ||||
-rw-r--r-- | src/bltGrPenBar.C | 22 | ||||
-rw-r--r-- | src/bltGrPenBar.h | 2 | ||||
-rw-r--r-- | src/bltGrPenLine.C | 24 | ||||
-rw-r--r-- | src/bltGrPenLine.h | 2 | ||||
-rw-r--r-- | src/bltGrText.C | 316 | ||||
-rw-r--r-- | src/bltGrText.h | 72 | ||||
-rw-r--r-- | src/bltGraph.C | 28 | ||||
-rw-r--r-- | src/bltGraph.h | 2 | ||||
-rw-r--r-- | src/bltGraphBar.C | 18 | ||||
-rw-r--r-- | src/bltGraphBar.h | 2 | ||||
-rw-r--r-- | src/bltGraphLine.C | 16 | ||||
-rw-r--r-- | src/bltGraphLine.h | 2 | ||||
-rw-r--r-- | src/bltGraphSup.C | 14 |
27 files changed, 492 insertions, 473 deletions
diff --git a/src/bltGrAxis.C b/src/bltGrAxis.C index 5d4fd9f..f81c1a3 100644 --- a/src/bltGrAxis.C +++ b/src/bltGrAxis.C @@ -263,7 +263,12 @@ Axis::Axis(Graph* graphPtr, const char* name, int margin, Tcl_HashEntry* hPtr) ops->reqMax =NAN; ops->reqScrollMin =NAN; ops->reqScrollMax =NAN; - Blt_Ts_InitStyle(ops->limitsTextStyle); + + ops->limitsTextStyle.anchor =TK_ANCHOR_NW; + ops->limitsTextStyle.color =NULL; + ops->limitsTextStyle.font =NULL; + ops->limitsTextStyle.angle =0; + ops->limitsTextStyle.justify =TK_JUSTIFY_LEFT; optionTable_ = Tk_CreateOptionTable(graphPtr_->interp_, optionSpecs); } @@ -286,8 +291,6 @@ Axis::~Axis() if (hashPtr_) Tcl_DeleteHashEntry(hashPtr_); - Blt_Ts_FreeStyle(graphPtr_->display_, &ops->limitsTextStyle); - if (tickGC_) Tk_FreeGC(graphPtr_->display_, tickGC_); @@ -367,8 +370,8 @@ int Axis::configure() titleWidth_ = titleHeight_ = 0; if (ops->title) { - unsigned int w, h; - Blt_GetTextExtents(ops->titleFont, 0, ops->title, -1, &w, &h); + int w, h; + Blt_GetTextExtents(ops->titleFont, ops->title, -1, &w, &h); titleWidth_ = (unsigned short int)w; titleHeight_ = (unsigned short int)h; } @@ -417,8 +420,8 @@ void Axis::mapStacked(int count, int margin) height_ = slice; } - unsigned int w, h; - Blt_GetTextExtents(ops->tickFont, 0, "0", 1, &w, &h); + int w, h; + Blt_GetTextExtents(ops->tickFont, "0", 1, &w, &h); screenMin_ += (slice * count) + 2 + h / 2; screenRange_ = slice - 2 * 2 - h; screenScale_ = 1.0f / screenRange_; @@ -512,28 +515,19 @@ void Axis::draw(Drawable drawable) ops->borderWidth, ops->relief); if (ops->title) { - TextStyle ts; + TextStyle ts(graphPtr_); + TextStyleOptions* tops = (TextStyleOptions*)ts.ops(); - Blt_Ts_InitStyle(ts); - ts.flags_ |= UPDATE_GC; + tops->angle = titleAngle_; + tops->font = ops->titleFont; + tops->anchor = titleAnchor_; + tops->color = (flags & ACTIVE) ? ops->activeFgColor : ops->titleColor; + tops->justify = ops->titleJustify; - ts.angle = titleAngle_; - ts.font = ops->titleFont; - ts.anchor = titleAnchor_; - if (flags & ACTIVE) - ts.color = ops->activeFgColor; - else - ts.color = ops->titleColor; - ts.justify = ops->titleJustify; ts.xPad_ = 1; ts.yPad_ = 0; - if ((titleAngle_ == 90.0) || (titleAngle_ == 270.0)) - ts.maxLength_ = height_; - else - ts.maxLength_ = width_; - Blt_Ts_DrawText(graphPtr_->tkwin_, drawable, ops->title, -1, &ts, - (int)titlePos_.x, (int)titlePos_.y); + ts.drawText(drawable, ops->title, titlePos_.x, titlePos_.y); } if (ops->scrollCmdObjPtr) { @@ -597,26 +591,22 @@ void Axis::draw(Drawable drawable) } if (ops->showTicks) { - TextStyle ts; + TextStyle ts(graphPtr_); + TextStyleOptions* tops = (TextStyleOptions*)ts.ops(); - Blt_Ts_InitStyle(ts); - ts.flags_ |= UPDATE_GC; + tops->angle = ops->tickAngle; + tops->font = ops->tickFont; + tops->anchor = tickAnchor_; + tops->color = (flags & ACTIVE) ? ops->activeFgColor : ops->tickColor; - ts.angle = ops->tickAngle; - ts.font = ops->tickFont; ts.xPad_ = 2; ts.yPad_ = 0; - ts.anchor = tickAnchor_; - if (flags & ACTIVE) - ts.color = ops->activeFgColor; - else - ts.color = ops->tickColor; for (Blt_ChainLink link=Blt_Chain_FirstLink(tickLabels_); link; link = Blt_Chain_NextLink(link)) { TickLabel *labelPtr = (TickLabel*)Blt_Chain_GetValue(link); - Blt_DrawText(graphPtr_->tkwin_, drawable, labelPtr->string, &ts, - (int)labelPtr->anchorPos.x, (int)labelPtr->anchorPos.y); + ts.drawText(drawable, labelPtr->string, labelPtr->anchorPos.x, + labelPtr->anchorPos.y); } } @@ -655,8 +645,6 @@ void Axis::drawLimits(Drawable drawable) int hMin = graphPtr_->bottom_ - gops->yPad - 2; int hMax = hMin; - ops->limitsTextStyle.flags_ |= UPDATE_GC; - const int spacing =8; int isHoriz = isHorizontal(); char* minPtr =NULL; @@ -677,24 +665,23 @@ void Axis::drawLimits(Drawable drawable) maxPtr = tmp; } + TextStyle ts(graphPtr_, &ops->limitsTextStyle); if (maxPtr) { if (isHoriz) { ops->limitsTextStyle.angle = 90.0; ops->limitsTextStyle.anchor = TK_ANCHOR_SE; - Dim2D textDim; - Blt_DrawText2(graphPtr_->tkwin_, drawable, maxPtr, &ops->limitsTextStyle, - graphPtr_->right_, hMax, &textDim); - hMax -= (textDim.height + spacing); + int ww, hh; + ts.drawText2(drawable, maxPtr, graphPtr_->right_, hMax, &ww, &hh); + hMax -= (hh + spacing); } else { ops->limitsTextStyle.angle = 0.0; ops->limitsTextStyle.anchor = TK_ANCHOR_NW; - Dim2D textDim; - Blt_DrawText2(graphPtr_->tkwin_, drawable, maxPtr, &ops->limitsTextStyle, - vMax, graphPtr_->top_, &textDim); - vMax += (textDim.width + spacing); + int ww, hh; + ts.drawText2(drawable, maxPtr, vMax, graphPtr_->top_, &ww, &hh); + vMax += (ww + spacing); } } if (minPtr) { @@ -703,18 +690,16 @@ void Axis::drawLimits(Drawable drawable) if (isHoriz) { ops->limitsTextStyle.angle = 90.0; - Dim2D textDim; - Blt_DrawText2(graphPtr_->tkwin_, drawable, minPtr, &ops->limitsTextStyle, - graphPtr_->left_, hMin, &textDim); - hMin -= (textDim.height + spacing); + int ww, hh; + ts.drawText2(drawable, minPtr, graphPtr_->left_, hMin, &ww, &hh); + hMin -= (hh + spacing); } else { ops->limitsTextStyle.angle = 0.0; - Dim2D textDim; - Blt_DrawText2(graphPtr_->tkwin_, drawable, minPtr, &ops->limitsTextStyle, - vMin, graphPtr_->bottom_, &textDim); - vMin += (textDim.width + spacing); + int ww, hh; + ts.drawText2(drawable, minPtr, vMin, graphPtr_->bottom_, &ww, &hh); + vMin += (ww + spacing); } } } @@ -1148,8 +1133,6 @@ void Axis::resetTextStyles() { AxisOptions* ops = (AxisOptions*)ops_; - Blt_Ts_ResetStyle(graphPtr_->tkwin_, &ops->limitsTextStyle); - XGCValues gcValues; unsigned long gcMask; gcMask = (GCForeground | GCLineWidth | GCCapStyle); @@ -1702,37 +1685,38 @@ void Axis::print(Blt_Ps ps) ops->borderWidth, ops->relief); if (ops->title) { - TextStyle ts; + TextStyle ts(graphPtr_); + TextStyleOptions* tops = (TextStyleOptions*)ts.ops(); - Blt_Ts_InitStyle(ts); + tops->angle = titleAngle_; + tops->font = ops->titleFont; + tops->anchor = titleAnchor_; + tops->justify = ops->titleJustify; + tops->color = ops->titleColor; - ts.angle = titleAngle_; - ts.font = ops->titleFont; - ts.anchor = titleAnchor_; - ts.justify = ops->titleJustify; - ts.color = ops->titleColor; ts.xPad_ = 1; ts.yPad_ = 0; - Blt_Ps_DrawText(ps, ops->title, &ts, titlePos_.x, titlePos_.y); + + ts.printText(ps, ops->title, titlePos_.x, titlePos_.y); } if (ops->showTicks) { - TextStyle ts; + TextStyle ts(graphPtr_); + TextStyleOptions* tops = (TextStyleOptions*)ts.ops(); - Blt_Ts_InitStyle(ts); + tops->angle = ops->tickAngle; + tops->font = ops->tickFont; + tops->anchor = tickAnchor_; + tops->color = ops->tickColor; - ts.angle = ops->tickAngle; - ts.font = ops->tickFont; - ts.anchor = tickAnchor_; - ts.color = ops->tickColor; ts.xPad_ = 2; ts.yPad_ = 0; for (Blt_ChainLink link=Blt_Chain_FirstLink(tickLabels_); link; link = Blt_Chain_NextLink(link)) { TickLabel *labelPtr = (TickLabel*)Blt_Chain_GetValue(link); - Blt_Ps_DrawText(ps, labelPtr->string, &ts, labelPtr->anchorPos.x, - labelPtr->anchorPos.y); + ts.printText(ps, labelPtr->string, labelPtr->anchorPos.x, + labelPtr->anchorPos.y); } } @@ -1797,47 +1781,43 @@ void Axis::printLimits(Blt_Ps ps) maxPtr = tmp; } - unsigned int textWidth; - unsigned int textHeight; + int textWidth, textHeight; + TextStyle ts(graphPtr_, &ops->limitsTextStyle); if (maxPtr) { - Blt_GetTextExtents(ops->tickFont, 0, maxPtr, -1, &textWidth, &textHeight); + Blt_GetTextExtents(ops->tickFont, maxPtr, -1, &textWidth, &textHeight); if ((textWidth > 0) && (textHeight > 0)) { if (isHoriz) { ops->limitsTextStyle.angle = 90.0; ops->limitsTextStyle.anchor = TK_ANCHOR_SE; - Blt_Ps_DrawText(ps, maxPtr, &ops->limitsTextStyle, - (double)graphPtr_->right_, hMax); + ts.printText(ps, maxPtr, (double)graphPtr_->right_, hMax); hMax -= (textWidth + spacing); } else { ops->limitsTextStyle.angle = 0.0; ops->limitsTextStyle.anchor = TK_ANCHOR_NW; - Blt_Ps_DrawText(ps, maxPtr, &ops->limitsTextStyle, - vMax, (double)graphPtr_->top_); + ts.printText(ps, maxPtr, vMax, (double)graphPtr_->top_); vMax += (textWidth + spacing); } } } if (minPtr) { - Blt_GetTextExtents(ops->tickFont, 0, minPtr, -1, &textWidth, &textHeight); + Blt_GetTextExtents(ops->tickFont, minPtr, -1, &textWidth, &textHeight); if ((textWidth > 0) && (textHeight > 0)) { ops->limitsTextStyle.anchor = TK_ANCHOR_SW; if (isHoriz) { ops->limitsTextStyle.angle = 90.0; - Blt_Ps_DrawText(ps, minPtr, &ops->limitsTextStyle, - (double)graphPtr_->left_, hMin); + ts.printText(ps, minPtr, (double)graphPtr_->left_, hMin); hMin -= (textWidth + spacing); } else { ops->limitsTextStyle.angle = 0.0; - Blt_Ps_DrawText(ps, minPtr, &ops->limitsTextStyle, - vMin, (double)graphPtr_->bottom_); + ts.printText(ps, minPtr, vMin, (double)graphPtr_->bottom_); vMin += (textWidth + spacing); } } diff --git a/src/bltGrAxis.h b/src/bltGrAxis.h index 8ecf325..f16ec09 100644 --- a/src/bltGrAxis.h +++ b/src/bltGrAxis.h @@ -111,7 +111,7 @@ typedef struct { const char *formatCmd; int descending; int labelOffset; - TextStyle limitsTextStyle; + TextStyleOptions limitsTextStyle; const char *limitsFormat; int lineWidth; int logScale; diff --git a/src/bltGrElemBar.C b/src/bltGrElemBar.C index 1b6b3b0..1902927 100644 --- a/src/bltGrElemBar.C +++ b/src/bltGrElemBar.C @@ -185,7 +185,6 @@ BarElement::BarElement(Graph* graphPtr, const char* name, Tcl_HashEntry* hPtr) activeRects_ =NULL; nBars_ =0; nActive_ =0; - xPad_ =0; xeb_.segments =NULL; xeb_.length =0; @@ -1303,15 +1302,17 @@ void BarElement::DrawBarValues(Drawable drawable, BarPen* penPtr, XRectangle *bars, int nBars, int *barToData) { BarElementOptions* ops = (BarElementOptions*)ops_; - BarPenOptions* penOps = (BarPenOptions*)penPtr->ops(); + BarPenOptions* pops = (BarPenOptions*)penPtr->ops(); BarGraphOptions* gops = (BarGraphOptions*)graphPtr_->ops_; - const char *fmt = penOps->valueFormat; + const char *fmt = pops->valueFormat; if (!fmt) fmt = "%g"; + TextStyle ts(graphPtr_, &pops->valueStyle); int count = 0; XRectangle *rp, *rend; + for (rp = bars, rend = rp + nBars; rp < rend; rp++) { Point2d anchorPos; char string[TCL_DOUBLE_SPACE * 2 + 2]; @@ -1320,11 +1321,11 @@ void BarElement::DrawBarValues(Drawable drawable, BarPen* penPtr, double y = ops->coords.y->values[barToData[count]]; count++; - if (penOps->valueShow == SHOW_X) + if (pops->valueShow == SHOW_X) snprintf(string, TCL_DOUBLE_SPACE, fmt, x); - else if (penOps->valueShow == SHOW_Y) + else if (pops->valueShow == SHOW_Y) snprintf(string, TCL_DOUBLE_SPACE, fmt, y); - else if (penOps->valueShow == SHOW_BOTH) { + else if (pops->valueShow == SHOW_BOTH) { snprintf(string, TCL_DOUBLE_SPACE, fmt, x); strcat(string, ","); snprintf(string + strlen(string), TCL_DOUBLE_SPACE, fmt, y); @@ -1342,46 +1343,46 @@ void BarElement::DrawBarValues(Drawable drawable, BarPen* penPtr, if (y < gops->baseline) anchorPos.y += rp->height; } - Blt_DrawText(graphPtr_->tkwin_, drawable, string, &penOps->valueStyle, - (int)anchorPos.x, (int)anchorPos.y); + + ts.drawText(drawable, string, anchorPos.x, anchorPos.y); } } void BarElement::SegmentsToPostScript(Blt_Ps ps, BarPen* penPtr, XRectangle *bars, int nBars) { - BarPenOptions* penOps = (BarPenOptions*)penPtr->ops(); + BarPenOptions* pops = (BarPenOptions*)penPtr->ops(); XRectangle *rp, *rend; - if (!penOps->fill && !penOps->outlineColor) + if (!pops->fill && !pops->outlineColor) return; for (rp = bars, rend = rp + nBars; rp < rend; rp++) { if ((rp->width < 1) || (rp->height < 1)) { continue; } - if (penOps->stipple != None) { + if (pops->stipple != None) { Blt_Ps_Rectangle(ps, rp->x, rp->y, rp->width - 1, rp->height - 1); - if (penOps->fill) { - Blt_Ps_XSetBackground(ps, Tk_3DBorderColor(penOps->fill)); + if (pops->fill) { + Blt_Ps_XSetBackground(ps, Tk_3DBorderColor(pops->fill)); Blt_Ps_Append(ps, "gsave fill grestore\n"); } - if (penOps->outlineColor) { - Blt_Ps_XSetForeground(ps, penOps->outlineColor); + if (pops->outlineColor) { + Blt_Ps_XSetForeground(ps, pops->outlineColor); } else { - Blt_Ps_XSetForeground(ps, Tk_3DBorderColor(penOps->fill)); + Blt_Ps_XSetForeground(ps, Tk_3DBorderColor(pops->fill)); } - Blt_Ps_XSetStipple(ps, graphPtr_->display_, penOps->stipple); - } else if (penOps->outlineColor) { - Blt_Ps_XSetForeground(ps, penOps->outlineColor); + Blt_Ps_XSetStipple(ps, graphPtr_->display_, pops->stipple); + } else if (pops->outlineColor) { + Blt_Ps_XSetForeground(ps, pops->outlineColor); Blt_Ps_XFillRectangle(ps, (double)rp->x, (double)rp->y, (int)rp->width - 1, (int)rp->height - 1); } - if ((penOps->fill) && (penOps->borderWidth > 0) && - (penOps->relief != TK_RELIEF_FLAT)) { - Blt_Ps_Draw3DRectangle(ps, penOps->fill, (double)rp->x, (double)rp->y, + if ((pops->fill) && (pops->borderWidth > 0) && + (pops->relief != TK_RELIEF_FLAT)) { + Blt_Ps_Draw3DRectangle(ps, pops->fill, (double)rp->x, (double)rp->y, (int)rp->width, (int)rp->height, - penOps->borderWidth, penOps->relief); + pops->borderWidth, pops->relief); } } } @@ -1390,48 +1391,48 @@ void BarElement::BarValuesToPostScript(Blt_Ps ps, BarPen* penPtr, XRectangle *bars, int nBars, int *barToData) { - BarPenOptions* penOps = (BarPenOptions*)penPtr->ops(); + BarPenOptions* pops = (BarPenOptions*)penPtr->ops(); BarElementOptions* ops = (BarElementOptions*)ops_; BarGraphOptions* gops = (BarGraphOptions*)graphPtr_->ops_; - XRectangle *rp, *rend; - char string[TCL_DOUBLE_SPACE * 2 + 2]; - double x, y; - Point2d anchorPos; - int count = 0; - const char* fmt = penOps->valueFormat; + const char* fmt = pops->valueFormat; if (!fmt) fmt = "%g"; + TextStyle ts(graphPtr_, &pops->valueStyle); + XRectangle *rp, *rend; for (rp = bars, rend = rp + nBars; rp < rend; rp++) { - x = ops->coords.x->values[barToData[count]]; - y = ops->coords.y->values[barToData[count]]; + double x = ops->coords.x->values[barToData[count]]; + double y = ops->coords.y->values[barToData[count]]; + count++; - if (penOps->valueShow == SHOW_X) + char string[TCL_DOUBLE_SPACE * 2 + 2]; + if (pops->valueShow == SHOW_X) snprintf(string, TCL_DOUBLE_SPACE, fmt, x); - else if (penOps->valueShow == SHOW_Y) + else if (pops->valueShow == SHOW_Y) snprintf(string, TCL_DOUBLE_SPACE, fmt, y); - else if (penOps->valueShow == SHOW_BOTH) { + else if (pops->valueShow == SHOW_BOTH) { snprintf(string, TCL_DOUBLE_SPACE, fmt, x); strcat(string, ","); snprintf(string + strlen(string), TCL_DOUBLE_SPACE, fmt, y); } + + Point2d anchorPos; if (gops->inverted) { anchorPos.y = rp->y + rp->height * 0.5; anchorPos.x = rp->x + rp->width; - if (x < gops->baseline) { + if (x < gops->baseline) anchorPos.x -= rp->width; - } - } else { + } + else { anchorPos.x = rp->x + rp->width * 0.5; anchorPos.y = rp->y; - if (y < gops->baseline) { + if (y < gops->baseline) anchorPos.y += rp->height; - } } - Blt_Ps_DrawText(ps, string, &penOps->valueStyle, anchorPos.x, - anchorPos.y); + + ts.printText(ps, string, anchorPos.x, anchorPos.y); } } diff --git a/src/bltGrElemBar.h b/src/bltGrElemBar.h index 103bd56..388d47a 100644 --- a/src/bltGrElemBar.h +++ b/src/bltGrElemBar.h @@ -92,7 +92,6 @@ class BarElement : public Element { XRectangle* activeRects_; int nBars_; int nActive_; - int xPad_; GraphSegments xeb_; GraphSegments yeb_; diff --git a/src/bltGrElemLine.C b/src/bltGrElemLine.C index 6113012..0f195c1 100644 --- a/src/bltGrElemLine.C +++ b/src/bltGrElemLine.C @@ -2737,59 +2737,57 @@ void LineElement::DrawValues(Drawable drawable, LinePen* penPtr, int length, Point2d *points, int *map) { LineElementOptions* ops = (LineElementOptions*)ops_; - LinePenOptions* penOps = (LinePenOptions*)penPtr->ops(); + LinePenOptions* pops = (LinePenOptions*)penPtr->ops(); Point2d *pp, *endp; double *xval, *yval; const char* fmt; char string[TCL_DOUBLE_SPACE * 2 + 2]; - fmt = penOps->valueFormat; + fmt = pops->valueFormat; if (fmt == NULL) fmt = "%g"; + TextStyle ts(graphPtr_, &pops->valueStyle); int count = 0; xval = ops->coords.x->values, yval = ops->coords.y->values; - // be sure to update style->gc, things might have changed - penOps->valueStyle.flags_ |= UPDATE_GC; for (pp = points, endp = points + length; pp < endp; pp++) { double x = xval[map[count]]; double y = yval[map[count]]; count++; - if (penOps->valueShow == SHOW_X) + if (pops->valueShow == SHOW_X) snprintf(string, TCL_DOUBLE_SPACE, fmt, x); - else if (penOps->valueShow == SHOW_Y) + else if (pops->valueShow == SHOW_Y) snprintf(string, TCL_DOUBLE_SPACE, fmt, y); - else if (penOps->valueShow == SHOW_BOTH) { + else if (pops->valueShow == SHOW_BOTH) { snprintf(string, TCL_DOUBLE_SPACE, fmt, x); strcat(string, ","); snprintf(string + strlen(string), TCL_DOUBLE_SPACE, fmt, y); } - Blt_DrawText(graphPtr_->tkwin_, drawable, string, &penOps->valueStyle, - Round(pp->x), Round(pp->y)); + ts.drawText(drawable, string, pp->x, pp->y); } } void LineElement::GetSymbolPostScriptInfo(Blt_Ps ps, LinePen* penPtr, int size) { - LinePenOptions* penOps = (LinePenOptions*)penPtr->ops(); + LinePenOptions* pops = (LinePenOptions*)penPtr->ops(); /* Set line and foreground attributes */ - XColor* fillColor = penOps->symbol.fillColor; + XColor* fillColor = pops->symbol.fillColor; if (!fillColor) - fillColor = penOps->traceColor; + fillColor = pops->traceColor; - XColor* outlineColor = penOps->symbol.outlineColor; + XColor* outlineColor = pops->symbol.outlineColor; if (!outlineColor) - outlineColor = penOps->traceColor; + outlineColor = pops->traceColor; - if (penOps->symbol.type == SYMBOL_NONE) - Blt_Ps_XSetLineAttributes(ps, penOps->traceColor, penOps->traceWidth + 2, - &penOps->traceDashes, CapButt, JoinMiter); + if (pops->symbol.type == SYMBOL_NONE) + Blt_Ps_XSetLineAttributes(ps, pops->traceColor, pops->traceWidth + 2, + &pops->traceDashes, CapButt, JoinMiter); else { - Blt_Ps_XSetLineWidth(ps, penOps->symbol.outlineWidth); + Blt_Ps_XSetLineWidth(ps, pops->symbol.outlineWidth); Blt_Ps_XSetDashes(ps, (Blt_Dashes *)NULL); } @@ -2799,7 +2797,7 @@ void LineElement::GetSymbolPostScriptInfo(Blt_Ps ps, LinePen* penPtr, int size) * already. */ Blt_Ps_Append(ps, "\n/DrawSymbolProc {\n"); - switch (penOps->symbol.type) { + switch (pops->symbol.type) { case SYMBOL_NONE: break; /* Do nothing */ case SYMBOL_BITMAP: @@ -2811,24 +2809,24 @@ void LineElement::GetSymbolPostScriptInfo(Blt_Ps ps, LinePen* penPtr, int size) * Compute how much to scale the bitmap. Don't let the scaled * bitmap exceed the bounding square for the symbol. */ - Tk_SizeOfBitmap(graphPtr_->display_, penOps->symbol.bitmap, &w, &h); + Tk_SizeOfBitmap(graphPtr_->display_, pops->symbol.bitmap, &w, &h); sx = (double)size / (double)w; sy = (double)size / (double)h; scale = MIN(sx, sy); - if (penOps->symbol.mask != None) { + if (pops->symbol.mask != None) { Blt_Ps_VarAppend(ps, "\n % Bitmap mask is \"", - Tk_NameOfBitmap(graphPtr_->display_, penOps->symbol.mask), + Tk_NameOfBitmap(graphPtr_->display_, pops->symbol.mask), "\"\n\n ", NULL); Blt_Ps_XSetBackground(ps, fillColor); - Blt_Ps_DrawBitmap(ps, graphPtr_->display_, penOps->symbol.mask, + Blt_Ps_DrawBitmap(ps, graphPtr_->display_, pops->symbol.mask, scale, scale); } Blt_Ps_VarAppend(ps, "\n % Bitmap symbol is \"", - Tk_NameOfBitmap(graphPtr_->display_, penOps->symbol.bitmap), + Tk_NameOfBitmap(graphPtr_->display_, pops->symbol.bitmap), "\"\n\n ", NULL); Blt_Ps_XSetForeground(ps, outlineColor); - Blt_Ps_DrawBitmap(ps, graphPtr_->display_, penOps->symbol.bitmap, + Blt_Ps_DrawBitmap(ps, graphPtr_->display_, pops->symbol.bitmap, scale, scale); } break; @@ -2837,7 +2835,7 @@ void LineElement::GetSymbolPostScriptInfo(Blt_Ps ps, LinePen* penPtr, int size) Blt_Ps_XSetBackground(ps, fillColor); Blt_Ps_Append(ps, " gsave fill grestore\n"); - if (penOps->symbol.outlineWidth > 0) { + if (pops->symbol.outlineWidth > 0) { Blt_Ps_Append(ps, " "); Blt_Ps_XSetForeground(ps, outlineColor); Blt_Ps_Append(ps, " stroke\n"); @@ -2850,7 +2848,7 @@ void LineElement::GetSymbolPostScriptInfo(Blt_Ps ps, LinePen* penPtr, int size) void LineElement::SymbolsToPostScript(Blt_Ps ps, LinePen* penPtr, int size, int nSymbolPts, Point2d *symbolPts) { - LinePenOptions* penOps = (LinePenOptions*)penPtr->ops(); + LinePenOptions* pops = (LinePenOptions*)penPtr->ops(); double symbolSize; static const char* symbolMacros[] = @@ -2860,7 +2858,7 @@ void LineElement::SymbolsToPostScript(Blt_Ps ps, LinePen* penPtr, int size, GetSymbolPostScriptInfo(ps, penPtr, size); symbolSize = (double)size; - switch (penOps->symbol.type) { + switch (pops->symbol.type) { case SYMBOL_SQUARE: case SYMBOL_CROSS: case SYMBOL_PLUS: @@ -2883,21 +2881,21 @@ void LineElement::SymbolsToPostScript(Blt_Ps ps, LinePen* penPtr, int size, Point2d *pp, *endp; for (pp = symbolPts, endp = symbolPts + nSymbolPts; pp < endp; pp++) { Blt_Ps_Format(ps, "%g %g %g %s\n", pp->x, pp->y, - symbolSize, symbolMacros[penOps->symbol.type]); + symbolSize, symbolMacros[pops->symbol.type]); } } void LineElement::SetLineAttributes(Blt_Ps ps, LinePen* penPtr) { - LinePenOptions* penOps = (LinePenOptions*)penPtr->ops(); + LinePenOptions* pops = (LinePenOptions*)penPtr->ops(); /* Set the attributes of the line (color, dashes, linewidth) */ - Blt_Ps_XSetLineAttributes(ps, penOps->traceColor, penOps->traceWidth, - &penOps->traceDashes, CapButt, JoinMiter); - if ((LineIsDashed(penOps->traceDashes)) && - (penOps->traceOffColor)) { + Blt_Ps_XSetLineAttributes(ps, pops->traceColor, pops->traceWidth, + &pops->traceDashes, CapButt, JoinMiter); + if ((LineIsDashed(pops->traceDashes)) && + (pops->traceOffColor)) { Blt_Ps_Append(ps, "/DashesProc {\n gsave\n "); - Blt_Ps_XSetBackground(ps, penOps->traceOffColor); + Blt_Ps_XSetBackground(ps, pops->traceOffColor); Blt_Ps_Append(ps, " "); Blt_Ps_XSetDashes(ps, (Blt_Dashes *)NULL); Blt_Ps_Append(ps, "stroke\n grestore\n} def\n"); @@ -2926,32 +2924,32 @@ void LineElement::ValuesToPostScript(Blt_Ps ps, LinePen* penPtr, int *pointToData) { LineElementOptions* ops = (LineElementOptions*)ops_; - LinePenOptions* penOps = (LinePenOptions*)penPtr->ops(); + LinePenOptions* pops = (LinePenOptions*)penPtr->ops(); - const char* fmt = penOps->valueFormat; + const char* fmt = pops->valueFormat; if (fmt == NULL) fmt = "%g"; + TextStyle ts(graphPtr_, &pops->valueStyle); int count = 0; Point2d *pp, *endp; for (pp = symbolPts, endp = symbolPts + nSymbolPts; pp < endp; pp++) { - double x, y; - - x = ops->coords.x->values[pointToData[count]]; - y = ops->coords.y->values[pointToData[count]]; + double x = ops->coords.x->values[pointToData[count]]; + double y = ops->coords.y->values[pointToData[count]]; count++; char string[TCL_DOUBLE_SPACE * 2 + 2]; - if (penOps->valueShow == SHOW_X) + if (pops->valueShow == SHOW_X) snprintf(string, TCL_DOUBLE_SPACE, fmt, x); - else if (penOps->valueShow == SHOW_Y) + else if (pops->valueShow == SHOW_Y) snprintf(string, TCL_DOUBLE_SPACE, fmt, y); - else if (penOps->valueShow == SHOW_BOTH) { + else if (pops->valueShow == SHOW_BOTH) { snprintf(string, TCL_DOUBLE_SPACE, fmt, x); strcat(string, ","); snprintf(string + strlen(string), TCL_DOUBLE_SPACE, fmt, y); } - Blt_Ps_DrawText(ps, string, &penOps->valueStyle, pp->x, pp->y); + + ts.printText(ps, string, pp->x, pp->y); } } diff --git a/src/bltGrLegd.C b/src/bltGrLegd.C index 9024d34..f78c6cd 100644 --- a/src/bltGrLegd.C +++ b/src/bltGrLegd.C @@ -182,12 +182,17 @@ Legend::Legend(Graph* graphPtr) titleWidth_ =0; titleHeight_ =0; - Blt_Ts_InitStyle(ops->style); - Blt_Ts_InitStyle(ops->titleStyle); - ops->style.justify = TK_JUSTIFY_LEFT; - ops->style.anchor = TK_ANCHOR_NW; - ops->titleStyle.justify = TK_JUSTIFY_LEFT; - ops->titleStyle.anchor = TK_ANCHOR_NW; + ops->style.anchor =TK_ANCHOR_NW; + ops->style.color =NULL; + ops->style.font =NULL; + ops->style.angle =0; + ops->style.justify =TK_JUSTIFY_LEFT; + + ops->titleStyle.anchor =TK_ANCHOR_NW; + ops->titleStyle.color =NULL; + ops->titleStyle.font =NULL; + ops->titleStyle.angle =0; + ops->titleStyle.justify =TK_JUSTIFY_LEFT; bindTable_ = Blt_CreateBindingTable(graphPtr->interp_, graphPtr->tkwin_, graphPtr, PickEntryProc, Blt_GraphTags); @@ -203,10 +208,8 @@ Legend::Legend(Graph* graphPtr) Legend::~Legend() { - LegendOptions* ops = (LegendOptions*)ops_; + // LegendOptions* ops = (LegendOptions*)ops_; - Blt_Ts_FreeStyle(graphPtr_->display_, &ops->style); - Blt_Ts_FreeStyle(graphPtr_->display_, &ops->titleStyle); Blt_DestroyBindingTable(bindTable_); if (focusGC_) @@ -254,8 +257,8 @@ void Legend::map(int plotWidth, int plotHeight) height_ =0; width_ = 0; - Blt_Ts_GetExtents(&ops->titleStyle, ops->title, - &titleWidth_, &titleHeight_); + TextStyle tts(graphPtr_, &ops->titleStyle); + tts.getExtents(ops->title, &titleWidth_, &titleHeight_); // Count the number of legend entries and determine the widest and tallest // label. The number of entries would normally be the number of elements, @@ -263,6 +266,7 @@ void Legend::map(int plotWidth, int plotHeight) int nEntries =0; int maxWidth =0; int maxHeight =0; + TextStyle ts(graphPtr_, &ops->style); for (Blt_ChainLink link=Blt_Chain_FirstLink(graphPtr_->elements_.displayList); link; link = Blt_Chain_NextLink(link)) { Element* elemPtr = (Element*)Blt_Chain_GetValue(link); @@ -271,8 +275,8 @@ void Legend::map(int plotWidth, int plotHeight) if (!elemOps->label) continue; - unsigned int w, h; - Blt_Ts_GetExtents(&ops->style, elemOps->label, &w, &h); + int w, h; + ts.getExtents(elemOps->label, &w, &h); if (maxWidth < (int)w) maxWidth = w; @@ -401,10 +405,6 @@ void Legend::draw(Drawable drawable) Pixmap pixmap = Tk_GetPixmap(graphPtr_->display_, Tk_WindowId(tkwin), w, h, Tk_Depth(tkwin)); - // be sure to update style->gc, things might have changed - ops->style.flags_ |= UPDATE_GC; - ops->titleStyle.flags_ |= UPDATE_GC; - if (ops->normalBg) Tk_Fill3DRectangle(tkwin, pixmap, ops->normalBg, 0, 0, w, h, 0, TK_RELIEF_FLAT); @@ -445,12 +445,16 @@ void Legend::draw(Drawable drawable) int x = ops->xPad + ops->borderWidth; int y = ops->yPad + ops->borderWidth; - Blt_DrawText(tkwin, pixmap, ops->title, &ops->titleStyle, x, y); + + TextStyle tts(graphPtr_, &ops->titleStyle); + tts.drawText(pixmap, ops->title, x, y); if (titleHeight_ > 0) y += titleHeight_ + ops->yPad; int count = 0; int yStart = y; + TextStyle ts(graphPtr_, &ops->style); + for (Blt_ChainLink link=Blt_Chain_FirstLink(graphPtr_->elements_.displayList); link; link = Blt_Chain_NextLink(link)) { Element* elemPtr = (Element*)Blt_Chain_GetValue(link); @@ -483,10 +487,10 @@ void Legend::draw(Drawable drawable) elemOps->legendRelief); } elemPtr->drawSymbol(pixmap, x + xSymbol, y + ySymbol, symbolSize); - Blt_DrawText(tkwin, pixmap, elemOps->label, &ops->style, - x + xLabel, - y + ops->entryBW + ops->iyPad); + + ts.drawText(pixmap, elemOps->label, x+xLabel, y+ops->entryBW+ops->iyPad); count++; + if (focusPtr_ == elemPtr) { if (isSelected) { XColor* color = (flags & FOCUS) ? @@ -497,10 +501,9 @@ void Legend::draw(Drawable drawable) XDrawRectangle(graphPtr_->display_, pixmap, focusGC_, x + 1, y + 1, entryWidth_ - 3, entryHeight_ - 3); - if (isSelected) { + if (isSelected) XSetForeground(graphPtr_->display_, focusGC_, ops->focusColor->pixel); - } } // Check when to move to the next column @@ -528,8 +531,8 @@ void Legend::draw(Drawable drawable) Tk_Draw3DRectangle(tkwin, pixmap, bg, 0, 0, w, h, ops->borderWidth, ops->relief); - XCopyArea(graphPtr_->display_, pixmap, drawable, graphPtr_->drawGC_, 0, 0, w, h, - x_, y_); + XCopyArea(graphPtr_->display_, pixmap, drawable, graphPtr_->drawGC_, + 0, 0, w, h, x_, y_); switch ((Position)ops->position) { case PLOT: @@ -586,12 +589,15 @@ void Legend::print(Blt_Ps ps) x += ops->borderWidth; y += ops->borderWidth; - Blt_Ps_DrawText(ps, ops->title, &ops->titleStyle, x, y); + TextStyle tts(graphPtr_, &ops->titleStyle); + tts.printText(ps, ops->title, x, y); if (titleHeight_ > 0) y += titleHeight_ + ops->yPad; int count = 0; double yStart = y; + TextStyle ts(graphPtr_, &ops->style); + for (Blt_ChainLink link=Blt_Chain_FirstLink(graphPtr_->elements_.displayList); link; link = Blt_Chain_NextLink(link)) { Element* elemPtr = (Element*)Blt_Chain_GetValue(link); @@ -616,8 +622,7 @@ void Legend::print(Blt_Ps ps) } } elemPtr->printSymbol(ps, x + xSymbol, y + ySymbol, symbolSize); - Blt_Ps_DrawText(ps, elemOps->label, &ops->style, - x + xLabel, y + ops->entryBW + ops->iyPad); + ts.printText(ps, elemOps->label, x + xLabel, y + ops->entryBW + ops->iyPad); count++; if ((count % nRows_) > 0) diff --git a/src/bltGrLegd.h b/src/bltGrLegd.h index 63e3d86..10a153d 100644 --- a/src/bltGrLegd.h +++ b/src/bltGrLegd.h @@ -76,7 +76,7 @@ typedef struct { int exportSelection; Blt_Dashes focusDashes; XColor* focusColor; - TextStyle style; + TextStyleOptions style; int hide; int ixPad; int iyPad; @@ -99,7 +99,7 @@ typedef struct { int selRelief; const char *takeFocus; const char *title; - TextStyle titleStyle; + TextStyleOptions titleStyle; } LegendOptions; class Legend { @@ -131,8 +131,8 @@ class Legend { Element *selAnchorPtr_; Element *selMarkPtr_; Blt_Chain selected_; - unsigned int titleWidth_; - unsigned int titleHeight_; + int titleWidth_; + int titleHeight_; protected: void setOrigin(); diff --git a/src/bltGrMarkerText.C b/src/bltGrMarkerText.C index 37c793a..b898c2d 100644 --- a/src/bltGrMarkerText.C +++ b/src/bltGrMarkerText.C @@ -91,19 +91,25 @@ TextMarker::TextMarker(Graph* graphPtr, const char* name, Tcl_HashEntry* hPtr) : Marker(graphPtr, name, hPtr) { ops_ = (TextMarkerOptions*)calloc(1, sizeof(TextMarkerOptions)); - Blt_Ts_InitStyle(((TextMarkerOptions*)ops_)->style); - optionTable_ = Tk_CreateOptionTable(graphPtr->interp_, optionSpecs); + TextMarkerOptions* ops = (TextMarkerOptions*)ops_; + + ops->style.anchor =TK_ANCHOR_NW; + ops->style.color =NULL; + ops->style.font =NULL; + ops->style.angle =0; + ops->style.justify =TK_JUSTIFY_LEFT; anchorPt_.x =0; anchorPt_.y =0; width_ =0; height_ =0; fillGC_ =NULL; + + optionTable_ = Tk_CreateOptionTable(graphPtr->interp_, optionSpecs); } TextMarker::~TextMarker() { - Blt_Ts_FreeStyle(graphPtr_->display_, &((TextMarkerOptions*)ops_)->style); } int TextMarker::configure() @@ -148,10 +154,8 @@ void TextMarker::draw(Drawable drawable) Convex, CoordModeOrigin); } - // be sure to update style->gc, things might have changed - ops->style.flags_ |= UPDATE_GC; - Blt_Ts_DrawText(graphPtr_->tkwin_, drawable, ops->string, -1, - &ops->style, anchorPt_.x, anchorPt_.y); + TextStyle ts(graphPtr_, &ops->style); + ts.drawText(drawable, ops->string, anchorPt_.x, anchorPt_.y); } void TextMarker::map() @@ -167,9 +171,9 @@ void TextMarker::map() width_ =0; height_ =0; - unsigned int w; - unsigned int h; - Blt_Ts_GetExtents(&ops->style, ops->string, &w, &h); + int w, h; + TextStyle ts(graphPtr_, &ops->style); + ts.getExtents(ops->string, &w, &h); double rw; double rh; @@ -270,5 +274,6 @@ void TextMarker::postscript(Blt_Ps ps) Blt_Ps_XFillPolygon(ps, points, 4); } - Blt_Ps_DrawText(ps, ops->string, &ops->style, anchorPt_.x, anchorPt_.y); + TextStyle ts(graphPtr_, &ops->style); + ts.printText(ps, ops->string, anchorPt_.x, anchorPt_.y); } diff --git a/src/bltGrMarkerText.h b/src/bltGrMarkerText.h index 9149f2b..e2a3536 100644 --- a/src/bltGrMarkerText.h +++ b/src/bltGrMarkerText.h @@ -50,7 +50,7 @@ namespace Blt { Tk_Anchor anchor; XColor* fillColor; - TextStyle style; + TextStyleOptions style; const char* string; } TextMarkerOptions; diff --git a/src/bltGrMisc.h b/src/bltGrMisc.h index 6656ea8..f75c2db 100644 --- a/src/bltGrMisc.h +++ b/src/bltGrMisc.h @@ -141,11 +141,6 @@ typedef struct { Point2d q; } Segment2d; -typedef struct { - short int width; - short int height; -} Dim2D; - typedef enum { CID_NONE, CID_AXIS_X, CID_AXIS_Y, CID_ELEM_BAR, CID_ELEM_LINE, CID_MARKER_BITMAP, CID_MARKER_IMAGE, CID_MARKER_LINE, CID_MARKER_POLYGON, diff --git a/src/bltGrPSOutput.C b/src/bltGrPSOutput.C index 28e8708..321a8fc 100644 --- a/src/bltGrPSOutput.C +++ b/src/bltGrPSOutput.C @@ -693,13 +693,9 @@ static void TextLayoutToPostScript(Blt_Ps ps, int x, int y, TextLayout *textPtr) } #endif -void Blt_Ps_DrawText( - Blt_Ps ps, - const char *string, /* String to convert to PostScript */ - TextStyle *tsPtr, /* Text attribute information */ - double x, double y) /* Window coordinates where to print text */ -{ #if 0 +void Blt_Ps_DrawText(Blt_Ps ps, const char *string, double x, double y) +{ TextLayout *textPtr; Point2d t; @@ -732,8 +728,8 @@ void Blt_Ps_DrawText( TextLayoutToPostScript(ps, 0, 0, textPtr); free(textPtr); Blt_Ps_Append(ps, "EndText\n"); -#endif } +#endif void Blt_Ps_XDrawLines(Blt_Ps ps, XPoint *points, int n) { diff --git a/src/bltGrPSOutput.h b/src/bltGrPSOutput.h index 0d3915c..1f6593a 100644 --- a/src/bltGrPSOutput.h +++ b/src/bltGrPSOutput.h @@ -124,9 +124,6 @@ extern void Blt_Ps_DrawPhoto(Blt_Ps ps, Tk_PhotoHandle photoToken, extern void Blt_Ps_XDrawWindow(Blt_Ps ps, Tk_Window tkwin, double x, double y); -extern void Blt_Ps_DrawText(Blt_Ps ps, const char *string, - TextStyle *attrPtr, double x, double y); - extern void Blt_Ps_DrawBitmap(Blt_Ps ps, Display *display, Pixmap bitmap, double scaleX, double scaleY); diff --git a/src/bltGrPen.C b/src/bltGrPen.C index 1180e14..05064a0 100644 --- a/src/bltGrPen.C +++ b/src/bltGrPen.C @@ -54,8 +54,7 @@ Pen::~Pen() if (hashPtr_) Tcl_DeleteHashEntry(hashPtr_); - PenOptions* ops = (PenOptions*)ops_; - Blt_Ts_FreeStyle(graphPtr_->display_, &ops->valueStyle); + // PenOptions* ops = (PenOptions*)ops_; Tk_FreeConfigOptions((char*)ops_, optionTable_, graphPtr_->tkwin_); diff --git a/src/bltGrPen.h b/src/bltGrPen.h index ef7e049..ecc02e7 100644 --- a/src/bltGrPen.h +++ b/src/bltGrPen.h @@ -43,7 +43,7 @@ typedef struct { XColor* errorBarColor; int valueShow; const char* valueFormat; - TextStyle valueStyle; + TextStyleOptions valueStyle; } PenOptions; class Pen { diff --git a/src/bltGrPenBar.C b/src/bltGrPenBar.C index b1abe8d..71b315f 100644 --- a/src/bltGrPenBar.C +++ b/src/bltGrPenBar.C @@ -82,31 +82,41 @@ static Tk_OptionSpec barPenOptionSpecs[] = { BarPen::BarPen(Graph* graphPtr, const char* name, Tcl_HashEntry* hPtr) : Pen(graphPtr, name, hPtr) { - optionTable_ = Tk_CreateOptionTable(graphPtr_->interp_, barPenOptionSpecs); ops_ = calloc(1, sizeof(BarPenOptions)); + BarPenOptions* ops = (BarPenOptions*)ops_; manageOptions_ =1; fillGC_ =NULL; outlineGC_ =NULL; errorBarGC_ =NULL; - BarPenOptions* ops = (BarPenOptions*)ops_; - Blt_Ts_InitStyle(ops->valueStyle); + ops->valueStyle.anchor =TK_ANCHOR_NW; + ops->valueStyle.color =NULL; + ops->valueStyle.font =NULL; + ops->valueStyle.angle =0; + ops->valueStyle.justify =TK_JUSTIFY_LEFT; + + optionTable_ = Tk_CreateOptionTable(graphPtr_->interp_, barPenOptionSpecs); } BarPen::BarPen(Graph* graphPtr, const char* name, void* options) : Pen(graphPtr, name, NULL) { - optionTable_ = Tk_CreateOptionTable(graphPtr_->interp_, barPenOptionSpecs); ops_ = options; + BarPenOptions* ops = (BarPenOptions*)ops_; manageOptions_ =0; fillGC_ =NULL; outlineGC_ =NULL; errorBarGC_ =NULL; - BarPenOptions* ops = (BarPenOptions*)ops_; - Blt_Ts_InitStyle(ops->valueStyle); + ops->valueStyle.anchor =TK_ANCHOR_NW; + ops->valueStyle.color =NULL; + ops->valueStyle.font =NULL; + ops->valueStyle.angle =0; + ops->valueStyle.justify =TK_JUSTIFY_LEFT; + + optionTable_ = Tk_CreateOptionTable(graphPtr_->interp_, barPenOptionSpecs); } BarPen::~BarPen() diff --git a/src/bltGrPenBar.h b/src/bltGrPenBar.h index 5d45b14..b5a9fa9 100644 --- a/src/bltGrPenBar.h +++ b/src/bltGrPenBar.h @@ -41,7 +41,7 @@ typedef struct { XColor* errorBarColor; int valueShow; const char *valueFormat; - TextStyle valueStyle; + TextStyleOptions valueStyle; XColor* outlineColor; Tk_3DBorder fill; diff --git a/src/bltGrPenLine.C b/src/bltGrPenLine.C index b1e8d49..af6fe8e 100644 --- a/src/bltGrPenLine.C +++ b/src/bltGrPenLine.C @@ -225,35 +225,47 @@ static Tk_OptionSpec linePenOptionSpecs[] = { LinePen::LinePen(Graph* graphPtr, const char* name, Tcl_HashEntry* hPtr) : Pen(graphPtr, name, hPtr) { - optionTable_ = Tk_CreateOptionTable(graphPtr_->interp_, linePenOptionSpecs); ops_ = calloc(1, sizeof(LinePenOptions)); + LinePenOptions* ops = (LinePenOptions*)ops_; manageOptions_ =1; traceGC_ =NULL; errorBarGC_ =NULL; - LinePenOptions* ops = (LinePenOptions*)ops_; - Blt_Ts_InitStyle(ops->valueStyle); ops->symbol.bitmap = None; ops->symbol.mask = None; ops->symbol.type = SYMBOL_NONE; + + ops->valueStyle.anchor =TK_ANCHOR_NW; + ops->valueStyle.color =NULL; + ops->valueStyle.font =NULL; + ops->valueStyle.angle =0; + ops->valueStyle.justify =TK_JUSTIFY_LEFT; + + optionTable_ = Tk_CreateOptionTable(graphPtr_->interp_, linePenOptionSpecs); } LinePen::LinePen(Graph* graphPtr, const char* name, void* options) : Pen(graphPtr, name, NULL) { - optionTable_ = Tk_CreateOptionTable(graphPtr_->interp_, linePenOptionSpecs); ops_ = options; + LinePenOptions* ops = (LinePenOptions*)ops_; manageOptions_ =0; traceGC_ =NULL; errorBarGC_ =NULL; - LinePenOptions* ops = (LinePenOptions*)ops_; - Blt_Ts_InitStyle(ops->valueStyle); ops->symbol.bitmap = None; ops->symbol.mask = None; ops->symbol.type = SYMBOL_NONE; + + ops->valueStyle.anchor =TK_ANCHOR_NW; + ops->valueStyle.color =NULL; + ops->valueStyle.font =NULL; + ops->valueStyle.angle =0; + ops->valueStyle.justify =TK_JUSTIFY_LEFT; + + optionTable_ = Tk_CreateOptionTable(graphPtr_->interp_, linePenOptionSpecs); } LinePen::~LinePen() diff --git a/src/bltGrPenLine.h b/src/bltGrPenLine.h index b584083..d2077ec 100644 --- a/src/bltGrPenLine.h +++ b/src/bltGrPenLine.h @@ -59,7 +59,7 @@ typedef struct { XColor* errorBarColor; int valueShow; const char* valueFormat; - TextStyle valueStyle; + TextStyleOptions valueStyle; Symbol symbol; int traceWidth; diff --git a/src/bltGrText.C b/src/bltGrText.C index 85c5020..5cfe26f 100644 --- a/src/bltGrText.C +++ b/src/bltGrText.C @@ -36,38 +36,195 @@ extern "C" { }; #include "bltText.h" +#include "bltGraph.h" +#include "bltPs.h" -#define ROUND(x) ((int)((x) + (((x)<0.0) ? -0.5 : 0.5))) #define ROTATE_0 0 #define ROTATE_90 1 #define ROTATE_180 2 #define ROTATE_270 3 -void Blt_GetTextExtents(Tk_Font font, int leader, const char *text, int textLen, - unsigned int *widthPtr, unsigned int *heightPtr) +TextStyle::TextStyle(Graph* graphPtr) +{ + ops_ = (TextStyleOptions*)calloc(1, sizeof(TextStyleOptions)); + TextStyleOptions* ops = (TextStyleOptions*)ops_; + graphPtr_ = graphPtr; + manageOptions_ = 1; + + ops->anchor =TK_ANCHOR_NW; + ops->color =NULL; + ops->font =NULL; + ops->angle =0; + ops->justify =TK_JUSTIFY_LEFT; + + xPad_ = 0; + yPad_ = 0; + gc_ = NULL; +} + +TextStyle::TextStyle(Graph* graphPtr, TextStyleOptions* ops) +{ + ops_ = (TextStyleOptions*)ops; + graphPtr_ = graphPtr; + manageOptions_ = 0; + + xPad_ = 0; + yPad_ = 0; + gc_ = NULL; +} + +TextStyle::~TextStyle() +{ + // TextStyleOptions* ops = (TextStyleOptions*)ops_; + + if (gc_) + Tk_FreeGC(graphPtr_->display_, gc_); + + if (manageOptions_) + free(ops_); +} + +void TextStyle::drawText(Drawable drawable, const char *text, int x, int y) +{ + TextStyleOptions* ops = (TextStyleOptions*)ops_; + + if (!text || !(*text)) + return; + + if (!gc_) + resetStyle(); + + int w1, h1; + Tk_TextLayout layout = Tk_ComputeTextLayout(ops->font, text, -1, -1, + ops->justify, 0, &w1, &h1); + Point2d rr = rotateText(x, y, w1, h1); + TkDrawAngledTextLayout(graphPtr_->display_, drawable, gc_, layout, + rr.x, rr.y, ops->angle, 0, -1); +} + +void TextStyle::drawText2(Drawable drawable, const char *text, + int x, int y, int* ww, int* hh) +{ + TextStyleOptions* ops = (TextStyleOptions*)ops_; + + if (!text || !(*text)) + return; + + if (!gc_) + resetStyle(); + + int w1, h1; + Tk_TextLayout layout = Tk_ComputeTextLayout(ops->font, text, -1, -1, + ops->justify, 0, &w1, &h1); + Point2d rr = rotateText(x, y, w1, h1); + TkDrawAngledTextLayout(graphPtr_->display_, drawable, gc_, layout, + rr.x, rr.y, ops->angle, 0, -1); + + float angle = fmod(ops->angle, 360.0); + if (angle < 0.0) + angle += 360.0; + + if (angle != 0.0) { + double rotWidth, rotHeight; + Blt_GetBoundingBox(w1, h1, angle, &rotWidth, &rotHeight, (Point2d*)NULL); + w1 = rotWidth; + h1 = rotHeight; + } + + *ww = w1; + *hh = h1; +} + +void TextStyle::printText(Blt_Ps ps, const char *text, int x, int y) +{ + // TextStyleOptions* ops = (TextStyleOptions*)ops_; + + if (!text || !(*text)) + return; +} + +void TextStyle::resetStyle() +{ + TextStyleOptions* ops = (TextStyleOptions*)ops_; + + unsigned long gcMask; + gcMask = GCFont; + + XGCValues gcValues; + gcValues.font = Tk_FontId(ops->font); + if (ops->color) { + gcMask |= GCForeground; + gcValues.foreground = ops->color->pixel; + } + GC newGC = Tk_GetGC(graphPtr_->tkwin_, gcMask, &gcValues); + if (gc_) + Tk_FreeGC(graphPtr_->display_, gc_); + + gc_ = newGC; +} + +Point2d TextStyle::rotateText(int x, int y, int w1, int h1) +{ + TextStyleOptions* ops = (TextStyleOptions*)ops_; + + // Matrix t0 = Translate(-x,-y); + // Matrix t1 = Translate(-w1/2,-h1/2); + // Matrix rr = Rotate(angle); + // Matrix t2 = Translate(w2/2,h2/2); + // Matrix t3 = Translate(x,y); + + double angle = ops->angle; + double ccos = cos(M_PI*angle/180.); + double ssin = sin(M_PI*angle/180.); + double w2, h2; + Blt_GetBoundingBox(w1, h1, angle, &w2, &h2, (Point2d *)NULL); + + double x1 = x+w1/2.; + double y1 = y+h1/2.; + double x2 = w2/2.+x; + double y2 = h2/2.+y; + + double rx = x*ccos + y*ssin + (-x1*ccos -y1*ssin +x2); + double ry = -x*ssin + y*ccos + ( x1*ssin -y1*ccos +y2); + + return Blt_AnchorPoint(rx, ry, w2, h2, ops->anchor); +} + +void TextStyle::getExtents(const char *text, int* ww, int* hh) +{ + TextStyleOptions* ops = (TextStyleOptions*)ops_; + + int w, h; + Blt_GetTextExtents(ops->font, text, -1, &w, &h); + *ww = w + 2*xPad_; + *hh = h + 2*yPad_; +} + +void Blt_GetTextExtents(Tk_Font font, const char *text, int textLen, + int* ww, int* hh) { if (!text) { - *widthPtr =0; - *heightPtr =0; + *ww =0; + *hh =0; return; } Tk_FontMetrics fm; Tk_GetFontMetrics(font, &fm); - unsigned int lineHeight = fm.linespace; + int lineHeight = fm.linespace; if (textLen < 0) textLen = strlen(text); - unsigned int maxWidth =0; - unsigned int maxHeight =0; - unsigned int lineLen =0; + int maxWidth =0; + int maxHeight =0; + int lineLen =0; const char *line =NULL; const char *p, *pend; for (p = line = text, pend = text + textLen; p < pend; p++) { if (*p == '\n') { if (lineLen > 0) { - unsigned int lineWidth = Tk_TextWidth(font, line, lineLen); + int lineWidth = Tk_TextWidth(font, line, lineLen); if (lineWidth > maxWidth) maxWidth = lineWidth; } @@ -82,22 +239,13 @@ void Blt_GetTextExtents(Tk_Font font, int leader, const char *text, int textLen, if ((lineLen > 0) && (*(p - 1) != '\n')) { maxHeight += lineHeight; - unsigned int lineWidth = Tk_TextWidth(font, line, lineLen); + int lineWidth = Tk_TextWidth(font, line, lineLen); if (lineWidth > maxWidth) maxWidth = lineWidth; } - *widthPtr = maxWidth; - *heightPtr = maxHeight; -} - -void Blt_Ts_GetExtents(TextStyle *tsPtr, const char *text, - unsigned int *widthPtr, unsigned int *heightPtr) -{ - unsigned int w, h; - Blt_GetTextExtents(tsPtr->font, tsPtr->leader_, text, -1, &w, &h); - *widthPtr = w + 2*tsPtr->xPad_; - *heightPtr = h + 2*tsPtr->yPad_; + *ww = maxWidth; + *hh = maxHeight; } /* @@ -242,8 +390,8 @@ void Blt_GetBoundingBox(int width, int height, float angle, * *--------------------------------------------------------------------------- */ -Point2d -Blt_AnchorPoint(double x, double y, double w, double h, Tk_Anchor anchor) +Point2d Blt_AnchorPoint(double x, double y, double w, double h, + Tk_Anchor anchor) { Point2d t; @@ -285,123 +433,3 @@ Blt_AnchorPoint(double x, double y, double w, double h, Tk_Anchor anchor) return t; } -static Point2d Rotate_Text(int x, int y, int w1, int h1, TextStyle* stylePtr) -{ - // Matrix t0 = Translate(-x,-y); - // Matrix t1 = Translate(-w1/2,-h1/2); - // Matrix rr = Rotate(angle); - // Matrix t2 = Translate(w2/2,h2/2); - // Matrix t3 = Translate(x,y); - - double angle, ccos, ssin; - double w2, h2; - double x1, y1, x2, y2; - double rx, ry; - - angle = stylePtr->angle; - ccos = cos(M_PI*angle/180.); - ssin = sin(M_PI*angle/180.); - Blt_GetBoundingBox(w1, h1, angle, &w2, &h2, (Point2d *)NULL); - - x1 = x+w1/2.; - y1 = y+h1/2.; - x2 = w2/2.+x; - y2 = h2/2.+y; - - rx = x*ccos + y*ssin + (-x1*ccos -y1*ssin +x2); - ry = -x*ssin + y*ccos + ( x1*ssin -y1*ccos +y2); - - return Blt_AnchorPoint(rx, ry, w2, h2, stylePtr->anchor); -} - -void Blt_Ts_DrawText(Tk_Window tkwin, Drawable drawable, const char *text, - int textLen, TextStyle *stylePtr,int x, int y) -{ - if (!text || !(*text)) - return; - - if ((stylePtr->gc_ == NULL) || (stylePtr->flags_ & UPDATE_GC)) - Blt_Ts_ResetStyle(tkwin, stylePtr); - - int w1, h1; - Tk_TextLayout layout = Tk_ComputeTextLayout(stylePtr->font, text, textLen,-1, - stylePtr->justify, 0, &w1, &h1); - Point2d rr = Rotate_Text(x, y, w1, h1, stylePtr); - TkDrawAngledTextLayout(Tk_Display(tkwin), drawable, stylePtr->gc_, layout, - rr.x, rr.y, stylePtr->angle, 0, textLen); -} - -void Blt_DrawText2(Tk_Window tkwin, Drawable drawable, const char *text, - TextStyle *stylePtr, int x, int y, Dim2D *areaPtr) -{ - if (!text || !(*text)) - return; - - if ((stylePtr->gc_ == NULL) || (stylePtr->flags_ & UPDATE_GC)) - Blt_Ts_ResetStyle(tkwin, stylePtr); - - int w1, h1; - Tk_TextLayout layout = Tk_ComputeTextLayout(stylePtr->font, text, -1, -1, - stylePtr->justify, 0, &w1, &h1); - Point2d rr = Rotate_Text(x, y, w1, h1, stylePtr); - TkDrawAngledTextLayout(Tk_Display(tkwin), drawable, stylePtr->gc_, layout, - rr.x, rr.y, stylePtr->angle, 0, -1); - - float angle = fmod(stylePtr->angle, 360.0); - if (angle < 0.0) - angle += 360.0; - - if (angle != 0.0) { - double rotWidth, rotHeight; - Blt_GetBoundingBox(w1, h1, angle, &rotWidth, &rotHeight, - (Point2d *)NULL); - w1 = ROUND(rotWidth); - h1 = ROUND(rotHeight); - } - - areaPtr->width = w1; - areaPtr->height = h1; -} - -void Blt_DrawText(Tk_Window tkwin, Drawable drawable, const char *text, - TextStyle *stylePtr, int x, int y) -{ - if (!text || (*text == '\0')) - return; - - if (!stylePtr->gc_ || (stylePtr->flags_ & UPDATE_GC)) - Blt_Ts_ResetStyle(tkwin, stylePtr); - - int w1, h1; - Tk_TextLayout layout = Tk_ComputeTextLayout(stylePtr->font, text, -1, -1, - stylePtr->justify, 0, &w1, &h1); - Point2d rr = Rotate_Text(x, y, w1, h1, stylePtr); - TkDrawAngledTextLayout(Tk_Display(tkwin), drawable, stylePtr->gc_, layout, - rr.x, rr.y, stylePtr->angle, 0, -1); -} - -void Blt_Ts_ResetStyle(Tk_Window tkwin, TextStyle *stylePtr) -{ - GC newGC; - XGCValues gcValues; - unsigned long gcMask; - - gcMask = GCFont; - gcValues.font = Tk_FontId(stylePtr->font); - if (stylePtr->color) { - gcMask |= GCForeground; - gcValues.foreground = stylePtr->color->pixel; - } - newGC = Tk_GetGC(tkwin, gcMask, &gcValues); - if (stylePtr->gc_) - Tk_FreeGC(Tk_Display(tkwin), stylePtr->gc_); - - stylePtr->gc_ = newGC; - stylePtr->flags_ &= ~UPDATE_GC; -} - -void Blt_Ts_FreeStyle(Display *display, TextStyle *stylePtr) -{ - if (stylePtr->gc_) - Tk_FreeGC(display, stylePtr->gc_); -} diff --git a/src/bltGrText.h b/src/bltGrText.h index 111b286..7a8247c 100644 --- a/src/bltGrText.h +++ b/src/bltGrText.h @@ -27,67 +27,55 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef _BLT_TEXT_H -#define _BLT_TEXT_H +#ifndef __BltText_h__ +#define __BltText_h__ #include <tk.h> #include "bltGrMisc.h" -#define UPDATE_GC 1 +class Graph; +typedef struct _Blt_Ps *Blt_Ps; -class TextStyle { - public: +typedef struct { Tk_Anchor anchor; XColor* color; Tk_Font font; double angle; Tk_Justify justify; +} TextStyleOptions; + +class TextStyle { + protected: + Graph* graphPtr_; + void* ops_; + GC gc_; + int manageOptions_; - unsigned short int leader_; - short int underline_; + public: int xPad_; int yPad_; - int maxLength_; - unsigned int state_; - unsigned short flags_; - GC gc_; + + protected: + void resetStyle(); + Point2d rotateText(int, int, int, int); + + public: + TextStyle(Graph*); + TextStyle(Graph*, TextStyleOptions*); + virtual ~TextStyle(); + + void* ops() {return ops_;} + void drawText(Drawable, const char*, int, int); + void drawText2(Drawable, const char*, int, int, int*, int*); + void printText(Blt_Ps, const char*, int, int); + void getExtents(const char*, int*, int*); }; -extern void Blt_GetTextExtents(Tk_Font font, int leader, const char *text, - int textLen, unsigned int *widthPtr, - unsigned int *heightPtr); -extern void Blt_Ts_GetExtents(TextStyle *tsPtr, const char *text, - unsigned int *widthPtr, unsigned int *heightPtr); -extern void Blt_Ts_ResetStyle(Tk_Window tkwin, TextStyle *tsPtr); -extern void Blt_Ts_FreeStyle(Display *display, TextStyle *tsPtr); -extern void Blt_DrawText(Tk_Window tkwin, Drawable drawable, - const char *string, TextStyle *tsPtr, - int x, int y); -extern void Blt_DrawText2(Tk_Window tkwin, Drawable drawable, - const char *string, TextStyle *tsPtr, - int x, int y, Dim2D * dimPtr); -extern void Blt_Ts_DrawText(Tk_Window tkwin, Drawable drawable, - const char *text, int textLen, TextStyle *tsPtr, - int x, int y); +extern void Blt_GetTextExtents(Tk_Font, const char*, int, int*, int*); extern void Blt_GetBoundingBox (int width, int height, float angle, double *widthPtr, double *heightPtr, Point2d *points); extern Point2d Blt_AnchorPoint (double x, double y, double width, double height, Tk_Anchor anchor); -#define Blt_Ts_InitStyle(ts) \ - ((ts).anchor = TK_ANCHOR_NW, \ - (ts).color = (XColor*)NULL, \ - (ts).font = NULL, \ - (ts).angle = 0.0, \ - (ts).justify = TK_JUSTIFY_LEFT, \ - (ts).leader_ = 0, \ - (ts).underline_ = -1, \ - (ts).xPad_ = 0, \ - (ts).yPad_ = 0, \ - (ts).maxLength_ = -1, \ - (ts).state_ = 0, \ - (ts).flags_ = 0, \ - (ts).gc_ = NULL) - #endif diff --git a/src/bltGraph.C b/src/bltGraph.C index 968e3a9..5a915f9 100644 --- a/src/bltGraph.C +++ b/src/bltGraph.C @@ -148,7 +148,7 @@ Graph::Graph(ClientData clientData, Tcl_Interp* interp, Graph::~Graph() { - GraphOptions* ops = (GraphOptions*)ops_; + // GraphOptions* ops = (GraphOptions*)ops_; destroyMarkers(); destroyElements(); // must come before legend and others @@ -166,7 +166,6 @@ Graph::~Graph() if (drawGC_) Tk_FreeGC(display_, drawGC_); - Blt_Ts_FreeStyle(display_, &ops->titleTextStyle); if (cache_ != None) Tk_FreePixmap(display_, cache_); @@ -192,8 +191,9 @@ void Graph::configure() titleWidth_ =0; titleHeight_ =0; if (ops->title != NULL) { - unsigned int w, h; - Blt_Ts_GetExtents(&ops->titleTextStyle, ops->title, &w, &h); + int w, h; + TextStyle ts(this, &ops->titleTextStyle); + ts.getExtents(ops->title, &w, &h); titleHeight_ = h; } @@ -581,9 +581,10 @@ void Graph::drawMargins(Drawable drawable) x, y, w, h, ops->plotBW, ops->plotRelief); } - if (ops->title) - Blt_DrawText(tkwin_, drawable, ops->title, - &ops->titleTextStyle, titleX_, titleY_); + if (ops->title) { + TextStyle ts(this, &ops->titleTextStyle); + ts.drawText(drawable, ops->title, titleX_, titleY_); + } flags &= ~DRAW_MARGINS; } @@ -626,8 +627,8 @@ void Graph::printMargins(Blt_Ps ps) if (ops->title) { Blt_Ps_Append(ps, "% Graph title\n"); - Blt_Ps_DrawText(ps, ops->title, &ops->titleTextStyle, - (double)titleX_, (double)titleY_); + TextStyle ts(this, &ops->titleTextStyle); + ts.printText(ps, ops->title, (double)titleX_, (double)titleY_); } } @@ -1309,14 +1310,13 @@ Axis* Graph::nearestAxis(int x, int y) } if (ops->title) { - unsigned int w, h; + int w, h; double rw, rh; Point2d bbox[5]; - Blt_GetTextExtents(ops->titleFont, 0, ops->title,-1,&w,&h); + Blt_GetTextExtents(ops->titleFont, ops->title, -1, &w, &h); Blt_GetBoundingBox(w, h, axisPtr->titleAngle_, &rw, &rh, bbox); - Point2d t; - t = Blt_AnchorPoint(axisPtr->titlePos_.x, axisPtr->titlePos_.y, - rw, rh, axisPtr->titleAnchor_); + Point2d t = Blt_AnchorPoint(axisPtr->titlePos_.x, axisPtr->titlePos_.y, + rw, rh, axisPtr->titleAnchor_); // Translate the point so that the 0,0 is the upper left // corner of the bounding box t.x = x - t.x - (rw * 0.5); diff --git a/src/bltGraph.h b/src/bltGraph.h index e1bb1d6..7eb7acf 100644 --- a/src/bltGraph.h +++ b/src/bltGraph.h @@ -106,7 +106,7 @@ typedef struct { int backingStore; int doubleBuffer; Tk_Cursor cursor; - TextStyle titleTextStyle; + TextStyleOptions titleTextStyle; int reqHeight; XColor* highlightBgColor; XColor* highlightColor; diff --git a/src/bltGraphBar.C b/src/bltGraphBar.C index 5552613..849eb0f 100644 --- a/src/bltGraphBar.C +++ b/src/bltGraphBar.C @@ -218,17 +218,15 @@ BarGraph::BarGraph(ClientData clientData, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) : Graph(clientData, interp, objc, objv) { - Tk_SetClass(tkwin_, "Barchart"); - classId_ = CID_ELEM_BAR; - - optionTable_ = Tk_CreateOptionTable(interp_, optionSpecs); ops_ = (BarGraphOptions*)calloc(1, sizeof(BarGraphOptions)); BarGraphOptions* ops = (BarGraphOptions*)ops_; + Tk_SetClass(tkwin_, "Barchart"); + classId_ = CID_ELEM_BAR; + barGroups_ =NULL; nBarGroups_ =0; maxBarSetSize_ =0; - Tcl_InitHashTable(&setTable_, sizeof(BarSetKey) / sizeof(int)); ops->bottomMargin.site = MARGIN_BOTTOM; @@ -236,15 +234,19 @@ BarGraph::BarGraph(ClientData clientData, Tcl_Interp* interp, ops->topMargin.site = MARGIN_TOP; ops->rightMargin.site = MARGIN_RIGHT; - Blt_Ts_InitStyle(ops->titleTextStyle); ops->titleTextStyle.anchor = TK_ANCHOR_N; + ops->titleTextStyle.color =NULL; + ops->titleTextStyle.font =NULL; + ops->titleTextStyle.angle =0; + ops->titleTextStyle.justify =TK_JUSTIFY_LEFT; - if (createPen("active", 0, NULL) != TCL_OK) { + optionTable_ = Tk_CreateOptionTable(interp_, optionSpecs); + if ((Tk_InitOptions(interp_, (char*)ops_, optionTable_, tkwin_) != TCL_OK) || (GraphObjConfigure(this, interp_, objc-2, objv+2) != TCL_OK)) { valid_ =0; return; } - if ((Tk_InitOptions(interp_, (char*)ops_, optionTable_, tkwin_) != TCL_OK) || (GraphObjConfigure(this, interp_, objc-2, objv+2) != TCL_OK)) { + if (createPen("active", 0, NULL) != TCL_OK) { valid_ =0; return; } diff --git a/src/bltGraphBar.h b/src/bltGraphBar.h index 5fade66..a096b57 100644 --- a/src/bltGraphBar.h +++ b/src/bltGraphBar.h @@ -42,7 +42,7 @@ typedef struct { int backingStore; int doubleBuffer; Tk_Cursor cursor; - TextStyle titleTextStyle; + TextStyleOptions titleTextStyle; int reqHeight; XColor* highlightBgColor; XColor* highlightColor; diff --git a/src/bltGraphLine.C b/src/bltGraphLine.C index 23976a4..6403531 100644 --- a/src/bltGraphLine.C +++ b/src/bltGraphLine.C @@ -178,30 +178,34 @@ LineGraph::LineGraph(ClientData clientData, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) : Graph(clientData, interp, objc, objv) { - optionTable_ = Tk_CreateOptionTable(interp_, optionSpecs); ops_ = (LineGraphOptions*)calloc(1, sizeof(LineGraphOptions)); LineGraphOptions* ops = (LineGraphOptions*)ops_; Tk_SetClass(tkwin_, "Graph"); classId_ = CID_ELEM_LINE; - if (createPen("active", 0, NULL) != TCL_OK) { - valid_ =0; - return; - } ops->bottomMargin.site = MARGIN_BOTTOM; ops->leftMargin.site = MARGIN_LEFT; ops->topMargin.site = MARGIN_TOP; ops->rightMargin.site = MARGIN_RIGHT; - Blt_Ts_InitStyle(ops->titleTextStyle); ops->titleTextStyle.anchor = TK_ANCHOR_N; + ops->titleTextStyle.color =NULL; + ops->titleTextStyle.font =NULL; + ops->titleTextStyle.angle =0; + ops->titleTextStyle.justify =TK_JUSTIFY_LEFT; + optionTable_ = Tk_CreateOptionTable(interp_, optionSpecs); if ((Tk_InitOptions(interp_, (char*)ops_, optionTable_, tkwin_) != TCL_OK) || (GraphObjConfigure(this, interp_, objc-2, objv+2) != TCL_OK)) { valid_ =0; return; } + if (createPen("active", 0, NULL) != TCL_OK) { + valid_ =0; + return; + } + adjustAxes(); Tcl_SetStringObj(Tcl_GetObjResult(interp_), Tk_PathName(tkwin_), -1); diff --git a/src/bltGraphLine.h b/src/bltGraphLine.h index 6e4580f..ffd50dd 100644 --- a/src/bltGraphLine.h +++ b/src/bltGraphLine.h @@ -42,7 +42,7 @@ typedef struct { int backingStore; int doubleBuffer; Tk_Cursor cursor; - TextStyle titleTextStyle; + TextStyleOptions titleTextStyle; int reqHeight; XColor* highlightBgColor; XColor* highlightColor; diff --git a/src/bltGraphSup.C b/src/bltGraphSup.C index 644e09f..462e2da 100644 --- a/src/bltGraphSup.C +++ b/src/bltGraphSup.C @@ -520,17 +520,17 @@ void Graph::getAxisGeometry(Axis *axisPtr) TickLabel* labelPtr = axisPtr->makeLabel(x); Blt_Chain_Append(axisPtr->tickLabels_, labelPtr); nLabels++; - /* - * Get the dimensions of each tick label. Remember tick labels - * can be multi-lined and/or rotated. - */ - unsigned int lw, lh; /* Label width and height. */ - Blt_GetTextExtents(aops->tickFont, 0, labelPtr->string, -1, &lw, &lh); + + // Get the dimensions of each tick label. Remember tick labels + // can be multi-lined and/or rotated. + int lw, lh; + Blt_GetTextExtents(aops->tickFont, labelPtr->string, -1, &lw, &lh); labelPtr->width = lw; labelPtr->height = lh; if (aops->tickAngle != 0.0f) { - double rlw, rlh; /* Rotated label width and height. */ + // Rotated label width and height + double rlw, rlh; Blt_GetBoundingBox(lw, lh, aops->tickAngle, &rlw, &rlh, NULL); lw = ROUND(rlw), lh = ROUND(rlh); } |