./TilesTutorial/04.CurrentSelection/Tiles/TilesCommands.h. HandleCanDo is a protected function:
virtual bool HandleCanDo(const TTilesSelection& target) const;
./TilesTutorial/04.CurrentSelection/Tiles/TilesCommands.C:
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
bool
TChangeColorCommand::HandleCanDo(const TTilesSelection& target) const
{
// Returns True if the selection is not empty.
return !target.IsEmpty();
}
./TilesTutorial/04.CurrentSelection/Tiles/TilesSelections.h. ContainsTile is a public function:
bool ContainsTile(TileIndex) const;
./TilesTutorial/04.CurrentSelection/Tiles/TilesSelections.C:
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
bool
TTilesSelection::ContainsTile (TileIndex whichTile) const
{
// Verifies that the selection is not empty AND that the index is within the selected range.
return (!IsEmpty() && whichTile >= fLowBound && whichTile <= fHighBound);
}
./TilesTutorial/04.CurrentSelection/Tiles/TilesView.h. GetTilesSelection is a public function:
const TTilesSelection* GetTilesSelection () const;
./TilesTutorial/04.CurrentSelection/Tiles/TilesView.C:
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
const TTilesSelection *
TTilesView::GetTilesSelection () const
{
// Gets the current selection via the GUI bundle.
const TModelSelection* modelSelection = GetCurrentModelSelection();
// Casts the model selection to a TTilesSelection.
if (modelSelection) {
TTilesSelection* tilesSelection;
DynamicCastTo(tilesSelection, modelSelection);
return tilesSelection;
}
else {
return 0;
}
}
./TilesTutorial/04.CurrentSelection/Tiles/TilesView.C. New and modified code is shown in bold.
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
void
TTilesView::DrawContents(TGrafPort& port) const
{
const TModelPointerTo<TTilesModel> model(GetModelReference());
TGArea area;
GetBounds(area);
TGrafBundle whitebg (new TColorPaint(TRGBColor(.9,1,1)), TGrafBundle::kFill);
port.Draw (area, whitebg);
// Gets a pointer to the current selection. If there is none, this will be zero.
const TTilesSelection* currentSelection = GetTilesSelection();
bool inCurrentSelection = FALSE;
int numTiles = model->GetNumTiles();
for (int i = 0; i < numTiles; i++) {
const TTile* tile = model->GetTileForReading(i);
// Determines if each tile is selected and passes it to DrawTile.
// DrawTile highlights selected tiles.
if (currentSelection && currentSelection->ContainsTile(i)) {
inCurrentSelection = TRUE;
}
else {
inCurrentSelection = FALSE;
}
DrawTile(port, tile, inCurrentSelection);
}
}
./TilesTutorial/04.CurrentSelection/Tiles/TilesView.C. New and modified code is shown in bold.
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
// Takes an argument indicating whether the tile to draw is selected.
void
TTilesView::DrawTile (TGrafPort& port, const TTile* tile, bool inCurrentSelection) const
{
TGrafBundle* bundle = new TGrafBundle(new TColorPaint(tile->GetColor()),
new TColorPaint(TColorPaint::GetBlack()),
// If the tile is selected, draws a frame around it. Otherwise, it just uses a fill color.
inCurrentSelection ? TGrafBundle::kFillAndFrame : TGrafBundle::kFill);
bundle->AdoptFramePen(new TSolidPen(3.0, TPen::kOutsetFrame));
MGraphic* tileGraphic = ::CopyPointer(fTilesGraphics[tile->GetType()]);
tileGraphic->ScaleBy(tile->GetSize());
tileGraphic->TranslateBy(tile->GetPosition());
tileGraphic->AdoptBundle(bundle);
tileGraphic->Draw(port);
delete tileGraphic;
}
./TilesTutorial/04.CurrentSelection/Tiles/TilesView.C. New and modified code is shown in bold:
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
bool
TTilesView::MouseDown (TMouseDownEvent& mouseDownEvent)
{
TRGBColor newColor;
TileIndex whichTile;
TGPoint mousePoint = mouseDownEvent.GetEventPosition();
const TModelPointerTo<TTilesModel> model(GetModelReference());
for (whichTile = model->GetNumTiles() - 1; whichTile >= 0; whichTile--) {
if (model->GetTileForReading(whichTile)->ContainsPoint(mousePoint)) {
break;
}
}
// If a tile was clicked on, selects that tile. Otherwise, creates an empty selection. The
// selection is passed to the GUI bundle as the current selection.
TTilesSelection* selection = (TTilesSelection*) model->CreateSelection ();
if (whichTile >= 0) {
selection->SelectTile (whichTile);
AdoptCurrentModelSelection (selection);
}
else {
selection->DeselectAll();
AdoptCurrentModelSelection(selection);
}
return TRUE;
}
./TilesTutorial/04.CurrentSelection/Tiles/TilesView.C. New and modified code is shown in bold:
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
void
TTilesView::HandleAfterConnectionToViewRoot()
{
TDocumentComponentView::HandleAfterConnectionToViewRoot ();
BuildTilesGraphicsMapToModel();
SetAllocatedArea (TGArea(TGRect(TGPoint(0,0), TGPoint(200, 100))));
SetCoordinateView(TViewHandle(*this));
// Gets read-only access to the model.
const TModelPointerTo<TTilesModel> model(GetModelReference());
// Creates an empty selection on the model and passes it to the GUI
// bundle as the current selection.
TTilesSelection* selection = (TTilesSelection*) model->CreateSelection();
selection->DeselectAll();
AdoptCurrentModelSelection(selection);
}