136 lines
4.0 KiB
C#
136 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Net.Mime;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Controls.Primitives;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace ERD.Diagramming_Logic.Elements
|
|
{
|
|
internal class RectangleElement : Element
|
|
{
|
|
public override string GetMenuHeader()
|
|
{
|
|
return this.GetType().Name;
|
|
}
|
|
|
|
public override void CreateElement(object sender, RoutedEventArgs e)
|
|
{
|
|
TextBox rect = new TextBox()
|
|
{
|
|
Height = 150,
|
|
Width = 150,
|
|
//Stroke = Brushes.Black,
|
|
//StrokeThickness = 5,
|
|
//Fill = Brushes.Red
|
|
};
|
|
|
|
|
|
|
|
RepeatButton repeatButton = new RepeatButton()
|
|
{
|
|
Height = 150,
|
|
Width = 150,
|
|
Background = Brushes.Blue,
|
|
Delay = 500,
|
|
Interval = 1
|
|
};
|
|
|
|
repeatButton.Cursor = Cursors.SizeAll;
|
|
|
|
repeatButton.Content = rect;
|
|
|
|
repeatButton.Tag = "R" + (canvas.Children.Count - 1).ToString();
|
|
rect.MouseLeave += UnsetReadOnly;
|
|
rect.MouseMove += SetReadOnly;
|
|
Trace.WriteLine($"It's {(repeatButton.ActualWidth / 2)}");
|
|
Canvas.SetLeft(repeatButton, (canvas.ActualWidth / 2) - (repeatButton.Width / 2));
|
|
Canvas.SetTop(repeatButton, (canvas.ActualHeight / 2) - (repeatButton.Height / 2));
|
|
//repeatButton.Click += Holding;
|
|
repeatButton.MouseMove += Holding;
|
|
canvas.Children.Add(repeatButton);
|
|
|
|
|
|
|
|
}
|
|
|
|
private void SetReadOnly(object sender, MouseEventArgs e)
|
|
{
|
|
if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) return;
|
|
TextBox box = sender as TextBox;
|
|
box.Cursor = Cursors.SizeAll;
|
|
box.Background = Brushes.LightBlue;
|
|
box.Focusable = false;
|
|
}
|
|
|
|
private void UnsetReadOnly(object sender, MouseEventArgs e)
|
|
{
|
|
TextBox box = sender as TextBox;
|
|
box.IsReadOnly = false;
|
|
box.Background = Brushes.White;
|
|
box.Cursor = Cursors.IBeam;
|
|
box.Focusable = true;
|
|
}
|
|
|
|
private Point mousePosition, objectPosition;
|
|
|
|
private void Holding(object sender, RoutedEventArgs e)
|
|
{
|
|
if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) return;
|
|
var button = sender as RepeatButton;
|
|
if (mousePosition.X == 0 && objectPosition.X == 0)
|
|
{
|
|
mousePosition = Handler.window.mousePoint;
|
|
return;
|
|
}
|
|
|
|
var newMousePos = Handler.window.mousePoint;
|
|
|
|
var delta = newMousePos - mousePosition;
|
|
objectPosition.X = Canvas.GetLeft(button) + delta.X;
|
|
objectPosition.Y = Canvas.GetTop(button) + delta.Y;
|
|
|
|
|
|
Canvas.SetLeft(button, objectPosition.X);
|
|
Canvas.SetTop(button, objectPosition.Y);
|
|
|
|
mousePosition.X = 0;
|
|
objectPosition.X = 0;
|
|
}
|
|
|
|
|
|
private void OnHold(object sender, MouseButtonEventArgs e)
|
|
{
|
|
|
|
/*
|
|
Point dragStartPoint, objectStartLocation;
|
|
Trace.WriteLine("Nigger");
|
|
var r = sender as Rectangle ?? throw new InvalidOperationException();
|
|
|
|
dragStartPoint.X = e.GetPosition(Handler.window).X;
|
|
dragStartPoint.Y = e.GetPosition(Handler.window).Y;
|
|
|
|
objectStartLocation.X = Canvas.GetLeft(r);
|
|
objectStartLocation.Y = Canvas.GetTop(r);
|
|
|
|
double deltaX = Handler.window.mousePoint.X - dragStartPoint.X;
|
|
double deltaY = Handler.window.mousePoint.Y - dragStartPoint.Y;*/
|
|
|
|
|
|
}
|
|
|
|
public RectangleElement(CanvasHandler handler) : base(handler)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
}
|