1.38 class device

A (graphical) device is a collection of graphical objects. As device itself is a graphical objects; devices may be nested. Class device describes the management of such a collection: adding (displaying) graphical objects; erasing graphical objects; changing them; dispatching events over their displayed graphical objects; etc.

Devices communicate changed area's to their super-device and eventually to the window, which takes care of planning and executing the actual redisplay of the X-window.

The PCE-user normally uses the behaviour of devices via the classes figure or one of the sub-classes of window. Class device itself may be used for the definition of compound graphical objects.

The graphical<-area of a device is by definition the bounding box of all graphical<-displayed graphical objects.

See also
- graphical<-common_device
- graphical-device
- topic Compound Graphicals
- class graphical
- class event
- object->recogniser

1.38.1 Instance variables

device-bad_bounding_box: bool
Indicates that the contents has been changed such that the bounding-box (area) needs to be recomputed.
device-bad_format: bool
Indicates the contents has been changed such that the attached format object needs to be recomputed.
See also
class format
device-clip_area: area*
If not @nil, no pixels outside this area are affected. The area of the entire device is the intersection of the union of the area's of all graphicals and the clip_area.

The variable is defined at the level of class device for technical reasons. The clip_area mechanism is activated at the level of class figure.

Defaults: @nil (no clipping is done).

device <- format: format*
When not @nil, the positions of the graphicals displayed on the device is computed using the attached format.

If a device has a device<-format, graphicals cannot be moved any more. Also, the position argument of device->display is simply ignored.

See also
class format
device <- graphicals: chain
Chain of graphicals displayed on the device. The first graphical is the one that is entirely in the background; the last is entirely in the foreground. See graphical->expose and friends to change the stacking order of overlapping graphicals.

The contents of this chain may be queried but not changed. Use the manipulation behaviour defined on devices and graphicals to change the contents of the device. Note that the collection enumeration methods device->for_all and device->for_some are also available for devices. The following example changes the pen thickness of all graphicals of a device to 2:

send(Device, for_some, @default,
         message(@arg1, pen, 2)),
See also
- device<-contains
- graphical-device
- device<-member
- device->for_some
- device->for_all
device <- level: int
Nesting depth from the window. The window itself has device<-level equals 0. Used for quick detection of a common device for two graphicals.

See also device->reparent.

device-offset: point
Offset of the coordinate-system to the coordinate-system of it's device. Managed via the geometry-changing behaviour of devices (device->position, etc.).
See also
device->position
device <- pointed: chain
Chain of (graphical) members whose bounding-box overlap the position of the mouse. Internally used to generate area_enter and area_exit events and perform event-dispatching. May be used from code that handles an event to detect which graphicals overlap the mouse-position.

The first element of this chain is the top-most graphical. The others are further and further in the background.

See also
- device->update_pointed
- device<-pointed_objects
device-recompute: chain
@see graphical->compute

1.38.2 Send methods

device ->advance: from=[graphical]*, propagate=[bool], direction=[{forwards,backwards}]
Advance the keyboard-focus to the next graphical object of this device for which the test graphical->_wants_keyboard_focus succeeds. Used by text_item to implement text_item->advance.

This method cycles through the device<-graphicals chain. If the argument is a graphical and there is no graphical that requests the keyboard focus further down the device<-graphicals chain and the device is not the window itself, and propagate not is @off, it will invoke device->advance on its graphical<-device, passing itself as argument. This behaviour allows for handling the keyboard focus in dialog-windows built from nested devices.

Otherwise, If no graphical wants to have the keyboard focus, the keyboard focus of the graphical<-window is set to @nil.

Defaults: If graphical is @default, the first graphical accepting device->_wants_keyboard_focus is given the focus.

See also
- text_item->_wants_keyboard_focus
- text_item-advance
- window->keyboard_focus
device ->append_dialog_item: item=graphical, relative_to_last=[{below,right,next_row}]
Append a graphical object using the dialog-layout mechanism. This method may be used to define sub-dialogs. See‘dialog device->append’for details.
device ->changed_union: ox=int, oy=int, ow=int, oh=int
If the union of the displayed graphicals (see area->union) has changed, this method is called. The arguments indicate the old union of the graphicals. This method may be used to implement custom scroll_bar objects with figure objects.
device ->clear: [{destroy,free,erase}]
Remove all graphicals from the device. The argument controls what happens to the removed graphicals. By default it uses device->erase, leaving destruction to the reference-count garbage collector. Using free the graphicals will be send a object->free, ensuring destruction of the graphicals, but not their parts and using destroy ensures deep destruction of the displayed graphicals based on visual->destroy.
See also
device->erase
device ->compute:
Send device->compute to all members of -recompute, next recomputes the device<-format if requested by -bad_format and finally recomputes the graphical<-area (bounding box) requested by -bad_bounding_box.
device ->display: graphical, position=[point]
Display a graphical object on the device. This is the principal way of drawing on a device. It performs the following operations:

device ->erase: graphical
Erase a graphical from the device. The graphical is removed from the device<-graphicals chain of the device, the graphical's graphical<-device is set to @nil and the display is updated.

Note that the graphical is only destroyed if it had no other references. To make sure the graphical is destroyed, use object->free. To be sure all sub-graphicals are removed as well, use visual->destroy.

See also
- graphical->reparent
- device->clear
device ->event: event
Process an event. It performs the following operations:

device ->for_all: [name], code
Run code on all graphicals with given graphical<->name. Stops with failure executing code fails for some graphical. If name is @default, code is executed on all member graphicals, which makes the method equivalent to
send(Dev?graphicals, for_all, Code)
See also
- device->for_some
- chain->for_all
- device-graphicals
device ->for_some: [name], code
Run code on all member graphicals that have graphical<-name equal to name. The exit status is ignored and device->for_some always succeeds. If name is @default, code is run on all device<-graphicals in the device object.

Defaults: If name is @default, code is executed on all member graphicals.

See also
- device->for_all
- device-graphicals
device ->foreground: colour
The foreground colour of a device determines the colour used to draw member graphicals that have graphical<-colour not equal to @default. Device ->foreground' is equivalent to Graphical graphical->colour‘.
See also
- graphical->colour
- class colour
device ->format: format*|name, [any]
This method has two modes of operation:

device ->geometry: x=[int], y=[int], width=[int], height=[int]
device->geometry updates device<-offset (the offset of the device's coordinate system relative to its super-device) such that the top-left corner is at (X, Y).

The graphical<-width and graphical<-height of a device is defined to be the union of the area of the member graphicals (intersected with device<-clip_area) and the W and H parameters of the geometry request are thus ignored.

See also
graphical->geometry
device ->initialise:
Create an empty device.
device ->layout_dialog: gap=[size], size=[size], border=[size]
This method implements the layout of dialog objects (see dialog->layout). It may be used to define compound dialog windows or to exploit the layout mechanism for dialog windows in a normal window or graphical device.
device ->modified_item: graphical, bool
Virtual method, fails. Dialog item's send this message to their device after they have been modified. If this message succeeds, they assume the dialog is an attribute editor and will not forward their device<-message. Otherwise they will immediately forward their device<-message. See also dialog->modified_item.
device ->move: point
Move the origin of the device to be at point. Note that this need not be the top-left corner. To set the top-left corner, use‘Device graphical->set: X, Y’.
See also
- device->y
- device->x
- device->position
device ->position: point
Inherits description from: device-offset
See also
- device-offset
- device->move
device ->reference: [point]
Move the reference-point (offset) of the device to be at point, but move the member graphicals the same amount in the other direction, such that they remain displayed at the same position.

The default reference point is the top-left corner of the bounding box of all the member graphicals.

device ->reparent:
Called from PCE graphics kernel if something has changed to the graphical<-device organisation up in the graphical<-device hierarchy. This general method performs the following:

device ->resize: x_factor=real, y_factor=[real], origin=[point]
Resize the member graphicals of the device in X and Y direction. See graphical->resize for details on the parameters.

Defaults:

The following defaults apply:

device ->room: area
Test if there are no graphicals that have‘Graphical graphical<->displayed: @on’and overlap with area on the device. See also device<-inside.
See also
device<-inside
device ->selection: graphical|chain*
Set the member graphicals that have graphical<->selected. If the argument is a graphical, this graphical will be selected. If it is a chain of graphicals, each member of this chain will be selected. If the argument is @nil, no graphical will be selected.

All graphicals displayed on this device, except for the indicated one's will be deselected.

See also
- device<-selection
- graphical-selected
device ->unlink:
device->erases all device<-graphicals from the device and then calls graphical->unlink. Note that erased graphicals are only garbage-collected if they have no references from other objects. See also‘visual visual->destroy.
device ->update_pointed: event
Update the device<-pointed chain to represent all graphicals displayed on the device for which event is in the event_area. Graphicals that are deleted from the chain are send an area_exit event. Graphicals that are added to the chain are send an area_enter event. If on or more of the mouse-buttons are down, these events are area_cancel and area_resume.
See also
- device->event
- device-pointed
- topic Event types
device ->x: int
Set the X-coordinate of the origin. See device->move
See also
device->move
device ->y: int
Set the Y-coordinate of the origin. See device->move
See also
device->move

1.38.3 Get methods

device <-catch_all: name -> graphical
Find a displayed graphical by it's name. To find a graphical named hello, type
?- get(Device, hello_member, Hello).

NOTE: Graphicals may also be found using device<-member.

Diagnostics: Asking for a graphical that does not exist will trap the no_behaviour error.

See also
device<-member
device <-contains: -> chain
Implementation of the visual part-of hierarchy. Equivalent to‘Device device<-graphicals’.
See also
- device-graphicals
- visual<-contains
device <-find: at=[point|event], condition=[code] -> graphical
Find the most local graphical overlapping with at for which condition succeeds.

This methods uses a similar search technique as used by device->event and is first of all intended to help writing gestures that have to relate two graphical objects, possibly not placed on the same device object. Examples are class connect_gesture or a drag-and-drop gesture.

device<-find performs the following steps:

device <-inside: area -> chain
Returns a new chain object with all graphicals that are entirely inside the argument area. If no graphicals can be found, an empty chain is returned. Described with selection because it is commonly used to implement selecting multiple graphicals by dragging a box around them. See PceDraw.
See also
- device->room
- area->inside
device <-member: graphical_name=name -> graphical
Return the first graphical of device<-graphicals that has name name. This mechanism is commonly used to address parts of a device.

Diagnostics: Fails if no graphical with the requested name exists.

See also
- device<-catch_all
- device<-get_catch_all
- graphical-name
- device-graphicals
device <-offset: -> point
Inherits description from: device-offset
See also
- device<-y
- device<-x
- device<-position
device <-pointed_objects: at=point|event, append_to=[chain] -> chain
Determines all objects that overlap with some position. This method is used internally to determine the objects to which an event should be send. The first argument describes the position. It is either a point or an event. In the latter case the position of the event is taken.

If chain is supplied, this chain is filled with the matching graphicals. This chain is chain->cleared first. If it is @default, a new chain object with the matching graphicals it returned.

The matching graphicals are the graphicals for which‘Graphical graphical->in_event_area’succeeds. The graphicals are stored in the chain, such that the top-most graphical is the head of the chain.

See also
- device-pointed
- graphical->in_event_area
device <-position: -> point
Inherits description from: device-offset
See also
device<-offset
device <-selection: -> chain
Returns a new chain with all graphicals that have‘Graphical graphical<-selected: @on’. If there are no such graphicals, an empty chain is returned.
See also
- device->selection
- graphical-selected
device <-x: -> int
Returns the X-coordinate of device<-offset.
See also
device<-offset
device <-y: -> int
Returns the Y-coordinate of device<-offset.
See also
device<-offset