|
Class: GraphicsContext
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
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
copyrightCOPYRIGHT (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.
Signal constants
-
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
-
defaultFont
-
get the default font used for drawing
-
defaultFont: aFont
-
set the default font used for drawing
constants
-
capButt
-
return a constant to specify butt cap
-
capNotLast
-
return a constant to specify not-last cap
-
capProjecting
-
return a constant to specify projecting cap
-
capRound
-
return a constant to specify round cap
-
joinBevel
-
return a constant to specify bevel join
-
joinMiter
-
return a constant to specify miter join
-
joinRound
-
return a constant to specify round join
initialization
-
initialize
-
setup some defaults - these are usually redefined
during startup.
instance creation
-
new
-
return a new instance of myself. Redefined to initialize
the new thingy
queries
-
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.
Compatibility-ST80
-
displayArc: origin radius: radius from: startAngle angle: angle
-
draw an arc around a point
-
displayArcBoundedBy: boundingBox startAngle: startAngle sweepAngle: sweepAngle
-
draw an arc/circle/ellipse - ST-80 compatibility
-
displayArcBoundedBy: boundingBox startAngle: startAngle sweepAngle: sweepAngle at: origin
-
draw an arc/circle/ellipse - ST-80 compatibility
-
displayLineFrom: startPoint to: endPoint translateBy: anOffset
-
draw a line - ST-80 compatibility
-
displayPolyline: aPolygon
-
draw a polygon - ST-80 compatibility
-
displayRectangularBorder: aRectangle
-
draw a rectangle - ST-80 compatibility
-
displayRectangularBorder: aRectangle at: aPoint
-
draw a rectangle - ST-80 compatibility
-
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.
-
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.
-
findFont: aFontDescription
-
given a fontDescription, return a device font for it
on my device.
-
phase
-
return the origin within the mask (used to draw with patterns).
This is an alias for ST/X's #maskOrigin
-
phase: aPoint
-
set the origin within the mask (used to draw with patterns).
This is an alias for ST/X's #maskOrigin:
-
setDevicePattern: aColorOrMask
-
ST/X can paint in any color or image
-
tilePhase
-
return the origin within the mask (used to draw with patterns).
This is an alias for ST/X's #maskOrigin
-
tilePhase: aPoint
-
set the origin within the mask (used to draw with patterns).
This is an alias for ST/X's #maskOrigin
-
widthOfString: aString
-
given a string, return its width in pixels if
drawn on the receiver's device.
-
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
-
fill: aRectangle fillColor: aColor
-
fill a rectangle with the given color color
-
fillRectangle: aRectangle color: aColor
-
fill a rectangle with the given paint color
accessing
-
backgroundPaint
-
return the background paint color.
(used for opaqueForms and opaqueStrings)
-
backgroundPaint: aColor
-
set the background painting color (which is used for
opaqueForms and opaqueStrings). aColor can be a dithered one.
-
basicFont
-
return the font for drawing
-
blackColor
-
return the black color on this device.
This is the same as 'Color black onDevice:self device', but much faster.
-
capStyle
-
return the current cap-style for line-drawing.
possible styles are: #notLast, #butt, #round, #projecting
-
capStyle: aStyleSymbol
-
set the cap-style for line-drawing;
possible styles are: #notLast, #butt, #round, #projecting
-
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)
-
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.
-
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.
-
clippingBounds: aRectangleOrNil
-
set the clipping rectangle for drawing (in logical coordinates);
a nil argument turn off clipping (i.e. whole view is drawable)
-
clippingBoundsOrNil
-
return the clipping bounds (a Rectangle) for drawing in logical coordinates, nil if there is none.
-
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.
-
font
-
return the current drawing font
-
font: aFont
-
set the drawing font
** This method must be redefined in concrete classes (subclassResponsibility) **
-
function
-
return the current drawing function
-
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) **
-
graphicsContext
-
for ST-80 compatibility
-
graphicsDevice
-
same as #device, for ST-80 compatibility
-
joinStyle
-
return the current join-style for polygon-drawing.
possible styles are: #miter, #bevel, #round
-
joinStyle: aStyleSymbol
-
set the join-style of lines in polygon-drawing;
possible styles are: #miter, #bevel, #round
-
lineStyle
-
return the current line-drawing-style.
possible styles are: #solid, #dashed, #doubleDashed,
#dotted, #dashDot or #dashDotDot.
-
lineStyle: aStyleSymbol
-
set the line-drawing-style;
possible styles are: #solid, #dashed, #doubleDashed,
#dotted, #dashDot or #dashDotDot.
-
lineWidth
-
return the current drawing linewidth
-
lineWidth: aNumber
-
set the line drawing width in pixels
-
mask
-
return the current drawing mask
-
mask: aForm
-
set the drawing mask
** This method must be redefined in concrete classes (subclassResponsibility) **
-
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
-
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:
-
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:
-
medium
-
return the destination medium i.e. the underlying graphics device
-
paint
-
return the current paint drawing color
-
paint: aColor
-
set the drawing painting color, aColor can be a dithered one
-
paint: fgColor on: bgColor
-
set the paint and backgroundPaint, used for text and bitmaps.
Both colors may be dithered colors
-
setDevice: aDevice
-
-
viewOrigin
-
return the drawable's visible origin (for scrolling)
-
whiteColor
-
return the white color on this device.
This is the same as 'Color white onDevice:self device', but much faster.
accessing-transformation
-
scale
-
return the scale factor (as point) of the transformation
-
scale: aPoint
-
set the scale factor of the transformation
-
scale: scale translation: aPoint
-
-
transformation
-
return the transformation
-
transformation: aTransformation
-
set the transformation
-
translateBy: aPoint
-
add to the translation offset of the transformation
-
translation
-
return the translation factor (as point) of the transformation
-
translation: aPoint
-
set the translation offset of the transformation
basic drawing
-
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) **
-
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
-
displayHorizontalWavelineFromX: x0 y: y0 toX: x1
-
draw a horizontal wave-line from x0/y0 to x1/y0
-
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) **
-
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) **
-
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) **
-
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) **
-
displayPolygon: aPolygon
-
draw a polygon
- this could be recoded to draw using displayLine
** This method must be redefined in concrete classes (subclassResponsibility) **
-
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) **
-
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) **
-
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
-
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) **
-
fillPolygon: points
-
fill a polygon with current paint color
** This method must be redefined in concrete classes (subclassResponsibility) **
-
fillRectangleX: x y: y width: w height: h
-
fill a rectangle with current paint color
** This method must be redefined in concrete classes (subclassResponsibility) **
-
fillRectangleX: x y: y width: w height: h color: aColor
-
fill a rectangle with given color
drawing
-
display: someObject at: aPoint
-
draw someObject - this must understand the #displayOn:at: message
-
displayArcIn: aRectangle from: startAngle angle: angle
-
draw an arc in a box
-
displayArcOrigin: origin corner: corner from: startAngle angle: angle
-
draw an arc in a box
-
displayCircle: aPoint radius: r
-
draw a circle around a center point
-
displayCircleIn: aRectangle
-
draw a circle in a box
-
displayCircleX: x y: y radius: r
-
draw a circle around a center point
-
displayForm: aFormOrImage
-
draw a form (or image) at the origin
-
displayForm: aFormOrImage at: aPoint
-
draw a form (or image)
-
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) **
-
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.
-
displayImage: aFormOrImage
-
draw an image (or form).
Provided for ST-80 compatibilty;
in ST/X, images are also handled by #displayForm:
-
displayImage: aFormOrImage at: aPoint
-
draw an image (or form).
Provided for ST-80 compatibilty;
in ST/X, images are also handled by #displayForm:
-
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:
-
displayLineFrom: point1 to: point2
-
draw a line
-
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
-
displayOpaqueString: aString from: start to: stop at: aPoint
-
draw part of a string - drawing both fg and bg
-
displayOpaqueString: aString x: x y: y
-
draw a string with both fg and bg
-
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.
].
|
-
displayPoint: aPoint
-
draw a pixel
-
displayPointX: x y: y
-
draw a point at x/y
-
displayRectangle: aRectangle
-
draw a rectangle
-
displayRectangleOrigin: origin corner: corner
-
draw a rectangle
-
displayRectangleOrigin: origin extent: extent
-
draw a rectangle
-
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
|
-
displayString: aString at: aPoint
-
draw a string - drawing fg only
-
displayString: aString centeredAt: aPoint
-
draw a string - drawing fg only
-
displayString: aString centeredAtX: x y: y
-
draw a string - drawing fg only
-
displayString: aString from: start to: stop at: aPoint
-
draw part of a string - drawing fg only
-
displayString: aString x: x y: y
-
draw a string - drawing fg only
-
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.
|
-
displayString: aString x: x y: y angle: drawAngle opaque: opaque
-
** This method must be redefined in concrete classes (subclassResponsibility) **
drawing in device coordinates
-
displayDeviceLineFromX: x1 y: y1 toX: x2 y: y2
-
draw a line in device coordinates
-
displayDeviceRectangleX: x y: y width: w height: h
-
draw a rectangle in device coordinates
-
fillDeviceRectangleX: x y: y width: w height: h
-
fill a rectangle with current paint color (device coordinates)
edge drawing
-
drawEdgesForX: x y: y width: w height: h level: lvl
-
draw 3D edges into a rectangle
-
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
-
edgeDrawn: whichOne
-
a redefinable hook for views which like to draw
over their edges (some checkToggles do).
Nothing done here.
evaluating in another context
-
withFont: aFont do: aBlock
-
evaluate aBlock with changed drawing font.
-
withLineWidth: lw do: aBlock
-
evaluate aBlock with changed line width.
-
withPaint: fgColor do: aBlock
-
evaluate aBlock with changed paint color.
-
withPaint: fgColor on: bgColor do: aBlock
-
evaluate aBlock with changed paint color.
filling
-
clearRectangle: aRectangle
-
clear the rectangular area in the receiver to white
-
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.
-
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.
-
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.
-
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.
-
fillCircle: aPoint radius: aNumber
-
draw a filled circle around aPoint
-
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.
-
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.
-
fillRectangle: aRectangle
-
fill a rectangle with current paint color
-
fillRectangleLeft: left top: top right: cornerX bottom: cornerY
-
draw a filled rectangle.
Notice: the cornerPoint itself is NOT included
-
fillRectangleOrigin: origin corner: corner
-
draw a filled rectangle.
Notice: the cornerPoint itself is NOT included
-
fillRectangleOrigin: origin extent: extent
-
draw a filled rectangle.
Notice: the cornerPoint itself is NOT included
-
fillRectangleOrigin: origin width: w height: h
-
draw a filled rectangle.
Notice: the cornerPoint itself is NOT included
-
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
-
initialize
-
set up some useful default values
misc
-
clippedTo: aRectangle do: aBlock
-
-
flush
-
send all buffered drawing to the device.
-
sync
-
send all buffered drawing to the device and wait until the device responds
printing & storing
-
storeOn: aStream
-
blocked: ascii storeString not possible (recursive - view - subviews - container)
queries
-
fontAscent
-
answer the ascent of the current font on the current device
testing
-
isPSGraphicsContext
-
is this a postscript graphics context?
text printing
-
withLineStyle: aSymbol lineWidth: lw paint: paintColor do: aBlock
-
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.
|
|