Agregado EqualWidth, EqualHeight, EqualAngle, JoinHorizontally, JoinVertically
This commit is contained in:
parent
5ee91dd26a
commit
326c615887
|
@ -1,14 +1,12 @@
|
|||
using System.Globalization;
|
||||
using CtrEditor.ObjetosSim;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
using System.Diagnostics;
|
||||
using CtrEditor.ObjetosSim;
|
||||
using CtrEditor.FuncionesBase;
|
||||
using Xceed.Wpf.Toolkit.PropertyGrid;
|
||||
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
|
||||
using UserControl = System.Windows.Controls.UserControl;
|
||||
|
||||
|
@ -298,12 +296,12 @@ namespace CtrEditor
|
|||
{
|
||||
// Limpiar la selección en el ListBox
|
||||
viewModel.SelectedItemOsList = null;
|
||||
|
||||
|
||||
// Limpiar la selección múltiple
|
||||
_objectManager.ClearSelection();
|
||||
_objectManager.RemoveResizeRectangles();
|
||||
|
||||
|
||||
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
@ -376,7 +374,7 @@ namespace CtrEditor
|
|||
private void Canvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// Aceptar el evento si viene del canvas o de la imagen de fondo
|
||||
if ((e.Source == ImagenEnTrabajoCanvas || e.Source == imagenDeFondo || e.Source is UserControl) &&
|
||||
if ((e.Source == ImagenEnTrabajoCanvas || e.Source == imagenDeFondo || e.Source is UserControl) &&
|
||||
DataContext is MainViewModel viewModel)
|
||||
{
|
||||
e.Handled = true;
|
||||
|
@ -387,8 +385,8 @@ namespace CtrEditor
|
|||
private void ShowContextMenu(Point position)
|
||||
{
|
||||
var contextMenu = new ContextMenu();
|
||||
var multiSelectMenuItem = new MenuItem
|
||||
{
|
||||
var multiSelectMenuItem = new MenuItem
|
||||
{
|
||||
Header = "Modo Multi-Selección",
|
||||
IsCheckable = true,
|
||||
StaysOpenOnClick = false
|
||||
|
@ -397,7 +395,7 @@ namespace CtrEditor
|
|||
if (DataContext is MainViewModel viewModel)
|
||||
{
|
||||
multiSelectMenuItem.IsChecked = viewModel.IsMultiSelectionActive;
|
||||
multiSelectMenuItem.Click += (s, e) =>
|
||||
multiSelectMenuItem.Click += (s, e) =>
|
||||
{
|
||||
viewModel.IsMultiSelectionActive = multiSelectMenuItem.IsChecked;
|
||||
};
|
||||
|
@ -406,7 +404,10 @@ namespace CtrEditor
|
|||
if (_objectManager.SelectedObjects.Count > 1)
|
||||
{
|
||||
var alignmentMenu = new MenuItem { Header = "Alinear" };
|
||||
|
||||
var sizeMenu = new MenuItem { Header = "Igualar Tamaño" };
|
||||
var joinMenu = new MenuItem { Header = "Unir" };
|
||||
|
||||
// Opciones de alineación
|
||||
alignmentMenu.Items.Add(new MenuItem { Header = "Alinear a la Izquierda", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.Left)) });
|
||||
alignmentMenu.Items.Add(new MenuItem { Header = "Alinear a la Derecha", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.Right)) });
|
||||
alignmentMenu.Items.Add(new MenuItem { Header = "Alinear Arriba", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.Top)) });
|
||||
|
@ -418,15 +419,26 @@ namespace CtrEditor
|
|||
alignmentMenu.Items.Add(new MenuItem { Header = "Distribuir Horizontalmente", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.DistributeHorizontally)) });
|
||||
alignmentMenu.Items.Add(new MenuItem { Header = "Distribuir Verticalmente", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.DistributeVertically)) });
|
||||
|
||||
// Opciones de igualar tamaño
|
||||
sizeMenu.Items.Add(new MenuItem { Header = "Igualar Ancho", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.EqualWidth)) });
|
||||
sizeMenu.Items.Add(new MenuItem { Header = "Igualar Alto", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.EqualHeight)) });
|
||||
sizeMenu.Items.Add(new MenuItem { Header = "Igualar Ángulo", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.EqualAngle)) });
|
||||
|
||||
// Opciones de unir
|
||||
joinMenu.Items.Add(new MenuItem { Header = "Unir Horizontalmente", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.JoinHorizontally)) });
|
||||
joinMenu.Items.Add(new MenuItem { Header = "Unir Verticalmente", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.JoinVertically)) });
|
||||
|
||||
contextMenu.Items.Add(alignmentMenu);
|
||||
contextMenu.Items.Add(sizeMenu);
|
||||
contextMenu.Items.Add(joinMenu);
|
||||
contextMenu.Items.Add(new Separator());
|
||||
}
|
||||
}
|
||||
|
||||
contextMenu.Items.Add(multiSelectMenuItem);
|
||||
contextMenu.PlacementTarget = ImagenEnTrabajoCanvas;
|
||||
contextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
|
||||
contextMenu.IsOpen = true;
|
||||
contextMenu.Items.Add(multiSelectMenuItem);
|
||||
contextMenu.PlacementTarget = ImagenEnTrabajoCanvas;
|
||||
contextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
|
||||
contextMenu.IsOpen = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,6 +143,71 @@ namespace CtrEditor
|
|||
}
|
||||
}
|
||||
|
||||
public void EqualWidth()
|
||||
{
|
||||
if (_selectedObjects.Count <= 1) return;
|
||||
|
||||
float averageWidth = _selectedObjects.Average(obj => obj.Ancho);
|
||||
foreach (var obj in _selectedObjects)
|
||||
{
|
||||
obj.Ancho = averageWidth;
|
||||
}
|
||||
}
|
||||
|
||||
public void EqualHeight()
|
||||
{
|
||||
if (_selectedObjects.Count <= 1) return;
|
||||
|
||||
float averageHeight = _selectedObjects.Average(obj => obj.Alto);
|
||||
foreach (var obj in _selectedObjects)
|
||||
{
|
||||
obj.Alto = averageHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public void EqualAngle()
|
||||
{
|
||||
if (_selectedObjects.Count <= 1) return;
|
||||
|
||||
float referenceAngle = _selectedObjects.First().Angulo;
|
||||
foreach (var obj in _selectedObjects)
|
||||
{
|
||||
obj.Angulo = referenceAngle;
|
||||
}
|
||||
}
|
||||
|
||||
public void JoinHorizontally()
|
||||
{
|
||||
if (_selectedObjects.Count <= 1) return;
|
||||
|
||||
var sortedObjects = _selectedObjects
|
||||
.OrderBy(obj => obj.Left)
|
||||
.ToList();
|
||||
|
||||
for (int i = 1; i < sortedObjects.Count; i++)
|
||||
{
|
||||
var previousObj = sortedObjects[i - 1];
|
||||
var currentObj = sortedObjects[i];
|
||||
currentObj.Left = previousObj.Left + previousObj.Ancho;
|
||||
}
|
||||
}
|
||||
|
||||
public void JoinVertically()
|
||||
{
|
||||
if (_selectedObjects.Count <= 1) return;
|
||||
|
||||
var sortedObjects = _selectedObjects
|
||||
.OrderBy(obj => obj.Top)
|
||||
.ToList();
|
||||
|
||||
for (int i = 1; i < sortedObjects.Count; i++)
|
||||
{
|
||||
var previousObj = sortedObjects[i - 1];
|
||||
var currentObj = sortedObjects[i];
|
||||
currentObj.Top = previousObj.Top + previousObj.Alto;
|
||||
}
|
||||
}
|
||||
|
||||
private Point GetObjectCenter(osBase obj)
|
||||
{
|
||||
double angleRad = obj.Angulo * Math.PI / 180.0;
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
using System.Windows;
|
||||
using CtrEditor.FuncionesBase;
|
||||
using CtrEditor.ObjetosSim;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using CtrEditor.FuncionesBase;
|
||||
using CtrEditor.ObjetosSim;
|
||||
using Color = System.Windows.Media.Color;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace CtrEditor
|
||||
{
|
||||
|
@ -20,7 +19,12 @@ namespace CtrEditor
|
|||
CenterHorizontally,
|
||||
CenterVertically,
|
||||
DistributeHorizontally,
|
||||
DistributeVertically
|
||||
DistributeVertically,
|
||||
EqualWidth,
|
||||
EqualHeight,
|
||||
EqualAngle,
|
||||
JoinHorizontally,
|
||||
JoinVertically
|
||||
}
|
||||
|
||||
public class ObjectManipulationManager
|
||||
|
@ -132,7 +136,7 @@ namespace CtrEditor
|
|||
|
||||
// Calcular el bounding box que contenga todos los objetos seleccionados
|
||||
Rect boundingBox = CalculateTotalBoundingBox(selectedObjects);
|
||||
|
||||
|
||||
FuncionesBase.MutableRect rectBox = new FuncionesBase.MutableRect(boundingBox);
|
||||
rectBox.Left -= (float)rectHighlightSize;
|
||||
rectBox.Right += (float)rectHighlightSize;
|
||||
|
@ -363,7 +367,7 @@ namespace CtrEditor
|
|||
}
|
||||
RemoveAllSelectionHighlights();
|
||||
RemoveResizeRectangles();
|
||||
|
||||
|
||||
if (_mainWindow.DataContext is MainViewModel viewModel)
|
||||
{
|
||||
viewModel.SelectedItemOsList = null;
|
||||
|
@ -764,6 +768,21 @@ namespace CtrEditor
|
|||
case AlignmentType.DistributeVertically:
|
||||
alignment.DistributeVertically();
|
||||
break;
|
||||
case AlignmentType.EqualWidth:
|
||||
alignment.EqualWidth();
|
||||
break;
|
||||
case AlignmentType.EqualHeight:
|
||||
alignment.EqualHeight();
|
||||
break;
|
||||
case AlignmentType.EqualAngle:
|
||||
alignment.EqualAngle();
|
||||
break;
|
||||
case AlignmentType.JoinHorizontally:
|
||||
alignment.JoinHorizontally();
|
||||
break;
|
||||
case AlignmentType.JoinVertically:
|
||||
alignment.JoinVertically();
|
||||
break;
|
||||
}
|
||||
|
||||
// Update the selection visuals after alignment
|
||||
|
|
Loading…
Reference in New Issue