" Views-world.st -- support for a windowful, windowful world Copyright (c) 2007 Ian Piumarta All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation. THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. Last edited: 2007-11-12 15:32:06 by piumarta on emilia.local " { import: Views } { import: Event } { import: EventHandler } WorldView : ShapedView ( eventHandler damage) WorldView new [ self := super new. eventHandler := EventHandler withWorld: self. ] WorldView damaged: aRectangle [ damage := damage = nil ifTrue: [aRectangle] ifFalse: [damage union: aRectangle]. ] WorldView forceDamageToScreenOn: aCanvas [ damage ifNil: [^self]. damage := (damage intersect: self bounds) expanded outsetBy: 2,2. aCanvas setClipRectangle: damage. self drawOn: aCanvas in: damage. " StdErr nextPutAll: damage printString; cr. aCanvas setSourceR: 0 G: 1 B: 0; rectangle: damage; setStrokeWidth: 1; stroke. " damage := nil. ] WorldView handleWorldEvent: anEvent [ "Event handler only for a world (quit, resize)" | handler | (handler := self propertyAt: anEvent name) ifNotNil: [handler value: self value: anEvent]. ^ anEvent handled ] WorldView mainLoop [ | event key | event := surface waitEvent. event ifNotNil: [ self dispatchEvent: event. ]. self forceDamageToScreenOn: surface painter. surface swapBuffers. ] WorldView dispatchEvent: anEvent [ anEvent handler: eventHandler. eventHandler handleEvent: anEvent. ] WorldView pushEventHandler: anEventHandler [ anEventHandler previous: eventHandler. eventHandler := anEventHandler. ] WorldView popEventHandler: anEventHandler [ eventHandler == anEventHandler ifFalse: [self error: 'non-LIFO event handlers']. eventHandler := eventHandler previous. ]