eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'GraphicsContext':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: GraphicsContext


Inheritance:

   Object
   |
   +--GraphicsContext
      |
      +--DeviceGraphicsContext

Package:
stx:libview
Category:
Graphics-Support
Version:
rev: 1.173 date: 2023/10/26 09:41:28
user: stefan
file: GraphicsContext.st directory: libview
module: stx stc-classLibrary: libview

Description:


this is an abstract superclass for all kinds of graphic drawables -
both windows and printed pages (i.e. printers) are inheriting from
this class (even drawables not at all associated with any device would do so).

Drawing is done in paint/bgPaint colors, which can be true colors (i.e.
directly supported by the underlying hardware) or simulated colors
(i.e. dithered colors or images).
The paint/bgPaint instance variables are set to the logical colors,
device specific drawable may like to keep actual colors in addition.

The transformation instance variable is typically nil, for a 1-to-1
coordinate mapping (i.e. x/y coordinates are pixels in the drawable).
If nonNil, the transformation must be an  instance of WindowingTransformation
and offers both a scale-factor and a translation.
Also, drawing in metric- or inch-units can be done using transformations.
(see instance creation methods of WindowingTransformation, and examples
 in 'doc/coding').

All drawing is defined upon a few basic drawing methods, which must be
implemented by subclasses (some subclasses also redefine the others for
more performance)

[Instance variables:]

    paint           <Color>         the paint used for drawing
    bgPaint         <Color>         the background used for drawing texts and bitmaps
    function        <Symbol>        the drawing function (i.e. #copy, #or, #xor ...)
                                    - not all Drawables support every function
                                    (i.e. paper only allows #copy)
    font            <Font>          the current font to be used for drawing
    lineStyle       <Symbol>        the lineStyle (i.e. #solid, #dashed, #doubleDashed)
    lineWidth       <SmallInteger>  the lineWidth (device dependent, usually pixels)
    joinStyle       <Symbol>        the style in which lines (in polygons)
                                    are joined (i.e. #miter, #bevel, #round)
    capStyle        <Symbol>        the style in which the last point of a line is drawn
                                    (i.e. #notLast, #butt, #round, #projecting)
    mask            <Form>          a mask used for drawing
                                    - not all Drawables support it
    maskOrigin      <Point>         the origin of the mask relative to
                                    the drawable's origin
    transformation
                    <WindowingTransformation>
                                    controls scale & translation of nonNil

    clipRect        <Rectangle>     a clip rectangle (device dep. usually pixels or inches)
                                    or nil.

[Class variables:[

    White           <Color>         cached white color - its needed so often
    Black           <Color>         cached black color - its needed so often

    DefaultFont     <Font>          default font to use

copyright

COPYRIGHT (c) 1992 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

Signal constants
o  drawingOnClosedDrawableSignal
return the signal which is raised, if drawing is attempted
on a closed drawable.
This is especially useful, if a forked thread animates
a view in the background, and is not properly synchronized
with the window thread - i.e. the window gets closed by the user,
and the background process continues to draw.
In this case, the background thread should handle this signal
and terminate itself in the handler.

accessing-defaults
o  defaultFont
get the default font used for drawing

o  defaultFont: aFont
set the default font used for drawing

constants
o  capButt
return a constant to specify butt cap

o  capNotLast
return a constant to specify not-last cap

o  capProjecting
return a constant to specify projecting cap

o  capRound
return a constant to specify round cap

o  joinBevel
return a constant to specify bevel join

o  joinMiter
return a constant to specify miter join

o  joinRound
return a constant to specify round join

initialization
o  initialize
setup some defaults - these are usually redefined
during startup.

instance creation
o  new
return a new instance of myself. Redefined to initialize
the new thingy

queries
o  isAbstract
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.


Instance protocol:

Compatibility-ST80
o  displayArc: origin radius: radius from: startAngle angle: angle
draw an arc around a point

o  displayArcBoundedBy: boundingBox startAngle: startAngle sweepAngle: sweepAngle
draw an arc/circle/ellipse - ST-80 compatibility

o  displayArcBoundedBy: boundingBox startAngle: startAngle sweepAngle: sweepAngle at: origin
draw an arc/circle/ellipse - ST-80 compatibility

o  displayLineFrom: startPoint to: endPoint translateBy: anOffset
draw a line - ST-80 compatibility

o  displayPolyline: aPolygon
draw a polygon - ST-80 compatibility

o  displayRectangularBorder: aRectangle
draw a rectangle - ST-80 compatibility

o  displayRectangularBorder: aRectangle at: aPoint
draw a rectangle - ST-80 compatibility

o  displayWedgeBoundedBy: boundingBox startAngle: startAngle sweepAngle: sweepAngle
fill an arc/circle/ellipse - ST-80 compatibility.
The angles may be floats or integer - they are given in degrees.
Positive angles are taken clockwise, negative angles are counterclockwise.

o  displayWedgeBoundedBy: boundingBox startAngle: startAngle sweepAngle: sweepAngle at: origin
fill an arc/circle/ellipse - ST-80 compatibility
The angles may be floats or integer - they are given in degrees.
Positive angles are taken clockwise, negative angles are counterclockwise.

o  findFont: aFontDescription
given a fontDescription, return a device font for it
on my device.

o  phase
return the origin within the mask (used to draw with patterns).
This is an alias for ST/X's #maskOrigin

o  phase: aPoint
set the origin within the mask (used to draw with patterns).
This is an alias for ST/X's #maskOrigin:

o  setDevicePattern: aColorOrMask
ST/X can paint in any color or image

o  tilePhase
return the origin within the mask (used to draw with patterns).
This is an alias for ST/X's #maskOrigin

o  tilePhase: aPoint
set the origin within the mask (used to draw with patterns).
This is an alias for ST/X's #maskOrigin

o  widthOfString: aString
given a string, return its width in pixels if
drawn on the receiver's device.

o  widthOfString: aString from: start to: stop
given a string, return the width in pixels if
a substring is drawn on the receiver's device.

Compatibility-Squeak
o  fill: aRectangle fillColor: aColor
fill a rectangle with the given color color

o  fillRectangle: aRectangle color: aColor
fill a rectangle with the given paint color

accessing
o  backgroundPaint
return the background paint color.
(used for opaqueForms and opaqueStrings)

o  backgroundPaint: aColor
set the background painting color (which is used for
opaqueForms and opaqueStrings). aColor can be a dithered one.

o  basicFont
return the font for drawing

o  blackColor
return the black color on this device.
This is the same as 'Color black onDevice:self device', but much faster.

o  capStyle
return the current cap-style for line-drawing.
possible styles are: #notLast, #butt, #round, #projecting

o  capStyle: aStyleSymbol
set the cap-style for line-drawing;
possible styles are: #notLast, #butt, #round, #projecting

o  characterEncoding
returns a symbol describing how the contents is encoded internally.
This is now obsolete, as we are always using unicode internally.
(encoding is something like #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc)

o  characterEncoding: encodingArg
define how the contents is encoded internally.
This should normally never be required, as ST/X now assumes
unicode (of which iso8859-1 is a subset) encoding.
The possibility to change the characterEncoding is provided as
a backward compatibility hook for programs which want to use
another encoding internally.
One such view is the CharacterSetView,
which wants to show character as they are actually present in a font.

o  clippingBounds
return the clip-rectangle for drawing (in logical coordinates).
If there is currently no active clip, return the underlying
medium (i.e. device) bounds. Added for ST-80 compatibility.

o  clippingBounds: aRectangleOrNil
set the clipping rectangle for drawing (in logical coordinates);
a nil argument turn off clipping (i.e. whole view is drawable)

o  clippingBoundsOrNil
return the clipping bounds (a Rectangle) for drawing in logical coordinates, nil if there is none.

o  dashStyle: aDashList offset: dashOffset
define dashes. Each element of the dashList specifies the length
of a corresponding dash. For example, setting it to [4 4]
defines 4on-4off dashing;
Setting it to [1 2 4 2] defines 1on-2off-4on-2off dashes.
The dashOffset specifies where in the dashList the dashing starts.
Ignored here - this may not be supported by all graphics devices.

o  font
return the current drawing font

o  font: aFont
set the drawing font

** This method must be redefined in concrete classes (subclassResponsibility) **

o  function
return the current drawing function

o  function: aFunctionSymbol
set the (bitblt) drawing function.
The argument is one of:
#copy,#copyInverted,#xor,#and,#andReverse
#andInverted,#or,#orReverse,#orInverted
#invert,#clear,#set,#noop,#equiv,#nand.
Notice: not all graphicMedia support all functions

** This method must be redefined in concrete classes (subclassResponsibility) **

o  graphicsContext
for ST-80 compatibility

o  graphicsDevice
same as #device, for ST-80 compatibility

o  joinStyle
return the current join-style for polygon-drawing.
possible styles are: #miter, #bevel, #round

o  joinStyle: aStyleSymbol
set the join-style of lines in polygon-drawing;
possible styles are: #miter, #bevel, #round

o  lineStyle
return the current line-drawing-style.
possible styles are: #solid, #dashed, #doubleDashed,
#dotted, #dashDot or #dashDotDot.

o  lineStyle: aStyleSymbol
set the line-drawing-style;
possible styles are: #solid, #dashed, #doubleDashed,
#dotted, #dashDot or #dashDotDot.

o  lineWidth
return the current drawing linewidth

o  lineWidth: aNumber
set the line drawing width in pixels

o  mask
return the current drawing mask

o  mask: aForm
set the drawing mask

** This method must be redefined in concrete classes (subclassResponsibility) **

o  maskOrigin
return the origin within the mask (used to draw with patterns).
Should be redefined in classes which support it.
This is an alias for ST-80's #phase

o  maskOrigin: aPoint
set the origin within the mask (used to draw with patterns).
Should be redefined in classes which support it.
This is an alias for ST-80's #phase:

o  maskOriginX: x y: y
set the origin within the mask (used to draw with patterns).
Should be redefined in classes which support it.
This is an alias for ST-80's #phase:

o  medium
return the destination medium i.e. the underlying graphics device

o  paint
return the current paint drawing color

o  paint: aColor
set the drawing painting color, aColor can be a dithered one

o  paint: fgColor on: bgColor
set the paint and backgroundPaint, used for text and bitmaps.
Both colors may be dithered colors

o  setDevice: aDevice

o  viewOrigin
return the drawable's visible origin (for scrolling)

o  whiteColor
return the white color on this device.
This is the same as 'Color white onDevice:self device', but much faster.

accessing-transformation
o  scale
return the scale factor (as point) of the transformation

o  scale: aPoint
set the scale factor of the transformation

o  scale: scale translation: aPoint

o  transformation
return the transformation

o  transformation: aTransformation
set the transformation

o  translateBy: aPoint
add to the translation offset of the transformation

o  translation
return the translation factor (as point) of the transformation

o  translation: aPoint
set the translation offset of the transformation

basic drawing
o  displayArcX: x y: y width: width height: height from: startAngle angle: angle
draw an arc in a box
- this could be recoded to draw using displayLine.
The angles may be float or integer - they are given in degrees.
Positive angles are taken clockwise, negative angles are counterclockwise.

** This method must be redefined in concrete classes (subclassResponsibility) **

o  displayDottedRectangleX: x y: y width: w height: h
draw a dotted-line rectangle
A general implementation is found here; deviceGC's
may reimplement this if directly supported by the device

o  displayHorizontalWavelineFromX: x0 y: y0 toX: x1
draw a horizontal wave-line from x0/y0 to x1/y0

o  displayLineFromX: x0 y: y0 toX: x1 y: y1
draw a line from x0/y0 to x1/y1

** This method must be redefined in concrete classes (subclassResponsibility) **

o  displayOpaqueForm: aForm x: x y: y
draw a form at x/y; if the form has depth 1, 1's in the form are
drawn in current fg, 0's in current bg color.
If the form has depth ~~ 1, it is copied as is onto the receiver

** This method must be redefined in concrete classes (subclassResponsibility) **

o  displayOpaqueString: aString from: index1 to: index2 x: x y: y
draw part of a string with both fg and bg at x/y in current font

** This method must be redefined in concrete classes (subclassResponsibility) **

o  displayOpaqueString: aString from: index1 to: index2 x: x y: y maxWidth: maxWidth
draw part of a string with both fg and bg at x/y in current font

** This method must be redefined in concrete classes (subclassResponsibility) **

o  displayPolygon: aPolygon
draw a polygon
- this could be recoded to draw using displayLine

** This method must be redefined in concrete classes (subclassResponsibility) **

o  displayRectangleX: x y: y width: w height: h
draw a rectangle
- this could be recoded to draw using displayLine

** This method must be redefined in concrete classes (subclassResponsibility) **

o  displayString: aString from: index1 to: index2 x: x y: y
draw part of a string with fg at x/y in current font

** This method must be redefined in concrete classes (subclassResponsibility) **

o  displayString: aString from: index1 to: index2 x: x y: y opaque: opaque
draw part of a string with both fg and bg at x/y in current font

basic filling
o  fillArcX: x y: y width: w height: h from: start angle: angle
fill an arc with current paint color.
The angles may be floats or integer - they are given in degrees.

** This method must be redefined in concrete classes (subclassResponsibility) **

o  fillPolygon: points
fill a polygon with current paint color

** This method must be redefined in concrete classes (subclassResponsibility) **

o  fillRectangleX: x y: y width: w height: h
fill a rectangle with current paint color

** This method must be redefined in concrete classes (subclassResponsibility) **

o  fillRectangleX: x y: y width: w height: h color: aColor
fill a rectangle with given color

drawing
o  display: someObject at: aPoint
draw someObject - this must understand the #displayOn:at: message

o  displayArcIn: aRectangle from: startAngle angle: angle
draw an arc in a box

o  displayArcOrigin: origin corner: corner from: startAngle angle: angle
draw an arc in a box

o  displayCircle: aPoint radius: r
draw a circle around a center point

o  displayCircleIn: aRectangle
draw a circle in a box

o  displayCircleX: x y: y radius: r
draw a circle around a center point

o  displayForm: aFormOrImage
draw a form (or image) at the origin

o  displayForm: aFormOrImage at: aPoint
draw a form (or image)

o  displayForm: aFormOrImage x: x y: y
draw a form (or image) at x/y;
if the form has depth 1, 1's in the form are
drawn in current paint color, 0's are ignored.
If the form has depth ~~ 1, the current fg color setting is ignored.

** This method must be redefined in concrete classes (subclassResponsibility) **

o  displayForm: aFormOrImage x: x y: y opaque: opaque
draw a form (or image) at x/y;
if the form has depth 1, 1's in the form are
drawn in current paint color, 0's are ignored.
If the form has depth ~~ 1, the current fg color setting is ignored.

o  displayImage: aFormOrImage
draw an image (or form).
Provided for ST-80 compatibilty;
in ST/X, images are also handled by #displayForm:

o  displayImage: aFormOrImage at: aPoint
draw an image (or form).
Provided for ST-80 compatibilty;
in ST/X, images are also handled by #displayForm:

o  displayImage: aFormOrImage x: x y: y
draw an image (or form).
Provided for ST-80 compatibilty;
in ST/X, images are also handled by #displayForm:

o  displayLineFrom: point1 to: point2
draw a line

o  displayLineFromX: xStart y: yStart toX: xEnd y: yEnd brush: aForm
draw a line using a brush.
Here, a slow fallback is used, drawing into a
temporary bitmap first, which is then displayed

o  displayOpaqueString: aString from: start to: stop at: aPoint
draw part of a string - drawing both fg and bg

o  displayOpaqueString: aString x: x y: y
draw a string with both fg and bg

o  displayOpaqueString: aString x: x y: y angle: drawAngle
draw a string along a (possibly non-horizontal) line,
drawing both fg and bg pixels.
The angle is in degrees, clock-wise, starting with 0 for
a horizontal draw.
Drawing is done by first drawing the string into a temporary bitmap,
which is rotated and finally drawn as usual.
NOTICE: due to the rotation of the temporary bitmap, this is a slow
operation - not to be used with cillions of strings ...

Usage example(s):

     |v|

     v := View new.
     v extent:300@200.
     v openAndWaitUntilVisible.
     0 to:360 by:45 do:[:a |
         v paint:Color black on:Color red.
         v displayOpaqueString:'hello world' x:100 y:100 angle:a.
     ].

o  displayPoint: aPoint
draw a pixel

o  displayPointX: x y: y
draw a point at x/y

o  displayRectangle: aRectangle
draw a rectangle

o  displayRectangleOrigin: origin corner: corner
draw a rectangle

o  displayRectangleOrigin: origin extent: extent
draw a rectangle

o  displayRoundRectangleX: left y: top width: width height: height wCorner: wCorn hCorner: hCorn
BIG KLUDGE WARNING HERE: the code below looks "good" on windows displays;

Usage example(s):

     |v|

     (v := View new) extent:200@200; openAndWaitUntilVisible.
     v displayRoundRectangleX:10 y:10 width:100 height:100 wCorner:20 hCorner:20

o  displayString: aString at: aPoint
draw a string - drawing fg only

o  displayString: aString centeredAt: aPoint
draw a string - drawing fg only

o  displayString: aString centeredAtX: x y: y
draw a string - drawing fg only

o  displayString: aString from: start to: stop at: aPoint
draw part of a string - drawing fg only

o  displayString: aString x: x y: y
draw a string - drawing fg only

o  displayString: aString x: x y: y angle: drawAngle
draw a string along a (possibly non-horizontal) line - drawing fg only.
The angle is in degrees, clock-wise, starting with 0 for
a horizontal draw.
Drawing is done by first drawing the string into a temporary bitmap,
which is rotated and finally drawn as usual.
NOTICE: due to the rotation of the temporary bitmap, this is a slow
operation - not to be used with cillions of strings ...

Usage example(s):

     |v|

     v := View new.
     v extent:300@200.
     v openAndWaitUntilVisible.
     0 to:360 by:90 do:[:a |
         v paint:Color black.
         v displayString:'hello world' x:100 y:100 angle:a.
     ].

Usage example(s):

     |v|

     v := View new.
     v extent:400@400.
     v openAndWait.
     0 to:360 by:5 do:[:a |
         v paint:Color black.
         v displayString:'.........hello' x:200 y:200 angle:a.
     ].

Usage example(s):

     |v|

     v := View new.
     v extent:200@100.
     v openAndWait.
     v displayString:' hello' x:90 y:50 angle:0.
     v displayString:' hello' x:90 y:50 angle:45.
     v displayString:' hello' x:90 y:50 angle:90.
     v displayString:' hello' x:90 y:50 angle:180.
     v displayString:' hello' x:90 y:50 angle:270.

Usage example(s):

     |v|

     v := View new.
     v extent:200@100.
     v openAndWait.
     v displayString:'hello' x:50 y:50 angle:0.
     v displayString:'hello' x:50 y:50 angle:45.
     v displayString:'hello' x:50 y:50 angle:90.
     v displayString:'hello' x:50 y:50 angle:135.
     v displayString:'hello' x:50 y:50 angle:180.
     v displayString:'hello' x:50 y:50 angle:225.
     v displayString:'hello' x:50 y:50 angle:270.
     v displayString:'hello' x:50 y:50 angle:315.

o  displayString: aString x: x y: y angle: drawAngle opaque: opaque

** This method must be redefined in concrete classes (subclassResponsibility) **

drawing in device coordinates
o  displayDeviceLineFromX: x1 y: y1 toX: x2 y: y2
draw a line in device coordinates

o  displayDeviceRectangleX: x y: y width: w height: h
draw a rectangle in device coordinates

o  fillDeviceRectangleX: x y: y width: w height: h
fill a rectangle with current paint color (device coordinates)

edge drawing
o  drawEdgesForX: x y: y width: w height: h level: lvl
draw 3D edges into a rectangle

o  drawEdgesForX: x y: y width: w height: h level: lvl shadow: shadowColor light: lightColor halfShadow: halfShadowColor halfLight: halfLightColor style: edgeStyle
draw 3D edges into a rectangle

o  edgeDrawn: whichOne
a redefinable hook for views which like to draw
over their edges (some checkToggles do).
Nothing done here.

evaluating in another context
o  withFont: aFont do: aBlock
evaluate aBlock with changed drawing font.

o  withLineWidth: lw do: aBlock
evaluate aBlock with changed line width.

o  withPaint: fgColor do: aBlock
evaluate aBlock with changed paint color.

o  withPaint: fgColor on: bgColor do: aBlock
evaluate aBlock with changed paint color.

filling
o  clearRectangle: aRectangle
clear the rectangular area in the receiver to white

o  fillArc: origin radius: r from: startAngle angle: angle
draw a filled arc around a point.
The angles may be floats or integer - they are given in degrees.
Positive angles are taken clockwise, negative angles are counterclockwise.

o  fillArcIn: aRectangle from: startAngle angle: angle
draw a filled arc in a box.
The angles may be floats or integer - they are given in degrees.
Positive angles are taken clockwise, negative angles are counterclockwise.

o  fillArcOrigin: origin corner: corner from: startAngle angle: angle
draw a filled arc in a box.
The angles may be floats or integer - they are given in degrees.
Positive angles are taken clockwise, negative angles are counterclockwise.

o  fillArcX: x y: y width: w height: h from: startAngle to: endAngle
draw a filled arc in a box, given startAngle and endAngle.
The angles may be floats or integer - they are given in degrees.
Positive angles are taken clockwise, negative angles are counterclockwise.

o  fillCircle: aPoint radius: aNumber
draw a filled circle around aPoint

o  fillCircleIn: aRectangle
draw a filled circle in a box.
The angles may be floats or integer - they are given in degrees.
Positive angles are taken clockwise, negative angles are counterclockwise.

o  fillCircleX: x y: y radius: r
draw a filled circle around x@y.
The angles may be floats or integer - they are given in degrees.
Positive angles are taken clockwise, negative angles are counterclockwise.

o  fillRectangle: aRectangle
fill a rectangle with current paint color

o  fillRectangleLeft: left top: top right: cornerX bottom: cornerY
draw a filled rectangle.
Notice: the cornerPoint itself is NOT included

o  fillRectangleOrigin: origin corner: corner
draw a filled rectangle.
Notice: the cornerPoint itself is NOT included

o  fillRectangleOrigin: origin extent: extent
draw a filled rectangle.
Notice: the cornerPoint itself is NOT included

o  fillRectangleOrigin: origin width: w height: h
draw a filled rectangle.
Notice: the cornerPoint itself is NOT included

o  fillRoundRectangleX: left y: top width: width height: height wCorner: wCorn hCorner: hCorn
bug workaround

Usage example(s):

     |v|

     (v := View new) extent:200@200; openAndWaitUntilVisible.
     v fillRoundRectangleX:10 y:10 width:100 height:100 wCorner:20 hCorner:20

initialization
o  initialize
set up some useful default values

misc
o  clippedTo: aRectangle do: aBlock

o  flush
send all buffered drawing to the device.

o  sync
send all buffered drawing to the device and wait until the device responds

printing & storing
o  storeOn: aStream
blocked: ascii storeString not possible (recursive - view - subviews - container)

queries
o  fontAscent
answer the ascent of the current font on the current device

testing
o  isPSGraphicsContext
is this a postscript graphics context?

text printing
o  withLineStyle: aSymbol lineWidth: lw paint: paintColor do: aBlock


Examples:


drawing uses a paint color (which may be a dithered one) which is used like a `pen'. A few drawing operations (opaqueForm and opaqueString drawing) use two colors, the paint and a backgroundPaint. For example, normal string drawing (#displayString:...) only draws the font's on-pixels in the current paint, leaving off-pixels unchanged. In contrast, #drawOpaqueString:.. also changes these to the bgPaint color. The bgPaint can be changed with #backgroundPaint: or #paint:on: (which modifies both). lets try it in a view:
    |v|

    v := View new.
    v openAndWaitUntilVisible.

    v paint:(Color red).
    v displayString:'hello' x:10 y:50
the same using opaque drawing:
    |v|

    v := View new.
    v openAndWait.

    v paint:(Color red) on:(Color yellow).
    v displayOpaqueString:'hello' x:10 y:50
Lines are drawn using the paint color (if solid) or both paint and bgPaint (dashed lines). The look of the line is controlled by joinStyle, capStyle, lineWidth and lineStyle. `lineStyle' can be one of #solid, #dashed, #doubleDashed where: #solid - is for solid lines, drawn with the current paint color #dashed - for dashed lines, where only the on-dashes are drawn with the current paint color #doubleDashed - dashed lines, draws on-dashes with paint color, off-dashes with bgPaint for example:
    |v|

    v := View new.
    v openAndWait.

    v paint:(Color red) on:(Color blue).
    v displayLineFrom:(10@10) to:(90@90).

    v lineStyle:#dashed.
    v displayLineFrom:(90@10) to:(10@90).

    v lineStyle:#doubleDashed.
    v displayRectangle:((5@5) corner:(95@95)).
changing the line-width:
    |v|

    v := View new.
    v openAndWait.

    v paint:(Color red).
    v displayLineFrom:(20@20) to:(80@80).

    v lineWidth:5.
    v displayLineFrom:(80@20) to:(20@80).

    v lineWidth:8.
    v displayRectangle:((5@5) corner:(95@95)).
with wide lines, the corners (of polygons or rectangles) can be one of the joinStyles: #miter, #bevel, #round. The default is #miter.
    |v|

    v := View new extent:200@200.
    v openAndWait.

    v lineWidth:15.
    v paint:(Color red).

    v displayRectangle:((65@65) corner:(135@135)).

    v joinStyle:#bevel.
    v displayRectangle:((45@45) corner:(155@155)).

    v joinStyle:#round.
    v displayRectangle:((25@25) corner:(175@175)).
the endPoints look is controlled with capStyle; possible values are: #notLast, #butt, #round, #projecting. The default is #butt. #notLast is mostly useful when exoring (inverting): it will not draw the endPoint, to allow another line to join the previous line without inverting this point twice. (See the X manual for more info).
    |v|

    v := View new extent:200@200.
    v openAndWait.

    v lineWidth:15.
    v paint:(Color red).

    v displayLineFrom:(25@25) to:(175@25).

    v capStyle:#round.
    v displayLineFrom:(25@55) to:(175@55).

    v capStyle:#projecting.
    v displayLineFrom:(25@85) to:(175@85).
You can use a bitmap as a point color: (this may be slow on some graphics devices, though)
    |v|

    v := View new extent:200@200.
    v openAndWait.

    v lineWidth:15.
    v paint:(Image fromFile:'granite_small.tiff').

    v displayLineFrom:(25@25) to:(175@25).

    v capStyle:#round.
    v displayLineFrom:(25@55) to:(175@55).

    v capStyle:#projecting.
    v displayLineFrom:(25@85) to:(175@85).
all views support a translation and scale, so you can draw in another coordinate system:
    |v|

    v := View new extent:200@200.
    v openAndWait.

    v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.

    v scale:(2@2); translation:50.
    v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.

    v scale:(0.5@0.5); translation:0.
    v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
if scaling is on, it is often useful to be able to draw individual things unscaled - this still translates the position, but uses the unscaled font (for example, to draw strings in a graphic):
    |v|

    v := View new extent:200@200.
    v openAndWait.

    v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
    v displayString:'hello' x:50 y:40.

    v scale:(2@4).
    v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
    v displayUnscaledString:'hello' x:50 y:40.
Filled objects are drawin using the #fillXXX methods; for example, displayRectangleXXX draws the outline, while fillRectangleXXX draws a filled one:
    |v|

    v := View new extent:200@200.
    v openAndWait.

    v displayArcIn:(20@20 corner:50@50) from:0 angle:180.
    v paint:Color yellow.
    v fillArcIn:(120@120 corner:150@150) from:0 angle:180.

    v paint:Color red.
    v displayCircle:150@50 radius:30.
    v paint:Color blue.
    v fillCircle:50@150 radius:30.
polygons:
    |v poly1 poly2|

    poly1 := OrderedCollection new.
    poly1 add:(10 @ 10).
    poly1 add:(100 @ 50).
    poly1 add:(50 @ 50).
    poly1 add:(20 @ 100).
    poly1 add:(10 @ 100).

    poly2 := poly1 copy.
    poly2 add:(poly2 first).

    v := View new extent:200@200.
    v openAndWait.

    v scale:2.
    v paint:Color red.
    v fillPolygon:poly1.

    v scale:1.
    v paint:Color blue.
    v displayPolygon:poly2.

    v scale:0.5.
    v paint:Color yellow.
    v fillPolygon:poly1.



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 16:01:47 GMT