public LayerState MouseMovement(MyMouseEventArgs e) { LayerState result = LayerState.Normal; bool canSelect = CanSelectLayer(e.Location); if (canSelect) { result = LayerState.Selectable; } if (selectedLayer == StateHandler.DummySelected && canSelect == false) { return LayerState.Normal; } switch (StateHandler.SelectedLayerState) { case LayerState.Moving: { Rectangle oldRegion = selectedLayer.Region; selectedLayer.Move(MoveTracker.GetDelta(e.Location)); // 2-step update: first on old region and then on the new one //NotifyGraphicsHandler(RenderingPolicy.MinimalUpdatePolicy(oldRegion)); NotifyGraphicsHandler(RenderingPolicy.MinimalUpdatePolicy(selectedLayer.Region, oldRegion)); break; } case LayerState.Resizing: { Rectangle oldRegion = selectedLayer.Region; selectedLayer.Resize((Size)MoveTracker.GetDelta(e.Location)); // Update the largest invalidated region Rectangle invalidatedRegion = oldRegion.Contains(selectedLayer.Region) ? oldRegion : selectedLayer.Region; NotifyGraphicsHandler(RenderingPolicy.MinimalUpdatePolicy(invalidatedRegion)); break; } } return result; }
public void MouseUp(MyMouseEventArgs e) { if (StateHandler.SelectedLayerState != LayerState.Normal) { NotifyGraphicsHandler(RenderingPolicy.MinimalUpdatePolicy(selectedLayer.Region)); StateHandler.SelectedLayerState = LayerState.Normal; } }
public void MouseDown(MyMouseEventArgs e) { if (e.Button != MyMouseEventArgs.MyMouseButton.Left) return; // Deselect all layers if (CanSelectLayer(e.Location) == false) { DeselectLayers(); return; } // Keep track of initial mouse down //pointDown = e.Location; // Selection test at the mouse position Layer layer; if (CanSelectLayer(e.Location, out layer) == false) return; // The exterior region is 4 pixels inside from the layer Edges Rectangle resizeInterior = layer.Region; resizeInterior.Inflate(-4, -4); StateHandler.SelectedLayerState = resizeInterior.Contains(e.Location) ? LayerState.Moving : LayerState.Resizing; // Logic to respond to the state change if (StateHandler.SelectedLayerState == LayerState.Moving) { // Movement begin MoveTracker.BeginTracking(e.Location, layer.Region.Location); //pointOffset.X = pointDown.X - layer.Region.Left; //pointOffset.Y = pointDown.Y - layer.Region.Top; } SelectedLayer = layer; }