[Q] how to cache a drawn morph

Baveco, Hans Hans.Baveco at wur.nl
Wed Mar 2 21:28:21 UTC 2005


I have a morph that takes long to draw, with several submorph with extensive #drawOn: aCanvas methods.
I would like to cache the result of all this drawing of submorphs but can't figure out how to do this correctly, especially my problem is when & where to create this cache (a Form, I suppose). Adding the following naive method to my morph almost does it right, except that the created Form (the inst.var. image in the code below) will also have other morphs' content on it, when my morph is partly hidden by other morphs. The #forceToScreen: does not have any noticeable impact on the outcome, I think.
 
drawSubmorphsOn: aCanvas 
 "Display submorphs back to front. First attempt at caching a Form (otherwise this method should be deleted)"
 submorphs isEmpty ifTrue: [^self].
 (image isNil or: [image extent ~= self innerBounds extent])
  ifTrue: [super drawSubmorphsOn: aCanvas.
   aCanvas forceToScreen: self innerBounds.
   image := aCanvas contentsOfArea: self innerBounds]
  ifFalse: [aCanvas paintImage: image at: self innerBounds origin]
 
 
In the hierarchy of drawing morphs, this is probably not the right place to create/update the cache? How do I obtain a Form with only the drawings of my morph's submorphs on it?
Is there a standard way to achieve this caching (there is a CachingMorph somewhere, but I don't understand how it is supposed to work).. 
 
Any help much appreciated!
 
Hans
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 4842 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20050302/a397fbb8/attachment.bin


More information about the Squeak-dev mailing list