[comp.lang.smalltalk] A SMALLtalk-80 goodie

pieter@prls.UUCP (Pieter van der Meulen) (03/10/89)

The following example allows you to create new Cursor
from a small String, e.g. 'S', 'III', or (5 printString).
A simple count down example is included in the comment
of the method below.

Have fun, Pieter.

----------------------cut here--------------------------
!Cursor class methodsFor: 'instance creation'!

fromString: aString emphasis: anInteger
	"Create a Cursor specified by aString. 
	Be sure to keep aString small, e.g. 'S' or '2'.
	The emphasis is specified by anInteger and
	could be 1 (normal), 2 (bold), 3 (italic), etc.
	Written by Pieter S. van der Meulen."

	"Cursor blank showWhile: [9 to: 0 by: -1 do: [:aNumber | 
		(Cursor fromString: aNumber printString emphasis: 2) 
			showWhile: [(Delay forMilliseconds: 500) wait]]]"

	| aForm aCursor |
	aForm _ (Text string: aString emphasis: anInteger) asDisplayText form.
	aCursor _ Cursor
				extent: 16 @ 16
				fromArray: #(65535 32769 32769 32769 32769
32769 32769 32769 32769 32769 32769 32769 32769 32769 32769 65535)
				offset: 0 @ 0.
	aCursor
		copyBits: aForm boundingBox
		from: aForm
		at: 8 @ 8 - aForm boundingBox center
		clippingBox: (aCursor boundingBox insetBy: 1 @ 1)
		rule: Form over
		mask: Form black.
	^aCursor! !
----------------------cut here--------------------------
-- 
---------------------------------------------
P.S. van der Meulen, MS 02        prls!pieter
PRLS, Signetics div. of NAPC      -----------
811 E.Arques Avenue, Sunnyvale, CA 94088-3409