martin.drautzburg at web.de
Sun Apr 27 23:39:23 UTC 2003
ingo at 2b1.de writes:
You asked: How can I make it resizable?
I am a newbie myself, but this is what I'd do:
You need to draw your TicTacToe fields with respect to the owning Morph
(the TicTacToe). Therefore the TicTacToe field needs to know its row
and column and thus needs 2 more instance variables:
BorderedMorph subclass: #TicTacToeField
instanceVariableNames: 'mark row col '
You then initialize them by passing row and column. And you can forget
about all other geometry stuff during initialisation because the
TicTacToeField will take care of that:
| temp |
self extent: 300 @ 300.
turn _ 0.
winner _ nil.
do: [:x | 1
do: [:y |
temp _ TicTacToeField new row: y;
self addMorph: temp]]
Next thing is to compute the real geometry of TicTacToe field. Lets
put this into an extra method:
| height width posx posy |
height _ (owner height / 3) asInteger.
width _ (owner width / 3) asInteger.
self extent: width @ height.
posx _ self col - 1 * width.
posy _ self row - 1 * height.
self position: owner position + (posx @ posy)
This has to be called before we draw the field, so:
| markBounds |
super drawOn: canvas.
ifNotNil: [markBounds _ self bounds scaleBy: 0.75.
More information about the Squeak-dev