View become white when I Click away Smalltalk

70 views Asked by At

Hello so I have a Main application that draw a Circle and a rectangle but when I click away they juste disappear here is the code I use

initialize
shapesView := ShapesView new.
shapesModel := ShapesModel new.
shapesView model: shapesModel. 

and I have the component initialisation in

postOpenWith: aBuilder
shapesView initializeComponents.

in the ShapesView class I have aModel accessor and this methode , my Model and controller are still empty

initializeComponents
| shape gc|
gc := self graphicsContext.
gc paint: ColorValue red.
shape := MyRectangle origin: 2@2 extent: 50@75.
shape displayFilledOn: gc.
gc paint: ColorValue blue.
shape := MyCircle center: 100@100 radius: 50.
shape displayFilledOn: gc.
2

There are 2 answers

0
ArdenT On BEST ANSWER

As you found, for the shapes to be persistent, the drawing should be in a "displayOn: gc" method (as JayK mentioned) in the ShapeView class (instance side), which should do the drawing you specify: gc paint: ColorValue red.

shape := MyRectangle origin: 2@2 extent: 50@75.

shape displayFilledOn: gc.

gc paint: ColorValue blue.

shape := MyCircle center: 100@100 radius: 50.

shape displayFilledOn: gc.

The shapes could be created in an intializeComponents, but the api calls displayOn: whenever a re-display of the view is needed.
Changing the model or resizing the window will cause an invalidation and re-display. hth - Arden Thomas

0
Kay Tila On

What you need to do is to find out which method is being sent when the UI Element is gaining focus again. How this is done varies from Smalltalk dialect to dialect. The way, you have implemented this now just means you just draw it once. This does not mean it is being redrawn at all.