aboutsummaryrefslogtreecommitdiff
path: root/generic/Icon.c
diff options
context:
space:
mode:
authorlecoanet2005-05-10 07:59:48 +0000
committerlecoanet2005-05-10 07:59:48 +0000
commit79f65d040d72f778f66f8eefdaffb6acd9799a38 (patch)
treed1e43508242bd9d6ba85e4147e444d12830b8d3a /generic/Icon.c
parent72fd6b4d5f695731d2b6f4c553f7f9bcd0c43476 (diff)
downloadtkzinc-79f65d040d72f778f66f8eefdaffb6acd9799a38.zip
tkzinc-79f65d040d72f778f66f8eefdaffb6acd9799a38.tar.gz
tkzinc-79f65d040d72f778f66f8eefdaffb6acd9799a38.tar.bz2
tkzinc-79f65d040d72f778f66f8eefdaffb6acd9799a38.tar.xz
Merge of the newly developped postscript code (still not fully functional).
Diffstat (limited to 'generic/Icon.c')
-rw-r--r--generic/Icon.c129
1 files changed, 101 insertions, 28 deletions
diff --git a/generic/Icon.c b/generic/Icon.c
index 38c4ac9..5b9eae8 100644
--- a/generic/Icon.c
+++ b/generic/Icon.c
@@ -228,6 +228,57 @@ Query(ZnItem item,
/*
+ * Compute the transformation to be used and the origin
+ * of the icon (upper left point in item coordinates).
+ */
+static ZnTransfo *
+ComputeTransfoAndOrigin(ZnItem item,
+ ZnPoint *origin)
+{
+ IconItem icon = (IconItem) item;
+ int w, h;
+ ZnTransfo *t;
+
+ ZnSizeOfImage(icon->image, &w, &h);
+
+ /*
+ * The connected item support anchors, this is checked by configure.
+ */
+ if (item->connected_item != ZN_NO_ITEM) {
+ ZnTransfo inv;
+
+ item->connected_item->class->GetAnchor(item->connected_item,
+ icon->connection_anchor,
+ origin);
+
+ /* GetAnchor return a position in device coordinates not in
+ * the item coordinate space. To compute the icon origin
+ * (upper left corner), we must apply the inverse transform
+ * to the ref point before calling anchor2origin.
+ */
+ ZnTransfoInvert(item->transfo, &inv);
+ ZnTransformPoint(&inv, origin, origin);
+ /*
+ * The relevant transform in case of an attachment is the item
+ * transform alone. This is case of local coordinate space where
+ * only the translation is a function of the whole transform
+ * stack, scale and rotation are reset.
+ */
+ t = item->transfo;
+ }
+ else {
+ origin->x = origin->y = 0;
+ t = item->wi->current_transfo;
+ }
+
+ ZnAnchor2Origin(origin, (ZnReal) w, (ZnReal) h, icon->anchor, origin);
+ //origin->x = ZnNearestInt(origin->x);
+ //origin->y = ZnNearestInt(origin->y);
+
+ return t;
+}
+
+/*
**********************************************************************************
*
* ComputeCoordinates --
@@ -238,10 +289,11 @@ static void
ComputeCoordinates(ZnItem item,
ZnBool force)
{
- ZnWInfo *wi = item->wi;
- IconItem icon = (IconItem) item;
- int width, height, i;
- ZnPoint pos, quad[4];
+ //ZnWInfo *wi = item->wi;
+ IconItem icon = (IconItem) item;
+ int width, height, i;
+ ZnPoint quad[4];
+ ZnTransfo *t;
ZnResetBBox(&item->item_bounding_box);
@@ -252,34 +304,16 @@ ComputeCoordinates(ZnItem item,
return;
}
- if (icon->image != ZnUnspecifiedImage) {
- ZnSizeOfImage(icon->image, &width, &height);
- }
-
+ ZnSizeOfImage(icon->image, &width, &height);
+ t = ComputeTransfoAndOrigin(item, quad);
- /*
- * The connected item support anchors, this is checked by
- * configure.
- */
- if (item->connected_item != ZN_NO_ITEM) {
- ZnTransfo t;
-
- item->connected_item->class->GetAnchor(item->connected_item,
- icon->connection_anchor, quad);
- ZnTransfoInvert(wi->current_transfo, &t);
- ZnTransformPoint(&t, quad, &pos);
- }
- else {
- pos.x = pos.y = 0;
- }
- ZnAnchor2Origin(&pos, (ZnReal) width, (ZnReal) height, icon->anchor, quad);
quad[1].x = quad[0].x;
quad[1].y = quad[0].y + height;
quad[2].x = quad[0].x + width;
quad[2].y = quad[1].y;
quad[3].x = quad[2].x;
quad[3].y = quad[0].y;
- ZnTransformPoints(wi->current_transfo, quad, icon->dev, 4);
+ ZnTransformPoints(t, quad, icon->dev, 4);
for (i = 0; i < 4; i++) {
icon->dev[i].x = ZnNearestInt(icon->dev[i].x);
@@ -726,10 +760,49 @@ Pick(ZnItem item,
*
**********************************************************************************
*/
-static void
-PostScript(ZnItem item,
- ZnBool prepass)
+static int
+PostScript(ZnItem item,
+ ZnBool prepass,
+ ZnBBox *area)
{
+ ZnWInfo *wi = item->wi;
+ IconItem icon = (IconItem) item;
+ int w, h, result;
+ ZnPoint origin;
+ char path[500];
+
+ if (prepass || (icon->image == ZnUnspecifiedImage)) {
+ return TCL_OK;
+ }
+
+ ZnSizeOfImage(icon->image, &w, &h);
+
+ ComputeTransfoAndOrigin(item, &origin);
+
+ sprintf(path, "/InitialTransform load setmatrix\n"
+ "[%.15g %.15g %.15g %.15g %.15g %.15g] concat\n"
+ "1 -1 scale\n"
+ "%.15g %.15g translate\n",
+ wi->current_transfo->_[0][0], wi->current_transfo->_[0][1],
+ wi->current_transfo->_[1][0], wi->current_transfo->_[1][1],
+ wi->current_transfo->_[2][0], wi->current_transfo->_[2][1],
+ origin.x, origin.y - h);
+ Tcl_AppendResult(wi->interp, path, NULL);
+
+ if (ZnImageIsBitmap(icon->image)) {
+ if (Tk_PostscriptColor(wi->interp, wi->ps_info,
+ ZnGetGradientColor(icon->color, 0.0, NULL)) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ result = ZnPostscriptBitmap(wi->interp, wi->win, wi->ps_info,
+ icon->image, 0, 0, w, h);
+ }
+ else {
+ result = Tk_PostscriptImage(ZnImageTkImage(icon->image), wi->interp, wi->win,
+ wi->ps_info, 0, 0, w, h, prepass);
+ }
+
+ return result;
}