Beispiel #1
0
 public void MoveElement(GraphicElement el, Point delta)
 {
     if (el.OnScreen())
     {
         Trace.WriteLine("*** MoveElement " + el.GetType().Name);
         int dx  = delta.X.Abs();
         int dy  = delta.Y.Abs();
         var els = EraseIntersectionsTopToBottom(el, dx, dy);
         // X1
         //el.MoveUndoRedo(delta, false);
         el.Move(delta);
         el.UpdatePath();
         UpdateConnections(el);
         DrawBottomToTop(els, dx, dy);
         UpdateScreen(els, dx, dy);
     }
     else
     {
         el.CancelBackground();
         // X1
         //el.MoveUndoRedo(delta, false);
         el.Move(delta);
         // TODO: Display element if moved back on screen at this point?
     }
 }
Beispiel #2
0
        public void Redraw(GraphicElement el, int dx = 0, int dy = 0)
        {
            Trace.WriteLine("*** Redraw1 " + el.GetType().Name);
            var els = EraseIntersectionsTopToBottom(el, dx, dy);

            DrawBottomToTop(els, dx, dy);
            UpdateScreen(els, dx, dy);
        }
Beispiel #3
0
        public void Redraw(GraphicElement el, Action <GraphicElement> afterErase)
        {
            Trace.WriteLine("*** Redraw2 " + el.GetType().Name);
            var els = EraseIntersectionsTopToBottom(el);

            UpdateScreen(els);
            afterErase(el);
            el.UpdatePath();
            DrawBottomToTop(els);
            UpdateScreen(els);
        }
Beispiel #4
0
        /// <summary>
        /// Direct update of display rectangle, used in DynamicConnector.
        /// </summary>
        public void UpdateDisplayRectangle(GraphicElement el, Rectangle newRect, Point delta)
        {
            Trace.WriteLine("*** UpdateDisplayRectangle " + el.GetType().Name);
            int dx  = delta.X.Abs();
            int dy  = delta.Y.Abs();
            var els = EraseIntersectionsTopToBottom(el, dx, dy);

            el.DisplayRectangle = newRect;
            el.UpdatePath();
            DrawBottomToTop(els, dx, dy);
            UpdateScreen(els, dx, dy);
        }
        // We're using reflect here so that the call:
        // ex: this.ChangePropertyWithUndoRedo<string>(el, "Text", "Text"));
        // can be as general purpose as possible, otherwise we have to write separate undo/redo handlers for each property, which is just gross.
        public static void ChangePropertyWithUndoRedo <T>(this ElementProperties props, GraphicElement el, string elementPropertyName, string propertyName)
        {
            T            save      = default(T);
            T            redosave  = default(T);
            PropertyInfo piElement = el.GetType().GetProperty(elementPropertyName);
            PropertyInfo piThis    = props.GetType().GetProperty(propertyName);

            el.Canvas.Controller.UndoStack.Do((@do, redo) =>
            {
                if (redo)
                {
                    piElement.SetValue(el, redosave);
                    piThis.SetValue(props, redosave);
                    el.Canvas.Controller.ElementSelected.Fire(props, new ElementEventArgs()
                    {
                        Element = el
                    });
                    el.UpdateProperties();
                    el.UpdatePath();
                    el.Canvas.Controller.Redraw(el);
                }
                else if (@do)
                {
                    save     = CastObject <T>(piElement.GetValue(el));
                    T newVal = CastObject <T>(piThis.GetValue(props));
                    piElement.SetValue(el, newVal);
                    redosave = newVal;
                }
                else
                {
                    piElement.SetValue(el, save);
                    piThis.SetValue(props, save);
                    el.Canvas.Controller.ElementSelected.Fire(props, new ElementEventArgs()
                    {
                        Element = el
                    });
                    el.UpdateProperties();
                    el.UpdatePath();
                    el.Canvas.Controller.Redraw(el);
                }
            });
        }
        public void MoveElementTo(GraphicElement el, Point location)
        {
            Point delta = new Point(location.X - el.DisplayRectangle.Left, location.Y - el.DisplayRectangle.Top);

            if (el.OnScreen())
            {
                Trace.WriteLine("*** MoveElement " + el.GetType().Name);
                int dx  = delta.X.Abs();
                int dy  = delta.Y.Abs();
                var els = EraseOurselvesAndIntersectionsTopToBottom(el, dx, dy);
                el.Move(delta);
                el.UpdatePath();
                UpdateConnections(el);
                DrawBottomToTop(els, dx, dy);
                UpdateScreen(els, dx, dy);
            }
            else
            {
                el.CancelBackground();
                el.Move(delta);
                // TODO: Display element if moved back on screen at this point?
            }
        }