|
|
Class: WindowingTransformation
Object
|
+--WindowingTransformation
- Package:
- stx:libview
- Category:
- Graphics-Transformations
- Version:
- rev:
1.22
date: 2004/05/07 12:03:59
- user: stefan
- file: WindowingTransformation.st directory: libview
- module: stx stc-classLibrary: libview
- Author:
- Claus Gittinger
instances of WindowingTransformation can be used to scale, translate or
generally transform other objects in 2D space.
They can also be set as the translation in a graphic context,
which will then apply this to all of its drawing operations
(see GraphicContext>>transformation:).
All 2-D objects are supposed to be able to be transformed using
instances of me. Multiple instances of me can also be combined to form a
single composite transformation.
[Instance variables:]
scale <Number> or <Point> representing a linear scaling factor.
nil is interpreted as 1@1
translation <Number> or <Point> representing a translation in 2-D.
nil is interpreted as 0@0
instance creation
-
identity
-
returns a windowing transformation with no scaling (1@1)
and no translation (0@0).
-
scale: aScale translation: aTranslation
-
returns a windowing transformation with a scale factor of
aScale and a translation offset of aTranslation.
-
unit: unitSymbol on: device
-
returns a windowing transformation with scaling
for unitSymbol and no translation (0@0).
With such a transformation, you can draw in your preferred
units.
UnitSymbol may be #mm, #cm, #inch, #point, #twip or #pixel (default).
Twip is 1/20th of a point, point is 1/72th of an inch
(i.e. the print-unit which is also used for font sizes etc.)
- not to confuse with device pixels.
-
window: sourceRectangle viewport: destinationRectangle
-
returns a windowing transformation with a scale and
translation computed from sourceRectangle and destinationRectangle.
The scale and transformation are computed such that sourceRectangle
is transformed to destinationRectangle. Typically sourceRectangle
represents the logical coordinateSpace while destinationRectangle
represents the device coordinateSpace.
accessing
-
scale
-
return a copy of the Point that represents the
current scale of the receiver.
-
scale: aScale
-
Set the receiver's scale to aScale, a Point or Number.
-
scale: aScale translation: aTranslation
-
sets the scale to aScale and the translation to aTranslation.
-
scaleOfOne
-
Set the scale of the receiver to the identity scale
-
scaleX
-
return the current x-scale of the receiver.
-
scaleY
-
return the current x-scale of the receiver.
-
translation
-
return a copy of the receiver's translation.
-
translation: aTranslation
-
Set the receiver's translation to aTranslation, a Point or Number.
-
translationX
-
return the receiver's x-translation.
-
translationY
-
return the receiver's x-translation.
applying transform
-
applyInverseScaleX: aNumber
-
apply the scale only (if widths are to be transformed)
-
applyInverseScaleY: aNumber
-
apply the scale only (if heights are to be transformed)
-
applyInverseTo: anObject
-
Apply the inverse of the receiver to anObject
and return the result. This can be used to map back from logical
to physical coordinates, for example.
-
applyInverseToX: aNumber
-
Apply the receiver to a number representing an x-coordinate
and return the result.
-
applyInverseToY: aNumber
-
Apply the receiver to a number representing an y-coordinate
and return the result.
-
applyScaleX: aNumber
-
apply the scale only (if widths are to be transformed)
-
applyScaleY: aNumber
-
apply the scale only (if heights are to be transformed)
-
applyTo: anObject
-
Apply the receiver to anObject and return the result.
-
applyToX: aNumber
-
Apply the receiver to a number representing an x-coordinate
and return the result.
-
applyToY: aNumber
-
Apply the receiver to a number representing an y-coordinate
and return the result.
-
compose: aTransformation
-
return a new WindowingTransformation that is the
composition of the receiver and aTransformation.
The effect of applying the resulting WindowingTransformation
to an object is the same as that of first applying
aTransformation to the object and then applying the
receiver to its result.
-
transformPoint: p
-
Apply the receiver to a point.
This is destructive in that the point is being modified,
not a copy.
printing & storing
-
printOn: aStream
-
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.
private
-
checkScale: aScale
-
Converts aScale to the internal format of a floating-point Point.
-
inverseScale
-
return with a Point representing the inverse of my
scale.
-
inverseTranslation
-
return with a Point representing the inverse of my
translation.
testing
-
noScale
-
return true if the identity scale is in effect;
return false, otherwise.
transformations
-
scaleBy: aScale
-
scale the receiver.
This is a destructive operation, modifying the transformation
represented by the receiver
-
scaledBy: aScale
-
return a new WindowingTransformation with the scale and translation of
the receiver both scaled by aScale.
-
translateBy: aTranslation
-
translate the receiver.
This is a destructive operation, modifying the transformation
represented by the receiver
-
translatedBy: aPoint
-
return a new WindowingTransformation with the same scale and
rotations as the receiver and with a translation of the current
translation plus aPoint.
example (drawing in inches):
|v|
v := View new realize.
(Delay forSeconds:3) wait.
v transformation:(WindowingTransformation unit:#inch on:Display).
'now, we can think of drawing in inches ...'.
v displayLineFrom:0.5@0.5 to:1@1
|
example (drawing in millimeters):
|v|
v := View new realize.
(Delay forSeconds:3) wait.
v transformation:(WindowingTransformation unit:#mm on:Display).
'now, we can think of drawing in millimeters ...'.
v displayLineFrom:5@5 to:20@5
|
example (drawing magnified):
|v|
v := View new realize.
(Delay forSeconds:3) wait.
v transformation:(WindowingTransformation scale:2 translation:0).
'now, everything is magnfied by 2'.
v displayLineFrom:10@10 to:30@30
|
example (drawing shrunk):
|v|
v := View new realize.
(Delay forSeconds:3) wait.
v transformation:(WindowingTransformation scale:0.5 translation:0).
'now, everything is shrunk by 2'.
v displayLineFrom:10@10 to:30@30
|
|