Marcado en purpura el objeto tomado de referencia
This commit is contained in:
parent
38ca212d9f
commit
0a52c543e6
|
@ -7,10 +7,12 @@ namespace CtrEditor
|
||||||
public class ObjectAlignment
|
public class ObjectAlignment
|
||||||
{
|
{
|
||||||
private readonly ObservableCollection<osBase> _selectedObjects;
|
private readonly ObservableCollection<osBase> _selectedObjects;
|
||||||
|
private readonly osBase _referenceObject;
|
||||||
|
|
||||||
public ObjectAlignment(ObservableCollection<osBase> selectedObjects)
|
public ObjectAlignment(ObservableCollection<osBase> selectedObjects, osBase referenceObject = null)
|
||||||
{
|
{
|
||||||
_selectedObjects = selectedObjects;
|
_selectedObjects = selectedObjects;
|
||||||
|
_referenceObject = referenceObject ?? selectedObjects.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AlignLeft()
|
public void AlignLeft()
|
||||||
|
@ -139,11 +141,11 @@ namespace CtrEditor
|
||||||
{
|
{
|
||||||
if (_selectedObjects.Count <= 1) return;
|
if (_selectedObjects.Count <= 1) return;
|
||||||
|
|
||||||
float averageWidth = _selectedObjects.Average(obj => GetEffectiveDimensions(obj).Width);
|
float referenceWidth = GetEffectiveDimensions(_referenceObject).Width;
|
||||||
foreach (var obj in _selectedObjects)
|
foreach (var obj in _selectedObjects.Where(o => o != _referenceObject))
|
||||||
{
|
{
|
||||||
var currentDims = GetEffectiveDimensions(obj);
|
var currentDims = GetEffectiveDimensions(obj);
|
||||||
SetEffectiveDimensions(obj, averageWidth, currentDims.Height);
|
SetEffectiveDimensions(obj, referenceWidth, currentDims.Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,11 +153,11 @@ namespace CtrEditor
|
||||||
{
|
{
|
||||||
if (_selectedObjects.Count <= 1) return;
|
if (_selectedObjects.Count <= 1) return;
|
||||||
|
|
||||||
float averageHeight = _selectedObjects.Average(obj => GetEffectiveDimensions(obj).Height);
|
float referenceHeight = GetEffectiveDimensions(_referenceObject).Height;
|
||||||
foreach (var obj in _selectedObjects)
|
foreach (var obj in _selectedObjects.Where(o => o != _referenceObject))
|
||||||
{
|
{
|
||||||
var currentDims = GetEffectiveDimensions(obj);
|
var currentDims = GetEffectiveDimensions(obj);
|
||||||
SetEffectiveDimensions(obj, currentDims.Width, averageHeight);
|
SetEffectiveDimensions(obj, currentDims.Width, referenceHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,8 +165,8 @@ namespace CtrEditor
|
||||||
{
|
{
|
||||||
if (_selectedObjects.Count <= 1) return;
|
if (_selectedObjects.Count <= 1) return;
|
||||||
|
|
||||||
float referenceAngle = _selectedObjects.First().Angulo;
|
float referenceAngle = _referenceObject.Angulo;
|
||||||
foreach (var obj in _selectedObjects)
|
foreach (var obj in _selectedObjects.Where(o => o != _referenceObject))
|
||||||
{
|
{
|
||||||
obj.Angulo = referenceAngle;
|
obj.Angulo = referenceAngle;
|
||||||
}
|
}
|
||||||
|
|
|
@ -393,22 +393,14 @@ namespace CtrEditor
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Agregar destacados de selección para los objetos ya seleccionados
|
UpdateAllSelectionHighlights();
|
||||||
foreach (var obj in _selectedObjects)
|
|
||||||
{
|
|
||||||
if (obj.VisualRepresentation != null)
|
|
||||||
{
|
|
||||||
AddSelectionHighlight(obj.VisualRepresentation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddSelectionHighlight(UserControl userControl)
|
private void AddSelectionHighlight(UserControl userControl, bool isReference = false)
|
||||||
{
|
{
|
||||||
if (userControl == null) return;
|
if (userControl == null) return;
|
||||||
|
|
||||||
// Primero remover cualquier highlight existente para este control
|
|
||||||
RemoveSelectionHighlight(userControl);
|
RemoveSelectionHighlight(userControl);
|
||||||
|
|
||||||
Rect boundingBox = VisualTreeHelper.GetDescendantBounds(userControl);
|
Rect boundingBox = VisualTreeHelper.GetDescendantBounds(userControl);
|
||||||
|
@ -420,8 +412,10 @@ namespace CtrEditor
|
||||||
Width = transformedBoundingBox.Width,
|
Width = transformedBoundingBox.Width,
|
||||||
Height = transformedBoundingBox.Height,
|
Height = transformedBoundingBox.Height,
|
||||||
Fill = Brushes.Transparent,
|
Fill = Brushes.Transparent,
|
||||||
Stroke = new SolidColorBrush(Color.FromArgb(180, 255, 0, 0)),
|
Stroke = new SolidColorBrush(isReference ?
|
||||||
StrokeThickness = 2,
|
Color.FromArgb(180, 128, 0, 128) : // Purple for reference
|
||||||
|
Color.FromArgb(180, 255, 0, 0)), // Red for others
|
||||||
|
StrokeThickness = isReference ? 3 : 2, // Más grueso para el de referencia
|
||||||
Tag = "SelectionHighlight",
|
Tag = "SelectionHighlight",
|
||||||
IsHitTestVisible = false
|
IsHitTestVisible = false
|
||||||
};
|
};
|
||||||
|
@ -453,21 +447,28 @@ namespace CtrEditor
|
||||||
_selectionHighlightPairs.Clear();
|
_selectionHighlightPairs.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateSelectionHighlights()
|
private void UpdateAllSelectionHighlights()
|
||||||
{
|
{
|
||||||
if (_mainWindow.DataContext is MainViewModel viewModel && viewModel.IsMultiSelectionActive)
|
if (_mainWindow.DataContext is MainViewModel viewModel && viewModel.IsMultiSelectionActive)
|
||||||
{
|
{
|
||||||
RemoveAllSelectionHighlights();
|
RemoveAllSelectionHighlights();
|
||||||
|
bool isFirst = true;
|
||||||
foreach (var selectedObject in _selectedObjects)
|
foreach (var selectedObject in _selectedObjects)
|
||||||
{
|
{
|
||||||
if (selectedObject.VisualRepresentation != null)
|
if (selectedObject.VisualRepresentation != null)
|
||||||
{
|
{
|
||||||
AddSelectionHighlight(selectedObject.VisualRepresentation);
|
AddSelectionHighlight(selectedObject.VisualRepresentation, isFirst);
|
||||||
|
isFirst = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateSelectionHighlights()
|
||||||
|
{
|
||||||
|
UpdateAllSelectionHighlights();
|
||||||
|
}
|
||||||
|
|
||||||
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
if (!_isDrawingCanvas)
|
if (!_isDrawingCanvas)
|
||||||
|
@ -557,7 +558,7 @@ namespace CtrEditor
|
||||||
}
|
}
|
||||||
_startPointUserControl = currentPosition;
|
_startPointUserControl = currentPosition;
|
||||||
|
|
||||||
UpdateSelectionHighlights();
|
UpdateAllSelectionHighlights();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
private void UserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||||
|
@ -575,6 +576,7 @@ namespace CtrEditor
|
||||||
|
|
||||||
RemoveAllSelectionHighlights(); // Remover antes de actualizar
|
RemoveAllSelectionHighlights(); // Remover antes de actualizar
|
||||||
UpdateSelectionVisuals();
|
UpdateSelectionVisuals();
|
||||||
|
UpdateAllSelectionHighlights();
|
||||||
|
|
||||||
// Restaurar los rectángulos de selección si es necesario
|
// Restaurar los rectángulos de selección si es necesario
|
||||||
if (_mainWindow.DataContext is MainViewModel viewModel && viewModel.IsMultiSelectionActive)
|
if (_mainWindow.DataContext is MainViewModel viewModel && viewModel.IsMultiSelectionActive)
|
||||||
|
@ -703,7 +705,7 @@ namespace CtrEditor
|
||||||
}
|
}
|
||||||
_startPointUserControl = currentPosition;
|
_startPointUserControl = currentPosition;
|
||||||
|
|
||||||
UpdateSelectionHighlights();
|
UpdateAllSelectionHighlights();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleResizeForObject(osBase obj, Point currentPosition, bool activateSizeWidth, bool activateSizeHeight)
|
private void HandleResizeForObject(osBase obj, Point currentPosition, bool activateSizeWidth, bool activateSizeHeight)
|
||||||
|
@ -737,14 +739,14 @@ namespace CtrEditor
|
||||||
_lastAngle = (float)angle;
|
_lastAngle = (float)angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateSelectionHighlights();
|
UpdateAllSelectionHighlights();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AlignObjects(AlignmentType alignmentType)
|
public void AlignObjects(AlignmentType alignmentType)
|
||||||
{
|
{
|
||||||
if (_selectedObjects.Count <= 1) return;
|
if (_selectedObjects.Count <= 1) return;
|
||||||
|
|
||||||
var alignment = new ObjectAlignment(_selectedObjects);
|
var alignment = new ObjectAlignment(_selectedObjects, _selectedObjects.FirstOrDefault());
|
||||||
|
|
||||||
switch (alignmentType)
|
switch (alignmentType)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue