GNU TeXmacsUser manualReferenceAboutEnglish
Graphics interface between C++ and Scheme

Warning 1. Most of this page describes the interface as it was designed in 2005. The routines editor->graphics, graphics->editor, grid-project, grid-point-pertinence<?, graphics-find-disk and graphics-find-rectangle do not exist in the current implementation. The actual interface is summarized in the last section of this page.

Rationale

TeXmacs both implements a low-level part of the graphics in C++ and the high-level user interface in Scheme. This API describes how both parts interact.

The low-level C++ mainly takes care of transforming the graphical markup in a typeset box. It also provides routines for translating between physical coordinates (relative to the window) into logical coordinates (the local coordinate system of the graphics) and routines for interacting with the typeset boxes (finding the closest objects to a given point or region or projecting a point on a grid).

Definitions
Editor coordinates

The coordinates of the outermost typeset box. Mouse events are typically passed in these coordinates. The corresponding data type is SI.

Graphics coordinates

The coordinates of the innermost graphics corresponding to the current cursor position.

Grid

The current grid relative to the graphics for editing objects (this grid may theoretically be different from the grid which is displayed). The current grid consists both of a mathematical type of grid (no grid, cartesian grid, polar grid, etc.), together with special points which correspond either to control points, intersections of curves with the grid, intersections of curves, or self-intersections of curves.

Grid point

A point on the grid is a triple (p distance type), where p is a point in graphics coordinates, distance its distance to the point which was projected on the grid (see grid-project below) and type the type of grid point with a potential origin. For instance, type can be plain or something like (control t) for a control point corresponding to the tree t in the document.

Coordinate transformations
(editor->graphics p)
(get graphics coordinates)

Transform a point p of the form (x y) from the editor coordinates into the graphics coordinates.

(graphics->editor p)
(get editor coordinates)

Transform a point p of the form (x y) from the graphics coordinates into the editor coordinates.

Grid routines
(grid-project p)
(project point on grid)

Given a point p (in graphics coordinates), find its projection on the current grid, the distance part of the projection being the distance between p and its projection.

Note: the routine grid-project can also be used in order to find editable shapes and groups close to the current pointer position. Indeed, the corresponding control points are understood to lie on the grid in our sense.

(grid-point-pertinence<? p q)

(grid-point-pertinence<=? p q)
(order by pertinence)

Grid points are ordered by pertinence as a function of type and distance. For instance, control points have higher pertinence than plain grid points and closer grid points are considered better than farther ones.

Selection of shapes
(graphics-find-disk p r)
(search shapes in disk)

Return the list of all trees in the graphics which intersect a disk with center p and radius r (in graphics coordinates).

(graphics-find-rectangle p q)
(search shapes in rectangle)

Return the list of all trees in the graphics which intersect a rectangle with corners p and q (in graphics coordinates).

Computations with shapes
(box-info t what)
(get bounding box for a shape)

Get a bounding box (and other information) about a shape t. t can be a tree or a scheme tree, and what is a string of letters which specify the requested coordinates, like "lbrt" (left, bottom, right and top of the logical box) or "LBRT" (the same for the ink box). The routine is implemented in

graphics-utils.scm

by typesetting the markup box-info with texmacs-exec*; the analogous routines frame-direct and frame-inverse transform points between the coordinates of the graphics and the coordinates of the typeset document.

Remark 2. This section might be extended, since a lot of the graphical intelligence is implemented in the C++ code. For instance, we might want to compute the intersections of two curves inside the Scheme code. Also, when we will allow for user macros, we might want routines which return the graphical expansion of the macro (the constituent elementary shapes, i.e. polylines, splines, etc.).

The current interface

In the current implementation, the C++ editor (

src/Edit/Interface/edit_graphics.cpp

) handles mouse events inside graphics as follows: it transforms the mouse position into graphics coordinates, projects it on the current grid (taking into account the control points of nearby objects), and then calls one of the Scheme routines graphics-move, graphics-release-left, graphics-start-drag-left, graphics-dragging-left, graphics-end-drag-left, graphics-release-middle, graphics-release-right, graphics-start-drag-right, graphics-dragging-right, graphics-end-drag-right and graphics-drop-object, with the resulting coordinates as strings (the left button routines also receive the time and the pressure of the pen). The mouse wheel calls (graphics-wheel dx dy) instead, with the motion as fractions of the width and the height of the graphics, which moves the origin (see

graphics/graphics-kbd.scm

). The other routines are defined in

progs/graphics/graphics-edit.scm

and dispatch on the current graphical mode. The main glued routines which may be used by these handlers are:

(get-graphical-x)

(get-graphical-y)

(get-graphical-pixel)
(current position)

The coordinates of the last (adjusted) mouse position in graphics coordinates, and the size of a pixel in the same unit.

(graphical-select x y)

(graphical-select-area x1 y1 x2 y2)
(find objects)

Return the list of the objects close to a point resp. inside a rectangle, given in graphics coordinates, as a tree of lists of paths, ordered by pertinence.

(set-graphical-object t)

(get-graphical-object)
(the temporary object)

Set resp. get the markup (typically the object under construction together with its control points) which is displayed on top of the graphics without being part of the document.

(invalidate-graphical-object)
(redraw the temporary object)

Ask for the region of the temporary object to be drawn again, after it was changed. The predicate (in-graphics?) tests whether the cursor is inside a graphics.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".