RectangleShape (class)
public RectangleShape {inherits Shape}
Package: CURL.GUI.SHAPES

An implementation of Shape that looks like a rectangle.

Description

This object draws a plain rectangle, with border. A separate class, RoundedRectangleShape, is available for drawing rectangles with rounded corners.

Notes

This class uses the following shape options:

Example


Example
{import * from CURL.GUI.SHAPES}

{let shape:RectangleShape =
    {RectangleShape
        {GRect 0cm, 2cm, 0cm, 1cm},
        border-width = 0m,
        color = FillPattern.silver,
        border-color = FillPattern.navy,
        translation = {Distance2d 1cm, .5cm}
    }
}

{HBox
    "border-width (in pixels): ",
    {TextField
        width = .5in,
        value = "0",
        {on ValueFinished at field:TextField do
            set shape.border-width = {field.value.to-double} * 1px
        }
    }
}

{Canvas
    width = 4cm,
    height = 2cm,
    shape
}

Constructors
default:Construct a new RectangleShape.
constructor public {RectangleShape.default rectangle:GRect, ...}
Properties
border-color:The color of any borders or outlines present in this (or child) shapes.
nonlocal option public RectangleShape.border-color:FillPattern
border-line-style:The style in which this Shape's border will be rendered.
local option public RectangleShape.border-line-style:LineStyle
border-width:The thickness of the border around this RectangleShape.
local option public RectangleShape.border-width:any =0pt
color:The color of this shape and its children.
nonlocal option public RectangleShape.color:FillPattern
display-context:The DisplayContext associated with this object.
nonlocal option public RectangleShape.display-context:#DisplayContext
rectangle:The bounds of the rectangle.
accessor public final RectangleShape.rectangle:GRect
setter public final RectangleShape.rectangle:GRect
style-element:The "element" or "type" of this Visual, for the purpose of styling.
accessor public RectangleShape.style-element:String
Properties inherited from Shape: as-Shape, draw-operation, option-parent, selection-context, shape-parent, shape-selectable, stroke-thickness, transformation, visible?
Properties inherited from ShapeContainerBase: as-ShapeRoot, shape-children
Properties inherited from Visual: _style-element, clonable-class?, completely-clonable-children?, cursor, data-source, dragee, font-size, input-method-enabled?, input-method-keyboard-mode, name, options, options-present-here, style-class, style-manager, style-options, test-description, test-name, test-parent?, test-type-name, test-visible?, tooltip, user-data
Properties inherited from DataBindingTarget: data-binding-context, data-bindings
Properties inherited from EventTarget: event-handlers
Properties inherited from OptionListInterface: option-register-proc, registered-option-keys
Methods
draw:Draw this object's visual representation.
public {RectangleShape.draw renderer2d:Renderer2d}:void
get-own-bounds:Calculate the rectangular rendering bounds of this Shape, in its local coordinate system.
public {RectangleShape.get-own-bounds dest:GRect = {GRect.empty}}:GRect
get-own-layout-bounds:Calculate the rectangular layout bounds of this Shape, in its local coordinate system.
public {RectangleShape.get-own-layout-bounds
    lc:LayoutContext,
    width-first?:bool = true,
    dest:GRect = {GRect.empty}
}:GRect
self-contains-point?:Determine whether or not a point lies within this Shape.
public {RectangleShape.self-contains-point?
    x:Distance,
    y:Distance
}:bool
self-intersects-polygon?:Determine whether a polygon intersects this Shape.
public {RectangleShape.self-intersects-polygon?
    polygon:ShapeSelectionPolygon
}:bool
transformation-changed:Notification that Shape.transformation has changed.
public {RectangleShape.transformation-changed}:void
Methods inherited from Shape: apply-rotation, apply-scale, apply-transformation, apply-translation, apply-translation-in-parent, constrain-own-layout-bounds, constrain-shape-layout-bounds, contains-point?, detach, find-graphical-ancestor, fire-crossing-event, fire-in-child, get-display-context, get-down-orientation-in-shape-parent, get-graphical-root, get-local-device-pixel-size, get-origin-in-graphical-ancestor, get-origin-in-root, get-origin-in-shape-parent, get-origin-in-shape-root, get-own-bounds-in-shape-root, get-right-orientation-in-shape-parent, get-shape-bounds, get-shape-bounds-in-shape-root, get-shape-layout-bounds, get-top-left-in-ancestor, get-transformation-to-shape-root, keyword-init-arg, option-change-notify, overdraw-for-selection, quantize-line-thickness, request-draw, request-draw-self, reset-transformation, set-rotation, set-scale, set-transformation, set-translation-in-parent, to-Graphic, transform-from-display-coordinates, transform-from-graphical-root-coordinates, transform-point-from-shape-root, transform-point-to-shape-root, transform-to-display-coordinates, transform-to-graphical-root-coordinates, transform-vector-from-shape-root, transform-vector-to-shape-root, transformation-changing
Methods inherited from ShapeContainerBase: add, clear, draw-shape-child, draw-shape-children, get-all-children-at-point, get-child-at-point, get-leaf-at-point, get-shape-root, note-attached, note-detaching, notify-option-children, on-drag-enter, on-pointer-enter, on-pointer-envelope-event, register-options, remove, set-shape-index, set-shape-index-after, set-shape-index-before, shape-container-fire-inferior-crossing-event, shape-container-handle-crossing, shape-container-pick-child, shape-container-pointer-enter-occurred, shape-container-pointer-leave-occurred
Methods inherited from Visual: add-from-init-args, add-option, add-style-option, animate, change-cursor, clonable-appearance?, clone-appearance, clone-appearance-helper, find-test-children, get-focus-manager, get-layout-context, get-test-parent, get-test-property, get-text, get-view, maybe-fire-attach-event, maybe-fire-detach-event, non-keyword-init-arg, note-caret-position, on-drag-leave, on-pointer-leave, pop-cursor, prepare-test-object, prepare-test-parent, push-cursor, quantize-width, release-key-focus, remove-option, remove-style-option, request-key-focus, scroll-to-include, test-record, test-run, xy-offset-to
Methods inherited from GraphicOptions: any-to-Distance
Methods inherited from GuiEventTarget: handle-event, on-action, on-cancel-mode, on-command-changed, on-commit, on-composition-change-event, on-composition-result-event, on-context-menu-event, on-current-record-change-request, on-current-record-changed, on-destroy-notify, on-destroy-requested, on-drag-over, on-drag-pointer, on-drag-started, on-drop, on-end-composition-event, on-focus-event, on-focus-in, on-focus-out, on-grab-release, on-gui-event, on-input-method-event, on-inspection, on-key-event, on-key-press, on-pointer-button, on-pointer-crossing, on-pointer-event, on-pointer-motion, on-pointer-press, on-pointer-release, on-pointer-scroll, on-raw-key-event, on-raw-key-press, on-raw-key-release, on-reset, on-selectable-added, on-selectable-removed, on-selection-changed, on-selection-context-activated, on-selection-context-deactivated, on-selection-event, on-start-composition-event, on-start-event, on-stop-event, on-view-activate, on-view-deactivate, on-window-close, remove-event-handlers-for-event-class
Methods inherited from DataBindingTarget: add-data-binding, get-data-binding, refresh-data-binding, remove-data-binding, unset-property, update-data-binding, validate-data-binding
Methods inherited from EventTarget: accepts-event-class?, add-event-handler, event-handler-present?, remove-event-handler, verify-event
Methods inherited from OptionListInterface: change-option-parent-notify, clone-options, get-option, get-option-by-name, local-add-notify, local-remove-notify, name-to-option-key, new-option-item, option-changed, option-lookup, option-lookup-here, option-propagate-notify, option-set?, propagate-option-change, remove-styles, set-option-by-name, set-style-option-by-name, unset-option-by-name, unset-style-option-by-name
Methods inherited from BasicEventTarget: enqueue-event
Methods inherited from InitRestArgParser: process-rest-args
Methods inherited from Object: object-describe, object-describe-for-debugging, object-serialize

Constructor Details
default (constructor)
public {RectangleShape.default rectangle:GRect, ...}

Construct a new RectangleShape.

rectangle: The bounds of the rectangle.
...: Any normal Shape construction arguments may be passed, including option initializers, transformations, or child Shapes. See Shape.default for details.

Notes

The values stored into RectangleShape.rectangle may be different from those in the rectangle passed in. In particular, if the rectangle is inverted such that, for instance, -rectangle.lextent is greater than rectangle.rextent, the inverted dimensions will be swapped. The rectangle passed in will not itself be modified, however.


Property Details
border-color (nonlocal option)
public RectangleShape.border-color:FillPattern

The color of any borders or outlines present in this (or child) shapes.

Notes

All shape objects have this option, either inherited or set directly on the object.

Some shape objects do not make use of this property directly. A ShapeGroup for example, does not use this property. It may nevertheless useful to set properties such as this one on a ShapeGroup object, since all of the shape children of the object will inherit those properties by default.


border-line-style (local option)
public RectangleShape.border-line-style:LineStyle

The style in which this Shape's border will be rendered.

Description

Please see LineStyle for more information.


border-width (local option)
public RectangleShape.border-width:any =0pt

The thickness of the border around this RectangleShape.

Description

This is a local option, and applies only to the current object; in other words, it functions similarly to Graphic.border-width.

Legal types of values are:

The default value is 0pt, which means that no border is drawn. Examples of legal values include:

Note that using a width that evaluates to one pixel results in a performance boost which may be substantial. (This is because the border may be rendered using line-based primitives, rather than solid-filled primitives.) The easiest way to cause this is to use 1pixel (or 1px). However, you must take the Shape's transformation into account. If it has had a scale factor of 2, 2 applied, then a border-width of 1pixel will in fact cover two device pixels, and thus will be slower. The appropriate value in this case would be 0.5px.

Please see Shape.quantize-line-thickness for a more detailed explanation of how values are converted and quantized to pixels.


color (nonlocal option)
public RectangleShape.color:FillPattern

The color of this shape and its children.

Description

If you do not desire a filled shape, this option may be set to FillPattern.transparent. Note that this will not generally affect the results of Shape.self-contains-point? or the mouse events delivered to the shape.

Notes

All shape objects have this option, either inherited or set directly on the object.

Some shape objects do not make use of this property directly. A ShapeGroup for example, does not use this property. It may nevertheless useful to set properties such as this one on a ShapeGroup object, since all of the shape children of the object will inherit those properties by default.


display-context (nonlocal option)
public RectangleShape.display-context:#DisplayContext

The DisplayContext associated with this object.

Programming Notes

This option is used for communication purposes within the Curl graphics system. It should not be casually set or unset by user code. It should also not usually be read directly by user code: if you want the current DisplayContext, you should fetch it by calling Visual.get-display-context.

Every graphic hierarchy that can be displayed, whether in a window on the screen or on a printed page, must have at its root an object that sets the display-context option to a DisplayContext object that is suitable for the display medium by means of which the graphic hierarchy will be seen. Thus, an object can tell that it has been attached to a displayable graphic hierarchy by watching for the display-context option's value to change from null to a non-null DisplayContext object. Accordingly, subclasses of Visual that need to take specific actions when they become connected to a displayable graphic hierarchy monitor the display-context option by including an option declaration such as

{nonlocal-option public display-context:#DisplayContext
change handler}


where the code in change handler looks at the current value of the display-context option (available within the change handler as the value of the variable display-context), watching for changes between null and non-null values, and takes any actions that are needed.

Programmers using this programming idiom should be aware, however, that it is fairly common when rearranging graphical displays to detach graphical objects temporarily from a graphic hierarchy and then reattach them to the same hierarchy, which will cause the detached objects to temporarily see the display-context object become null and then become non-null again. Code that monitors changes in the display-context option should take this possibility into account and avoid taking undesired actions in this case.


rectangle (accessor)
accessor public final RectangleShape.rectangle:GRect
setter public final RectangleShape.rectangle:GRect

The bounds of the rectangle.

Description

Do not modify the contents of this GRect. Instead, assign a new value to RectangleShape.rectangle.

Note that the object passed in to the setter (as well as the rectangle argument in the constructor) is copied, not stored by reference, so you do not need to worry about modifying it later or reusing it for other purposes.

Notes

The values stored into RectangleShape.rectangle may be different from those in the rectangle passed in. In particular, if the rectangle is inverted such that, for instance, -rectangle.lextent is greater than rectangle.rextent, the inverted dimensions will be swapped. The rectangle passed in will not itself be modified, however.


style-element (accessor)
accessor public RectangleShape.style-element:String

The "element" or "type" of this Visual, for the purpose of styling.

Description

This implementation returns the value of Visual._style-element but is normally overridden to return a constant value.

Overriding

If a subclass of Visual should be stylable separately from other types of objects, this getter should be overridden to return an appropriate string. By convention, this string is the name of the class or the name of the markup that produces the object.

An override must return self._style-element if it is not the empty string.
Introduced in: version 6.0


Method Details
draw (method)
public {RectangleShape.draw renderer2d:Renderer2d}:void

Draw this object's visual representation.

renderer2d: The Renderer2d that this object should use to draw itself.

Overriding

When subclassing Shape, this method must be overridden.


get-own-bounds (method)
public {RectangleShape.get-own-bounds dest:GRect = {GRect.empty}}:GRect

Calculate the rectangular rendering bounds of this Shape, in its local coordinate system.

dest: An optional GRect object to be used to return the data.

Returns

A GRect object containing the bounds. This will always be the same object as dest. This GRect must be well-formed; that is, the following must be true: -dest.lextent <= dest.rextent and -dest.ascent <= dest.descent

Description

The bounds returned should cover all pixels that will be painted by this object but do not include all of the children of this object.

Notes

Rendering bounds (get-own-bounds) and layout bounds (get-own-layout-bounds) are typically similar, but may differ. In particular, the rendering bounds may be generously inclusive, but the layout bounds must describe the Shape precisely in order for adjacent items to abut properly.

Overriding

When subclassing Shape, this method must be overridden. The dest parameter must be used to return the data.


get-own-layout-bounds (method)
public {RectangleShape.get-own-layout-bounds
    lc:LayoutContext,
    width-first?:bool = true,
    dest:GRect = {GRect.empty}
}:GRect

Calculate the rectangular layout bounds of this Shape, in its local coordinate system.

lc: The LayoutContext in effect for this layout negotiation.
width-first?: For GraphicShapes, indicates whether the bounds should be calculated using using width-first layout negotation. This parameter is not typically used by other subclasses.
dest: An optional GRect object to be used to return the data.

Returns

A GRect object containing the bounds. This will always be the same object as dest. This GRect must be well-formed; that is, the following must be true: -dest.lextent <= dest.rextent and -dest.ascent <= dest.descent

Description

The bounds returned are those that best describe the object for layout purposes but do not include all of the children of this object.

Notes

Rendering bounds (get-own-bounds) and layout bounds (get-own-layout-bounds) are typically similar, but may differ. In particular, the rendering bounds may be generously inclusive, but the layout bounds must describe the Shape precisely in order for adjacent items to abut properly.

Overriding

The default implementation merely calls get-own-bounds. The dest parameter must be used to return the data.


self-contains-point? (method)
public {RectangleShape.self-contains-point?
    x:Distance,
    y:Distance
}:bool

Determine whether or not a point lies within this Shape.

x: The X coordinate of the point.
y: The Y coordinate of the point.

Returns

true if this Shape contains (x, y).

Description

The point is in this object's local coordinate system. This method does not consider its children.

Overriding

When subclassing Shape, this method must be overridden. This method determines when mouse events (such as PointerMotion) will be delivered to this object, among other things.

Generally, you should implement this method to determine whether or not the point lies within any of the rendered primitives of the shape, not simply whether or not it is within the bounds of the shape. However, you are free to implement it using whatever metric you desire.


self-intersects-polygon? (method)
public {RectangleShape.self-intersects-polygon?
    polygon:ShapeSelectionPolygon
}:bool

Determine whether a polygon intersects this Shape.

polygon: An object containing set of points that describe a polygon in this shape's local coordinate space. It is guaranteed that this polygon will be convex and will use a counter-clockwise winding order.

Description

This method is very similar to Shape.self-contains-point?, except that it deals with an area rather than a point. It is primarily used to support area-based selection, but it may also be directly called.

Overriding

When subclassing Shape, this method must be overridden. It need not consider children.

Generally, you should implement this method to determine whether or not the area intersects with any of the rendered primitives of the shape, not simply whether or not it is within the bounds of the shape. However, you are free to implement it using whatever metric you desire. Users will experience strange results when selecting this object if the implementation of this method disagrees with Shape.self-contains-point?.

If you are not using any selection features, this method can be implemented to simply return false.


transformation-changed (method)
public {RectangleShape.transformation-changed}:void

Notification that Shape.transformation has changed.

Overriding

Important note: Any overriding implementation of this method should include a call to the superclass implementation in order to ensure that the new area of the object is invalidated.