Previous Topic Tutorial Home Page Next Topic
Constructing the Interactive Image of the Puzzle


Construct the puzzle image as a composition of its distinct parts.
ImageBvr createImage() {

int i;
int j;
double x = 0;
double y = 0;
ImageBvr totalIm = emptyImage;

build up the cells
for (i = 0; i < _squares; i++, y += _inc) {
x = 0;
for (j = 0; j < _squares; j++, x += _inc) {

Skip the last one, to leave empty space.
if (i == _squares - 1 && j == _squares - 1) continue;

Crop to get next cell and move lower left corner to the origin.
ImageBvr croppedIm = _unitSourceIm.
crop(point2(toBvr(x), toBvr(y)),
point2(toBvr(x + _inc), toBvr(y + _inc)));
croppedIm = croppedIm.transform(translate(toBvr(-x), toBvr(-y)));

make pickable
PickableImage pick = new PickableImage(croppedIm);
ImageBvr pickableCroppedIm = pick.getImageBvr();

extract probe event and create pick event
DXMEvent probedEvent = pick.getPickEvent();
DXMEvent pickedEvent = andEvent(leftButtonDown, probedEvent);

Initially translate back to original space.
Transform2Bvr initXf = translate(toBvr(x), toBvr(y));

Allow transform to change as it's picked.
Transform2Bvr xf = (Transform2Bvr)
untilNotify(initXf, pickedEvent,
new ImagePicker(i, j, pickedEvent, this));

The entire cell is the transform applied to the cell at the origin.
ImageBvr movingIm = pickableCroppedIm.transform(xf);

accumulate the cells of the puzzle
totalIm = overlay(movingIm, totalIm);
}
first for
}
second for

Establish initial empty cell.
_emptyRow = _squares - 1;
_emptyCol = _squares - 1;

return totalIm;

}


© 1998 Microsoft Corporation. All rights reserved. Terms of Use.

Previous Topic Tutorial Home Page Next Topic