1
- using Avalonia . Media ;
1
+ using Avalonia . Controls ;
2
+ using Avalonia . Media ;
2
3
using Avalonia . Platform ;
3
4
using Pixed . Application . Controls ;
4
5
using Pixed . Application . Input ;
6
+ using Pixed . Application . Menu ;
5
7
using Pixed . Application . Models ;
6
8
using Pixed . Application . Zoom ;
7
9
using Pixed . Common ;
8
10
using Pixed . Common . Services . Keyboard ;
9
11
using Pixed . Common . Tools ;
12
+ using Pixed . Common . Tools . Selection ;
10
13
using Pixed . Core ;
11
14
using Pixed . Core . Models ;
12
15
using Pixed . Core . Utils ;
@@ -21,6 +24,8 @@ internal class PaintCanvasViewModel : ExtendedViewModel, IDisposable
21
24
{
22
25
private readonly ApplicationData _applicationData ;
23
26
private readonly ToolsManager _toolSelector ;
27
+ private readonly SelectionMenu _selectionMenu ;
28
+ private readonly SelectionManager _selectionManager ;
24
29
private RenderModel _renderModel ;
25
30
private SKBitmap ? _overlay ;
26
31
private ImageBrush _transparentBrush ;
@@ -43,6 +48,7 @@ internal class PaintCanvasViewModel : ExtendedViewModel, IDisposable
43
48
private double _zoomValue = 1 ;
44
49
private bool _isFramesViewButtonVisible ;
45
50
private bool _isPropertiesViewButtonVisible ;
51
+ private bool _isSelectionButtonVisible = false ;
46
52
47
53
private readonly IDisposable _projectModified ;
48
54
private readonly IDisposable _projectChanged ;
@@ -81,6 +87,7 @@ internal class PaintCanvasViewModel : ExtendedViewModel, IDisposable
81
87
public ActionCommand CloseFramesView { get ; }
82
88
public ActionCommand OpenPropertiesView { get ; }
83
89
public ActionCommand ClosePropertiesView { get ; }
90
+ public ActionCommand < Control > OpenSelectionMenu { get ; }
84
91
85
92
public int ToolSize
86
93
{
@@ -169,6 +176,16 @@ public double ZoomValue
169
176
OnPropertyChanged ( nameof ( ScaledGridHeight ) ) ;
170
177
}
171
178
}
179
+
180
+ public bool IsSelectionButtonVisible
181
+ {
182
+ get => _isSelectionButtonVisible ;
183
+ set
184
+ {
185
+ _isSelectionButtonVisible = value ;
186
+ OnPropertyChanged ( ) ;
187
+ }
188
+ }
172
189
public double ZoomOffsetX { get ; set ; }
173
190
public double ZoomOffsetY { get ; set ; }
174
191
@@ -217,10 +234,13 @@ public bool IsPropertiesViewButtonVisible
217
234
}
218
235
}
219
236
220
- public PaintCanvasViewModel ( ApplicationData applicationData , ToolsManager toolSelector , ToolMoveCanvas toolMoveCanvas , SelectionManager selectionManager , FramesSectionViewModel framesSectionViewModel , PropertiesSectionViewModel propertiesSectionViewModel )
237
+ public PaintCanvasViewModel ( ApplicationData applicationData , ToolsManager toolSelector , ToolMoveCanvas toolMoveCanvas , SelectionManager selectionManager ,
238
+ FramesSectionViewModel framesSectionViewModel , PropertiesSectionViewModel propertiesSectionViewModel , SelectionMenu selectionMenu )
221
239
{
222
240
_applicationData = applicationData ;
223
241
_toolSelector = toolSelector ;
242
+ _selectionMenu = selectionMenu ;
243
+ _selectionManager = selectionManager ;
224
244
_frame = new Frame ( 32 , 32 ) ;
225
245
_renderModel = new RenderModel
226
246
{
@@ -329,6 +349,8 @@ public PaintCanvasViewModel(ApplicationData applicationData, ToolsManager toolSe
329
349
SelectionOverlay . UpdateSelection ( null ) ;
330
350
SelectionOverlay . DrawLines = false ;
331
351
}
352
+
353
+ IsSelectionButtonVisible = false ;
332
354
} ) ;
333
355
334
356
_selectionCreated = Subjects . SelectionCreated . Subscribe ( selection =>
@@ -338,6 +360,7 @@ public PaintCanvasViewModel(ApplicationData applicationData, ToolsManager toolSe
338
360
SelectionOverlay . DrawLines = true ;
339
361
SelectionOverlay . UpdateSelection ( selection ) ;
340
362
Subjects . OverlayModified . OnNext ( null ) ;
363
+ IsSelectionButtonVisible = true ;
341
364
}
342
365
} ) ;
343
366
@@ -364,6 +387,13 @@ public PaintCanvasViewModel(ApplicationData applicationData, ToolsManager toolSe
364
387
CloseFramesView = new ActionCommand ( ( ) => framesSectionViewModel . IsVisible = false ) ;
365
388
OpenPropertiesView = new ActionCommand ( ( ) => propertiesSectionViewModel . IsVisible = true ) ;
366
389
ClosePropertiesView = new ActionCommand ( ( ) => propertiesSectionViewModel . IsVisible = false ) ;
390
+ OpenSelectionMenu = new ActionCommand < Control > ( obj =>
391
+ {
392
+ var menu = _selectionMenu . GetMenu ( ) ;
393
+ menu . Placement = PlacementMode . BottomEdgeAlignedLeft ;
394
+ menu . PlacementAnchor = Avalonia . Controls . Primitives . PopupPositioning . PopupAnchor . TopLeft ;
395
+ menu . ShowAt ( obj ) ;
396
+ } ) ;
367
397
}
368
398
public void RecalculateFactor ( Point windowSize )
369
399
{
@@ -450,7 +480,7 @@ private void LeftMouseDownAction(MouseEvent mouseEvent)
450
480
}
451
481
452
482
_leftPressed = true ;
453
- _toolSelector . SelectedTool ? . ApplyTool ( mouseEvent . Point , _frame , ref _overlay , _currentKeyState ) ;
483
+ _toolSelector . SelectedTool ? . ApplyTool ( mouseEvent . Point , _frame , ref _overlay , _currentKeyState , _selectionManager . Selection ) ;
454
484
UpdateRenderModel ( ) ;
455
485
Subjects . FrameModified . OnNext ( _frame ) ;
456
486
}
@@ -463,7 +493,7 @@ private void LeftMouseUpAction(MouseEvent mouseEvent)
463
493
}
464
494
465
495
_leftPressed = false ;
466
- _toolSelector . SelectedTool ? . ReleaseTool ( mouseEvent . Point , _frame , ref _overlay , _currentKeyState ) ;
496
+ _toolSelector . SelectedTool ? . ReleaseTool ( mouseEvent . Point , _frame , ref _overlay , _currentKeyState , _selectionManager . Selection ) ;
467
497
UpdateRenderModel ( ) ;
468
498
469
499
if ( _toolSelector . SelectedTool != null && _toolSelector . SelectedTool . AddToHistory )
@@ -484,7 +514,16 @@ private void RightMouseDownAction(MouseEvent mouseEvent)
484
514
}
485
515
486
516
_rightPressed = true ;
487
- _toolSelector . SelectedTool ? . ApplyTool ( mouseEvent . Point , _frame , ref _overlay , _currentKeyState ) ;
517
+
518
+ if ( _toolSelector . SelectedTool is ToolSelectBase selection )
519
+ {
520
+ var flyout = _selectionMenu . GetMenu ( ) ;
521
+ flyout . ShowAt ( View , true ) ;
522
+ }
523
+ else if ( _toolSelector . SelectedTool is BaseTool tool )
524
+ {
525
+ tool . ApplyTool ( mouseEvent . Point , _frame , ref _overlay , _currentKeyState , _selectionManager . Selection ) ;
526
+ }
488
527
UpdateRenderModel ( ) ;
489
528
}
490
529
@@ -496,7 +535,7 @@ private void RightMouseUpAction(MouseEvent mouseEvent)
496
535
}
497
536
498
537
_rightPressed = false ;
499
- _toolSelector . SelectedTool ? . ReleaseTool ( mouseEvent . Point , _frame , ref _overlay , _currentKeyState ) ;
538
+ _toolSelector . SelectedTool ? . ReleaseTool ( mouseEvent . Point , _frame , ref _overlay , _currentKeyState , _selectionManager . Selection ) ;
500
539
UpdateRenderModel ( ) ;
501
540
502
541
if ( _toolSelector . SelectedTool != null && _toolSelector . SelectedTool . AddToHistory )
@@ -525,12 +564,12 @@ private void MouseMoveAction(MouseEvent mouseEvent)
525
564
526
565
if ( _leftPressed || _rightPressed )
527
566
{
528
- _toolSelector . SelectedTool . MoveTool ( mouseEvent . Point , _frame , ref _overlay , _currentKeyState ) ;
567
+ _toolSelector . SelectedTool . MoveTool ( mouseEvent . Point , _frame , ref _overlay , _currentKeyState , _selectionManager . Selection ) ;
529
568
UpdateRenderModel ( ) ;
530
569
}
531
570
else
532
571
{
533
- _toolSelector . SelectedTool . UpdateHighlightedPixel ( mouseEvent . Point , _frame , ref _overlay ) ;
572
+ _toolSelector . SelectedTool . UpdateHighlightedPixel ( mouseEvent . Point , _frame , ref _overlay , _selectionManager . Selection ) ;
534
573
UpdateRenderModel ( ) ;
535
574
}
536
575
@@ -541,7 +580,7 @@ private void MouseLeaveAction()
541
580
{
542
581
if ( _rightPressed || _leftPressed )
543
582
{
544
- _toolSelector . SelectedTool ? . ReleaseTool ( new Point ( ) , _frame , ref _overlay , _currentKeyState ) ;
583
+ _toolSelector . SelectedTool ? . ReleaseTool ( new Point ( ) , _frame , ref _overlay , _currentKeyState , _selectionManager . Selection ) ;
545
584
UpdateRenderModel ( ) ;
546
585
}
547
586
_rightPressed = false ;
0 commit comments