Creating Graphical Objects

Introduction
Creating an Graphical Object
Interactive Object Creation
Using Splines

There are five different methods to define the coordinates for a graphical object in Jeszra.

Creating Coordinates

Inside a Palette Items

All vector graphics palette items accept predefined coordinates as part of their »properties«. The coordinates have to precede the object properties.


Predefined coordinates and item properties are modifiable within the »Insert Dialog«, before a new object is instantiated.

Edit from within the Inspector

The coordinates of a graphical object are edit able in the Inspector’s »Geometry« section. Usually, it´s not possible to extend or remove coordinates from this list.

Interactive

The graphical palettes contain items with interactive coordinates. These items feature an ellipsis (...), to indicate that they track direct coordinates. Light blue rectangles are used to indicate the coordinates of Salomon’s Star in Figure 6.5, “Indicated Coordinates”.

Figure 6.5. Indicated Coordinates


A new graphical object is created, when disseclecting the palette item. Either by turning it off or by selecting another item inside the same palette.

Auto Splines

Requires the tclspline 1.0 package.

Tk canvas has built-in Splines support for line and polygon objects. Splines are controlled by the »-smooth« and »-splinesteps« properties.

The same functionality can be used, within Jeszra, for TkZinc 3.3.4 »curve« and TkPath »path« objects, too. The »Smooth Paths and Curves« checkbutton in the »General« preferences page activates the spline conversion. After which all interactively defined coordinates are converted into Splines using cubic bézier segments.

Direct Manipulation

The coordinates of Tk canvas objects are displayed inside the graphical view.

Coordinates are direct modifiable inside the graphical view. Use Drag'n'Drop operations on coordinate indicators, to modify the coordinate Coordinate indicators are represented as small light blue or red rectangles. A context menu exists for each coordinate of a TkPath path object. This context menu allow to mix smoothed and straigh lines during creation. Previous coordinates are deletable and micro adjustments are also possible by using the keyboard cursor keys.

The coordinate context menu for an existing path object contains another important functionality: »Simplify«. »Simplify« reduces the complexity of the selected spline segment, in a path coordinate list, by half. Generally speaking a smoothed path object may have unnecessary many coordinates. Use »Simplify« multiple times in order to reduce the complexity further. These type of direct manipulation isn't supported for TkZinc 3.3.4 curve objects. Path coordinates may have one kind out of many: such as points, cubic and quadratic bézier curves, absolute and relative movements and more. For TkZinc 3.3.4 curve a smaller subset exist: cubic bézier curves and points.

The Inspector allows to change and create new points of any kind for a TkPath path object. Assume that the following sequence is shown inside the Inspector »Geometry« section:


Then replace the »L« with the two control points of a cubic Bézier curve –the following point definition »125.0, 58.0« gets recycled as the target point of the segment.

Refresh the Geometry section manually, after changing a path coordinate.

There is a problem with coordinate changes in TkPath. Jeszra moves the path object by 0 pixels to mitigate this problem.

You may also create or delete coordinates from a path object inside the Inspector.

Graphical objects are treated like windows in Jeszra. The conventional way to insert a graphical object into a graphical view is by clicking on the palette item representing it.

This requires that the palette item contains predefined coordinates; as seen in Example 6.1, “Predefined Coordinates”. Then move or alter the coordinates of the newly created graphical object as you see fit.

Figure 6.6. Salomon’s Star


Figure 6.6, “Salomon’s Star” is a polygon from the Tk canvas palette, described inside the section called “Tk Canvas”. »Salomon’s Star« is hidden inside the palette. To make the item visible: use the »Toolbar Editor« on the palette and drag the »Salomon´s Star« into the top area. You reach the »Toolbar Editor« through the »Customize Toolbar« command from the context menu.

The light blue rectangles represent the coordinates of the Star. The coordinates are editable inside the Inspector or directly in the graphical view.

Figure 6.7. Inspector Coordinates


Figure 6.7, “Inspector Coordinates” lists the coordinates of Figure 6.6, “Salomon’s Star” in the Inspector »Geometry« section. These coordinates can be changed right away.

Line and polygon items have a »-smooth« property. Smooth activates splines with cubic Bézier segments for the object. Figure 6.8, “Smooth Star” displays the star from Figure 6.6, “Salomon’s Star” with »-smooth« turned on.

Figure 6.8. Smooth Star


The coordinates of each Tk canvas and TkPath object are direct modifiable. Figure 6.9, “Direct Modified Coordinates” displays the star from Figure 6.6, “Salomon’s Star”, after the last coordinate was dragged to the crossing help lines.

Figure 6.9. Direct Modified Coordinates


The shape of the star changes during dragging a coordinate. The same direct manipulation rule applies for every other canvas and TkPath object.

Figure 6.10. A Path... Object


Figure 6.10, “A Path... Object” shows a path object during defining the coordinates of the star. The red rectangles are the coordinates of the soon to be created star. New coordinates snap to help lines, but not to other graphical objects. Snap to object is not yet possible for TkZinc 3.3.4, too.

Snap to object is planned for future Jeszra releases. TkPath 0.3 or higher will be required to implement this functionality.

The »path« object supports various coordinate types. Each coordinate is preceded by a single alphabetical character identifying the kind of the following coordinate(s).

Table 6.2, “Path Coordinates” –an excerpt from the TkPath documentation– displays all types and their syntax.



Jeszra may auto-generate splines from a simple path coordinate list using »M«, »L« and »Z« coordinates. The »L« coordinates are then altogether replaced with »C« coordinates. This differs to plain canvas lines and polygons. In a Tk canvas »-smooth« does not change the coordinates of line and polygon objects.

Figure 6.11. Path with Splines


The »Z« coordinate influences how Jeszra will generate splines. »Z« tells that the path is a closed object and thus an additional Bézier curve is calculated by Jeszra to connect the last (just before Z) with the first (M) point.

Figure 6.12. Open Curve with Splines


Figure 6.12, “Open Curve with Splines” displays a open curve, in this case from a TkZinc 3.3.4 curve. The path curve will be identical to this TkZinc 3.3.4 curve when there is no closing »Z« at the end of the coordinates.

The same splines rules apply for TkZinc 3.3.4 curves as outlined for TkPath. TkZinc 3.3.4 curve do not support as much coordinate types as path; and closing a curve is accomplished by setting the »-closed« property. The »-closed« property has to be set to »1«, while the new curve is created. Otherwise an open curve is assumed and no Bézier segment added between the last point and the first! This is shown in Figure 6.12, “Open Curve with Splines”.


Jeszra uses the full defined cubic Bézier definition when auto generating splines for the curve object; better avoid the deprecated variant.