summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bltGrMarkerBitmap.C6
-rwxr-xr-xconfigure2
-rwxr-xr-xconfigure.in2
-rw-r--r--src/bltGrAxis.h2
-rw-r--r--src/bltGrLegd.h2
-rw-r--r--src/bltGrMarkerText.C6
-rw-r--r--src/bltGrPSOutput.C10
-rw-r--r--src/bltGrPSOutput.h1
-rw-r--r--src/bltGrPen.h2
-rw-r--r--src/bltGrText.C2
-rw-r--r--src/bltGrText.h6
-rw-r--r--src/bltGraph.C14
-rw-r--r--src/bltGraph.h2
-rw-r--r--src/bltGraphSup.C190
14 files changed, 213 insertions, 34 deletions
diff --git a/bltGrMarkerBitmap.C b/bltGrMarkerBitmap.C
index 1794394..60e2db2 100644
--- a/bltGrMarkerBitmap.C
+++ b/bltGrMarkerBitmap.C
@@ -186,8 +186,8 @@ void BitmapMarker::map()
Tk_SizeOfBitmap(graphPtr_->display_, ops->bitmap, &lwidth, &lheight);
Point2d lanchorPt = mapPoint(ops->worldPts->points, ops->xAxis, ops->yAxis);
- lanchorPt =
- Blt_AnchorPoint(lanchorPt.x, lanchorPt.y, lwidth, lheight, ops->anchor);
+ lanchorPt = graphPtr_->anchorPoint(lanchorPt.x, lanchorPt.y,
+ lwidth, lheight, ops->anchor);
lanchorPt.x += ops->xOffset;
lanchorPt.y += ops->yOffset;
@@ -209,7 +209,7 @@ void BitmapMarker::map()
// This is needed for print a background in PostScript.
double rotWidth, rotHeight;
Point2d polygon[5];
- Blt_GetBoundingBox(width_, height_, 0, &rotWidth, &rotHeight, polygon);
+ graphPtr_->getBoundingBox(width_, height_, 0, &rotWidth, &rotHeight, polygon);
// Adjust each point of the polygon. Both scale it to the new size and
// translate it to the actual screen position of the bitmap.
diff --git a/configure b/configure
index 8730123..66b3bed 100755
--- a/configure
+++ b/configure
@@ -5557,6 +5557,7 @@ done
bltGrPen.C
bltGrPenBar.C
bltGrPenLine.C
+ bltGrText.C
bltGraph.C
bltGraphBar.C
bltGraphLine.C
@@ -5570,7 +5571,6 @@ done
bltOp.C
bltSpline.C
bltSwitch.C
- bltText.C
bltUtil.c
bltVecCmd.c
bltVecMath.c
diff --git a/configure.in b/configure.in
index 308ebcd..a9f91c4 100755
--- a/configure.in
+++ b/configure.in
@@ -102,6 +102,7 @@ TEA_ADD_SOURCES([
bltGrPen.C
bltGrPenBar.C
bltGrPenLine.C
+ bltGrText.C
bltGraph.C
bltGraphBar.C
bltGraphLine.C
@@ -115,7 +116,6 @@ TEA_ADD_SOURCES([
bltOp.C
bltSpline.C
bltSwitch.C
- bltText.C
bltUtil.c
bltVecCmd.c
bltVecMath.c
diff --git a/src/bltGrAxis.h b/src/bltGrAxis.h
index f16ec09..5022a17 100644
--- a/src/bltGrAxis.h
+++ b/src/bltGrAxis.h
@@ -44,7 +44,7 @@ class Graph;
class PageSetup;
#include "bltGrMisc.h"
-#include "bltText.h"
+#include "bltGrText.h"
#include "bltPs.h"
typedef struct {
diff --git a/src/bltGrLegd.h b/src/bltGrLegd.h
index 10a153d..d47f03e 100644
--- a/src/bltGrLegd.h
+++ b/src/bltGrLegd.h
@@ -36,7 +36,7 @@
#include <tk.h>
#include "bltGrMisc.h"
-#include "bltText.h"
+#include "bltGrText.h"
class Graph;
class Element;
diff --git a/src/bltGrMarkerText.C b/src/bltGrMarkerText.C
index b898c2d..be25682 100644
--- a/src/bltGrMarkerText.C
+++ b/src/bltGrMarkerText.C
@@ -177,7 +177,7 @@ void TextMarker::map()
double rw;
double rh;
- Blt_GetBoundingBox(w, h, ops->style.angle, &rw, &rh, outline_);
+ graphPtr_->getBoundingBox(w, h, ops->style.angle, &rw, &rh, outline_);
width_ = rw;
height_ = rh;
for (int ii=0; ii<4; ii++) {
@@ -188,8 +188,8 @@ void TextMarker::map()
outline_[4].y = outline_[0].y;
Point2d anchorPtr = mapPoint(ops->worldPts->points, ops->xAxis, ops->yAxis);
- anchorPtr = Blt_AnchorPoint(anchorPtr.x, anchorPtr.y, width_,
- height_, ops->anchor);
+ anchorPtr = graphPtr_->anchorPoint(anchorPtr.x, anchorPtr.y,
+ width_, height_, ops->anchor);
anchorPtr.x += ops->xOffset;
anchorPtr.y += ops->yOffset;
diff --git a/src/bltGrPSOutput.C b/src/bltGrPSOutput.C
index 321a8fc..26abe39 100644
--- a/src/bltGrPSOutput.C
+++ b/src/bltGrPSOutput.C
@@ -708,12 +708,10 @@ void Blt_Ps_DrawText(Blt_Ps ps, const char *string, double x, double y)
double rw, rh;
angle = fmod(tsPtr->angle, (double)360.0);
- Blt_GetBoundingBox(textPtr->width, textPtr->height, angle, &rw, &rh,
- (Point2d *)NULL);
- /*
- * Find the center of the bounding box
- */
- t = Blt_AnchorPoint(x, y, rw, rh, tsPtr->anchor);
+ graphPtr_->getBoundingBox(textPtr->width, textPtr->height, angle, &rw, &rh,
+ NULL);
+
+ t = graphPtr_->anchorPoint(x, y, rw, rh, tsPtr->anchor);
t.x += rw * 0.5;
t.y += rh * 0.5;
}
diff --git a/src/bltGrPSOutput.h b/src/bltGrPSOutput.h
index 307b2d8..da12229 100644
--- a/src/bltGrPSOutput.h
+++ b/src/bltGrPSOutput.h
@@ -33,7 +33,6 @@
#include <tk.h>
#include "bltConfig.h"
-//#include "bltGrText.h"
#define POSTSCRIPT_BUFSIZ ((BUFSIZ*2)-1)
struct _Blt_Ps {
diff --git a/src/bltGrPen.h b/src/bltGrPen.h
index ecc02e7..525cdb9 100644
--- a/src/bltGrPen.h
+++ b/src/bltGrPen.h
@@ -32,7 +32,7 @@
#include <tk.h>
-#include "bltText.h"
+#include "bltGrText.h"
class Graph;
diff --git a/src/bltGrText.C b/src/bltGrText.C
index b540e04..bf299a3 100644
--- a/src/bltGrText.C
+++ b/src/bltGrText.C
@@ -35,7 +35,7 @@ extern "C" {
#include <tkInt.h>
};
-#include "bltText.h"
+#include "bltGrText.h"
#include "bltGraph.h"
#include "bltPs.h"
diff --git a/src/bltGrText.h b/src/bltGrText.h
index 7a8247c..60d1009 100644
--- a/src/bltGrText.h
+++ b/src/bltGrText.h
@@ -72,10 +72,4 @@ class TextStyle {
void getExtents(const char*, int*, int*);
};
-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);
-
#endif
diff --git a/src/bltGraph.C b/src/bltGraph.C
index bdaad2c..210870e 100644
--- a/src/bltGraph.C
+++ b/src/bltGraph.C
@@ -1293,11 +1293,11 @@ Axis* Graph::nearestAxis(int x, int y)
TickLabel *labelPtr = (TickLabel*)Blt_Chain_GetValue(link);
double rw, rh;
Point2d bbox[5];
- Blt_GetBoundingBox(labelPtr->width, labelPtr->height,
- ops->tickAngle, &rw, &rh, bbox);
+ getBoundingBox(labelPtr->width, labelPtr->height, ops->tickAngle,
+ &rw, &rh, bbox);
Point2d t;
- t = Blt_AnchorPoint(labelPtr->anchorPos.x, labelPtr->anchorPos.y,
- rw, rh, axisPtr->tickAnchor_);
+ t = anchorPoint(labelPtr->anchorPos.x, labelPtr->anchorPos.y,
+ rw, rh, axisPtr->tickAnchor_);
t.x = x - t.x - (rw * 0.5);
t.y = y - t.y - (rh * 0.5);
@@ -1314,9 +1314,9 @@ Axis* Graph::nearestAxis(int x, int y)
double rw, rh;
Point2d bbox[5];
getTextExtents(ops->titleFont, ops->title, -1, &w, &h);
- Blt_GetBoundingBox(w, h, axisPtr->titleAngle_, &rw, &rh, bbox);
- Point2d t = Blt_AnchorPoint(axisPtr->titlePos_.x, axisPtr->titlePos_.y,
- rw, rh, axisPtr->titleAnchor_);
+ getBoundingBox(w, h, axisPtr->titleAngle_, &rw, &rh, bbox);
+ Point2d t = 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 ee62432..dd44e7e 100644
--- a/src/bltGraph.h
+++ b/src/bltGraph.h
@@ -38,7 +38,7 @@ extern "C" {
};
#include "bltGrMisc.h"
-#include "bltText.h"
+#include "bltGrText.h"
typedef struct _Blt_Ps *Blt_Ps;
diff --git a/src/bltGraphSup.C b/src/bltGraphSup.C
index 962ab57..3ac2b6c 100644
--- a/src/bltGraphSup.C
+++ b/src/bltGraphSup.C
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
+#include <math.h>
#include "bltGraph.h"
#include "bltGrAxis.h"
@@ -40,6 +41,10 @@ using namespace Blt;
#define ROUND(x) ((int)((x) + (((x)<0.0) ? -0.5 : 0.5)))
#define AXIS_PAD_TITLE 2
+#define ROTATE_0 0
+#define ROTATE_90 1
+#define ROTATE_180 2
+#define ROTATE_270 3
/*
*---------------------------------------------------------------------------
@@ -532,7 +537,7 @@ void Graph::getAxisGeometry(Axis *axisPtr)
if (aops->tickAngle != 0.0f) {
// Rotated label width and height
double rlw, rlh;
- Blt_GetBoundingBox(lw, lh, aops->tickAngle, &rlw, &rlh, NULL);
+ getBoundingBox(lw, lh, aops->tickAngle, &rlw, &rlh, NULL);
lw = ROUND(rlw), lh = ROUND(rlh);
}
if (axisPtr->maxTickWidth_ < int(lw))
@@ -627,3 +632,186 @@ void Graph::getTextExtents(Tk_Font font, const char *text, int textLen,
*hh = maxHeight;
}
+/*
+ *---------------------------------------------------------------------------
+ *
+ * Computes the dimensions of the bounding box surrounding a rectangle
+ * rotated about its center. If pointArr isn't NULL, the coordinates of
+ * the rotated rectangle are also returned.
+ *
+ * The dimensions are determined by rotating the rectangle, and doubling
+ * the maximum x-coordinate and y-coordinate.
+ *
+ * w = 2 * maxX, h = 2 * maxY
+ *
+ * Since the rectangle is centered at 0,0, the coordinates of the
+ * bounding box are (-w/2,-h/2 w/2,-h/2, w/2,h/2 -w/2,h/2).
+ *
+ * 0 ------- 1
+ * | |
+ * | x |
+ * | |
+ * 3 ------- 2
+ *
+ * Results:
+ * The width and height of the bounding box containing the rotated
+ * rectangle are returned.
+ *
+ *---------------------------------------------------------------------------
+ */
+void Graph::getBoundingBox(int width, int height, float angle,
+ double *rotWidthPtr, double *rotHeightPtr,
+ Point2d *bbox)
+{
+ int i;
+ double sinTheta, cosTheta;
+ double radians;
+ double xMax, yMax;
+ double x, y;
+ Point2d corner[4];
+
+ angle = fmod(angle, 360.0);
+ if (fmod(angle, (double)90.0) == 0.0) {
+ int ll, ur, ul, lr;
+ double rotWidth, rotHeight;
+
+ /* Handle right-angle rotations specially. */
+
+ int quadrant = (int)(angle / 90.0);
+ switch (quadrant) {
+ case ROTATE_270: /* 270 degrees */
+ ul = 3, ur = 0, lr = 1, ll = 2;
+ rotWidth = (double)height;
+ rotHeight = (double)width;
+ break;
+ case ROTATE_90: /* 90 degrees */
+ ul = 1, ur = 2, lr = 3, ll = 0;
+ rotWidth = (double)height;
+ rotHeight = (double)width;
+ break;
+ case ROTATE_180: /* 180 degrees */
+ ul = 2, ur = 3, lr = 0, ll = 1;
+ rotWidth = (double)width;
+ rotHeight = (double)height;
+ break;
+ default:
+ case ROTATE_0: /* 0 degrees */
+ ul = 0, ur = 1, lr = 2, ll = 3;
+ rotWidth = (double)width;
+ rotHeight = (double)height;
+ break;
+ }
+ if (bbox) {
+ x = rotWidth * 0.5;
+ y = rotHeight * 0.5;
+ bbox[ll].x = bbox[ul].x = -x;
+ bbox[ur].y = bbox[ul].y = -y;
+ bbox[lr].x = bbox[ur].x = x;
+ bbox[ll].y = bbox[lr].y = y;
+ }
+ *rotWidthPtr = rotWidth;
+ *rotHeightPtr = rotHeight;
+ return;
+ }
+ /* Set the four corners of the rectangle whose center is the origin. */
+ corner[1].x = corner[2].x = (double)width * 0.5;
+ corner[0].x = corner[3].x = -corner[1].x;
+ corner[2].y = corner[3].y = (double)height * 0.5;
+ corner[0].y = corner[1].y = -corner[2].y;
+
+ radians = (-angle / 180.0) * M_PI;
+ sinTheta = sin(radians), cosTheta = cos(radians);
+ xMax = yMax = 0.0;
+
+ /* Rotate the four corners and find the maximum X and Y coordinates */
+
+ for (i = 0; i < 4; i++) {
+ x = (corner[i].x * cosTheta) - (corner[i].y * sinTheta);
+ y = (corner[i].x * sinTheta) + (corner[i].y * cosTheta);
+ if (x > xMax)
+ xMax = x;
+
+ if (y > yMax)
+ yMax = y;
+
+ if (bbox) {
+ bbox[i].x = x;
+ bbox[i].y = y;
+ }
+ }
+
+ /*
+ * By symmetry, the width and height of the bounding box are twice the
+ * maximum x and y coordinates.
+ */
+ *rotWidthPtr = xMax + xMax;
+ *rotHeightPtr = yMax + yMax;
+}
+
+/*
+ *---------------------------------------------------------------------------
+ *
+ * Blt_AnchorPoint --
+ *
+ * Translates a position, using both the dimensions of the bounding box,
+ * and the anchor direction, returning the coordinates of the upper-left
+ * corner of the box. The anchor indicates where the given x-y position
+ * is in relation to the bounding box.
+ *
+ * 7 nw --- 0 n --- 1 ne
+ * | |
+ * 6 w 8 center 2 e
+ * | |
+ * 5 sw --- 4 s --- 3 se
+ *
+ * The coordinates returned are translated to the origin of the bounding
+ * box (suitable for giving to XCopyArea, XCopyPlane, etc.)
+ *
+ * Results:
+ * The translated coordinates of the bounding box are returned.
+ *
+ *---------------------------------------------------------------------------
+ */
+Point2d Graph::anchorPoint(double x, double y, double w, double h,
+ Tk_Anchor anchor)
+{
+ Point2d t;
+
+ switch (anchor) {
+ case TK_ANCHOR_NW: /* 7 Upper left corner */
+ break;
+ case TK_ANCHOR_W: /* 6 Left center */
+ y -= (h * 0.5);
+ break;
+ case TK_ANCHOR_SW: /* 5 Lower left corner */
+ y -= h;
+ break;
+ case TK_ANCHOR_N: /* 0 Top center */
+ x -= (w * 0.5);
+ break;
+ case TK_ANCHOR_CENTER: /* 8 Center */
+ x -= (w * 0.5);
+ y -= (h * 0.5);
+ break;
+ case TK_ANCHOR_S: /* 4 Bottom center */
+ x -= (w * 0.5);
+ y -= h;
+ break;
+ case TK_ANCHOR_NE: /* 1 Upper right corner */
+ x -= w;
+ break;
+ case TK_ANCHOR_E: /* 2 Right center */
+ x -= w;
+ y -= (h * 0.5);
+ break;
+ case TK_ANCHOR_SE: /* 3 Lower right corner */
+ x -= w;
+ y -= h;
+ break;
+ }
+
+ t.x = x;
+ t.y = y;
+ return t;
+}
+