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;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Threading;
|
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 MouseEventArgs = System.Windows.Input.MouseEventArgs;
|
||||||
using UserControl = System.Windows.Controls.UserControl;
|
using UserControl = System.Windows.Controls.UserControl;
|
||||||
|
|
||||||
|
@ -406,7 +404,10 @@ namespace CtrEditor
|
||||||
if (_objectManager.SelectedObjects.Count > 1)
|
if (_objectManager.SelectedObjects.Count > 1)
|
||||||
{
|
{
|
||||||
var alignmentMenu = new MenuItem { Header = "Alinear" };
|
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 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 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)) });
|
alignmentMenu.Items.Add(new MenuItem { Header = "Alinear Arriba", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.Top)) });
|
||||||
|
@ -418,10 +419,20 @@ namespace CtrEditor
|
||||||
alignmentMenu.Items.Add(new MenuItem { Header = "Distribuir Horizontalmente", Command = new RelayCommand(() => _objectManager.AlignObjects(AlignmentType.DistributeHorizontally)) });
|
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)) });
|
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(alignmentMenu);
|
||||||
|
contextMenu.Items.Add(sizeMenu);
|
||||||
|
contextMenu.Items.Add(joinMenu);
|
||||||
contextMenu.Items.Add(new Separator());
|
contextMenu.Items.Add(new Separator());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
contextMenu.Items.Add(multiSelectMenuItem);
|
contextMenu.Items.Add(multiSelectMenuItem);
|
||||||
contextMenu.PlacementTarget = ImagenEnTrabajoCanvas;
|
contextMenu.PlacementTarget = ImagenEnTrabajoCanvas;
|
||||||
|
@ -429,6 +440,7 @@ namespace CtrEditor
|
||||||
contextMenu.IsOpen = true;
|
contextMenu.IsOpen = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class FloatValidationRule : ValidationRule
|
public class FloatValidationRule : ValidationRule
|
||||||
{
|
{
|
||||||
|
|
|
@ -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)
|
private Point GetObjectCenter(osBase obj)
|
||||||
{
|
{
|
||||||
double angleRad = obj.Angulo * Math.PI / 180.0;
|
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.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using System.Windows.Threading;
|
|
||||||
using CtrEditor.FuncionesBase;
|
|
||||||
using CtrEditor.ObjetosSim;
|
|
||||||
using Color = System.Windows.Media.Color;
|
using Color = System.Windows.Media.Color;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
|
|
||||||
namespace CtrEditor
|
namespace CtrEditor
|
||||||
{
|
{
|
||||||
|
@ -20,7 +19,12 @@ namespace CtrEditor
|
||||||
CenterHorizontally,
|
CenterHorizontally,
|
||||||
CenterVertically,
|
CenterVertically,
|
||||||
DistributeHorizontally,
|
DistributeHorizontally,
|
||||||
DistributeVertically
|
DistributeVertically,
|
||||||
|
EqualWidth,
|
||||||
|
EqualHeight,
|
||||||
|
EqualAngle,
|
||||||
|
JoinHorizontally,
|
||||||
|
JoinVertically
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ObjectManipulationManager
|
public class ObjectManipulationManager
|
||||||
|
@ -764,6 +768,21 @@ namespace CtrEditor
|
||||||
case AlignmentType.DistributeVertically:
|
case AlignmentType.DistributeVertically:
|
||||||
alignment.DistributeVertically();
|
alignment.DistributeVertically();
|
||||||
break;
|
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
|
// Update the selection visuals after alignment
|
||||||
|
|
Loading…
Reference in New Issue