Qt paths have a few quirks which are good to know about if you're working with them at a lower level.
At creation time, paths have
elementCount() == 0,
but after a line is created,
elementCount() == 2. The first element
moveTo to the origin; second is the
lineTo you asked for.
brown paths maintain this behavior.
TODO: This is out of date and may not be true.
lineTo(0, 0), a
moveTo(0, 0) is performed instead:
>>> from brown.core import brown; brown.setup() >>> line_to_origin = PathInterface((5, 6)) >>> line_to_origin.line_to((0, 0)) >>> assert(line_to_origin._qt_path == line_to_origin.qt_object.path()) >>> assert(line_to_origin._qt_path.elementCount() == 1) >>> assert(line_to_origin._qt_path.elementAt(0).isMoveTo() == True) >>> line_to_elsewhere = PathInterface((5, 6)) >>> line_to_elsewhere.line_to((1, 0)) >>> assert(line_to_elsewhere._qt_path == line_to_elsewhere.qt_object.path()) >>> assert(line_to_elsewhere._qt_path.elementCount() == 2) >>> assert(line_to_elsewhere._qt_path.elementAt(0).isMoveTo() == True) >>> assert(line_to_elsewhere._qt_path.elementAt(1).isLineTo() == True)
QPainterPath::ElementTypeis ambiguous in differentiating between curve control points and curve end points. They are stored sequentially in the path element list; the first element in the sequence is a
CurveToElement(enum 2), all following elements in the curve are
CurveToDataElement(enum 3). Despite this, all elements until the last in the sequence are control points; the final element is the curve end point.
For instance, if a cubic line is drawn with two control points -
cubic_to((0, 5), (10, 5), (10, 0)) - they are stored in the Qt
element list as
[CurveToElement, CurveToDataElement, CurveToDataElement],
which the brown API translates to:
[control_point, control_point, curve_to]
Interface for a generic graphic path object.
(brown_object, pos, pen, brush,
(Path): The path this interface belongs to
(PenInterface): The pen to draw outlines with.
(BrushInterface): The brush to draw outlines with.
(Unit or None): The local starting position for the
path clipping region. Use
None to render from the start.
(Unit or None): The width of the path clipping region.
None to render to the end
This is the location from which operations like line_to() will draw,
relative to the position of the Path (
This property is read-only. To move the current position, use the move_to() method, implicitly closing the current sub-path and beginning a new one.
— The number of elements in the path.
— The absolute x position of the object
— The absolute y position of the object
— The pen to draw outlines with.
Draw a cubic spline from the current position to a new point.
(Point): The local position of the 1st control point
(Point): The local position of the 2nd control point
(Point): The local position of the end point
self.current_draw_pos to the new end point.
Close the current sub-path and start a new one.
Close the current sub-path and start a new one at (0, 0).
This is equivalent to
Find the element at a given index and return it.
(int): The element index. Use -1 for the last index.
Render the line to the scene.
Synchronize the contents of self.qt_path to self.qt_object