protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnPreviewMouseLeftButtonDown(e); _Control rootElement = GetCanvasRootChild(e.OriginalSource as DependencyObject) as _Control; HandlerMouseButtonLeftDown(e, rootElement); }
// Use this for initialization void Start() { //offset = transform.position - player.transform.position ; position.y = transform.position.y; this.hitbox = player.GetComponent<Rigidbody2D> (); playerScript = player.GetComponent<_Control> (); }
public AccessControlModel(_Control control, bool getProperties = true, bool getChildrenRecursively = true) { Control = control ?? throw new ArgumentNullException(nameof(control)); Name = control.Name; Type = ((AcControlType)TryGetPropertyValue <int>("ControlType")).ToString(); Caption = TryGetPropertyValue <string>("Caption"); Value = TryGetPropertyValue <string>("Value"); Left = TryGetPropertyValue <int>("Left"); Top = TryGetPropertyValue <int>("Top"); Width = TryGetPropertyValue <int>("Width"); Height = TryGetPropertyValue <int>("Height"); Report = new Lazy <AccessReportModel>(() => new AccessReportModel(Control.Report)); if (getProperties && control.Properties.Count > 0) { LoadProperties(); } if (getChildrenRecursively) { LoadChildren(getProperties); } }
private void SetSelected(_Control control) { _selectedControls.Add(control); if (null == _adornerLayer) { _adornerLayer = AdornerLayer.GetAdornerLayer(control); } int rootHasCode = control.GetHashCode(); if (!_adorners.ContainsKey(rootHasCode)) { if (control is _Line) { _adorners.Add(rootHasCode, new LineAdorner(control as _Line)); } else { _adorners.Add(rootHasCode, new ElementAdorner(control)); } } ElementAdorner rootAdorner = _adorners[rootHasCode]; _adornerLayer.Add(rootAdorner); LoadAdorner(rootAdorner); }
private void HandlerMouseButtonLeftDown(MouseButtonEventArgs e, _Control rootElement) { if (null != rootElement) { if (null == _adornerLayer) { _adornerLayer = AdornerLayer.GetAdornerLayer(rootElement); } int rootHasCode = rootElement.GetHashCode(); if (!_adorners.ContainsKey(rootHasCode)) { if (rootElement is _Line) { _adorners.Add(rootHasCode, new LineAdorner(rootElement as _Line)); } else { _adorners.Add(rootHasCode, new ElementAdorner(rootElement)); } } ElementAdorner rootAdorner = _adorners[rootHasCode]; if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { if (_selectedControls.Contains(rootElement)) { _adornerLayer.Remove(rootAdorner); UnLoadAdorner(rootAdorner); _selectedControls.Remove(rootElement); } else { _adornerLayer.Add(rootAdorner); LoadAdorner(rootAdorner); _selectedControls.Add(rootElement); rootAdorner.RaisePreviewMouseLeftButtonDown(e); } } else { CleanSelection(); _adornerLayer.Add(rootAdorner); LoadAdorner(rootAdorner); _selectedControls.Add(rootElement); rootAdorner.RaisePreviewMouseLeftButtonDown(e); } } else { CleanSelection(); } if (null != SelectionChangedAction) { SelectionChangedAction(_selectedControls); } }
private void OnElementMoved(_Control element, Rect rect) { if (null != ElementMovedAction) { ElementMovedAction(element, rect); } }
private void OnElementMoving(_Control element, Rect rect) { if (!DesginCanvas.IsAutoAlign) { return; } List <AutoAlignLine> alignLines = new List <AutoAlignLine>(); foreach (UIElement ui in DesginCanvas.Children) { if (DesginCanvas.SelectedControls.Contains(ui as _Control)) { continue; } if (ui is _Control && !(ui is _Line)) { AutoAlignLine alignLine = AlignCanvas.MeasureAlign(element, ui as _Control); if (!alignLine.IsEmpty) { alignLines.Add(alignLine); } } } AlignCanvas.DrawAlignLines(alignLines); }
private Point OnLineMoved(_Line source, Point point1, Point point2) { if (!DesginCanvas.IsAutoAlign) { return(point1); } Point a = new Point(point1.X + source.Left, point1.Y + source.Top); Point b = new Point(point2.X + source.Left, point2.Y + source.Top); AlignCanvas.Clear(); Point point = new Point(double.NaN, double.NaN); foreach (UIElement ui in DesginCanvas.Children) { if (DesginCanvas.SelectedControls.Contains(ui as _Control)) { continue; } if (ui is _Line) { _Line line = ui as _Line; point = AlignCanvas.MeasurePoint(a, b, new Point(line.Line.X1 + line.Left, line.Line.Y1 + line.Top), new Point(line.Line.X2 + line.Left, line.Line.Y2 + line.Top)); if (!double.IsNaN(point.X)) { return(new Point(point.X - source.Left, point.Y - source.Top)); } } else if (ui is _Rectangle) { _Control element = ui as _Control; Point a1 = new Point(element.Left, element.Top); Point b1 = new Point(element.Left + element.Width, element.Top); Point c1 = new Point(element.Left + element.Width, element.Top + element.Height); Point d1 = new Point(element.Left, element.Top + element.Height); point = AlignCanvas.MeasurePoint(a, b, a1, b1); if (!double.IsNaN(point.X)) { return(new Point(point.X - source.Left, point.Y - source.Top)); } else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, b, b1, c1)).X)) { return(new Point(point.X - source.Left, point.Y - source.Top)); } else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, b, c1, d1)).X)) { return(new Point(point.X - source.Left, point.Y - source.Top)); } else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, b, d1, a1)).X)) { return(new Point(point.X - source.Left, point.Y - source.Top)); } } } return(AlignCanvas.Orthogonal(point1, point2)); }
private void OnLinePoint1Adding(_Line source, Point a) { if (!DesginCanvas.IsAutoAlign) { return; } List <Point> points = new List <Point>(); foreach (UIElement ui in DesginCanvas.Children) { if (DesginCanvas.SelectedControls.Contains(ui as _Control)) { continue; } if (ui is _Line) { _Line line = ui as _Line; Point point = AlignCanvas.MeasurePoint(a, new Point(line.Line.X1 + line.Left, line.Line.Y1 + line.Top), new Point(line.Line.X2 + line.Left, line.Line.Y2 + line.Top)); if (!double.IsNaN(point.X)) { points.Add(point); } } else if (ui is _Rectangle) { _Control element = ui as _Control; Point a1 = new Point(element.Left, element.Top); Point b1 = new Point(element.Left + element.Width, element.Top); Point c1 = new Point(element.Left + element.Width, element.Top + element.Height); Point d1 = new Point(element.Left, element.Top + element.Height); Point point = AlignCanvas.MeasurePoint(a, a1, b1); if (!double.IsNaN(point.X)) { points.Add(point); } else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, b1, c1)).X)) { points.Add(point); } else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, c1, d1)).X)) { points.Add(point); } else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, d1, a1)).X)) { points.Add(point); } } } AlignCanvas.DrawAlignPoints(points); }
private void OnElementMoved(_Control element, Rect rect) { AlignCanvas.Clear(); if (!DesginCanvas.IsAutoAlign) { return; } foreach (UIElement ui in DesginCanvas.Children) { if (DesginCanvas.SelectedControls.Contains(ui as _Control)) { continue; } if (ui is _Control) { AutoAlignLine alignLine = AlignCanvas.MeasureAlign(element, ui as _Control); if (!alignLine.IsEmpty) { switch (alignLine.AlignType) { case AlignType.Left: element.Left = alignLine.X1; break; case AlignType.Top: element.Top = alignLine.Y1; break; case AlignType.Right: element.Left = alignLine.X1 - element.Width; break; case AlignType.Bottom: element.Top = alignLine.Y1 - element.Height; break; case AlignType.HorizontalCenter: element.Left = alignLine.X1 - element.Width / 2d; break; case AlignType.VerticalCenter: element.Top = alignLine.Y1 - element.Height / 2d; break; } break; } } } }
public void AddNewControl(_Control control) { this.Children.Add(control); CleanSelection(); SetSelected(control); if (null != SelectionChangedAction) { SelectionChangedAction(_selectedControls); } OnElementMoved(control, new Rect(control.Left, control.Top, control.Width, control.Height)); }
public AccessControlModel GetAccessControlByPath(Application application, ControlPathModel controlPath) { var form = application.Forms[controlPath.FormName]; _Control controlFound = null; var controls = form.Controls.OfType <_Control>().ToList(); for (var i = 0; i < controlPath.Count; i++) { var pathElement = controlPath[i]; controlFound = GetMatchingControl(controls, controlPath[i]); if (i == controlPath.Count - 1) { break; // don't load children of last element of path, it's probably not a container and wil throw a COM exception } controls = controlFound.Controls.OfType <_Control>().ToList(); } return(new AccessControlModel(controlFound, true, false)); }
public ElementAdorner(_Control adornedElement) : base(adornedElement) { _element = adornedElement; }
public void BeginAdd(_Control addBaseControl) { _addBaseControl = addBaseControl; this.Visibility = Visibility.Visible; }
public AutoAlignLine MeasureAlign(_Control source, _Control target) { if (Math.Abs(source.Left + source.Width / 2d - target.Left - target.Width / 2d) <= AUTO_ALIGN_SIZE) { return(new AutoAlignLine( target.Left + target.Width / 2d, target.Top - target.Height * 0.1d, target.Left + target.Width / 2d, target.Top + target.Height * 1.1d, AlignType.HorizontalCenter)); } else if (Math.Abs(source.Top + source.Height / 2d - target.Top - target.Height / 2d) <= AUTO_ALIGN_SIZE) { return(new AutoAlignLine( target.Left - target.Width * 0.1, target.Top + target.Height / 2d, target.Left + target.Width * 1.1, target.Top + target.Height / 2d, AlignType.VerticalCenter)); } else if (Math.Abs(source.Top - target.Top) <= AUTO_ALIGN_SIZE) { return(new AutoAlignLine( target.Left - target.Width * 0.1, target.Top, target.Left + target.Width * 1.1, target.Top, AlignType.Top)); } else if (Math.Abs(source.Left - target.Left) <= AUTO_ALIGN_SIZE) { return(new AutoAlignLine( target.Left, target.Top - target.Height * 0.1d, target.Left, target.Top + target.Height * 1.1, AlignType.Left)); } else if (Math.Abs(source.Left + source.Width - target.Left - target.Width) <= AUTO_ALIGN_SIZE) { return(new AutoAlignLine( target.Left + target.Width, target.Top - target.Height * 0.1d, target.Left + target.Width, target.Top + target.Height * 1.1, AlignType.Right)); } else if (Math.Abs(source.Top + source.Height - target.Top - target.Height) <= AUTO_ALIGN_SIZE) { return(new AutoAlignLine( target.Left - target.Width * 0.1, target.Top + target.Height, target.Left + target.Width * 1.1, target.Top + target.Height, AlignType.Bottom)); } else { return(AutoAlignLine.Empty); } }
private void OnAddLineCompeledAction(_Control control) { DesginCanvas.AddNewControl(control); }
private void OnAddElementCompletedAction(_Control control) { DesginCanvas.AddNewControl(control); }