--- a/GC.st Wed Apr 23 01:04:31 1997 +0200
+++ b/GC.st Wed Apr 23 01:11:09 1997 +0200
@@ -1323,6 +1323,151 @@
self displayString:aString from:1 to:(aString size) x:x y:y
!
+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.
+ Not yet finished (only multiples of 90 degrees work)."
+
+ |angle tempForm tempImage w h asc desc a xN yN p r nBL nTL nB a1 a2
+ dX dY sin cos|
+
+ angle := drawAngle.
+ angle >= 360 ifTrue:[
+ angle := angle - (((angle // 360)) * 360)
+ ] ifFalse:[
+ angle < 0 ifTrue:[
+ angle := angle - (((angle // 360)) * 360).
+ angle := angle + 360
+ ].
+ ].
+
+ angle = 0 ifTrue:[
+ ^ self displayString:aString x:x y:y
+ ].
+
+ w := font widthOf:aString.
+ h := font height.
+ asc := font ascent.
+ desc := h - asc.
+
+ tempForm := Form
+ width:w
+ height:h
+ on:device.
+
+ tempForm clear.
+ tempForm displayString:aString x:0 y:asc.
+
+ tempImage := (Depth1Image fromForm:tempForm) rotated:angle.
+
+ "/ adjust position for baseline.
+
+ angle = 90 ifTrue:[
+ xN := x - desc.
+ yN := y.
+ ] ifFalse:[
+ angle = 180 ifTrue:[
+ xN := x - w.
+ yN := y - desc "+ h - asc".
+ ] ifFalse:[
+ angle = 270 ifTrue:[
+ xN := x - asc.
+ yN := y - w.
+ ] ifFalse:[
+ "/ sigh: since the new image has different dimensions,
+ "/ the computation is somewhat more difficult here.
+ "/ remember: the image has been rotated around its center,
+ "/ then shifted towards the top-left origin.
+ p := (w@h) / 2.
+ r := p r.
+ a := p angle.
+ sin := angle degreesToRadians sin.
+ cos := angle degreesToRadians cos.
+ angle < 90 ifTrue:[
+ dX := desc * sin.
+ dY := asc * cos.
+ xN := x - dX.
+ yN := y - dY
+ ] ifFalse:[
+ angle < 180 ifTrue:[
+ dX := asc * sin.
+ dY := desc * cos.
+ xN := x + dX - (tempImage width).
+ yN := y + dY.
+'..180 ' print. dX print. ' 'print. dY printCR.
+ ] ifFalse:[
+ angle < 270 ifTrue:[
+ dX := asc * sin.
+ dY := desc * cos.
+'..270 ' print. dX print. ' 'print. dY printCR.
+ xN := x - dX - (tempImage width).
+ yN := y - dY - (tempImage height)
+ ] ifFalse:[
+ ]
+ ]
+ ].
+
+ tempImage mask:nil.
+ ]
+ ].
+ ].
+ self displayForm:tempImage x:xN y:yN.
+
+ "
+ |v|
+
+ v := View new.
+ v extent:300@200.
+ v openAndWait.
+ 0 to:360 by:90 do:[:a |
+ v paint:Color black.
+ v displayString:'hello world' x:100 y:100 angle:a.
+ ].
+ "
+ "
+ |v|
+
+ v := View new.
+ v extent:300@200.
+ v openAndWait.
+ 0 to:265 by:5 do:[:a |
+ v paint:Color black.
+ v displayString:'.........' x:100 y:100 angle:a.
+ ].
+ "
+ "
+ |v|
+
+ v := View new.
+ v extent:200@100.
+ v openAndWait.
+ v displayString:'ghello' x:50 y:50 angle:0.
+ v displayString:'ghello' x:50 y:50 angle:45.
+ v displayString:'ghello' x:50 y:50 angle:90.
+ v displayString:'ghello' x:50 y:50 angle:180.
+ v displayString:'ghello' x:50 y:50 angle:270.
+ "
+ "
+ |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.
+ "
+
+ "Modified: 23.4.1997 / 01:10:34 / cg"
+!
+
fillArcX:x y:y w:w h:h from:startAngle angle:angle
"draw a filled arc; apply transformation if nonNil"
@@ -1627,6 +1772,6 @@
!GraphicsContext class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/Attic/GC.st,v 1.54 1997-04-01 21:12:40 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/Attic/GC.st,v 1.55 1997-04-22 23:11:09 cg Exp $'
! !
GraphicsContext initialize!
--- a/GraphicsContext.st Wed Apr 23 01:04:31 1997 +0200
+++ b/GraphicsContext.st Wed Apr 23 01:11:09 1997 +0200
@@ -1323,6 +1323,151 @@
self displayString:aString from:1 to:(aString size) x:x y:y
!
+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.
+ Not yet finished (only multiples of 90 degrees work)."
+
+ |angle tempForm tempImage w h asc desc a xN yN p r nBL nTL nB a1 a2
+ dX dY sin cos|
+
+ angle := drawAngle.
+ angle >= 360 ifTrue:[
+ angle := angle - (((angle // 360)) * 360)
+ ] ifFalse:[
+ angle < 0 ifTrue:[
+ angle := angle - (((angle // 360)) * 360).
+ angle := angle + 360
+ ].
+ ].
+
+ angle = 0 ifTrue:[
+ ^ self displayString:aString x:x y:y
+ ].
+
+ w := font widthOf:aString.
+ h := font height.
+ asc := font ascent.
+ desc := h - asc.
+
+ tempForm := Form
+ width:w
+ height:h
+ on:device.
+
+ tempForm clear.
+ tempForm displayString:aString x:0 y:asc.
+
+ tempImage := (Depth1Image fromForm:tempForm) rotated:angle.
+
+ "/ adjust position for baseline.
+
+ angle = 90 ifTrue:[
+ xN := x - desc.
+ yN := y.
+ ] ifFalse:[
+ angle = 180 ifTrue:[
+ xN := x - w.
+ yN := y - desc "+ h - asc".
+ ] ifFalse:[
+ angle = 270 ifTrue:[
+ xN := x - asc.
+ yN := y - w.
+ ] ifFalse:[
+ "/ sigh: since the new image has different dimensions,
+ "/ the computation is somewhat more difficult here.
+ "/ remember: the image has been rotated around its center,
+ "/ then shifted towards the top-left origin.
+ p := (w@h) / 2.
+ r := p r.
+ a := p angle.
+ sin := angle degreesToRadians sin.
+ cos := angle degreesToRadians cos.
+ angle < 90 ifTrue:[
+ dX := desc * sin.
+ dY := asc * cos.
+ xN := x - dX.
+ yN := y - dY
+ ] ifFalse:[
+ angle < 180 ifTrue:[
+ dX := asc * sin.
+ dY := desc * cos.
+ xN := x + dX - (tempImage width).
+ yN := y + dY.
+'..180 ' print. dX print. ' 'print. dY printCR.
+ ] ifFalse:[
+ angle < 270 ifTrue:[
+ dX := asc * sin.
+ dY := desc * cos.
+'..270 ' print. dX print. ' 'print. dY printCR.
+ xN := x - dX - (tempImage width).
+ yN := y - dY - (tempImage height)
+ ] ifFalse:[
+ ]
+ ]
+ ].
+
+ tempImage mask:nil.
+ ]
+ ].
+ ].
+ self displayForm:tempImage x:xN y:yN.
+
+ "
+ |v|
+
+ v := View new.
+ v extent:300@200.
+ v openAndWait.
+ 0 to:360 by:90 do:[:a |
+ v paint:Color black.
+ v displayString:'hello world' x:100 y:100 angle:a.
+ ].
+ "
+ "
+ |v|
+
+ v := View new.
+ v extent:300@200.
+ v openAndWait.
+ 0 to:265 by:5 do:[:a |
+ v paint:Color black.
+ v displayString:'.........' x:100 y:100 angle:a.
+ ].
+ "
+ "
+ |v|
+
+ v := View new.
+ v extent:200@100.
+ v openAndWait.
+ v displayString:'ghello' x:50 y:50 angle:0.
+ v displayString:'ghello' x:50 y:50 angle:45.
+ v displayString:'ghello' x:50 y:50 angle:90.
+ v displayString:'ghello' x:50 y:50 angle:180.
+ v displayString:'ghello' x:50 y:50 angle:270.
+ "
+ "
+ |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.
+ "
+
+ "Modified: 23.4.1997 / 01:10:34 / cg"
+!
+
fillArcX:x y:y w:w h:h from:startAngle angle:angle
"draw a filled arc; apply transformation if nonNil"
@@ -1627,6 +1772,6 @@
!GraphicsContext class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/GraphicsContext.st,v 1.54 1997-04-01 21:12:40 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/GraphicsContext.st,v 1.55 1997-04-22 23:11:09 cg Exp $'
! !
GraphicsContext initialize!