コード例 #1
0
        internal IBlock StackBelow(TopLevelScript b1, IBlock b2)
        {
            ParentRelationship b2_oldRelationship = b2.ParentRelationship;
            BlockStack         b3 = MergeStacks(b2, b1.Block);

            RemoveScript(b1);
            Become(b2_oldRelationship, b2, b3);
            return(b3);
        }
コード例 #2
0
ファイル: BlockController.cs プロジェクト: samiz/kitsune
        void blockSpace_OnTopLevelDeleted(object sender, TopLevelScript tl)
        {
            IBlockView v      = blockViews[tl.Block];
            Rectangle  bounds = ViewBounds(v);

            allViews.Remove(v);
            Modified(this);
            Update(bounds);
        }
コード例 #3
0
ファイル: BlockController.cs プロジェクト: samiz/kitsune
        void blockSpace_OnTopLevelAdded(object sender, TopLevelScript tl)
        {
            IBlockView v = viewFactory.ViewFromBlock(tl.Block);

            allViews[v]   = tl.Location;
            v.RelativePos = tl.Location;
            v.Parent      = null;

            Update(ViewBounds(v));
            Modified(this);
        }
コード例 #4
0
ファイル: BlockController.cs プロジェクト: samiz/kitsune
        void blockSpace_OnTopLevelMoved(object sender, TopLevelScript tl)
        {
            IBlockView v  = blockViews[tl.Block];
            Rectangle  r1 = ViewBounds(v);

            v.RelativePos = tl.Location;
            allViews[v]   = tl.Location;
            Rectangle r2 = ViewBounds(v);

            Modified(this);
            Update(Rectangle.Union(r1, r2));
        }
コード例 #5
0
ファイル: BlockDeserializer.cs プロジェクト: samiz/kitsune
        private TopLevelScript ToTopLevelScript(JToken scriptJson, BlockSpace owner)
        {
            Point  location;
            IBlock block;
            int    x = int.Parse((string)scriptJson["location"][0]);
            int    y = int.Parse((string)scriptJson["location"][1]);

            location = new Point(x, y);
            block    = ToBlock(scriptJson["code"]);
            TopLevelScript ret = new TopLevelScript(location, block, owner);

            return(ret);
        }
コード例 #6
0
        internal string ToJson()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("[\n");
            for (int i = 0; i < Scripts.Count; ++i)
            {
                TopLevelScript scr = Scripts[i];
                sb.AppendLine(scr.ToJson());
                if (i + 1 < Scripts.Count)
                {
                    sb.Append(", ");
                }
            }
            sb.Append("\n]");
            return(sb.ToString());
        }
コード例 #7
0
ファイル: BlockDeserializer.cs プロジェクト: samiz/kitsune
        internal BlockSpace LoadBlockSpace(string json,
                                           BlockSpace blockSpace,
                                           Dictionary <string, BlockInfo> systemBlocks,
                                           Action <ProcDefBlock> handleDefineNewProc)
        {
            BlockSpace ret = blockSpace;

            this.blockSpace          = blockSpace;
            this.handleDefineNewProc = handleDefineNewProc;
            JArray o = JArray.Parse(json);

            for (int i = 0; i < o.Count; ++i)
            {
                JToken         scriptJson = o[i];
                TopLevelScript script     = ToTopLevelScript(scriptJson, ret);
                ret.AddScript(script);
            }

            return(ret);
        }
コード例 #8
0
ファイル: BlockController.cs プロジェクト: samiz/kitsune
        private void ConnectBlocks(DropRegion dr, TopLevelScript block)
        {
            Point destinationLoc = new Point();

            if (allViews.ContainsKey(dr.Destination))
            {
                destinationLoc = allViews[dr.Destination];
            }
            int sourceHeight = blockViews[block.Block].Assemble().Height;

            switch (dr.DropType)
            {
            case DropType.Above:

                IBlock finalStack = blockSpace.StackAbove(block, dr.Destination.Model);
                if (finalStack.ParentRelationship.Type == ParentRelationshipType.None)
                {
                    // We've stacked A above B, we need to reposition the result so that
                    // B's old location stays the same
                    TopLevelScript ts = blockSpace.FindScript(finalStack);
                    ts.Location = new Point(destinationLoc.X, destinationLoc.Y - sourceHeight + BlockStackView.NotchHeight);
                }
                break;

            case DropType.Below:
                blockSpace.StackBelow(block, dr.Destination.Model);
                break;

            case DropType.Between:
                blockSpace.RemoveScript(draggedModel);
                (dr.Destination.Model as BlockStack).Insert((int)dr.ExtraInfo, block.Block);
                break;

            case DropType.AsArgument:
                blockSpace.RemoveScript(draggedModel);
                (dr.Destination.Model as InvokationBlock).SetArg((int)dr.ExtraInfo, block.Block);
                break;
            }
        }
コード例 #9
0
        // 'a' shall become 'b', how?
        // - If a is toplevel, remove it and add b in its place
        // - If it isn't the parent has to replace a with b
        void Become(ParentRelationship pr, IBlock a, IBlock b)
        {
            if (pr.Type == ParentRelationshipType.None)
            {
                TopLevelScript tl = FindScript(a);
                RemoveScript(tl);
                AddScript(new TopLevelScript(tl.Location, b, this));
            }
            else
            {
                switch (pr.Type)
                {
                case ParentRelationshipType.Arg:
                    ((InvokationBlock)pr.Parent).SetArg(pr.Index, b);
                    break;

                case ParentRelationshipType.Stack:
                    //
                    break;
                }
            }
        }
コード例 #10
0
ファイル: BlockController.cs プロジェクト: andyhebear/kitsune
 void blockSpace_OnTopLevelDeleted(object sender, TopLevelScript tl)
 {
     IBlockView v = blockViews[tl.Block];
     Rectangle bounds = ViewBounds(v);
     allViews.Remove(v);
     Modified(this);
     Update(bounds);
 }
コード例 #11
0
ファイル: BlockController.cs プロジェクト: andyhebear/kitsune
        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();
            }
        }
コード例 #12
0
ファイル: BlockController.cs プロジェクト: andyhebear/kitsune
        void blockSpace_OnTopLevelAdded(object sender, TopLevelScript tl)
        {
            IBlockView v = viewFactory.ViewFromBlock(tl.Block);

            allViews[v] = tl.Location;
            v.RelativePos = tl.Location;
            v.Parent = null;

            Update(ViewBounds(v));
            Modified(this);
        }
コード例 #13
0
ファイル: BlockController.cs プロジェクト: samiz/kitsune
        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();
            }
        }
コード例 #14
0
 public void RemoveScript(TopLevelScript s)
 {
     Scripts.Remove(s);
     OnTopLevelDeleted(this, s);
 }
コード例 #15
0
ファイル: BlockController.cs プロジェクト: andyhebear/kitsune
 void blockSpace_OnTopLevelMoved(object sender, TopLevelScript tl)
 {
     IBlockView v = blockViews[tl.Block];
     Rectangle r1 = ViewBounds(v);
     v.RelativePos = tl.Location;
     allViews[v] = tl.Location;
     Rectangle r2 = ViewBounds(v);
     Modified(this);
     Update(Rectangle.Union(r1, r2));
 }
コード例 #16
0
ファイル: BlockSpace.cs プロジェクト: andyhebear/kitsune
 internal IBlock StackBelow(TopLevelScript b1, IBlock b2)
 {
     ParentRelationship b2_oldRelationship = b2.ParentRelationship;
     BlockStack b3 = MergeStacks(b2, b1.Block);
     RemoveScript(b1);
     Become(b2_oldRelationship, b2, b3);
     return b3;
 }
コード例 #17
0
ファイル: BlockSpace.cs プロジェクト: andyhebear/kitsune
 public void RemoveScript(TopLevelScript s)
 {
     Scripts.Remove(s);
     OnTopLevelDeleted(this, s);
 }
コード例 #18
0
ファイル: BlockController.cs プロジェクト: andyhebear/kitsune
        private void ConnectBlocks(DropRegion dr, TopLevelScript block)
        {
            Point destinationLoc = new Point();
            if(allViews.ContainsKey(dr.Destination))
                destinationLoc = allViews[dr.Destination];
            int sourceHeight = blockViews[block.Block].Assemble().Height;
            switch (dr.DropType)
            {
                case DropType.Above:

                    IBlock finalStack = blockSpace.StackAbove(block, dr.Destination.Model);
                    if (finalStack.ParentRelationship.Type == ParentRelationshipType.None)
                    {
                        // We've stacked A above B, we need to reposition the result so that
                        // B's old location stays the same
                        TopLevelScript ts = blockSpace.FindScript(finalStack);
                        ts.Location = new Point(destinationLoc.X, destinationLoc.Y - sourceHeight + BlockStackView.NotchHeight);
                    }
                    break;
                case DropType.Below:
                    blockSpace.StackBelow(block, dr.Destination.Model);
                    break;
                case DropType.Between:
                    blockSpace.RemoveScript(draggedModel);
                    (dr.Destination.Model as BlockStack).Insert((int)dr.ExtraInfo, block.Block);
                    break;
                case DropType.AsArgument:
                    blockSpace.RemoveScript(draggedModel);
                    (dr.Destination.Model as InvokationBlock).SetArg((int)dr.ExtraInfo, block.Block);
                    break;
            }
        }
コード例 #19
0
 internal void NotifyTopLevelMoved(TopLevelScript topLevelScript)
 {
     OnTopLevelMoved(this, topLevelScript);
 }
コード例 #20
0
ファイル: BlockSpace.cs プロジェクト: andyhebear/kitsune
 internal void NotifyTopLevelMoved(TopLevelScript topLevelScript)
 {
     OnTopLevelMoved(this, topLevelScript);
 }
コード例 #21
0
 public TopLevelScript AddScript(TopLevelScript s)
 {
     Scripts.Add(s);
     OnTopLevelAdded(this, s);
     return(s);
 }
コード例 #22
0
ファイル: BlockSpace.cs プロジェクト: andyhebear/kitsune
 public TopLevelScript AddScript(TopLevelScript s)
 {
     Scripts.Add(s);
     OnTopLevelAdded(this, s);
     return s;
 }
コード例 #23
0
 private TopLevelScript ToTopLevelScript(JToken scriptJson, BlockSpace owner)
 {
     Point location;
     IBlock block;
     int x = int.Parse((string)scriptJson["location"][0]);
     int y = int.Parse((string)scriptJson["location"][1]);
     location = new Point(x, y);
     block = ToBlock(scriptJson["code"]);
     TopLevelScript ret = new TopLevelScript(location, block, owner);
     return ret;
 }