1.67 class graphical

PCE contains a large number of classes related to creating and manipulating graphical objects. The graphics facilities were designed for interactively manipulating diagrams and graphical representations of information and knowledge. The graphics facilities are not suitable for 2-D or 3-D modeling of real-life objects (such as cars and planes).

The most commonly used subclasses of class graphical are:

class box			Rectangle (filled, rounded)
class ellipse
class line
class path			Multiple segment line (curved)
class bitmap		Image
class text			Short text objects
class device		Compound graphical objects
class dialog_item	Specialised items for dialogue

Example types of diagrams for which PCE has been used are the representation of graphs (hierarchies, lattices, flow-charts), tabular information, iconic representations of computer networks, knowledge bases and various graphical editors.

A graphical describes an image, all of whose affected pixels are within a rectangular area, represented by graphical<-area. The main role of class graphical to facilitate the communication to its graphical<-device. A device object is a collection of graphical objects. Class device is a subclass of class graphical. This allows us to display devices on devices, leading to nested graphicals with local coordinate systems.

Graphics in PCE is more complicated than most of the other facilities, although the maxim “if your needs are simple, it will be simple in PCE as well” still applies. Advanced use of graphics, however, requires a good understanding of the basic concepts and how they are applied.

Mouse and keyboard events are made available to a graphical using the method graphical->event. By default the primitive graphical classes do not respond to this message. There are two ways to make a graphical sensitive to the mouse and/or keyboard. The first is to associate a recogniser object using object->recogniser. The second is to redefine the graphical->event method.

1.67.1 Refining graphicals

A couple of methods are commonly redefined on class graphical for creating customised graphical objects:

1.67.2 Class variables

graphical.event_tolerance: 0.. = 5
Minimum size of event-area. This class-variable is used by graphical->in_event_area and graphical->in_event_area.
graphical.selection_handles: {corners,sides,corners_and_sides,line}* = corners_and_sides
Determines how graphical->paint_selected draws the selection indication, provided graphical<-selected is @on and the graphical<-window’s window<-selection_feedback equals handles. Values:
sides
Paint inverted blobs at the middle of all 4 sides of the bounding box.
corners
Paint inverted blobs at the 4 corners of the bounding box.
corners_and_sides
Combines the above possibilities
line
Specific for class line.
@(nil)
Don't draw any inverted blobs. Used with classes that define a private version of these functions (path->paint_selected).
graphical.visual_bell: bool =
@on @see graphical->flash @see window->flash @see graphical->alert
graphical.visual_bell_duration: int = 100
Length of flash in milliseconds
See also
- graphical->flash
- window->flash

1.67.3 Instance variables

graphical <- active: bool
If @off, the colour of the drawing pen will be set to object<-class_variable_value: inactive_colour. The method graphical->event will simply fail if graphical<-active is @off.
graphical-area: area
The area object associated with each graphical describes a bounding-box inside which all pixels affected by the graphical are. The area is used for:

graphical <- colour: [colour|pixmap]
The graphical<->colour attribute of a graphical describes the colour used to draw the affected pixels. It is either a colour object or @default. The latter implies the graphical<->colour attribute of the device is used.

Defaults: @default. For windows, the default colour is display<-foreground.

See also
class colour
graphical-connections: chain*
Chain of connection objects. Connections are lines relating two graphical objects. Connection are automatically updated when either of the connected graphicals is updated.
See also
topic Connections
graphical <- cursor: cursor*
Cursor displayed in this window when the graphical is in focus of events. When @nil, the cursor of the device is displayed.

Defaults: @nil.

See also
class cursor
graphical <- device: device*
The device (normally picture, dialog or figure) on which the graphical is displayed. A graphical can only be displayed on one device. The graphical<->device slot is used by graphicals to inform their device of changes, so the device can perform the appropriate redraw operations. The following is always true:
If the device of a graphical is not @nil, the graphical is
member of `Device <-graphicals` of this device and
visa-versa.

Normally, a graphical is assigned a device using device->display.

See also
- graphical-displayed
- device->display
- device-graphicals
- class device
graphical <- displayed: bool
If @off, the graphical will not be displayed even if it is member of a device. The initial value is @off. It is set to @on by device->display an @off by device->erase.

graphical->displayed is used to remove a graphical temporary from the display. See also figure->status.

Defaults: Initially @off. Set to @on by device->display.

See also
- graphical<-is_displayed
- device->display
- dialog_item->show
- graphical-device
graphical-handles: chain*
Chain of handles. Each handle defines a position to which a connection can attach. See T Connections.

Handles can be attached at the instance level and at the class level (see class->handles) or both.

Defaults: @nil (no handles at the instance level)

See also
- topic Connections
- graphical->handle
- class-handles
- class handle
graphical <- inverted: bool
If @on, graphical<->area is inverted after the graphical is painted, inverting all pixels in the bounding-box of the graphical. Note that this implies at inverted circle appears as a white circle in a black square (using white background and black foreground colours). Also note that graphicals below (i.e. hidden by this graphical) are inverted too.

Defaults: @off

See also
graphical-selected
graphical <-> name: name
The name of a graphical can be used to locate it on its device. Finding graphicals by name is a simple but very effective way. Graphicals generally do not visualise their graphical<-name.

See device<-member and device<-catch_all.

See also
- frame<-get_catch_all
- device<-get_catch_all
- device<-member
graphical <- pen: 0..
The pen attribute denotes the thickness in pixels of the drawing pen for drawing lines. It is defined at class graphical, but only applicable to classes whose images actually contain lines. If the pen is 0 (zero), lines are not displayed.

Defaults: 1

See also
graphical-texture
graphical <- request_compute: any*
When not @nil, indicates that the graphical is in inconsistent state. Used for graphical objects that require significant computation to determine their area and visual representation.

When no argument is specified with graphical->request_compute the variable will be filled with @on.

If a graphical->request_compute is invoked on a graphical, PCE's graphical kernel will invoke a graphical->compute on it if the graphical needs to be repainted or one of the dimensions of the graphical is requested. See graphical<-area, display->dispatch and graphical->compute.

See also
- graphical->compute
- graphical->request_compute
graphical <- selected: bool
Indicates whether or not the graphical is selected. The visual feedback is determined by the graphical.selection_style.
See also
- graphical.selection_style
- graphical->selected
- graphical->toggle_selected
- device<-selection
- device->selection
- graphical-inverted
graphical <- texture: texture_name
Stipple pattern used for drawing lines. Applicable to all graphicals that have line elements in them. Values:
noneStraight line
dottedPattern: 1 on 2 off ...
dashedPattern: 7 on 7 off ...
dashdotPattern: 7 on 3 off 1 on 7 off ...
dashdottedPattern: 11 on 3 off 1 on 3 off 1 on 3 off 1 on 3 off
longdashPattern: 15 on 7 off ...
See also
graphical-pen

1.67.4 Send methods

graphical ->_redraw_area: area
Repaint the graphical. Area specified the area (in the coordinate system of the current device) that needs to be repainted. Area is guaranteed to overlap with graphical<-area, the bounding box of the pixels affected by this graphical.

This method is called by the graphical infra-structure of XPCE and should never be called directly. See also graphical->draw and graphical->compute.

This method may be redefined to create custom graphical objects. It is not obligatory for the redefinition to call the method of the super-class. The definition should not apply paint outside the graphical<-area of the graphical. If there is no simple way to avoid this, use graphical->clip and graphical->unclip to ensure this.

The definition can use graphical->draw to paint other graphical objects or one or more of the primitive drawing operations listed below:

graphical->draw_arc Draw ellipse-part or pie-part
graphical->draw_box Draw rectangle
graphical->draw_fill Fill/clear a rectangle
graphical->draw_image Draw an image object
graphical->draw_line Draw a line segment
graphical->draw_poly Draw a polygon
graphical->draw_text Draw a string

The pen, colours, etc. may be manipulated using the following methods:

graphical->save_graphics_state Save current settings
graphical->restore_graphics_state Restore old values
graphical->graphics_state Modify graphics state

The User Guide (Programming in PCE/Prolog) provides further documentation on redefining graphicals.

Another common approach to create custom graphics is by subclassing class device to define compound graphicals.

graphical ->_wants_keyboard_focus:
Test if graphicals wants keyboard events (fail). Used by‘device graphical->advance’and redefined by various sub-classes.
graphical ->below: graphical*
Put me below argument.
graphical ->left: graphical*
Put me left of argument.
graphical ->right: graphical*
Put me right of argument.
graphical ->above: graphical*
Integrates plain graphical objects in the layout system defined for class dialog. The graphical->above relation is stored using object->attribute. This method handles combinations of plain graphical objects and dialog_item objects correctly.

See also graphical->above, dialog->layout and device->layout_dialog.

graphical ->alert:
Alert the user of an error. Depending on the graphical.visual_bell, either graphical->flash or graphical->bell are invoked.

Defaults: Depends on the resource graphical.visual_bell.

See also
- visual->report
- graphical->flash
- window->flash
- graphical->bell
- graphical.visual_bell
- display->inform
- editor-error_message
graphical ->reference: point
Dialog item integration.
graphical ->alignment: {left,center,right,column}
Dialog item integration. These methods associate the requested value using an object->attribute. See dialog_item->alignment and dialog_item->reference for details.
graphical ->apply: [bool]
Virtual method, defined by most subclasses of class dialog_item. This method should forward the graphical<-message of the dialog_item if the dialog_item has been modified by the user or the argument is @on. See also dialog->apply
graphical ->area: area
Changes position and size. Implemented using graphical->set.
See also
graphical->set
graphical ->auto_align: bool
Inherits description from: graphical<-auto_align
graphical ->bell: [int]
Rings the bell on the associated display. The argument is the volume.
See also
- window->flash
- display->bell
- graphical->alert
graphical ->center: point
Moves the graphical such that the center of its area becomes point. Moving is realised using graphical->set.
See also
graphical->set
graphical ->unclip:
Undo previous graphical->clip.
graphical ->clip: [area]
Clip subsequent drawing actions to the indicated rectangle. If the rectangle is @default, all operations are clipped to the graphical<-area of the graphical. Note that on entry of graphical->_redraw_area clipping is set to the argument area, which will normally be larger than graphical<-area.

Each graphical->clip must be undone by an graphical->unclip before graphical->_redraw_area returns. See also graphical->_redraw_area, graphical->graphics_state graphical->draw_line, etc.

graphical ->colour: [colour|pixmap]
@see graphical<-display_colour @see device->foreground @see class colour
graphical ->compute:
This method is invoked by PCE's graphical kernel when:

graphical ->connect: to=[graphical], link=[link], to_kind=[name], from_kind=[name]
Create a connection (line) to another graphical, which must be displayed on the same window, but not necessarily on the same device object.

graphical->connect simply invokes link<-connection passing the receiver as from, as well as to, from_kind and to_kind. The normal way to redefine the type of connection established is using either link->connection_class or by redefining link<-connection.

See also
- graphical->layout
- connection->initialise
- topic Connections
- graphical->handle
- graphical->disconnect
- graphical->connected
- class connection
graphical ->connected: to=[graphical], link=[link], to_kind=[name], from_kind=[name]
Test if graphical has a connection that matches the specification. Any of the values may be @default, which refers to anything. See graphical<-connections for a description of the arguments. The method graphical<-connected performs the same test, returning the connection object found.
See also
- graphical<-connections
- topic Connections
- graphical->connect
graphical ->container_size_changed: width=[int], height=[int]
graphical<-width or graphical<-height of graphical<-contained_in changed. Currently used only by class parbox. See parbox->line_width
graphical ->corner: point
Sets the corner opposite the origin of the graphical (see‘graphical graphical->orientation’) to the indicated position in the coordinate system of the graphical's device.

This method used to support resizing graphicals: sending graphical->corner messages to with the location of the device resizes the graphical. Resizing is now dealt with by class resize_gesture.

See also
- area<-corner
- graphical->set
- graphical<-corner
- graphical->corner_y
- graphical->corner_x
- graphical->orientation
graphical ->corner_x: int
@see graphical->corner
graphical ->corner_y: int
@see graphical->corner
graphical ->cursor: cursor*
@see graphical->focus @see window-displayed_cursor
graphical ->device: device*
Device I'm displayed on.
graphical ->disconnect: to=[graphical], link=[link], to_kind=[name], from_kind=[name]
object->free all connections to- and from this graphical that match the arguments. @default is taken to match anything. The arguments are described with graphical<-connections.
See also
- topic Connections
- graphical->connect
graphical ->display_on: device*
Display graphical on device. Equivalent to‘device graphical->display: graphical’, which is the recommended way to display graphical objects.
See also
device->display
graphical ->displayed: bool
If @on, graphical is visible.
graphical ->do_set: x=[int], y=[int], width=[int], height=[int]
Set X, Y, W and H for graphical. Unlike the other geometry management methods, this method calls graphical->geometry rather then graphical->request_geometry.
graphical ->draw: offset=[point], area=[area]
Draw the graphical on the current device. If offset is given, the coordinate system of the device is moved by the given offset prior to painting the graphical. The optional argument is the changed area of the device.

This method may be used to redefine graphical->_redraw_area. It should not be called outside this context.

graphical ->draw_arc: x=int, y=int, w=int, h=int, angle1=[real], angle2=[real], fill=[colour|image]*
Draw an ellipse-part. X,Y,W,H define the bounding box if the entire ellipse. Angle1 and Angle2 the start and end angles (in degrees). When omitted, an entire ellipse will be drawn.

Fill defines the fill-pattern used. If @nil, the shape is not filled.

This method is part of the user-defined graphics infra-structure described with graphical->_redraw_area and should not be called outside this context.

graphical ->draw_box: x=int, y=int, w=int, h=int, radius=[0..], fill=[image|colour|elevation], up=[bool]
Draw rectangular (rounded) box with the given X, Y, W, H. Radius defines the rounding radius for the corners. If the last argument is an image or colour object, the interior will be filled with this. If it is an elevation object, a 3D effect will be simulated. In this case up defines whether the box is painted elevated or lowered.

This method is part of the user-defined graphics infra-structure described with graphical->_redraw_area and should not be called outside this context.

graphical ->draw_fill: x=int, y=int, w=int, h=int, fill=[colour|image]*
Fill rectangle with specified pattern. If the pattern is @nil, the area is cleared to the current background. If the pattern is @default, the area is filled with the current foreground.

To fill a rounded rectangle, use graphical->draw_box with the pen set to 0.

This method is part of the user-defined graphics infra-structure described with graphical->_redraw_area and should not be called outside this context.

graphical ->draw_image: image, x=int, y=int, sx=[int], sy=[int], sw=[int], sh=[int], transparent=[bool]
Draw a bitmap or pixmap image. The image is drawn from X,Y. SX,SY,SW,SH define the source-area on the image. The default area is the entire image object. If the image is monochrome, (image<-kind), the on pixels are painted in the current foreground and the off pixels in the current background. If transparent is @on, the off pixels are not painted.

This method is part of the user-defined graphics infra-structure described with graphical->_redraw_area and should not be called outside this context.

graphical ->draw_line: x1=[int], y1=[int], x2=[int], y2=[int]
Draw line segment from (X1,Y1) to (X2,Y2) using the current settings of the graphics state (see graphical->graphics_state).

This method is part of the user-defined graphics infra-structure described with graphical->_redraw_area and should not be called outside this context.

graphical ->draw_poly: points=chain|vector, closed=[bool], fill=[colour|image]*
Draw/fill a polygon. Points is a chain object or vector object containing the points though which the polyline is drawn. If closed is @on, a line is drawn from the last to the first point. If fill is specified, the interior is filled with the given pattern.

This method is part of the user-defined graphics infra-structure described with graphical->_redraw_area and should not be called outside this context.

graphical ->draw_text: string=char_array, font, x=int, y=int, w=[0..], h=[0..], hadjust=[{left,center,right}], vadjust=[{top,center,bottom}]
Draw a string in the given font object. If only X and Y are given, they describe the left-side of the baseline. If W and H are given, the text is positioned in a box according the the alignment-specifiers hadjust an vadjust. The box described by X,Y,W,H does not need to be large enough to contain the text. For example, a box of size 0.0 and hadjust/vadjust center/center may be used to center text around a point.

Multiple lines are aligned according to hadjust (default: left).

The redraw-method below draws a text-box:

'_redraw_area'(TB, _Area:area) :->
        "Redraw text-box"::
        get_object(TB, area, area(X,Y,W,H)),
        send(TB, draw_box, X, Y, W, H),
        get(TB, font, Font),
        get(TB, string, String),
        send(TB, draw_text, String, Font,
             X, Y, W, H, center, center).

This method is part of the user-defined graphics infra-structure described with graphical->_redraw_area and should not be called outside this context.

graphical ->event: event
Process a (user-) event. This function is normally invoked by class device through event->post.

If the graphical has recogniser objects associated (see‘object graphical<-all_recognisers’) and graphical<-active equals @on, the recognisers are activated in the order they appear in this chain until one succeeds, after which this method returns successfully.

This method is redefined by many subclasses of class graphical to achieve predefined response to user-events. When programming user-defined (graphical) classes, this method is commonly used to attach predefined user-interface behaviour to the new class.

The following creates a box that may be moved using the middle button:

?- new(B, box(100,100)),
   send(B, recogniser, new(move_gesture)).

And the following example defines a class movable_box from which all instances can be moved:

:- pce_begin_class(movable_box, box).

:- pce_global(@movable_box_gesture,
                          new(move_gesture)).

event(B, Ev:event) :->
        (   send(B, send_super, event, Ev)
        ->  true
        ;	send(@movable_box_gesture, event, Ev)
        ).

:- pce_end_class.

Diagnostics: Fails silently if there are no recognisers or none of the recognisers accepted the event.

See also
- class recogniser
- object->recogniser
- object<-all_recognisers
- device->event
graphical ->expose: [graphical]
Moves graphical in the stacking order of its device such that it is displayed just on top of the argument graphical. If no argument is given, the grapical becomes the topmost one.

See also graphical->hide, graphical->swap and graphical->overlap.

Defaults: If the argument graphical is omited, the graphical will be moved to the top of the device's graphical stack.

Diagnostics: Always succeeds but has no effect if the argument graphical is not displayed on the same device.

See also
- graphical->swap
- graphical->hide
graphical ->flash: area=[area], time=[int]
Alert the user of a possible problem by shortly inverting the graphical. Area specifies the area to be inverted, relative to the graphical<-area of the graphical itself. Time is the time in milliseconds which the graphical remains in the inverted time; the time of the total operation is this time, plus two time the required time to invert the area. The default time the graphical is inverted is determined by graphical.visual_bell_duration.

See also window->flash, device->flash and tab->flash.

Normally one should invoke graphical->alert, which depending on graphical.visual_bell will either ring the bell or flash the graphical.

See also
- graphical->alert
- graphical.visual_bell_duration
- graphical.visual_bell
graphical ->focus: recogniser=[recogniser], cursor=[cursor], button=[name]
When the graphical is related to a window, invoke
send(Window, focus, Graphical, Recogniser, Cursor, Button).

Focusing further user-events to this graphical object.

See also
- window->focus
- graphical->focus_cursor
- graphical->cursor
graphical ->focus_cursor: cursor*
Invokes window->focus_cursor it the graphical is displayed in a window. Always succeeds. This will modify the cursor of the window until the window's focus is changed.
See also
- class cursor
- graphical->focus
- window->focus_cursor
- gesture-cursor
graphical ->generate_event: event_id
Generate a new event-object and post it to this graphical. The new event has the given id. Its window is the window in which the graphical is displayed. All other values default (to the values of the latest event).

Used internally to generate area_enter and area_exit events from other pointer-oriented events.

Diagnostics: Returns the value of event->post

See also
- event->initialise
- event->post
graphical ->geometry: x=[int], y=[int], width=[int], height=[int]
Invoked from graphical->request_geometry, which is, through graphical->set, invoked by all the methods that manipulate the geometry of graphical objects. The parameters are the requested X-, Y-, W and H values for the graphical. Values that need not be changed are passed as @default.

Sets the area and informs the graphical's device on the changed geometry. The device will answer with a graphical->_redraw_area when this is necessary.

This method is commonly refined, dealing with all possible resize and move requests. If this method is refined if should always call the graphical->geometry method of the super-class. It is allowed to change the parameters though The example below defines a box fits on a 10x10 pixel grid.

:- pce_begin_class(grid_box, box).

geometry(B, X:[int], Y:[int], W:[int], H:[int]) :->
        align_to_grid(X, NX),
        align_to_grid(Y, NY),
        align_to_grid(W, NW),
        align_to_grid(H, NH),
        send(B, send_super, geometry, NX, NY, NW, NH).

align_to_grid(@default, @default).
align_to_grid(Value, Aligned) :-
        Aligned is ((Value + 4) // 10) * 10.

:- pce_end_class.
See also
- graphical->set
- device->geometry
graphical ->graphics_state: pen=[0..], texture=[texture_name], colour=[colour|pixmap], background=[colour|pixmap]
Modify the graphics state. Only the specified values will be modified. This method will normally be called using the named-argument conventions of XPCE:
...,
send(Gr, graphics_state, pen := 2, colour := red),
...

It is not allowed to return from graphical->_redraw_area with a modified state. Therefore redraw-methods that modify the state should normally use graphical->save_graphics_state and graphical->restore_graphics_state. Here is a typical example, drawing a thicker line.

'_redraw_area'(MyGr, Area:area) :->
        send(MyGr, save_graphics_state),
        send(MyGr, graphics_state, pen := 2),
        send(MyGr, draw_line, 0,0,100,100),
        send(MyGr, restore_graphics_state).

NOTE: It is generally advised to paint graphical objects that require the same graphics state together. So, if you need to paint alternating thick and thin lines, first draw all thick lines and then all thin lines instead of switching the state between each line.

graphical ->handle: handle
Associates a handle with the graphical. A handle is a named connection-point, which position is determined by two expression objects in terms of the graphical<-width and graphical<-height of the graphical. Connections between graphicals can only be made if both graphicals have suitable handles defined.

Note that handles may also be attached at the class of the graphical. Such handles are used by all instances of the class. See class->handle.

See also
- class handle
- graphical<-handle
- topic Connections
- graphical->connect
- class connection
- graphical-handles
- class->handle
graphical ->height: int
Invokes graphical->set width specified H-value.
See also
graphical->set
graphical ->hide: [graphical]
Place in background or below argument. If the argument is @default, the receiver becomes the deepest nested graphical or, in other words, the head of the device<-graphicals chain.

See also graphical->expose, graphical->swap and graphical->overlap.

See also
- graphical->swap
- graphical->expose
graphical ->in_event_area: x=int, y=int
Used by class device to determine device<-pointed_objects. Performs the following steps:

  1. if the width or height is very small (< 5 pixels), it is enlarged to make it at least 5 pixels. Fails if (X,Y) is outside this (enlarged) area. The tolerance is read from the graphical.event_tolerance.
  2. if the class has the C-function‘class -in_event_area_function’defined, this function is called and its value is returned. Otherwise success is returned.

    Bugs: # The 5 pixels should be a resource

graphical ->initialise: x=[int], y=[int], width=[int], height=[int]
Initialise a graphical using the area components graphical<-x, graphical<-y, graphical<-width and graphical<-height. It sets the following defaults:
<-displayed		@off  (will be set by ->display)
<-device			@nil
<-area			new area from the arguments
<-pen			1	1
<-texture			none
<-colour			@default
<-selected		@off
<-name 			Classname  (box, ellipse, ...)
<-handles			@nil
<-inverted		@off
<-cursor			@nil
<-request_compute	@nil

Class graphical is a super-class of all graphical classes. Instances of this class can be created, but are probably of little use.

graphical ->keyboard_focus: [bool]
If @off, release the window->keyboard_focus. If @on or @default and the receiver passes the test graphical->_wants_keyboard_focus send window->keyboard_focus.

See also device->advance

graphical ->layout: attract=[real], nominal=[real], repel=[real], adapt=[int], iterations=[int], area=[area], network=[chain], move_only=[chain]
When graphical is member of a network (see graphical<-network) of connected graphicals (see graphical->connect), this method tries to give the entire graph of connected graphicals a sensible layout. Don't expect too much: this algorithm does not know anything about what your graph is representing.

The algorithm is based on [Eades:84]. It defines a number of springs between connected and non-connected nodes. The algorithm does a Monte-Carlo simulation using these springs.

The parameters are:

graphical ->move: point
Synonym for graphical->position: moves the origin of the graphical to the indicated position. Normally the origin is the top-left corner. Note however that this depends on the graphical<-orientation.

The origin of devices is the origin of the device's coordinate system.

See also
graphical->position
graphical ->normalise:
Equivalent to graphical->orientation: Ensures graphical<-width and graphical<-height are positive, making the origin the top-left corner of the graphical.
See also
graphical->orientation
graphical ->orientation: {north_west,south_west,north_east,south_east}
Some graphical objects may have negative graphical<-width and graphical<-height. The origin is the (X,Y) point of the graphical. (X+W, Y+H) refers to the opposite corner (see graphical<->corner). This method places the origin at one of the indicated corner. The graphicals location and size on the screen is not affected by this method. The values are:
north_west	W>=0, H>=0	(->normalise)
north_east	W < 0, H>=0
south_west	W>=0, H < 0
south_east	W < 0, H < 0
See also
- graphical<-size
- graphical<-orientation
- graphical->normalise
- graphical->corner
graphical ->paint_selected:
Paint the selection attributes if the graphical is graphical<-selected and the graphical<-window defines one of the following window<-selection_feedback values:

graphical ->pointer: point
Move the pointer relative to the coordinate system of the graphical: computes offset relative to window's coordinate system and then invokes window->pointer.

Diagnostics: Succeeds without side-effects if the graphical is not displayed.

See also
window->pointer
graphical ->popup: popup
Utility method to associate a popup with an object. It performs the following steps.

  1. If the object has a popup instance variable, it will fill this variable with the popup object and assume the class knows how to display it.
  2. Otherwise it will attach an attribute popup to the object and append the recogniser @_popup_gesture, which is a default popup_gesture object

    Bugs: Notably 1) is a dubious assumption.

    See also
    - class popup
    - object->attribute
    - class popup_gesture
graphical ->position: point
Move graphical such that graphical<-x and graphical<-y match the x- and y-coordinates of the argument point. Invokes graphical->set.

Synonym for graphical->move.

See also
- graphical->set
- graphical->move
graphical ->recogniser: recogniser
Add recogniser for user events (last). This is the normal way of associating event recogniser objects with graphical objects.

Recognisers associated this way are store very similar to attributes associated with object->attribute. If the graphical is saved to a file using object->save_in_file, the recognisers will be saved with the graphical object.

Using class-level programming, recognisers mat be associated with graphical objects in two ways: by redefining the graphical->initialise method, calling graphical->recogniser to associate event handling or by redefining the class graphical->event method.

The following example defines movable_box as a class:

:- pce_begin_class(movable_box, box).

:- pce_global(@movable_box_recogniser,
                          new(move_gesture)).

event(MB, Ev:event) :->
        "Associate @movable_box_recogniser"::
        (   send(MB, send_super, event, Ev)
        ;   send(@movable_box_recogniser, event, Ev)
        ).

:- pce_end_class.

See also: class gesture, class event, graphical->prepend_recongiser, event->post, pce_global/2.

graphical ->redraw: [area]
Request the graphical to repaint the specified area. When @default, the entire graphical is repainted. Should not be necessary for the application programmer as PCE takes care of redraw automatically. See also graphical->request_compute.
graphical ->relative_move: point
Move the graphical relative to its current position using the X- and Y-values of ^point^.
graphical ->reparent:
Updates the graphical<-device of possible associated connections. This method. It is invoked from class device when the position of the graphical in the consists-of tree relative to its window has changed:

graphical ->request_compute: [any]*
@see graphical-request_compute
graphical ->request_geometry: x=[int], y=[int], width=[int], height=[int]
Invoked internally from graphical->set, which in turn is invoked by all the methods that manipulate the geometry of graphical objects. The parameters are the requested X-, Y-, W and H values for the graphical. Values that need not be changed are passed as @default.

Invokes graphical->geometry to change the graphical<-area. The indirection graphical->request_geometry ==> graphical->geometry may be redefined when a graphical is constrained by some other object. For example, class window exploits this mechanism to let windows communicate with their tile object.

graphical ->resize: factor_x=real, factor_y=[real], origin=[point]
Realises together with device->resize resizing of collections of objects. This method resizes the graphical with specified factor relative to the given origin. The X- and Y-distance of each of the corners to this reference point is multiplies by resp. the X- and Y-resize factor (1st and 2nd argument).

Defaults: The following defaults apply:

graphical ->rotate: int
Exchanges graphical<-width and graphical<-height if the rotation is 90 or 270 degrees. graphical<-center is maintained.

Bugs: Someday, xpce should support real rotation and scaling at the level of class device.

graphical ->restore_graphics_state:
Restore saved pen, texture, colours and font.
graphical ->save_graphics_state:
Save the current setting for the device's pen, texture and fore- and background. The old values are restored using graphical->restore_graphics_state. Each graphical->save_graphics_state must be closed with a graphical->restore_graphics_state before graphical->_redraw_area returns. See also graphical->graphics_state.
graphical ->selected: bool
@see graphical->toggle_selected @see graphical-selected
graphical ->set: x=[int], y=[int], width=[int], height=[int]
Set the X-, Y-, W- and H- parameter of the graphical. This method is invoked by all the other geometry managing methods (graphical->size, graphical->position, graphical->x, ...).

Note that this method is faster than graphical->size, graphical->position, etc. when the geometry has to be changed from a set of integer values as no intermediate object has to be created.

It first determines whether any action is necessary (i.e. there is a non-default value that is not equal to the current value). If so, it invoked graphical->geometry which takes care of the class-dependent geometry-changing action.

Bugs: graphical->geometry is invoked using the internal function simpleSend(), which bypasses possible object-level methods. Geometry management can only be programmed at thee class level.

See also
- graphical->height
- graphical->width
- graphical->resize
- graphical->size
- graphical->corner
- graphical->position
- graphical->y
- graphical->x
- graphical->geometry
- graphical->center
- graphical->area
graphical ->size: size
Invokes graphical->set with specified W- and H-parameter.
See also
graphical->set
graphical ->swap: graphical
Swap the positions of both graphicals in the device's graphical<-graphicals chain. The background graphicals are at the head of this chain, wile the foreground graphicals are at the tail.
See also
- graphical->expose
- graphical->hide
graphical ->texture: texture_name
Stipple pattern of drawing pen.
graphical ->toggle_selected:
If graphical<-selected equals @on, invoke graphical->selected: @off and visa-versa. Useful for implementing selection handling.
See also
- graphical->selected
- graphical-selected
graphical ->unlink:
Delete possible connections using graphical->disconnect and remove the graphical from it's graphical<-device.
graphical ->width: int
Invokes graphical->set with specified X-value to set the width of the graphical.
See also
graphical->set
graphical ->x: int
Invokes graphical->set width specified X- value.
See also
graphical->set
graphical ->y: int
Invokes graphical->set width specified Y- value.
See also
graphical->set

1.67.5 Get methods

graphical <-absolute_position: [device] -> point
Returns a point object indicating the position of the top-left corner of the graphical in the coordinate system of the argument device (or window).

The position relative to the screen may be found using graphical<-display_position. See also graphical<-position and graphical<-area.

Defaults: When device is omited, returns the absolute position relative to the top-most device. If the graphical is displayed, this is the window in which the graphical is displayed.

Diagnostics: Fails silently if device is specified and graphical is not displayed on this device.

See also
- graphical<-position
- graphical<-display_position
- graphical<-absolute_y
- graphical<-absolute_x
graphical <-absolute_x: [device] -> int
X coordinate of graphical in coordinate system of device. See graphical<-absolute_position.
See also
graphical<-absolute_position
graphical <-absolute_y: [device] -> int
Y coordinate of graphical in coordinate system of device. See graphical<-absolute_position.
See also
graphical<-absolute_position
graphical <-alignment: -> name
Dialog_item integration. See graphical->alignment and dialog_item->alignment for details.
graphical <-all_recognisers: create=[bool] -> chain
Inherits description from: object<-all_attributes
graphical <-auto_label_align: -> bool
graphical <-auto_value_align: -> bool
graphical <-reference: -> point
graphical <-auto_align: -> bool
graphical->auto_align is for the integration with class dialog_item. It associates an object->attribute auto_align with the specified value. graphical<-auto_align returns the value of this attribute if present. Otherwise @on if one of the attributes graphical<-above, graphical<-below, graphical<-left, graphical<-right exists and @off otherwise.
graphical <-bottom_side: -> int
Y-coordinate of the bottom-side of the graphical in the coordinate system of its device. With positive height, this is graphical<-y + graphical<-height. With negative height, this is graphical<-y.
See also
- graphical<-top_side
- graphical<-right_side
- graphical<-left_side
graphical <-center: -> point
@see graphical<-center_y @see graphical<-center_x
graphical <-center_x: -> int
@see graphical<-center
graphical <-center_y: -> int
@see graphical<-center
graphical <-common_device: with=graphical -> device
Graphical devices may be used to create complex diagrams by combining simple and other complex diagrams (see class device). This method locates the most local device that displays both the receiver and the argument graphical.

graphical<-common_device is used internally to determine the device on which to draw connections between graphicals that are not displayed on the same device.

Diagnostics: Fails (silently) if no such device can be found. Note that this method always succeeds if both graphicals are displayed in the same window and always fails if they are displayed in different windows.

See also
- class connection
- class device
graphical <-connected: to=[graphical], link=[link], to_kind=[name], from_kind=[name] -> connection
Find specified connection object. See graphical->connected for details. If there are multiple connections matching the search the first one is returned. See also graphical<-connections.

This method may be redefined to hook the behaviour of graphical->layout.

graphical <-connections: to=[graphical], link=[link], from_kind=[name], to_kind=[name] -> chain
Compute a new chain with all connections of graphical. The arguments are:
to:Graphical at other side
link:Link that must be in the connection
from_kind:Name of the handle at the from-side
to_kind:Name of the handle at the to-side.

Fails if there are no connections.

Defaults: Omitted or default arguments imply any value is legal.

See also
- graphical<-network
- graphical->connected
graphical <-contained_in: -> device|node
Device this graphical is displayed on when not @nil. If the device is a tree object, it will return the associated node using graphical<-node.

Diagnostics: Fails if graphical<-device equals @nil.

See also
- tree<-contains
- graphical<-node
graphical <-convert: object -> graphical
General object are converted into graphicals by invoking graphical<-image on the object. This simplifies manipulation of non-graphical objects that manipulate a graphical (such as class node).
See also
node-image
graphical <-corner: -> point
New point defined as:
point(<-x + <-width, <-y + <-height)
See also
- graphical->corner
- graphical<-corner_y
graphical <-corner_x: -> int
X-coordinate of the corner, defined as
<-x + <-width.
See also
graphical<-corner_y
graphical <-corner_y: -> int
Y-coordinate of the corner, defined as
<-y + <-height
See also
- graphical<-corner
- graphical<-corner_x
graphical <-display: -> display
Display on which the graphical is displayed. Useful when using multiple displays (see class display).

Diagnostics: Fails (silently) if the graphical is not displayed (indirectly) on a window.

See also
graphical<-window
graphical <-display_colour: -> colour|pixmap
Return the colour in which the graphical is actually displayed. If the variable graphical<-colour equals @default, this is the graphical<-display_colour of the graphical's device. Otherwise it is the value of the graphical<-colour variable.

If the graphical is displayed, this will always return a colour. Otherwise this method fails if neither the graphical, nor its device specify the colour.

See also
- window->colour
- graphical->colour
graphical <-display_position: -> point
Determines the position of the top-left corner of the graphical relative to the display. Sometimes use to determine the position of a new (prompter) window. Note that the position of the current event, relative to the display may be found using
get(@event, position, @display, Point)

See event<-position and @event. See also graphical<-position and graphical<-absolute_position.

Diagnostics: Fails if graphical is not related to a window

Bugs: Yields incorrect results if the window is not actually displayed on the screen.

See also
graphical<-absolute_position
graphical <-distance: graphical -> int
Invokes area<-distance using the areas of both graphicals.

Bugs: Silently assumes that both graphicals are displayed on the same device.

See also
- graphical<-distance_y
- graphical<-distance_x
- area<-distance
graphical <-distance_x: graphical -> int
Yields an integer representing the distance between the graphicals in X-direction. Yields 0 if both areas overlap in X-direction.
See also
- area<-distance_x
- graphical<-distance_y
- graphical<-distance
graphical <-distance_y: graphical -> int
@see graphical<-distance_x @see graphical<-distance
graphical <-frame: -> frame
Frame on which the graphical is displayed.

Frames are commonly used to represent a tool of an application (or an entire application). This method provides an easy way to find the application object from some deep-down part of it.

Diagnostics: Fails silently if the graphical is not displayed.

See also
- graphical<-window
- frame<-frame
graphical <-handle: name -> handle
Returns handle object with specified name. First scans‘graphical -handles’followed by graphical<-handles of the graphical's class. The first matching handle is returned.

Diagnostics: Fails silently when there is no matching handle.

See also
- graphical<-handle_position
- graphical<-handles
- graphical->handle
graphical <-handle_position: name=name, device=[device] -> point
Determine position of the named handle in the coordinate system of the given device. The default device is the graphicals graphical<-device.

Defaults: When no device is specified, the coordinate system of the graphical's device is used.

Diagnostics: Fails if there is no such handle or the graphical is not displayed on the given device.

See also
- handle<-y
- handle<-x
- graphical<-handle
graphical <-handles: near=[point], kind=[name], distance=[int] -> chain
New chain with all handles (both from -handles as from class<-handles that are within distance pixels from the given point and have the given kind. Fails if no handles match the criterion.
See also
graphical<-handle
graphical <-height: -> int
Height in pixels. Note that for some graphicals this value may be negative, indication the top-side is above rather than below the y-position.
graphical <-is_displayed: [device] -> bool
Tests whether graphical is actually displayed, assuming device is displayed.

Defaults: When device is @default, succeeds if graphical and all deviced above it have graphical<-displayed: @on.

See also
graphical-displayed
graphical <-left_side: -> int
@see graphical<-bottom_side
graphical <-network: link=[link], from_kind=[name], to_kind=[name] -> chain
Computes a new chain, holding the receiving graphical and all graphicals that can be reached from it by following the specified types of connections:
link
When specified, follow only connections of this link
from , to
When specified, follow only links that are connected to the named handles

This method is save on cyclic graphs. See also graphical->layout.

See also
- graphical->layout
- graphical<-connections
graphical <-node: -> node
Return the node object that has node<-image equal to this graphical if the graphical is controlled by a node of a tree object. See also graphical<-contained_in.

Diagnostics: Fails silently when the node cannot be found.

Bugs: Only works if the node is attached to a tree and actually displayed. It checks whether the graphical's device is a tree and then uses‘node graphical<-find_node’to find the node object belonging to this graphical.

See also
- graphical<-contained_in
- node<-find_node
- tree->event
- node-image
- class node
graphical <-orientation: -> {north_west,south_west,north_east,south_east}
Inherits description from: graphical->orientation
See also
graphical->orientation
graphical <-position: -> point
@see graphical<-absolute_position
graphical <-right_side: -> int
@see graphical<-bottom_side
graphical <-size: -> size
New size object created from graphical<-height and graphical<-width of the graphical's area. Either or both of graphical<-width and graphical<-height may be negative. See graphical<->orientation.
See also
graphical->orientation
graphical <-top_side: -> int
@see graphical<-bottom_side
graphical <-window: -> window
Window on which the graphical is displayed. Yields itself if graphical is a window.

Diagnostics: Fails silently when graphical is not displayed on a window.

See also
- graphical<-display
- graphical<-frame