示例#1
0
 public void RemoveAction(ShapeAction shapeAction)
 {
     m_ShapeActionFactory.Remove(shapeAction);
     m_ShapeActions.Remove(shapeAction);
     shapeAction.BecameDirty -= OnBecameDirty;
     OnBecameDirty();
 }
        private void AddShapeAction(ShapeActionFactory.ShapeActionType actionType)
        {
            ShapeAction   shapeAction   = m_Stage.AddAction(actionType);
            VisualElement visualElement = ShapeActionEditorFactory.GetVisualElement(shapeAction, RemoveShapeAction);

            m_ShapeActionsListVisualElement.Add(visualElement);
        }
        public static VisualElement GetVisualElement(ShapeAction shapeAction,
                                                     Action <ShapeAction, VisualElement> deleteAction)
        {
            VisualElement visualElement = null;

            switch (shapeAction)
            {
            case SetActiveShapeAction setActiveShapeAction:
                visualElement = new SetActiveShapeActionEditor(setActiveShapeAction, deleteAction).GetVisualElement();
                break;

            case SetHighlightShapeAction setHighlightShapeAction:
                visualElement = new SetHighlightShapeActionEditor(setHighlightShapeAction, deleteAction).GetVisualElement();
                break;
            }

            if (visualElement == null)
            {
                return(null);
            }

            visualElement.AddToClassList("container");

            return(visualElement);
        }
示例#4
0
        private void ShapeMouseDownActions(MouseEventArgs e)
        {
            switch (curShapeAction)
            {
            case ShapeAction.Nothing:
                if (MouseOnShape(e.Location) == false)
                {
                    if (myMenu.DrawShape == true)
                    {
                        curShapeAction = ShapeAction.Drawing;
                        DrawMouseDown(e);
                        ClearSelectedShape();
                    }
                    OnSelectedShapeChanged(Canvas);
                }
                else
                {
                    curShapeAction = ShapeAction.MovingShape;
                    selectedShapes = GetSelectedShape(e);
                    SendMouseAction(selectedShapes, e, MouseAction.Down);

                    SelectedShape = selectedShapes[0] as LeShape;

                    OnSelectedShapeChanged(selectedShapes[0]);
                }
                break;

            default:
                break;
            }
        }
示例#5
0
    static void Main()
    {
        // Очевидно, что этот код должен работать
        ShapeAction <Shape> action = DrawShape;

        action(new Rectangle());

        /*
         * Интуитивно понятно, что любой метод, удовлетворяющий делегату
         * ShapeAction<Shape>, должен работать с объектом Rectangle, потому что
         * Rectangle является производным от Shape
         *
         * Всегда есть возможность присвоить менее специфичный метод
         * более специфичному делегату, но до появления версии .NET 4
         * нельзя было присвоить менее специфичный делегат более специфичному
         * делегату. Это очень важное различие.
         *
         * Теперь это можно, поскольку параметр-тип помечен модификатором "in".
         */

        // Следующие действия были возможны до появления .NET 4
        ShapeAction <Rectangle> rectAction1 = DrawShape;

        rectAction1(new Rectangle());

        // А это было невозможно до появления .NET 4
        ShapeAction <Rectangle> rectAction2 = action;

        rectAction2(new Rectangle());

        Console.ReadKey();
    }
示例#6
0
        public ShapeAction AddAction(ShapeActionFactory.ShapeActionType shapeActionType)
        {
            ShapeAction shapeAction = m_ShapeActionFactory.CreateShapeAction(shapeActionType);

            m_ShapeActions.Add(shapeAction);
            shapeAction.BecameDirty += OnBecameDirty;
            OnBecameDirty();
            return(shapeAction);
        }
示例#7
0
        private void ShapeMouseUpActions(MouseEventArgs e)
        {
            switch (curShapeAction)
            {
            case ShapeAction.Drawing:
                curShapeAction = ShapeAction.Nothing;
                AddNewShape(e);
                break;

            case ShapeAction.MovingShape:
                SendMouseAction(selectedShapes, e, MouseAction.Up);
                curShapeAction = ShapeAction.Nothing;
                break;
            }
        }
        protected override void SetBaseVisualElement(VisualElement visualElement)
        {
            VisualElement choseShapeField = new ChoseShapeDataField <ShapeData>(
                ShapeAction.ShapeDataFactory,
                ShapeAction,
                "Chose Shape: ",
                () => ShapeAction.ShapeData,
                shapeData => ShapeAction.SetShapeData(shapeData));

            visualElement.Add(choseShapeField);

            Toggle setActiveField = new Toggle("Set Active: ")
            {
                value = ShapeAction.Active
            };

            setActiveField.RegisterCallback <ChangeEvent <bool> >(evt => ShapeAction.SetIsActive(evt.newValue));

            visualElement.Add(setActiveField);
        }
示例#9
0
        protected override void SetBaseVisualElement(VisualElement visualElement)
        {
            VisualElement choseShapeField = new ChoseShapeDataField <ShapeData>(
                ShapeAction.ShapeDataFactory,
                ShapeAction,
                "Chose Shape: ",
                () => ShapeAction.ShapeData,
                shapeData => ShapeAction.SetShapeData(shapeData));

            visualElement.Add(choseShapeField);

            EnumField highlightField = new EnumField("Set Highlight")
            {
                value = ShapeAction.Highlight
            };

            highlightField.Init(ShapeAction.Highlight);
            highlightField.RegisterCallback <ChangeEvent <Enum> >(evt => ShapeAction.SetHighlightType((HighlightType)evt.newValue));

            visualElement.Add(highlightField);
        }
示例#10
0
        private void ShapeMouseDownActions(MouseEventArgs e)
        {
            switch (curShapeAction)
            {
            case ShapeAction.Nothing:
                if (CheckSelectedShape(e).Count == 0)
                {
                    curShapeAction = ShapeAction.Drawing;
                    ClearRealSelectedShape();
                    PrepareToDrawShape(e);
                }
                else
                {
                    curShapeAction = ShapeAction.MovingShape;
                    selectedShapes = CheckSelectedShape(e);
                    SendMouseAction(selectedShapes, e, MouseAction.Down);
                }
                break;

            default:
                break;
            }
        }
示例#11
0
 private void RemoveShapeAction(ShapeAction shapeAction, VisualElement visualElement)
 {
     m_Stage.RemoveAction(shapeAction);
     m_ShapeActionsListVisualElement.Remove(visualElement);
 }