Пример #1
0
 public MyUndoUnit(MyBusinessObject businessObject, double oldValue)
     : base("Change Value")
 {
     this.businessObject = businessObject;
     this.oldValue       = oldValue;
     this.newValue       = businessObject.Value;
 }
Пример #2
0
        /// <summary>
        /// When a node is removed, we detach the event handler.
        /// </summary>
        private void OnNodeRemoved(object source, ItemEventArgs <INode> evt)
        {
            MyBusinessObject tag = evt.Item.Tag as MyBusinessObject;

            if (tag != null)
            {
                tag.MyEditEvent -= OnUndoEventHandler;
            }
        }
            public void Paint(IRenderContext context, Graphics graphics)
            {
                var layout = Node.Layout;

                // Draw a rounded rectangle
                double roundingX = layout.Width * roundingFactor;
                double roundingY = layout.Height * roundingFactor;

                MyBusinessObject businessObject = Node.Tag as MyBusinessObject;

                GraphicsPath path = new GraphicsPath();

                path.AddBezier((float)layout.X, (float)(layout.Y + roundingY), (float)layout.X,
                               (float)(layout.Y + (roundingY / 2)),
                               (float)(layout.X + (roundingX / 2)), (float)layout.Y, (float)(layout.X + roundingX), (float)layout.Y);
                path.AddLine((float)(layout.X + roundingX), (float)layout.Y, (float)(layout.X + layout.Width - roundingX),
                             (float)layout.Y);

                path.AddBezier((float)(layout.X + layout.Width - roundingX), (float)(layout.Y),
                               (float)(layout.X + layout.Width - (roundingX / 2)), (float)(layout.Y),
                               (float)(layout.X + layout.Width), (float)(layout.Y + (roundingY / 2)), (float)(layout.X + layout.Width),
                               (float)(layout.Y + roundingY));
                path.AddLine((float)(layout.X + layout.Width), (float)(layout.Y + roundingY),
                             (float)(layout.X + layout.Width), (float)(layout.Y + layout.Height - roundingY));

                path.AddBezier((float)(layout.X + layout.Width), (float)(layout.Y + layout.Height - roundingY),
                               (float)(layout.X + layout.Width), (float)(layout.Y + layout.Height - (roundingY / 2)),
                               (float)(layout.X + layout.Width - (roundingX / 2)), (float)(layout.Y + layout.Height),
                               (float)(layout.X + layout.Width - roundingX), (float)(layout.Y + layout.Height));
                path.AddLine((float)(layout.X + layout.Width - roundingX), (float)(layout.Y + layout.Height),
                             (float)(layout.X + roundingX), (float)(layout.Y + layout.Height));

                path.AddBezier((float)(layout.X + roundingX), (float)(layout.Y + layout.Height),
                               (float)(layout.X + (roundingX / 2)), (float)(layout.Y + layout.Height),
                               (float)(layout.X), (float)(layout.Y + layout.Height - (roundingY / 2)), (float)(layout.X),
                               (float)(layout.Y + layout.Height - roundingY));
                path.AddLine((float)layout.X, (float)(layout.Y + layout.Height - roundingY), (float)(layout.X),
                             (float)(layout.Y + layout.Height - roundingY));

                graphics.FillPath(
                    new LinearGradientBrush(
                        new RectangleF((float)layout.X, (float)layout.Y, (float)layout.Width, (float)layout.Height),
                        BackgroundColor, Mix(BackgroundColor, Color.Black, 0.7), 90f), path);
                graphics.DrawPath(Pens.LightGray, path);

                if (businessObject != null)
                {
                    // Draw a line to vizualize the business object's value
                    graphics.DrawLine(Pens.Black, (float)(layout.X + 10), (float)(layout.Y + (layout.Height * 3 / 4)),
                                      (float)(layout.X + 10 + (layout.Width - 20) * businessObject.Value),
                                      (float)(layout.Y + (layout.Height * 3 / 4)));
                    // Display the business object's name
                    graphics.DrawString("Node", new Font("Arial", 8), Brushes.Black, (float)(layout.X + 10),
                                        (float)layout.Y + 10);
                }
            }
                public void CancelDrag(IInputModeContext inputModeContext, PointD originalLocation)
                {
                    // restore original value
                    MyBusinessObject myBusinessObject = node.Tag as MyBusinessObject;

                    if (myBusinessObject != null)
                    {
                        myBusinessObject.Value = originalValue;
                    }
                }
                public void InitializeDrag(IInputModeContext inputModeContext)
                {
                    // remember the original value so the drag can be cancelled correctly
                    MyBusinessObject myBusinessObject = node.Tag as MyBusinessObject;

                    if (myBusinessObject != null)
                    {
                        originalValue = myBusinessObject.Value;
                    }
                }
                public void DragFinished(IInputModeContext inputModeContext, PointD originalLocation, PointD newLocation)
                {
                    double           minVal           = node.Layout.X + 10;
                    double           maxVal           = node.Layout.X + node.Layout.Width - 10;
                    double           currentVal       = newLocation.X;
                    double           ratio            = ((currentVal - minVal) / (maxVal - minVal));
                    MyBusinessObject myBusinessObject = node.Tag as MyBusinessObject;

                    if (myBusinessObject != null)
                    {
                        myBusinessObject.Value = ratio;
                    }
                }