protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (!KeyDownShiftOnly() && !KeyDownControlOnly()) { Cursor = cursorMouseUp; } if (mouseDown) { this.previewRenderer.Visible = true; OnMouseMove(e); if (savedSurfaces.Count > 0) { PdnRegion saveMeRegion = new PdnRegion(); saveMeRegion.MakeEmpty(); foreach (PlacedSurface pi1 in savedSurfaces) { saveMeRegion.Union(pi1.Bounds); } PdnRegion simplifiedRegion = Utility.SimplifyAndInflateRegion(saveMeRegion); using (IrregularSurface weDrewThis = new IrregularSurface(renderArgs.Surface, simplifiedRegion)) { for (int i = savedSurfaces.Count - 1; i >= 0; --i) { PlacedSurface ps = (PlacedSurface)savedSurfaces[i]; ps.Draw(renderArgs.Surface); ps.Dispose(); } savedSurfaces.Clear(); if (hasDrawn) { HistoryMemento ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, ActiveLayerIndex, simplifiedRegion); weDrewThis.Draw(bitmapLayer.Surface); HistoryStack.PushNewMemento(ha); } } } mouseDown = false; modifierDown = 0; } if (brushRenderArgs != null) { if (brushRenderArgs.Surface != null) { brushRenderArgs.Surface.Dispose(); } } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); this.previewRenderer.BrushLocation = new Point(e.X, e.Y); this.previewRenderer.BrushSize = AppEnvironment.PenInfo.Width / 2.0f; if (mouseDown) { if (BtnDownMouseLeft(e) || BtnDownMouseRight(e)) { if (modifierDown == 0) { // if the primary and secondary colors are identical, // return...there's no point in committing any action if (colorReplacing == colorToReplace) { return; } // get our start and end coordinates, since we need // to trace along an action line -- the user will expect this behavior // if we don't, it'll look like a tin can riddled with bullet holes Point pointStartCorner = lastMouseXY; // start point Point pointEndCorner = new Point(e.X, e.Y); // end point // create the rectangle with the 'a' and 'b' points above Rectangle inspectionRect = Utility.PointsToRectangle(pointStartCorner, pointEndCorner); // inflate the region to address account for the pen width // then intersect with the Workspace to "clip" the boundary // the total area of the clipped rectangle includes the // width of the pen surrounding the points limited by either // the canvas perimeter or the selection outline inspectionRect.Inflate(1 + ceilingPenWidth / 2, 1 + ceilingPenWidth / 2); inspectionRect.Intersect(ActiveLayer.Bounds); // Enforce the selection area restrictions. // If within the selection area restrictions, build an image history bool gotWidth = inspectionRect.Width > 0; bool gotHeight = inspectionRect.Height > 0; bool isInClip = renderArgs.Graphics.IsVisible(inspectionRect); if ((gotWidth) && (gotHeight) && (isInClip)) { PlacedSurface savedPS = new PlacedSurface(renderArgs.Surface, inspectionRect); savedSurfaces.Add(savedPS); renderArgs.Graphics.CompositingMode = CompositingMode.SourceOver; // check the mouse buttons and if we've made it this far, at least // one of the mouse buttons (left|right) was depressed if (BtnDownMouseLeft(e)) { this.DrawOverPoints(pointStartCorner, pointEndCorner, colorReplacing, colorToReplace); } else { this.DrawOverPoints(pointStartCorner, pointEndCorner, colorToReplace, colorReplacing); } bitmapLayer.Invalidate(inspectionRect); Update(); } // update the lastMouseXY so we know how to "connect the dots" lastMouseXY = pointEndCorner; } else { switch (modifierDown & (Keys.Control | Keys.Shift)) { case Keys.Control: PickColor(e); break; case Keys.Shift: AdjustDrawingColor(e); break; default: break; } } } } }