WindowingTransformation.st
author Claus Gittinger <cg@exept.de>
Tue, 23 Apr 1996 22:12:21 +0200
changeset 601 2c4c1e797909
parent 219 9ff0660f447f
child 611 e0442439a3c6
permissions -rw-r--r--
commentary
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     1
"
48194c26a46c Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1992 by Claus Gittinger
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
     3
	      All Rights Reserved
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     4
48194c26a46c Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
48194c26a46c Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
48194c26a46c Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
48194c26a46c Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
48194c26a46c Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
48194c26a46c Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
48194c26a46c Initial revision
claus
parents:
diff changeset
    11
"
48194c26a46c Initial revision
claus
parents:
diff changeset
    12
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    13
Object subclass:#WindowingTransformation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    14
	instanceVariableNames:'scale translation'
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    15
	classVariableNames:''
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    16
	poolDictionaries:''
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    17
	category:'Graphics-Support'
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    18
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    19
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    20
!WindowingTransformation class methodsFor:'instance creation'!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    21
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    22
identity
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    23
    "returns a windowing transformation with no scaling (1@1) 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    24
     and no translation (0@0)."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    25
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    26
    ^ self basicNew scale:nil translation:nil 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    27
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    28
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    29
scale:aScale translation:aTranslation 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    30
    "returns a windowing transformation with a scale factor of  
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    31
     aScale and a translation offset of aTranslation."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    32
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    33
    ^ self basicNew scale:aScale translation:aTranslation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    34
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    35
    "
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    36
     |v|
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    37
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    38
     v := View new realize.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    39
     (Delay forSeconds:3) wait.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    40
     v transformation:(WindowingTransformation scale:2 translation:0).
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    41
     'now, everything is magnfied by 2'.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    42
     v displayLineFrom:10@10 to:30@30 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    43
    "
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    44
    "
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    45
     |v|
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    46
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    47
     v := View new realize.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    48
     (Delay forSeconds:3) wait.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    49
     v transformation:(WindowingTransformation scale:0.5 translation:0).
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    50
     'now, everything is shrunk by 2'.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    51
     v displayLineFrom:10@10 to:30@30 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    52
    "
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    53
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    54
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    55
unit:unitSymbol on:device 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    56
    "returns a windowing transformation with scaling 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    57
     for unitSymbol and no translation (0@0).
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    58
     With such a transformation, you can draw in your preferred 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    59
     units.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    60
     UnitSymbol may be #mm, #cm, #inch, #point, #twip or #pixel (default).
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    61
     Twip is 1/20th of a point, point is 1/72th of an inch
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    62
     (i.e. the print-unit which is also used for font sizes etc.) 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    63
     - not to confuse with device pixels."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    64
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    65
    |pixelPerUnitV pixelPerUnitH|
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
    66
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    67
    unitSymbol == #mm ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    68
	pixelPerUnitV := device verticalPixelPerMillimeter.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    69
	pixelPerUnitH := device horizontalPixelPerMillimeter 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    70
    ] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    71
	unitSymbol == #cm ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    72
	    pixelPerUnitV := device verticalPixelPerMillimeter * 10.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    73
	    pixelPerUnitH := device horizontalPixelPerMillimeter * 10 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    74
	] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    75
	    unitSymbol == #twip ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    76
		pixelPerUnitV := device verticalPixelPerInch / 1440.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    77
		pixelPerUnitH := device horizontalPixelPerInch / 1440 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    78
	    ] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    79
		unitSymbol == #point ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    80
		    pixelPerUnitV := device verticalPixelPerInch / 72.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    81
		    pixelPerUnitH := device horizontalPixelPerInch / 72 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    82
		] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    83
		    unitSymbol == #inch ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    84
			pixelPerUnitV := device verticalPixelPerInch.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    85
			pixelPerUnitH := device horizontalPixelPerInch 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    86
		    ] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    87
			"sorry: unknown unit is taken as pixel"
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    88
			^ self new scale:nil translation:nil
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    89
		    ]
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    90
		]
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    91
	    ]
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    92
	]
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    93
    ].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    94
    ^ self basicNew scale:(pixelPerUnitH @ pixelPerUnitV) translation:nil
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    95
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    96
    "
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    97
     |v|
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    98
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    99
     v := View new realize.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   100
     (Delay forSeconds:3) wait.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   101
     v transformation:(WindowingTransformation unit:#inch on:Display).
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   102
     'now, we can think of drawing in inches ...'.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   103
     v displayLineFrom:0.5@0.5 to:1@1 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   104
    "
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   105
!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   106
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   107
window:sourceRectangle viewport:destinationRectangle 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   108
    "returns a windowing transformation with a scale and
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   109
     translation computed from sourceRectangle and destinationRectangle.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   110
     The scale and transformation are computed such that sourceRectangle
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   111
     is transformed to destinationRectangle. Typically sourceRectangle
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   112
     represents the logical coordinateSpace while destinationRectangle 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   113
     represents the device coordinateSpace."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   114
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   115
    |sX sY tX tY newScale newTranslation|
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   116
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   117
    sX := destinationRectangle width / sourceRectangle width.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   118
    sY := destinationRectangle height / sourceRectangle height.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   119
    tX := destinationRectangle left - sourceRectangle left.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   120
    tY := destinationRectangle top - sourceRectangle top.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   121
    ((tX = 1.0) and:[tY = 1.0]) ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   122
	newTranslation := nil
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   123
    ] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   124
	newTranslation := tX @ tY
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   125
    ].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   126
    ((sX = 1.0) and:[sY = 1.0]) ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   127
	newScale := nil
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   128
    ] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   129
	newScale := sX @ sY
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   130
    ].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   131
    ^ self basicNew scale:newScale translation:newTranslation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   132
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   133
    "
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   134
     |v|
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   135
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   136
     v := View new realize.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   137
     (Delay forSeconds:3) wait.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   138
     v transformation:(WindowingTransformation 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   139
				window:(0@0 corner:1@1)
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   140
				viewport:(0@0 corner:100@100)).
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   141
     'now, we can think of drawing in 0..1/0..1 coordinates'.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   142
     v displayLineFrom:0.1@0.1 to:0.9@0.9 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   143
    "
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   144
! !
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   145
78
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   146
!WindowingTransformation class methodsFor:'documentation '!
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   147
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   148
copyright
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   149
"
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   150
 COPYRIGHT (c) 1992 by Claus Gittinger
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   151
	      All Rights Reserved
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   152
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   153
 This software is furnished under a license and may be used
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   154
 only in accordance with the terms of that license and with the
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   155
 inclusion of the above copyright notice.   This software may not
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   156
 be provided or otherwise made available to, or used by, any
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   157
 other person.  No title to or ownership of the software is
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   158
 hereby transferred.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   159
"
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   160
!
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   161
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   162
documentation
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   163
"
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   164
    instances of WindowingTransformation can be used to scale, translate or
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   165
    generally transform other objects in 2D space. 
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   166
    They can also be set as the translation in a graphic context, 
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   167
    which will then apply this to all of its drawing operations 
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   168
    (see GraphicContext>>transformation:).
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   169
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   170
    All 2-D objects are supposed to be able to be transformed using
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   171
    instances of me.  Multiple instances of me can also be combined to form a
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   172
    single composite transformation.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   173
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   174
    Instance variables are:
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   175
	scale           <Number> or <Point> representing a linear scaling factor.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   176
			nil is interpreted as 1@1
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   177
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   178
	translation     <Number> or <Point> representing a translation in 2-D.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   179
			nil is interpreted as 0@0
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   180
81
4ba554473294 *** empty log message ***
claus
parents: 78
diff changeset
   181
"
4ba554473294 *** empty log message ***
claus
parents: 78
diff changeset
   182
!
78
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   183
81
4ba554473294 *** empty log message ***
claus
parents: 78
diff changeset
   184
examples
4ba554473294 *** empty log message ***
claus
parents: 78
diff changeset
   185
"
78
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   186
    example (drawing in inches):
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   187
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   188
     |v|
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   189
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   190
     v := View new realize.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   191
     (Delay forSeconds:3) wait.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   192
     v transformation:(WindowingTransformation unit:#inch on:Display).
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   193
     'now, we can think of drawing in inches ...'.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   194
     v displayLineFrom:0.5@0.5 to:1@1 
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   195
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   196
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   197
    example (drawing in millimeters):
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   198
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   199
     |v|
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   200
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   201
     v := View new realize.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   202
     (Delay forSeconds:3) wait.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   203
     v transformation:(WindowingTransformation unit:#mm on:Display).
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   204
     'now, we can think of drawing in millimeters ...'.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   205
     v displayLineFrom:5@5 to:20@5 
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   206
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   207
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   208
    example (drawing magnified):
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   209
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   210
     |v|
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   211
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   212
     v := View new realize.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   213
     (Delay forSeconds:3) wait.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   214
     v transformation:(WindowingTransformation scale:2 translation:0).
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   215
     'now, everything is magnfied by 2'.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   216
     v displayLineFrom:10@10 to:30@30 
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   217
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   218
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   219
    example (drawing shrunk):
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   220
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   221
     |v|
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   222
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   223
     v := View new realize.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   224
     (Delay forSeconds:3) wait.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   225
     v transformation:(WindowingTransformation scale:0.5 translation:0).
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   226
     'now, everything is shrunk by 2'.
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   227
     v displayLineFrom:10@10 to:30@30 
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   228
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   229
"
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   230
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   231
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   232
version
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   233
    ^ '$Header: /cvs/stx/stx/libview/WindowingTransformation.st,v 1.11 1996-04-23 20:10:42 cg Exp $'
78
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   234
! !
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   235
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   236
!WindowingTransformation methodsFor:'accessing'!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   237
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   238
scale
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   239
    "return a copy of the Point that represents the
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   240
     current scale of the receiver."
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   241
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   242
    scale isNil ifTrue:[^ (1@1) copy].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   243
    ^ scale copy
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   244
!
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   245
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   246
scale:aScale
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   247
    "Set the receiver's scale to aScale, a Point or Number."
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   248
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   249
    aScale isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   250
	scale := aScale
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   251
    ] ifFalse:[
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   252
	scale := aScale asPoint.
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   253
    ].
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   254
!
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   255
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   256
scale:aScale translation:aTranslation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   257
    "sets the scale to aScale and the translation to aTranslation."
78
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   258
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   259
    aScale isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   260
	scale := aScale
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   261
    ] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   262
	scale := aScale asPoint.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   263
    ].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   264
    aTranslation isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   265
	translation := aTranslation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   266
    ] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   267
	translation := aTranslation asPoint
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   268
    ]
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   269
!
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   270
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   271
scaleOfOne
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   272
    "Set the scale of the receiver to the identity scale"
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   273
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   274
    scale := nil
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   275
!
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   276
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   277
translation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   278
    "return a copy of the receiver's translation."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   279
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   280
    translation isNil ifTrue:[^ (0@0) copy].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   281
    ^ translation copy
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   282
!
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   283
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   284
translation:aTranslation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   285
    "Set the receiver's translation to aTranslation, a Point or Number."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   286
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   287
    aTranslation isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   288
	translation := aTranslation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   289
    ] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   290
	translation := aTranslation asPoint
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   291
    ]
46
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
   292
! !
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   293
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   294
!WindowingTransformation methodsFor:'applying transform'!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   295
78
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   296
applyInverseScaleX:aNumber
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   297
    "apply the scale only (if widths are to be transformed)"
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   298
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   299
    scale isNil ifTrue:[^ aNumber].
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   300
    ^ aNumber / scale x
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   301
!
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   302
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   303
applyInverseScaleY:aNumber
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   304
    "apply the scale only (if heights are to be transformed)"
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   305
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   306
    scale isNil ifTrue:[^ aNumber].
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   307
    ^ aNumber / scale y
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   308
!
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   309
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   310
applyInverseTo:anObject 
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   311
    "Apply the inverse of the receiver to anObject
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   312
     and return the result. This can be used to map back from logical
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   313
     to physical coordinates, for example."
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   314
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   315
    |transformedObject|
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   316
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   317
    translation isNil ifTrue:[
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   318
	scale isNil ifTrue:[
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   319
	    ^ anObject
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   320
	].
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   321
	^ anObject scaledBy:self inverseScale 
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   322
    ].
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   323
    transformedObject := anObject translatedBy:(self inverseTranslation).
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   324
    scale notNil ifTrue:[
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   325
	transformedObject scaleBy:(self inverseScale).
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   326
    ].
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   327
    ^ transformedObject
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   328
!
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   329
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   330
applyInverseToX:aNumber
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   331
    "Apply the receiver to a number representing an x-coordinate
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   332
     and return the result."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   333
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   334
    |t s|
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   335
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   336
    scale isNil ifTrue:[s := 1] ifFalse:[s := scale x].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   337
    translation isNil ifTrue:[t := 0] ifFalse:[t := translation x].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   338
    ^ (aNumber - t) / s
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   339
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   340
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   341
applyInverseToY:aNumber
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   342
    "Apply the receiver to a number representing an y-coordinate
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   343
     and return the result."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   344
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   345
    |t s|
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   346
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   347
    scale isNil ifTrue:[s := 1] ifFalse:[s := scale y].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   348
    translation isNil ifTrue:[t := 0] ifFalse:[t := translation y].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   349
    ^ (aNumber - t) / s
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   350
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   351
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   352
applyScaleX:aNumber
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   353
    "apply the scale only (if widths are to be transformed)"
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   354
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   355
    scale isNil ifTrue:[^ aNumber].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   356
    ^ aNumber * scale x
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   357
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   358
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   359
applyScaleY:aNumber
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   360
    "apply the scale only (if heights are to be transformed)"
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   361
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   362
    scale isNil ifTrue:[^ aNumber].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   363
    ^ aNumber * scale y
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   364
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   365
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   366
applyTo:anObject 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   367
    "Apply the receiver to anObject and return the result."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   368
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   369
    |transformedObject|
78
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   370
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   371
    scale isNil ifTrue:[
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   372
	translation isNil ifTrue:[
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   373
	    ^ anObject
78
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   374
	].
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   375
	^ anObject translatedBy:translation 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   376
    ].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   377
    transformedObject := anObject scaledBy:scale.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   378
    translation notNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   379
	transformedObject translateBy:translation.
78
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   380
    ].
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   381
    ^ transformedObject
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   382
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   383
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   384
applyToX:aNumber
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   385
    "Apply the receiver to a number representing an x-coordinate
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   386
     and return the result."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   387
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   388
    |t s|
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   389
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   390
    scale isNil ifTrue:[s := 1] ifFalse:[s := scale x].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   391
    translation isNil ifTrue:[t := 0] ifFalse:[t := translation x].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   392
    ^ aNumber * s + t
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   393
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   394
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   395
applyToY:aNumber
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   396
    "Apply the receiver to a number representing an y-coordinate
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   397
     and return the result."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   398
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   399
    |t s|
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   400
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   401
    scale isNil ifTrue:[s := 1] ifFalse:[s := scale y].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   402
    translation isNil ifTrue:[t := 0] ifFalse:[t := translation y].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   403
    ^ aNumber * s + t
78
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   404
!
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   405
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   406
compose:aTransformation 
48194c26a46c Initial revision
claus
parents:
diff changeset
   407
    "return a new WindowingTransformation that is the
48194c26a46c Initial revision
claus
parents:
diff changeset
   408
     composition of the receiver and aTransformation.
48194c26a46c Initial revision
claus
parents:
diff changeset
   409
     The effect of applying the resulting WindowingTransformation
48194c26a46c Initial revision
claus
parents:
diff changeset
   410
     to an object is the same as that of first applying
48194c26a46c Initial revision
claus
parents:
diff changeset
   411
     aTransformation to the object and then applying the 
48194c26a46c Initial revision
claus
parents:
diff changeset
   412
     receiver to its result."
48194c26a46c Initial revision
claus
parents:
diff changeset
   413
48194c26a46c Initial revision
claus
parents:
diff changeset
   414
    |aTransformationScale newScale newTranslation|
48194c26a46c Initial revision
claus
parents:
diff changeset
   415
48194c26a46c Initial revision
claus
parents:
diff changeset
   416
    aTransformationScale := aTransformation scale.
78
1c9c22df3251 *** empty log message ***
claus
parents: 72
diff changeset
   417
    scale isNil ifTrue:[
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   418
	aTransformation noScale ifTrue:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   419
	    newScale := nil
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   420
	] ifFalse:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   421
	    newScale := aTransformationScale
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   422
	].
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   423
	newTranslation := translation + aTransformation translation
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   424
    ] ifFalse:[
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   425
	aTransformation noScale ifTrue:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   426
	    newScale := scale
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   427
	] ifFalse:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   428
	    newScale := scale * aTransformationScale
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   429
	].
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   430
	newTranslation := translation
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   431
			  + (scale * aTransformation translation)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   432
    ].
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   433
    ^ (self class) 
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   434
	  scale:newScale
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   435
	  translation:newTranslation
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   436
!
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   437
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   438
transformPoint:p 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   439
    "Apply the receiver to a point.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   440
     This is destructive in that the point is being modified,
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   441
     not a copy."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   442
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   443
    scale isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   444
	translation isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   445
	    ^ p
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   446
	].
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   447
	^ p + translation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   448
    ].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   449
    translation isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   450
	^ p * scale
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   451
    ].
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   452
    ^ (p * scale + translation)
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   453
! !
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   454
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   455
!WindowingTransformation methodsFor:'printing'!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   456
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   457
printOn:aStream
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   458
    aStream nextPutAll:self class name.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   459
    aStream nextPutAll:' scale: '.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   460
    scale printOn:aStream.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   461
    aStream nextPutAll:' translation: '.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   462
    translation printOn:aStream
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   463
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   464
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   465
!WindowingTransformation methodsFor:'private'!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   466
48194c26a46c Initial revision
claus
parents:
diff changeset
   467
checkScale:aScale
48194c26a46c Initial revision
claus
parents:
diff changeset
   468
    "Converts aScale to the internal format of a floating-point Point."
48194c26a46c Initial revision
claus
parents:
diff changeset
   469
48194c26a46c Initial revision
claus
parents:
diff changeset
   470
    |checkedScale|
48194c26a46c Initial revision
claus
parents:
diff changeset
   471
48194c26a46c Initial revision
claus
parents:
diff changeset
   472
    checkedScale := aScale asPoint.
48194c26a46c Initial revision
claus
parents:
diff changeset
   473
    ^ Point x:checkedScale x asFloat
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   474
	    y:checkedScale y asFloat
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   475
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   476
48194c26a46c Initial revision
claus
parents:
diff changeset
   477
inverseScale
48194c26a46c Initial revision
claus
parents:
diff changeset
   478
    "return with a Point representing the inverse of my
48194c26a46c Initial revision
claus
parents:
diff changeset
   479
     scale."
48194c26a46c Initial revision
claus
parents:
diff changeset
   480
48194c26a46c Initial revision
claus
parents:
diff changeset
   481
    |newScale|
48194c26a46c Initial revision
claus
parents:
diff changeset
   482
48194c26a46c Initial revision
claus
parents:
diff changeset
   483
    newScale := self checkScale:scale.
48194c26a46c Initial revision
claus
parents:
diff changeset
   484
    ^ Point x:(1.0 / newScale x)
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   485
	    y:(1.0 / newScale y)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   486
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   487
48194c26a46c Initial revision
claus
parents:
diff changeset
   488
inverseTranslation
48194c26a46c Initial revision
claus
parents:
diff changeset
   489
    "return with a Point representing the inverse of my
48194c26a46c Initial revision
claus
parents:
diff changeset
   490
     translation."
48194c26a46c Initial revision
claus
parents:
diff changeset
   491
48194c26a46c Initial revision
claus
parents:
diff changeset
   492
    |trans|
48194c26a46c Initial revision
claus
parents:
diff changeset
   493
48194c26a46c Initial revision
claus
parents:
diff changeset
   494
    trans := translation asPoint.
48194c26a46c Initial revision
claus
parents:
diff changeset
   495
    ^ Point x:trans x negated
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   496
	    y:trans y negated
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   497
! !
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   498
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   499
!WindowingTransformation methodsFor:'testing'!
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   500
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   501
noScale
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   502
    "return true if the identity scale is in effect;
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   503
     return false, otherwise."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   504
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   505
    ^ scale == nil
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   506
! !
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   507
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   508
!WindowingTransformation methodsFor:'transforming'!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   509
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   510
scaleBy:aScale 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   511
    "scale the receiver.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   512
     This is a destructive operation, modifying the transformation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   513
     represented by the receiver"
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   514
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   515
    |newScale|
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   516
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   517
    aScale isNil ifTrue:[^ self].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   518
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   519
    scale isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   520
	newScale := aScale asPoint
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   521
    ] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   522
	newScale := scale * aScale
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   523
    ].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   524
    translation notNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   525
	translation := translation * aScale.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   526
    ].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   527
    scale := newScale.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   528
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   529
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   530
scaledBy:aScale 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   531
    "return a new WindowingTransformation with the scale and translation of 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   532
     the receiver both scaled by aScale."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   533
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   534
    |checkedScale newScale newTranslation|
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   535
601
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   536
    aScale isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   537
	newScale := scale.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   538
	newTranslation := translation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   539
    ] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   540
	checkedScale := self checkScale:aScale.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   541
	scale isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   542
	    newScale := checkedScale
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   543
	] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   544
	    newScale := scale * checkedScale
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   545
	].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   546
	translation notNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   547
	    newTranslation := checkedScale * translation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   548
	]
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   549
    ].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   550
    ^ (self class) 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   551
	  scale:newScale
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   552
	  translation:newTranslation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   553
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   554
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   555
translateBy:aTranslation 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   556
    "translate the receiver.
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   557
     This is a destructive operation, modifying the transformation
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   558
     represented by the receiver"
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   559
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   560
    aTranslation isNil ifTrue:[^ self].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   561
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   562
    translation isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   563
	translation := 0@0
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   564
    ].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   565
    scale isNil ifTrue:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   566
	translation := translation + aTranslation asPoint
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   567
    ] ifFalse:[
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   568
	translation := translation + (scale * aTranslation)
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   569
    ].
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   570
!
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   571
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   572
translatedBy:aPoint 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   573
    "return a new WindowingTransformation with the same scale and 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   574
     rotations as the receiver and with a translation of the current 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   575
     translation plus aPoint."
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   576
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   577
    ^ (self class) 
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   578
	  scale:scale
2c4c1e797909 commentary
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   579
	  translation:(translation + aPoint)
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   580
! !
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   581