// $Revision: 1.3 $ // Copyright (c) 1994-1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_POLYGONINTERACTOR #include "PolygonInteractor.h" #endif #ifndef Taligent_GRAPHICS #include #endif #ifndef Taligent_ASSERTIONS #include #endif VersionDefinitionsMacro(TPolygonInteractor, 0); TPolygonInteractor::TPolygonInteractor(TGraphicView* view) : TInteractor(), MMouseEventHandler(), fViewHandle(*view), fPoints() { Assertion(view != NIL); view->AddInteractor(this); SetCoordinateView(fViewHandle); } TPolygonInteractor::~TPolygonInteractor() { TGraphicView* view = (TGraphicView*)fViewHandle.GetView(); if (view) { view->RemoveInteractor(*this); } } // The interactor will be called any time the mouse goes down in any view using the same // event responder. Note that the window is such a view (!) so in general it is always // possible this will be called when the mouse is outside the view we're tracking. This // differs from when a TView is handling the event-- it will never receive MouseDown // unless the mouse is in the view. // Interactors are different from other event handlers in that the event distributor // will not distribute the event on (via HandleDistributeEvent) if the device has // an interactor. An interactor handles all events for its device until it is done, // so if you want some other handler to get the event, you must stop the interactor, // or distribute it to that handler yourself. See MouseInput6. // Unfortunately, we don't find out if the mouse goes down in a view hierarchy that uses // a different responder. The view that started us will be deactivated, though, so it // has to override HandleDeactivate and stop us. // This method results in any of three states: // 1) the mouse was double-clicked in the view, so close the polyline and stop the interaction. // 2) the mouse was single-clicked in the view, so extend the polyline. // 3) the mouse was clicked outside the view, so forget the polyline and stop the interaction. bool TPolygonInteractor::MouseButtonDown(TMouseDownEvent& mouseDown, short) { TGraphicView* view = (TGraphicView*)fViewHandle.GetView(); Assertion(view != NIL); TGPoint point = mouseDown.GetEventPosition(); bool handled = view->ContainsPoint(point); if (handled) { if (mouseDown.GetClickCount() > 1) { view->AdoptGraphic(new TPolygon(fPoints)); SetDone(true); } else { fPoints.Append(point); view->AdoptGraphic(new TPolyline(fPoints)); } } else { view->AdoptGraphic(NIL); SetDone(true); } return handled; }