示例#1
0
 internal DataType Typeof(IBlock block)
 {
     if (block is InvokationBlock)
     {
         InvokationBlock invokation = block as InvokationBlock;
         return(blockInfos[invokation.Text].ReturnType);
     }
     else if (block is VarAccessBlock)
     {
         VarAccessBlock v = (VarAccessBlock)block;
         return(v.Declaration.Type);
     }
     return(DataType.Script);
 }
示例#2
0
        private IBlock ToVarAccess(JToken json)
        {
            string varName = json[1].ToString();

            if (currentProcDef == null)
            {
                throw new InvalidOperationException(string.Format("Variable {0} used outside of proc definition", varName));
            }
            if (!currentProcDef.GetArgNames().Contains(varName))
            {
                throw new InvalidOperationException(string.Format("Variable {0} undefined", varName));
            }
            VarDefBlock    vdb = currentProcDef.GetArg(varName);
            VarAccessBlock b   = new VarAccessBlock(vdb);

            return(b);
        }
示例#3
0
        internal void MouseDown(Point p)
        {
            if (state == CanvasState.TextEditing)
            {
                // Since the mousedown registered, we've clicked outside the textbox
                ResetTextEditState();
            }
            else if (state == CanvasState.Ready)
            {
                if (canvasView.PaletteRect.Contains(p))
                {
                    int x = canvasView.PaletteRect.Left;
                    int y = canvasView.PaletteRect.Top;
                    IBlock[] defaultArgs;
                    string funcName = palette.HitTest(p.Offseted(-x, -y), out defaultArgs);
                    if (funcName != "")
                    {
                        IBlock b = blockSpace.makeNewBlock(funcName,defaultArgs);
                        TopLevelScript s = AddTopLevel(b, p.Offseted(-5, -5));

                        dragged = blockViews[b];
                        draggingOrigin = p;
                        draggedModel = s;
                        state = CanvasState.Dragging;
                        PrepareDropRegions(b);
                        Update(ViewBounds(dragged));
                        return;
                    }
                }
                IBlockView hit = HitTest(p);
                if (hit == null)
                    return;
                if (!allViews.ContainsKey(hit))
                {
                    if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Stack)
                    {

                        int i = hit.Model.ParentRelationship.Index;

                        Point np = hit.AbsolutePos();
                        Rectangle bounds = ViewBounds(hit.AbsoluteAncestor());
                        BlockStack parent = (BlockStack)hit.Model.ParentRelationship.Parent;
                        TopLevelScript splitted = SplitBlockStack(parent, i, np);
                        Update(bounds);
                        draggedModel = splitted;
                        hit = blockViews[splitted.Block];
                    }
                    else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Arg)
                    {
                        if (hit is ITextualView)
                        {
                            // We shouldn't detach e.g a number argument from its block
                            // but we should enable the user to edit it

                            SetEditState((ITextualView) hit);
                            return;
                        }
                        int i = hit.Model.ParentRelationship.Index;

                        Point np = hit.AbsolutePos();
                        Rectangle bounds = ViewBounds(hit.AbsoluteAncestor());
                        InvokationBlock parent = (InvokationBlock)hit.Model.ParentRelationship.Parent;
                        TopLevelScript splitted = TakeoutBlockArgument(parent, i, np);
                        Update(bounds);
                        draggedModel = splitted;
                        hit = blockViews[splitted.Block];
                    }
                    else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.FormalParameter)
                    {
                        ProcDefBlock pd = (ProcDefBlock ) hit.Model.ParentRelationship.Parent;
                        VarAccessBlock va = new VarAccessBlock((VarDefBlock)pd.Bits[hit.Model.ParentRelationship.Index]);
                        TopLevelScript tls = AddTopLevel(va, p);
                        hit = ViewFromBlock(va);
                        draggedModel = tls;
                    }
                    else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.None)
                    {
                        hit = null;
                        draggedModel = null;
                    }
                }
                else
                {
                    draggedModel = blockSpace.FindScript(hit.Model);
                }
                if (hit != null)
                {
                    dragged = hit;
                    draggingOrigin = p;
                    state = CanvasState.Dragging;
                    PrepareDropRegions(hit.Model);
                }
                Update();
            }
        }
示例#4
0
        internal void MouseDown(Point p)
        {
            if (state == CanvasState.TextEditing)
            {
                // Since the mousedown registered, we've clicked outside the textbox
                ResetTextEditState();
            }
            else if (state == CanvasState.Ready)
            {
                if (canvasView.PaletteRect.Contains(p))
                {
                    int      x = canvasView.PaletteRect.Left;
                    int      y = canvasView.PaletteRect.Top;
                    IBlock[] defaultArgs;
                    string   funcName = palette.HitTest(p.Offseted(-x, -y), out defaultArgs);
                    if (funcName != "")
                    {
                        IBlock         b = blockSpace.makeNewBlock(funcName, defaultArgs);
                        TopLevelScript s = AddTopLevel(b, p.Offseted(-5, -5));

                        dragged        = blockViews[b];
                        draggingOrigin = p;
                        draggedModel   = s;
                        state          = CanvasState.Dragging;
                        PrepareDropRegions(b);
                        Update(ViewBounds(dragged));
                        return;
                    }
                }
                IBlockView hit = HitTest(p);
                if (hit == null)
                {
                    return;
                }
                if (!allViews.ContainsKey(hit))
                {
                    if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Stack)
                    {
                        int i = hit.Model.ParentRelationship.Index;

                        Point          np       = hit.AbsolutePos();
                        Rectangle      bounds   = ViewBounds(hit.AbsoluteAncestor());
                        BlockStack     parent   = (BlockStack)hit.Model.ParentRelationship.Parent;
                        TopLevelScript splitted = SplitBlockStack(parent, i, np);
                        Update(bounds);
                        draggedModel = splitted;
                        hit          = blockViews[splitted.Block];
                    }
                    else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Arg)
                    {
                        if (hit is ITextualView)
                        {
                            // We shouldn't detach e.g a number argument from its block
                            // but we should enable the user to edit it

                            SetEditState((ITextualView)hit);
                            return;
                        }
                        int i = hit.Model.ParentRelationship.Index;

                        Point           np       = hit.AbsolutePos();
                        Rectangle       bounds   = ViewBounds(hit.AbsoluteAncestor());
                        InvokationBlock parent   = (InvokationBlock)hit.Model.ParentRelationship.Parent;
                        TopLevelScript  splitted = TakeoutBlockArgument(parent, i, np);
                        Update(bounds);
                        draggedModel = splitted;
                        hit          = blockViews[splitted.Block];
                    }
                    else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.FormalParameter)
                    {
                        ProcDefBlock   pd  = (ProcDefBlock )hit.Model.ParentRelationship.Parent;
                        VarAccessBlock va  = new VarAccessBlock((VarDefBlock)pd.Bits[hit.Model.ParentRelationship.Index]);
                        TopLevelScript tls = AddTopLevel(va, p);
                        hit          = ViewFromBlock(va);
                        draggedModel = tls;
                    }
                    else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.None)
                    {
                        hit          = null;
                        draggedModel = null;
                    }
                }
                else
                {
                    draggedModel = blockSpace.FindScript(hit.Model);
                }
                if (hit != null)
                {
                    dragged        = hit;
                    draggingOrigin = p;
                    state          = CanvasState.Dragging;
                    PrepareDropRegions(hit.Model);
                }
                Update();
            }
        }
示例#5
0
 private IBlock ToVarAccess(JToken json)
 {
     string varName = json[1].ToString();
     if (currentProcDef == null)
         throw new InvalidOperationException(string.Format("Variable {0} used outside of proc definition", varName));
     if (!currentProcDef.GetArgNames().Contains(varName))
         throw new InvalidOperationException(string.Format("Variable {0} undefined", varName));
     VarDefBlock vdb = currentProcDef.GetArg(varName);
     VarAccessBlock b = new VarAccessBlock(vdb);
     return b;
 }