protected override void OnMouseMove(Document document, ToolMouseEventArgs e) { if (!is_drawing) { UpdateCursor(document, e.PointDouble); return; } var x = Utility.Clamp(e.PointDouble.X, 0, document.ImageSize.Width - 1); var y = Utility.Clamp(e.PointDouble.Y, 0, document.ImageSize.Height - 1); // Should always be true, set in OnMouseDown if (active_control.HasValue) { controls[active_control.Value].HandleMouseMove(x, y, e.State); } ClearHandles(document.Layers.ToolLayer); RefreshHandler(); var dirty = ReDraw(document, e.IsShiftPressed); if (document.Selection != null) { SelectionModeHandler.PerformSelectionMode(combine_mode, document.Selection.SelectionPolygons); document.Workspace.Invalidate(dirty.Union(last_dirty)); } last_dirty = dirty; }
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 OnMouseDown(Document document, ToolMouseEventArgs e) { document.Layers.ToolLayer.Clear(); stencil = new BitMask(document.ImageSize.Width, document.ImageSize.Height); base.OnMouseDown(document, e); }
protected override void OnMouseDown(Document document, ToolMouseEventArgs e) { if (e.MouseButton == MouseButton.Left) { button_down = MouseButton.Left; } else if (e.MouseButton == MouseButton.Right) { button_down = MouseButton.Right; } if (!document.Workspace.PointInCanvas(e.PointDouble)) { return; } var color = GetColorFromPoint(document, e.Point); if (button_down == MouseButton.Left) { palette.SetColor(true, color, false); } else if (button_down == MouseButton.Right) { palette.SetColor(false, color, false); } }
protected override void OnMouseMove(Document document, ToolMouseEventArgs e) { if (mouse_button == MouseButton.Left) { stroke_color = Palette.PrimaryColor; } else if (mouse_button == MouseButton.Right) { stroke_color = Palette.SecondaryColor; } else { last_point = point_empty; return; } // TODO: also multiply by pressure stroke_color = new Color(stroke_color.R, stroke_color.G, stroke_color.B, stroke_color.A * active_brush.StrokeAlphaMultiplier); var x = e.Point.X; var y = e.Point.Y; if (last_point.Equals(point_empty)) { last_point = e.Point; } if (document.Workspace.PointInCanvas(e.PointDouble)) { surface_modified = true; } var surf = document.Layers.CurrentUserLayer.Surface; var invalidate_rect = Gdk.Rectangle.Zero; var brush_width = BrushWidth; using (var g = document.CreateClippedContext()) { g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; g.LineWidth = brush_width; g.LineJoin = LineJoin.Round; g.LineCap = BrushWidth == 1 ? LineCap.Butt : LineCap.Round; g.SetSourceColor(stroke_color); invalidate_rect = active_brush.DoMouseMove(g, stroke_color, surf, x, y, last_point.X, last_point.Y); } // If we draw partially offscreen, Cairo gives us a bogus // dirty rectangle, so redraw everything. if (document.Workspace.IsPartiallyOffscreen(invalidate_rect)) { document.Workspace.Invalidate(); } else { document.Workspace.Invalidate(document.ClampToImageSize(invalidate_rect)); } last_point = e.Point; }
protected override void OnMouseUp(Document document, ToolMouseEventArgs e) { // Even though we've already set the color, we don't add it to the // recently used while we're moving the mouse around. We only want // to set it now, when the user releasing the mouse button. if (button_down == MouseButton.Left) { palette.SetColor(true, palette.PrimaryColor, true); } else if (button_down == MouseButton.Right) { palette.SetColor(false, palette.SecondaryColor, true); } button_down = MouseButton.None; if (ToolSelectionDropDown.SelectedItem.GetTagOrDefault(0) == 1 && tools.PreviousTool is not null) { tools.SetCurrentTool(tools.PreviousTool); } else if (ToolSelectionDropDown.SelectedItem.GetTagOrDefault(0) == 2) { tools.SetCurrentTool(nameof(PencilTool)); } }
protected override void OnMouseDown(Document document, ToolMouseEventArgs e) { // If we are already tracking, ignore any additional mouse down events if (mouseDown != MouseButton.None) { return; } shape_origin = e.PointDouble; switch (e.MouseButton) { case MouseButton.Left: SetCursor(cursorZoomIn); break; case MouseButton.Middle: SetCursor(cursorZoomPan); break; case MouseButton.Right: SetCursor(cursorZoomOut); break; } mouseDown = e.MouseButton; }
protected override void OnMouseDown(Document document, ToolMouseEventArgs e) { if (IsActive) { return; } original_point = e.PointDouble; if (!document.Workspace.PointInCanvas(e.PointDouble)) { return; } if (e.MouseButton == MouseButton.Right) { is_rotating = true; } else if (e.IsControlPressed) { is_scaling = true; } else { is_dragging = true; } using_mouse = true; OnStartTransform(document); }
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); }
protected override void OnMouseUp(Document document, ToolMouseEventArgs e) { var x = e.PointDouble.X; var y = e.PointDouble.Y; document.Layers.ToolLayer.Hidden = true; if (mouseDown == MouseButton.Left || mouseDown == MouseButton.Right) { if (e.MouseButton == MouseButton.Left) { if (Math.Abs(shape_origin.X - x) <= tolerance && Math.Abs(shape_origin.Y - y) <= tolerance) { document.Workspace.ZoomIn(); document.Workspace.RecenterView(x, y); } else { document.Workspace.ZoomToRectangle(CairoExtensions.PointsToRectangle(shape_origin, e.PointDouble)); } } else { document.Workspace.ZoomOut(); document.Workspace.RecenterView(x, y); } } mouseDown = MouseButton.None; is_drawing = false; SetCursor(cursorZoom); //restore regular cursor }
protected override void OnMouseDown(Document document, ToolMouseEventArgs e) { // If we are already drawing, ignore any additional mouse down events if (mouse_button != MouseButton.None) { return; } surface_modified = false; undo_surface = document.Layers.CurrentUserLayer.Surface.Clone(); mouse_button = e.MouseButton; Color tool_color; if (e.MouseButton == MouseButton.Left) { tool_color = palette.PrimaryColor; } else if (e.MouseButton == MouseButton.Right) { tool_color = palette.SecondaryColor; } else { last_point = point_empty; return; } Draw(document, e, tool_color, true); }
protected override void OnMouseUp(Document document, ToolMouseEventArgs e) { var surf = document.Layers.SelectionLayer.Surface; using (var g = new Context(surf)) { if (path != null) { g.AppendPath(path); path.Dispose(); path = null; } g.FillRule = FillRule.EvenOdd; g.ClosePath(); } document.Selection.SelectionPolygons.Clear(); document.Selection.SelectionPolygons.Add(lasso_polygon.ToList()); SelectionModeHandler.PerformSelectionMode(combine_mode, document.Selection.SelectionPolygons); document.Workspace.Invalidate(); if (hist != null) { document.History.PushNewItem(hist); hist = null; } lasso_polygon.Clear(); is_drawing = false; }
private void Draw(Document document, ToolMouseEventArgs e, Color tool_color, bool first_pixel) { var x = e.Point.X; var y = e.Point.Y; if (last_point.Equals(point_empty)) { last_point = e.Point; if (!first_pixel) { return; } } if (document.Workspace.PointInCanvas(e.PointDouble)) { surface_modified = true; } using (var g = document.CreateClippedContext()) { g.Antialias = Antialias.None; g.SetSourceColor(tool_color); if (UseAlphaBlending) { g.SetBlendMode(BlendMode.Normal); } else { g.Operator = Operator.Source; } g.LineWidth = 1; g.LineCap = LineCap.Square; if (first_pixel) { // Cairo does not support a single-pixel-long single-pixel-wide line g.Rectangle(x, y, 1.0, 1.0); g.Fill(); } else { // Adding 0.5 forces cairo into the correct square: // See https://bugs.launchpad.net/bugs/672232 g.MoveTo(last_point.X + 0.5, last_point.Y + 0.5); g.LineTo(x + 0.5, y + 0.5); g.Stroke(); } } var dirty = CairoExtensions.GetRectangleFromPoints(last_point, new Point(x, y), 4); document.Workspace.Invalidate(document.ClampToImageSize(dirty)); last_point = new Point(x, y); }
protected override void OnMouseMove(Document document, ToolMouseEventArgs e) { if (active) { document.Workspace.ScrollCanvas((int)(last_point.X - e.Root.X), (int)(last_point.Y - e.Root.Y)); last_point = new PointD(e.Root.X, e.Root.Y); } }
protected override void OnMouseDown(Document document, ToolMouseEventArgs e) { combine_mode = workspace.SelectionHandler.DetermineCombineMode(e); base.OnMouseDown(document, e); document.Selection.Visible = true; }
protected override void OnMouseDown (Document document, ToolMouseEventArgs e) { if (e.MouseButton == MouseButton.Left) fill_color = palette.PrimaryColor; else fill_color = palette.SecondaryColor; base.OnMouseDown (document, e); }
protected override void OnMouseDown(Document document, ToolMouseEventArgs e) { surface_modified = false; undo_surface = document.Layers.CurrentUserLayer.Surface.Clone(); path = null; document.Layers.ToolLayer.Clear(); document.Layers.ToolLayer.Hidden = false; }
protected override void OnMouseUp(Document document, ToolMouseEventArgs e) { if (!IsActive || !using_mouse) { return; } OnFinishTransform(document, transform); }
protected override void OnMouseUp(Document document, ToolMouseEventArgs e) { document.Layers.ToolLayer.Clear(); document.Layers.ToolLayer.Hidden = true; using (Context g = document.CreateClippedContext()) { g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; g.SetDash(DashPatternBox.GenerateDashArray(dash_pattern, BrushWidth), 0.0); if (path != null) { g.AppendPath(path); path.Dispose(); path = null; } g.ClosePath(); g.LineWidth = BrushWidth; g.FillRule = FillRule.EvenOdd; if (FillShape && StrokeShape) { g.SetSourceColor(fill_color); g.FillPreserve(); g.SetSourceColor(outline_color); g.Stroke(); } else if (FillShape) { g.SetSourceColor(outline_color); g.FillPreserve(); g.SetSourceColor(outline_color); g.Stroke(); } else { g.SetSourceColor(outline_color); g.Stroke(); } } if (surface_modified && undo_surface != null) { document.History.PushNewItem(new SimpleHistoryItem(Icon, Name, undo_surface, document.Layers.CurrentUserLayerIndex)); } else if (undo_surface != null) { undo_surface.Dispose(); } surface_modified = false; document.Workspace.Invalidate(); }
protected override void OnMouseDown(Document document, ToolMouseEventArgs e) { // If we are already drawing, ignore any additional mouse down events if (mouse_button != MouseButton.None) { return; } surface_modified = false; undo_surface = document.Layers.CurrentUserLayer.Surface.Clone(); mouse_button = e.MouseButton; OnMouseMove(document, e); }
protected override void OnMouseUp(Document document, ToolMouseEventArgs e) { // If the user didn't move the mouse, they want to deselect var tolerance = 0; if (Math.Abs(reset_origin.X - e.WindowPoint.X) <= tolerance && Math.Abs(reset_origin.Y - e.WindowPoint.Y) <= tolerance) { // Mark as being done interactive drawing before invoking the deselect action. // This will allow AfterSelectionChanged() to clear the selection. is_drawing = false; if (hist != null) { // Roll back any changes made to the selection, e.g. in OnMouseDown(). hist.Undo(); hist.Dispose(); hist = null; } PintaCore.Actions.Edit.Deselect.Activate(); } else { ClearHandles(document.Layers.ToolLayer); var dirty = ReDraw(document, e.IsShiftPressed); if (document.Selection != null) { SelectionModeHandler.PerformSelectionMode(combine_mode, document.Selection.SelectionPolygons); document.Selection.Origin = shape_origin; document.Selection.End = shape_end; document.Workspace.Invalidate(last_dirty.Union(dirty)); last_dirty = dirty; } if (hist != null) { document.History.PushNewItem(hist); hist = null; } } is_drawing = false; active_control = null; // Update the mouse cursor. UpdateCursor(document, e.PointDouble); }
protected override void OnMouseUp(Document document, ToolMouseEventArgs e) { if (!tracking || e.MouseButton != button) { return; } tracking = false; if (undo_surface != null) { document.History.PushNewItem(new SimpleHistoryItem(Icon, Name, undo_surface, document.Layers.CurrentUserLayerIndex)); } }
protected override void OnMouseDown(Document document, ToolMouseEventArgs e) { var pos = e.Point; // Don't do anything if we're outside the canvas if (pos.X < 0 || pos.X >= document.ImageSize.Width) { return; } if (pos.Y < 0 || pos.Y >= document.ImageSize.Height) { return; } base.OnMouseDown(document, e); using (var currentRegion = new Cairo.Region(document.GetSelectedBounds(true).ToCairoRectangleInt())) { // See if the mouse click is valid if (!currentRegion.ContainsPoint(pos.X, pos.Y) && LimitToSelection) { return; } var surface = document.Layers.CurrentUserLayer.Surface; var stencilBuffer = new BitMask(surface.Width, surface.Height); var tol = (int)(Tolerance * Tolerance * 256); Rectangle boundingBox; if (IsContinguousMode) { CairoExtensions.FillStencilFromPoint(surface, stencilBuffer, pos, tol, out boundingBox, currentRegion, LimitToSelection); } else { CairoExtensions.FillStencilByColor(surface, stencilBuffer, surface.GetColorBgraUnchecked(pos.X, pos.Y), tol, out boundingBox, currentRegion, LimitToSelection); } OnFillRegionComputed(document, stencilBuffer); // If a derived tool is only going to use the stencil, // don't waste time building the polygon set if (CalculatePolygonSet) { var polygonSet = stencilBuffer.CreatePolygonSet(boundingBox, 0, 0); OnFillRegionComputed(document, polygonSet); } } }
protected override void OnMouseUp(Document document, ToolMouseEventArgs e) { // If we were dragging the text around, finish that up if (tracking) { Cairo.PointD delta = new Cairo.PointD(e.PointDouble.X - startMouseXY.X, e.PointDouble.Y - startMouseXY.Y); clickPoint = new Point((int)(startClickPoint.X + delta.X), (int)(startClickPoint.Y + delta.Y)); CurrentTextEngine.Origin = clickPoint; RedrawText(false, true); tracking = false; SetCursor(null); } }
protected override void OnMouseDown(Document document, ToolMouseEventArgs e) { // If we are already panning, ignore any additional mouse down events if (active) { return; } // Don't scroll if the whole canvas fits (no scrollbars) if (!document.Workspace.CanvasFitsInWindow) { active = true; } last_point = new PointD(e.Root.X, e.Root.Y); }
protected override void OnMouseMove(Document document, ToolMouseEventArgs e) { var new_point = e.Point; var new_pointd = e.PointDouble; if (mouse_button == MouseButton.None) { last_point = point_empty; return; } if (last_point.Equals(point_empty)) { last_point = new_point; } if (document.Workspace.PointInCanvas(new_pointd)) { surface_modified = true; } using (var g = document.CreateClippedContext()) { var last_pointd = new PointD(last_point.X, last_point.Y); if (eraser_type == EraserType.Normal) { EraseNormal(g, last_pointd, new_pointd); } else if (eraser_type == EraserType.Smooth) { EraseSmooth(document.Layers.CurrentUserLayer.Surface, g, last_pointd, new_pointd); } } var dirty = CairoExtensions.GetRectangleFromPoints(last_point, new_point, BrushWidth + 2); if (document.Workspace.IsPartiallyOffscreen(dirty)) { document.Workspace.Invalidate(); } else { document.Workspace.Invalidate(document.ClampToImageSize(dirty)); } last_point = new_point; }
protected override void OnMouseMove(Document document, ToolMouseEventArgs e) { if (mouseDown == MouseButton.Left) { if (Math.Abs(shape_origin.X - e.PointDouble.X) > tolerance || Math.Abs(shape_origin.Y - e.PointDouble.Y) > tolerance) // if they've moved the mouse more than 10 pixels since they clicked { is_drawing = true; } //still draw rectangle after we have draw it one time... UpdateRectangle(document, e.PointDouble); } else if (mouseDown == MouseButton.Middle) { document.Workspace.ScrollCanvas((int)((shape_origin.X - e.PointDouble.X) * document.Workspace.Scale), (int)((shape_origin.Y - e.PointDouble.Y) * document.Workspace.Scale)); } }
protected override void OnMouseDown(Document document, ToolMouseEventArgs e) { if (is_drawing) { return; } hist = new SelectionHistoryItem(Icon, Name); hist.TakeSnapshot(); combine_mode = workspace.SelectionHandler.DetermineCombineMode(e); path = null; is_drawing = true; document.PreviousSelection.Dispose(); document.PreviousSelection = document.Selection.Clone(); }
protected override void OnMouseUp(Document document, ToolMouseEventArgs e) { painting = false; using (var g = new Cairo.Context(document.Layers.CurrentUserLayer.Surface)) { g.SetSource(document.Layers.ToolLayer.Surface); g.Paint(); } base.OnMouseUp(document, e); offset = new Cairo.Point(int.MinValue, int.MinValue); last_point = new Cairo.Point(int.MinValue, int.MinValue); document.Layers.ToolLayer.Clear(); document.Layers.ToolLayer.Hidden = true; document.Workspace.Invalidate(); }
protected override void OnMouseUp(Document document, ToolMouseEventArgs e) { if (undo_surface != null) { if (surface_modified) { document.History.PushNewItem(new SimpleHistoryItem(Icon, Name, undo_surface, document.Layers.CurrentUserLayerIndex)); } else { undo_surface.Dispose(); } } surface_modified = false; undo_surface = null; mouse_button = MouseButton.None; }