Example #1
0
        /// <summary>
        /// Clone onto the specified canvas the default shape.
        /// </summary>
        public virtual GraphicElement CloneDefault(Canvas canvas, Point offset)
        {
            GraphicElement el = (GraphicElement)Activator.CreateInstance(GetType(), new object[] { canvas });
            el.DisplayRectangle = el.DefaultRectangle();
            el.Move(offset);
            el.UpdateProperties();
            el.UpdatePath();

            return el;
        }
Example #2
0
        // 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);
                }
            });
        }