Mejorada la seleccion de objetos multiples
This commit is contained in:
parent
3dab570f5d
commit
67c6464ea1
|
@ -50,6 +50,8 @@ namespace CtrEditor
|
|||
private Rectangle _currentDraggingRectangle;
|
||||
private dataDebug _dataDebug = new dataDebug();
|
||||
private ObservableCollection<osBase> _selectedObjects = new ObservableCollection<osBase>();
|
||||
private List<Rectangle> _selectionHighlightRectangles = new List<Rectangle>(); // Add this line
|
||||
private List<(UserControl Control, Rectangle Highlight)> _selectionHighlightPairs = new List<(UserControl, Rectangle)>();
|
||||
|
||||
public ObjectManipulationManager(MainWindow mainWindow, Canvas canvas)
|
||||
{
|
||||
|
@ -324,6 +326,10 @@ namespace CtrEditor
|
|||
{
|
||||
_selectedObjects.Add(obj);
|
||||
obj.IsSelected = true;
|
||||
if (_mainWindow.DataContext is MainViewModel viewModel && viewModel.IsMultiSelectionActive)
|
||||
{
|
||||
AddSelectionHighlight(obj.VisualRepresentation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,6 +339,7 @@ namespace CtrEditor
|
|||
{
|
||||
_selectedObjects.Remove(obj);
|
||||
obj.IsSelected = false;
|
||||
RemoveSelectionHighlight(obj.VisualRepresentation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,6 +349,7 @@ namespace CtrEditor
|
|||
{
|
||||
DeselectObject(obj);
|
||||
}
|
||||
RemoveAllSelectionHighlights();
|
||||
RemoveResizeRectangles();
|
||||
|
||||
if (_mainWindow.DataContext is MainViewModel viewModel)
|
||||
|
@ -361,6 +369,82 @@ namespace CtrEditor
|
|||
ClearSelection();
|
||||
SelectObject(lastSelected);
|
||||
}
|
||||
RemoveAllSelectionHighlights();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Agregar destacados de selección para los objetos ya seleccionados
|
||||
foreach (var obj in _selectedObjects)
|
||||
{
|
||||
if (obj.VisualRepresentation != null)
|
||||
{
|
||||
AddSelectionHighlight(obj.VisualRepresentation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSelectionHighlight(UserControl userControl)
|
||||
{
|
||||
if (userControl == null) return;
|
||||
|
||||
// Primero remover cualquier highlight existente para este control
|
||||
RemoveSelectionHighlight(userControl);
|
||||
|
||||
Rect boundingBox = VisualTreeHelper.GetDescendantBounds(userControl);
|
||||
GeneralTransform transform = userControl.TransformToAncestor(_canvas);
|
||||
Rect transformedBoundingBox = transform.TransformBounds(boundingBox);
|
||||
|
||||
Rectangle highlightRect = new Rectangle
|
||||
{
|
||||
Width = transformedBoundingBox.Width,
|
||||
Height = transformedBoundingBox.Height,
|
||||
Fill = Brushes.Transparent,
|
||||
Stroke = new SolidColorBrush(Color.FromArgb(180, 255, 0, 0)),
|
||||
StrokeThickness = 2,
|
||||
Tag = "SelectionHighlight",
|
||||
IsHitTestVisible = false
|
||||
};
|
||||
|
||||
Canvas.SetLeft(highlightRect, transformedBoundingBox.Left);
|
||||
Canvas.SetTop(highlightRect, transformedBoundingBox.Top);
|
||||
Canvas.SetZIndex(highlightRect, (int)ZIndexEnum.RectangulosPropiead - 1);
|
||||
|
||||
_selectionHighlightPairs.Add((userControl, highlightRect));
|
||||
_canvas.Children.Add(highlightRect);
|
||||
}
|
||||
|
||||
private void RemoveSelectionHighlight(UserControl userControl)
|
||||
{
|
||||
var pairsToRemove = _selectionHighlightPairs.Where(p => p.Control == userControl).ToList();
|
||||
foreach (var pair in pairsToRemove)
|
||||
{
|
||||
_canvas.Children.Remove(pair.Highlight);
|
||||
_selectionHighlightPairs.Remove(pair);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveAllSelectionHighlights()
|
||||
{
|
||||
foreach (var pair in _selectionHighlightPairs)
|
||||
{
|
||||
_canvas.Children.Remove(pair.Highlight);
|
||||
}
|
||||
_selectionHighlightPairs.Clear();
|
||||
}
|
||||
|
||||
private void UpdateSelectionHighlights()
|
||||
{
|
||||
if (_mainWindow.DataContext is MainViewModel viewModel && viewModel.IsMultiSelectionActive)
|
||||
{
|
||||
RemoveAllSelectionHighlights();
|
||||
foreach (var selectedObject in _selectedObjects)
|
||||
{
|
||||
if (selectedObject.VisualRepresentation != null)
|
||||
{
|
||||
AddSelectionHighlight(selectedObject.VisualRepresentation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -443,6 +527,8 @@ namespace CtrEditor
|
|||
var dx = currentPosition.X - _startPointUserControl.X;
|
||||
var dy = currentPosition.Y - _startPointUserControl.Y;
|
||||
|
||||
RemoveAllSelectionHighlights(); // Remover antes de mover
|
||||
|
||||
foreach (var selectedObject in _selectedObjects)
|
||||
{
|
||||
var newX = Canvas.GetLeft(selectedObject.VisualRepresentation) + dx;
|
||||
|
@ -450,6 +536,8 @@ namespace CtrEditor
|
|||
selectedObject.Move((float)newX, (float)newY);
|
||||
}
|
||||
_startPointUserControl = currentPosition;
|
||||
|
||||
UpdateSelectionHighlights();
|
||||
}
|
||||
|
||||
private void UserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
|
@ -465,7 +553,18 @@ namespace CtrEditor
|
|||
rectangle.ReleaseMouseCapture();
|
||||
}
|
||||
|
||||
RemoveAllSelectionHighlights(); // Remover antes de actualizar
|
||||
UpdateSelectionVisuals();
|
||||
|
||||
// Restaurar los rectángulos de selección si es necesario
|
||||
if (_mainWindow.DataContext is MainViewModel viewModel && viewModel.IsMultiSelectionActive)
|
||||
{
|
||||
foreach (var selectedObject in _selectedObjects)
|
||||
{
|
||||
AddSelectionHighlight(selectedObject.VisualRepresentation);
|
||||
}
|
||||
}
|
||||
|
||||
_isDraggingUserControl = false;
|
||||
_isMovingUserControl = false;
|
||||
_currentDraggingRectangle = null;
|
||||
|
@ -574,6 +673,8 @@ namespace CtrEditor
|
|||
|
||||
private void HandleResize(Point currentPosition, HandleMode mode)
|
||||
{
|
||||
RemoveAllSelectionHighlights(); // Remover antes de redimensionar
|
||||
|
||||
foreach (var selectedObject in _selectedObjects)
|
||||
{
|
||||
bool resizeWidth = mode == HandleMode.ResizeWidth || mode == HandleMode.ResizeBoth;
|
||||
|
@ -581,6 +682,8 @@ namespace CtrEditor
|
|||
HandleResizeForObject(selectedObject, currentPosition, resizeWidth, resizeHeight);
|
||||
}
|
||||
_startPointUserControl = currentPosition;
|
||||
|
||||
UpdateSelectionHighlights();
|
||||
}
|
||||
|
||||
private void HandleResizeForObject(osBase obj, Point currentPosition, bool activateSizeWidth, bool activateSizeHeight)
|
||||
|
@ -593,6 +696,8 @@ namespace CtrEditor
|
|||
|
||||
private void HandleRotation(Point currentPosition)
|
||||
{
|
||||
RemoveAllSelectionHighlights(); // Remover antes de rotar
|
||||
|
||||
// Calcular el ángulo respecto al centro del bounding box que contiene todos los objetos seleccionados
|
||||
double deltaX = currentPosition.X - _transformedBoundingBoxCenter.X;
|
||||
double deltaY = currentPosition.Y - _transformedBoundingBoxCenter.Y;
|
||||
|
@ -611,6 +716,8 @@ namespace CtrEditor
|
|||
}
|
||||
_lastAngle = (float)angle;
|
||||
}
|
||||
|
||||
UpdateSelectionHighlights();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue