protected override void OnMouseDown(Document document, ToolMouseEventArgs e) { // We only do stuff with the left mouse button if (e.MouseButton != MouseButton.Left) { return; } // Ctrl click is set origin, regular click is begin drawing if (!e.IsControlPressed) { if (origin.IsNotSet()) { return; } painting = true; if (offset.IsNotSet()) { offset = new Cairo.Point(e.Point.X - origin.X, e.Point.Y - origin.Y); } document.Layers.ToolLayer.Clear(); document.Layers.ToolLayer.Hidden = false; surface_modified = false; undo_surface = document.Layers.CurrentUserLayer.Surface.Clone(); } else { origin = e.Point; } }
protected override void OnMouseMove(Document document, ToolMouseEventArgs e) { if (!painting || offset.IsNotSet()) { return; } var x = e.Point.X; var y = e.Point.Y; if (last_point.IsNotSet()) { last_point = e.Point; return; } using (var g = document.CreateClippedToolContext()) { g.Antialias = UseAntialiasing ? Cairo.Antialias.Subpixel : Cairo.Antialias.None; g.MoveTo(last_point.X, last_point.Y); g.LineTo(x, y); g.SetSource(document.Layers.CurrentUserLayer.Surface, offset.X, offset.Y); g.LineWidth = BrushWidth; g.LineCap = Cairo.LineCap.Round; g.Stroke(); } var dirty_rect = CairoExtensions.GetRectangleFromPoints(last_point, e.Point, BrushWidth + 2); last_point = e.Point; surface_modified = true; document.Workspace.Invalidate(dirty_rect); }