Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
MakesYT committed Mar 5, 2024
1 parent 60f31a1 commit 7e9891c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public event EventHandler<LocationOrSizeChangedEventArgs>? LocationOrSizeChanged

public DraggableArrowControl()
{

Focusable = true;
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
Expand Down Expand Up @@ -126,6 +126,7 @@ private void PointOnPointerPressed(object? sender, PointerPressedEventArgs e)
{
return;
}
Focus();
if (e.GetCurrentPoint(TopLevel.GetTopLevel(this)).Properties.IsLeftButtonPressed)
{
e.Pointer.Capture((IInputElement?)sender);
Expand Down Expand Up @@ -166,6 +167,7 @@ private void ContentOnPointerPressed(object? sender, PointerPressedEventArgs e)
{
return;
}
Focus();
var visualParent = (Canvas)this.GetVisualParent();
foreach (var canvasChild in visualParent.Children)
{
Expand Down Expand Up @@ -202,7 +204,7 @@ private void ContentOnPointerMoved(object? sender, PointerEventArgs e)
if (!Cursor.ToString().Equals("SizeAll"))
{
Cursor?.Dispose();
Cursor = Avalonia.Input.Cursor.Default;
Cursor = new Cursor(StandardCursorType.SizeAll);

}
if (_isDragging)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:KitopiaAvalonia.Controls"
xmlns:capture="clr-namespace:KitopiaAvalonia.Controls.Capture">
xmlns:capture="clr-namespace:KitopiaAvalonia.Controls.Capture"
>
<Design.PreviewWith>
<capture:DraggableResizeableControl Width="200" Height="200">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public bool OnlyShowReSizingBoxOnSelect
public DraggableResizeableControl()
{
_dragTransform = new TranslateTransform();
Focusable = true;
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
Expand Down Expand Up @@ -85,7 +86,7 @@ private void ResizeSizeBoxBorderOnPointerPressed(object? sender, PointerPressedE
{
return;
}

Focus();
if (e.GetCurrentPoint(TopLevel.GetTopLevel(this)).Properties.IsLeftButtonPressed)
{
e.Pointer.Capture((IInputElement?)sender);
Expand Down Expand Up @@ -323,8 +324,8 @@ private void ContentOnPointerCaptureLost(object? sender, PointerCaptureLostEvent
}
private void ContentOnPointerPressed(object? sender, PointerPressedEventArgs e)
{


Focus();
var visualParent = (Canvas)this.GetVisualParent();
foreach (var canvasChild in visualParent.Children)
{
Expand Down Expand Up @@ -362,8 +363,12 @@ private void ContentOnPointerMoved(object? sender, PointerEventArgs e)

if (OnlyShowReSizingBoxOnSelect)
{
Cursor?.Dispose();
Cursor=new Cursor(StandardCursorType.SizeAll);
if (!Cursor.ToString().Equals("SizeAll"))
{
Cursor?.Dispose();
Cursor = new Cursor(StandardCursorType.SizeAll);

}
}

if (_isDragging)
Expand Down
3 changes: 2 additions & 1 deletion KitopiaAvalonia/Controls/Capture/PenCaptureTool.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public PenCaptureTool()
Points = new();
Points.CollectionChanged += Update;
AffectsGeometry<PenCaptureTool>(PointsProperty,StrokeProperty,FillProperty,StrokeThicknessProperty);
Focusable = true;
}

public void Update(object? sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
Expand Down Expand Up @@ -196,7 +197,6 @@ public Geometry CreateDefiningGeometry()
context.BeginFigure(Points[index+1], false);
}

index++;
continue;
}

Expand All @@ -219,6 +219,7 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
{
return;
}
Focus();
var visualParent = (Canvas)this.GetVisualParent();
foreach (var canvasChild in visualParent.Children)
{
Expand Down
2 changes: 1 addition & 1 deletion KitopiaAvalonia/Controls/Capture/TextCaptureTool.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public TextCaptureTool()
_dragTransform = new TranslateTransform();
RenderTransform = _dragTransform;


Focusable = true;

}

Expand Down
4 changes: 2 additions & 2 deletions KitopiaAvalonia/Windows/ScreenCaptureWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<capture:PenCaptureTool Name="MosaicCanvas" Width="{Binding $parent[Canvas].Bounds.Width}" ZIndex="-1"
Height="{Binding $parent[Canvas].Bounds.Height}" Stroke="Black" Fill="Black" StrokeThickness="7">
</capture:PenCaptureTool>
<Rectangle ZIndex="1" Name="Rectangle" Width="{Binding $parent[Window].Bounds.Width}"
<Rectangle ZIndex="1" Name="Rectangle" Width="{Binding $parent[Window].Bounds.Width}" Focusable="True"
Height="{Binding $parent[Window].Bounds.Height}" PointerEntered="Rectangle_OnPointerEntered">
<Rectangle.Fill>
<SolidColorBrush Color="Black" Opacity="0.5" />
Expand All @@ -37,7 +37,7 @@

<Canvas ZIndex="3" Name="Canvas" Width="{Binding $parent[Canvas].Bounds.Width}"
Height="{Binding $parent[Canvas].Bounds.Height}"/>
<Border ZIndex="3" Padding="5" CornerRadius="4" IsVisible="False" d:IsHidden="False" Name="ToolBar">
<Border ZIndex="3" Padding="5" CornerRadius="4" IsVisible="False" d:IsHidden="False" Name="ToolBar" Focusable="True">
<Border.Background>
<SolidColorBrush Color="{DynamicResource SolidBackgroundFillColorBase}" Opacity="0.5" />
</Border.Background>
Expand Down
46 changes: 17 additions & 29 deletions KitopiaAvalonia/Windows/ScreenCaptureWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ private void SelectBox_OnPointerPressed(object? sender, PointerPressedEventArgs
dragarea._dragTransform.X = position.X;
dragarea._dragTransform.Y = position.Y;
dragarea.IsSelected = true;
dragarea.Width = 5;
dragarea.Height = 5;
var rectangle = new Avalonia.Controls.Shapes.Rectangle();
dragarea.Content = rectangle;

Expand All @@ -370,7 +372,7 @@ private void SelectBox_OnPointerPressed(object? sender, PointerPressedEventArgs
Adding截图工具 = true;
Now截图工具 = dragarea;


dragarea.Focus();
break;
}
case 截图工具.圆形:
Expand All @@ -380,7 +382,8 @@ private void SelectBox_OnPointerPressed(object? sender, PointerPressedEventArgs
var dragarea = new DraggableResizeableControl();
dragarea._dragTransform.X = position.X;
dragarea._dragTransform.Y = position.Y;

dragarea.Width = 5;
dragarea.Height = 5;
var rectangle = new Ellipse();
dragarea.Content = rectangle;
dragarea.IsSelected = true;
Expand All @@ -390,6 +393,7 @@ private void SelectBox_OnPointerPressed(object? sender, PointerPressedEventArgs
Canvas.Children.Add(dragarea);
Adding截图工具 = true;
Now截图工具 = dragarea;
dragarea.Focus();
break;
}
case 截图工具.箭头:
Expand All @@ -407,6 +411,7 @@ private void SelectBox_OnPointerPressed(object? sender, PointerPressedEventArgs
Canvas.Children.Add(dragarea);
Adding截图工具 = true;
Now截图工具 = dragarea;
dragarea.Focus();
break;
}
case 截图工具.批准:
Expand All @@ -424,6 +429,7 @@ private void SelectBox_OnPointerPressed(object? sender, PointerPressedEventArgs
Canvas.Children.Add(rectangle);
Adding截图工具 = true;
Now截图工具 = rectangle;
rectangle.Focus();
break;
}
case 截图工具.文本:
Expand All @@ -438,41 +444,24 @@ private void SelectBox_OnPointerPressed(object? sender, PointerPressedEventArgs

dragarea.IsSelected = true;
dragarea.Foreground = new SolidColorBrush(ColorPicker.Color!.Value);
dragarea.Text = "dsdsd";
dragarea.Text = "文本1";
dragarea.FontSize = 13+StrokeWidth.Value;
Canvas.Children.Add(dragarea);
Adding截图工具 = true;
Now截图工具 = dragarea;
dragarea.Focus();
break;
}
case 截图工具.马赛克:
{
var position = e.GetPosition(this);
_startPoint = position;
if (redoStack.TryPeek( out var result))
{
if (result.Type!=截图工具.马赛克)
{
redoStack.Push(new ScreenCaptureRedoInfo()
{
EditType = ScreenCaptureEditType.移动,
Type = 截图工具.马赛克,
points = new List<Point>(){position}
});
}else
{
redoStack.Peek().points.Add(position);
}
}
else
redoStack.Push(new ScreenCaptureRedoInfo()
{
redoStack.Push(new ScreenCaptureRedoInfo()
{
EditType = ScreenCaptureEditType.移动,
Type = 截图工具.马赛克,
points = new List<Point>(){position}
});
}
EditType = ScreenCaptureEditType.移动,
Type = 截图工具.马赛克,
points = new List<Point>(){position}
});
MosaicCanvas.Points.Add(position);
MosaicCanvas.StrokeThickness = 5 + StrokeWidth.Value;
Adding截图工具 = true;
Expand All @@ -481,6 +470,7 @@ private void SelectBox_OnPointerPressed(object? sender, PointerPressedEventArgs
}

}

e.Handled = true;
}

Expand Down Expand Up @@ -674,9 +664,6 @@ private void SelectBox_OnPointerReleased(object? sender, PointerReleasedEventArg
Type = 截图工具.马赛克,
points = new List<Point>(){e.GetPosition(this)}
});
}else
{
redoStack.Peek().points.Add(new Point(-1,-1));
}
}
else
Expand All @@ -691,6 +678,7 @@ private void SelectBox_OnPointerReleased(object? sender, PointerReleasedEventArg


MosaicCanvas.Points.Add( new Point(-1,-1));

renderTargetBitmap.Render(MosaicCanvas);

}
Expand Down

0 comments on commit 7e9891c

Please sign in to comment.