[squeak-dev] Form asSomethingOrOther

Bert Freudenberg bert at freudenbergs.de
Thu Aug 27 09:24:54 UTC 2009


On 27.08.2009, at 08:18, Colin Putney wrote:

>
> On 26-Aug-09, at 10:22 PM, Ronald Spengler wrote:
>
>> I have a Form (for use as a button) that I would like to serialize  
>> in a way that allows me to keep it as text in a method. I would  
>> like to do this the simplest way possible, optimizing for speed  
>> (not space.) Ideally it would look as much like this as possible:
>>
>> Foo>>someIcon
>>    ^ #( ... ) asForm
>>
>> What's the best way to do this?
>
> Create your form, then send #storeString to it. It will answer a  
> Smalltalk expression that recreates the form. Then just answer that  
> expression from your #someIcon method. OmniBrowser has a few  
> examples of this in the class OBMorphicIcons.


This is the simplest way, no doubt. If you care for the code size you  
might use something like the stuff below.

In this case, #storeString is 9371 bytes vs. 1580 bytes using a base64- 
encoded PNG (that compresses well).

- Bert -

biggerNormal
	"self biggerNormal show"
	"(Base64MimeConverter mimeEncode: ((FileStream readOnlyFileNamed:  
'EtoysCursor.png') binary)) upToEnd"

	^self constants at: #biggerNormal ifAbsentPut: [
		| form cursor |
		form := (PNGReadWriter on: (Base64MimeConverter mimeDecodeToBytes:
			'iVBORw0KGgoAAAANSUhEUgAAABsAAAArCAYAAACJrvP4AAAACXBIWXMAAAsTAAALEwEAmpwY
			AAAEF0lEQVRYCb2XS0hcVxjHj2/ 
G8ZWMQQbSGO2iRhERwRALBmJNoOOqwUXtYtxOTQJxI8SN
			CyXJqggVEghusrAuBB8IddUWF64CvnCj+AJrsYKio6JJOPn/j+dc5s6MztyZMR/ 
857v3PL7f
			/ 
c4595w7QmiTUvrN9ZV7wGhfB3jOunpgOoYtPQQm19fXn6DsulY2PJUSi4ARvLm5+SuiE5hS
			 
mAsBXSYzv99vLuXExMRL1H2jlRKoDYbAMhS4uLj4PJUwN4K5TTqEhQPHxsZeayCzTCrDqLC0
			tLQryTAqjNmFA1OR4YWwaMBk5/ 
BSWDRgMhnGhEUDJpphXDACqdDXIpEMHcHCF43TDB3Bks0w
			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			cnUQMx+f9P1H7c9PXyHUIcoy01HXX637AibwgHAnFRPGAAAAAElFTkSuQmCC'
				readStream)) nextImage.
		cursor := CursorWithAlpha extent: form extent depth: 32.
		form displayOn: cursor.
		cursor offset: -2 at -1.
		cursor preMultiplyAlpha.
		cursor]



More information about the Squeak-dev mailing list