News:
1. All changes in C XCircuit up to 3.7.12 are ported.
2. There is a proper drawing context that is explicitly passed everywhere
drawing is to be done; areawin->gc is gone. The context only has a QPainter*
and the matrix stack, but that's a start.
3. The Matrix derives from QTransform and only adds convenience functions and
the next pointer to implement intrusive stack. NB: a data structure is
intrusive when
the housekeeping data is added directly to the managed data.
We're at a stage where cool things can get done.
Below is current spline drawing code, for reference, and with extra
comments.
void spline::draw(Context* ctx) const
{
// spline polyline approximation, transformed to the viewport
XPoint tmppoints[SPLINESEGS];
// transform the approximation
makesplinepath(ctx, this, tmppoints);
// draw the approximation
strokepath(ctx, tmppoints, SPLINESEGS, style, width);
// draw editing handles
if (cycle != NULL) {
UDrawXLine(ctx, ctrl[0], ctrl[1]);
UDrawXLine(ctx, ctrl[3], ctrl[2]);
}
}
And here is the trivial porting to bare Qt: no more calling of makesplinepath
nor strokepath, and we don't depend on existing spline point cache either:
void spline::draw(Context* ctx) const
{
QPainterPath path;
ctx->gc()->setTransform(*ctx->DCTM());
// toF() converts integer XPoint to floating point QPointF
path.moveTo(ctrl[0].toF());
path.cubicTo(ctrl[1].toF(), ctrl[2].toF(), ctrl[3].toF());
ctx->gc()->strokePath(path, ctx->gc()->pen());
ctx->gc()->resetTransform();
if (cycle != NULL) {
// this spline is being edited
UDrawXLine(ctx, ctrl[0], ctrl[1]);
UDrawXLine(ctx, ctrl[3], ctrl[2]);
}
}
Note that we get rid of all spline approximation code, the strokepath,
transformation of path points, etc. -- that's plenty of code right there that
goes poof.
Of course there is a catch: we still need to be able to tell how close
a point is to a spline, as that is used for pointer hit detection and whatnot.
I will have to investigate the best way of doing that. A nice hybrid method
is presented in this paper:
<ftp://ftp.divms.uiowa.edu/pub/atkinson/CurvesAndSufacesClosestPoint.pdf>
Robust and Efficient Computation of the Closest Point on a Spline Curve,
by Wang, Kearney and Atkinson.
So now I have a new list of tasks, in no particular order:
1. Keep moving display state from areawin to context until UDrawObject can
be culled into objinst::draw()
2. Look at how we handle nearest object test, and how it may be integrated
into the QGraphicsItem framework.
3. Have each element derive for QGraphicsItem at a basic level: drawing and
transformation to be handled by QGraphicsItem methods, rest would stay for now.
Cheers, Kuba
_______________________________________________
Xcircuit-dev mailing list
[email protected]
http://www.opencircuitdesign.com/mailman/listinfo/xcircuit-dev