Section 4

There are just 2 places we need to modify in our code to use the new arrow/cursor behavior. For the instance method #mouseLeave:forMorph: on the class LaserGame needs to be enhanced to ensure the cursor gets reset to the default whenever the pointer leaves the game board. Here's the modified method.

mouseLeave: evt forMorph: aSketchMorph
    evt hand removeMouseListener: self.
    self sweepDirtyCells.
    self changed.
    self currentHand showTemporaryCursor: nil

The new piece of code is that "self currentHand showTemporaryCursor: nil" line. That will set the cursor's current cursor to be the default. This happens when the cursor is set to "nil". We will execute this whenever the pointer leaves the game board.

On the MirrorCellRenderer we must change the #showPositionHintFromWithinBoardOffset: instance method to set the cursor to be our new cross hair form. There's also some reformat of the previous version of this method.

showPositionHintFromWithinBoardOffset: aPoint     | cellPosn offsetWithinCell regionClass arrowAndOffset |
    cellPosn := self offsetWithinGridForm.
    offsetWithinCell := aPoint - cellPosn.
    regionClass := CellClickRegion clickRegionForPoint: offsetWithinCell.
    arrowAndOffset := regionClass scaledHintArrowAndOffsetFromWithinCell: offsetWithinCell.
    arrowAndOffset isNil
        ifTrue: [self currentHand showTemporaryCursor: nil]
        ifFalse: [
            | permissionToActOnCell arrowColor arrow offset |
            permissionToActOnCell := regionClass
                                        canActOnCellAtPoint: offsetWithinCell
                                        cell: self cell
                                        withinGrid: self grid.
            arrowColor := permissionToActOnCell
                ifTrue: [LaserGameColors allowActionArrowColor]
                ifFalse: [LaserGameColors denyActionArrowColor].
            arrow := arrowAndOffset value.
            offset := arrowAndOffset key.
            offset := self offsetWithinGridForm + offset.
                displayOn: self targetForm
                at: offset
                clippingBox: self targetForm computeBoundingBox
                rule: Form oldPaint
                fillColor: arrowColor.
            self currentHand
                showTemporaryCursor: LaserGameForms crossHair
                hotSpotOffset: (LaserGameForms crossHair extent // 2)]

Index Page Next Page

Copyright © 2007, 2008, 2009, 2010 Stephan B Wessels