Exemple #1
0
        public CBlockView(InvokationBlock model,
            BlockAttributes attribute,
            List<ContentView> contents,
            IEnumerable<BlockStackView> scripts, 
            CBlockImgParts parts, 
            List<ArgumentPartition> argPartitions)
        {
            this.model = model;
            this.attribute = attribute;
            Contents.AddRange(contents);
            Scripts.AddRange(scripts);
            this.ArgPartitions = argPartitions;
            int si = 0;
            foreach (ArgumentPartition p in argPartitions)
            {
                if (p.Type == ArgViewType.Script)
                    scriptIndexes.Add(si);
                si += p.N;
            }
            this.parts = parts;
            Changed += delegate(object sender) { };

            foreach (ContentView cv in contents)
            {
                cv.Parent = this;
                cv.Changed += new ViewChangedEvent(subView_Changed);
            }
            foreach (BlockStackView sv in scripts)
            {
                sv.Parent = this;
                sv.Changed += new ViewChangedEvent(subView_Changed);
            }
            Reassemble();
        }
Exemple #2
0
 internal BlockAttributes AttributeOf(IBlock block)
 {
     if (block is InvokationBlock)
     {
         InvokationBlock invokation = block as InvokationBlock;
         return(blockInfos[invokation.Text].Attribute);
     }
     else if (block is BlockStack)
     {
         BlockStack stack = (BlockStack)block;
         if (stack.Empty)
         {
             return(BlockAttributes.Stack);
         }
         if (AttributeOf(stack[0]) == BlockAttributes.Hat)
         {
             return(BlockAttributes.Hat);
         }
         if (AttributeOf(stack.Last()) == BlockAttributes.Cap)
         {
             return(BlockAttributes.Cap);
         }
         return(BlockAttributes.Stack);
     }
     else if (block is ProcDefBlock)
     {
         return(BlockAttributes.Hat);
     }
     else if (block is VarAccessBlock)
     {
         return(BlockAttributes.Report);
     }
     throw new NotImplementedException();
 }
Exemple #3
0
        private void Run()
        {
            // Assume only one block with 'when flag clicked' for now
            IBlock mainBlock = null;

            foreach (IBlock b in controller.GetTopLevelBlocks())
            {
                if (b is BlockStack)
                {
                    BlockStack stack = ((BlockStack)b);
                    IBlock     s     = stack[0];
                    if (s is InvokationBlock)
                    {
                        InvokationBlock ib = (InvokationBlock)s;
                        if (ib.Text == "when _flag_ clicked")
                        {
                            mainBlock = b;
                        }
                    }
                    else if (s is ProcDefBlock)
                    {
                        ProcDefBlock pdb = (ProcDefBlock)s;
                        Method       m   = compiler.DefineMethod(pdb, stack);
                        vm.DefineMethod(pdb.GetMethodString(), m);
                    }
                }
            }
            if (mainBlock != null)
            {
                Run(mainBlock);
            }
        }
Exemple #4
0
        public InvokationBlock ToInvokationBlock(JToken json)
        {
            string name            = json[0].ToString();
            string typeFingerPrint = json[1].ToString();
            string retTypeName     = json[2].ToString();

            TypeCheck(name, typeFingerPrint);
            DataType[]    argTypes = DataTypeNames.DecodeFingerprint(typeFingerPrint);
            DataType      retType  = DataTypeNames.TypeOf(retTypeName);
            List <IBlock> args     = new List <IBlock>();

            for (int i = 3; i < json.Count(); ++i)
            {
                args.Add(ToBlock(json[i]));
            }
            BlockAttributes attr;

            if (!blockSpace.RegisteredMethodAttribute(name, out attr))
            {
                attr = BlockAttributes.Stack;
            }
            InvokationBlock ib = new InvokationBlock(name, attr, argTypes, retType);

            ib.Args.AddRange(args.ToArray(), argTypes.ToArray());
            return(ib);
        }
Exemple #5
0
        internal IBlock TakeoutArg(InvokationBlock parent, int i)
        {
            IBlock arg = parent.Args[i];

            parent.SetArg(i, Default(parent.ArgTypes[i]));
            return(arg);
        }
Exemple #6
0
        public void DetachArgument(InvokationBlock b, int i, Point newLocation)
        {
            IBlock oldArg = b.Args[i];
            b.SetArg(i, Default(b.ArgTypes[i]));

            oldArg.ParentRelationship = new ParentRelationship();
            AddScript(new TopLevelScript(newLocation, oldArg, this));
        }
Exemple #7
0
        public void DetachArgument(InvokationBlock b, int i, Point newLocation)
        {
            IBlock oldArg = b.Args[i];

            b.SetArg(i, Default(b.ArgTypes[i]));

            oldArg.ParentRelationship = new ParentRelationship();
            AddScript(new TopLevelScript(newLocation, oldArg, this));
        }
Exemple #8
0
        private void testCBlockView(Point at)
        {
            InvokationBlock b = makeInvokationBlock("if % then % else %",
                                                    new DataType[] { DataType.Number, DataType.Script, DataType.Script },
                                                    DataType.Script,
                                                    new IBlock[] { new TextBlock(""), makeSampleBlockStack(), makeSampleBlockStack() });

            controller.AddTopLevel(b, at);
        }
Exemple #9
0
        public IBlock makeNewBlock(string text, IBlock[] args)
        {
            BlockInfo bi = blockInfos[text];

            InvokationBlock block = new InvokationBlock(text, BlockAttributes.Hat, bi.ArgTypes, bi.ReturnType);

            block.Args.AddRange(args.Select(a => a.DeepClone()).ToArray(), bi.ArgTypes);

            return(block);
        }
Exemple #10
0
        private InvokationBlock makeInvokationBlock(string invokation, DataType[] types, DataType retType, IBlock[] values)
        {
            List <DataType> typesList = new List <DataType>();

            typesList.AddRange(types);
            InvokationBlock ret = new InvokationBlock(invokation, BlockAttributes.Hat, typesList, retType);

            ret.Args.AddRange(values, types);
            return(ret);
        }
Exemple #11
0
        private void testReporterBlockView(Point at)
        {
            InvokationBlock b = makeInvokationBlock("sin %",
                                                    new DataType[] { DataType.Number },
                                                    DataType.Number,
                                                    new IBlock[] { makeInvokationBlock("% + %", new DataType[] { DataType.Number, DataType.Number },
                                                                                       DataType.Number,
                                                                                       new IBlock[] { new TextBlock(""), new TextBlock("") }) });

            controller.AddTopLevel(b, at);
        }
Exemple #12
0
        public IBlock DeepClone()
        {
            InvokationBlock ret = new InvokationBlock(Text, Attributes, ArgTypes, ReturnType);
            int             i   = 0;

            foreach (IBlock arg in Args)
            {
                ret.SetArg(i, arg.DeepClone());
            }
            return(ret);
        }
Exemple #13
0
 internal void Detach(BlockSpace blockSpace)
 {
     if (Parent is InvokationBlock)
     {
         InvokationBlock ib = Parent as InvokationBlock;
         ib.SetArg(Index, blockSpace.Default(ib.ArgTypes[Index]));
     }
     else if (Parent is BlockStack)
     {
         throw new InvalidOperationException();
     }
 }
Exemple #14
0
        public InvokationBlockView(InvokationBlock model, BlockAttributes attribute, ContentView content)
        {
            this.model     = model;
            this.content   = content;
            this.attribute = attribute;

            Changed            += delegate(object sender) { };
            content.Changed    += new ViewChangedEvent(content_Changed);
            content.Parent      = this;
            content.RelativePos = new Point(0, 0);

            Reassemble();
        }
        public InvokationBlockView(InvokationBlock model, BlockAttributes attribute, ContentView content)
        {
            this.model = model;
            this.content = content;
            this.attribute = attribute;

            Changed += delegate(object sender) { };
            content.Changed += new ViewChangedEvent(content_Changed);
            content.Parent = this;
            content.RelativePos = new Point(0, 0);

            Reassemble();
        }
Exemple #16
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);
 }
Exemple #17
0
        public IBlock makeNewBlock(string text)
        {
            BlockInfo bi = blockInfos[text];

            IBlock[] args = new IBlock[bi.ArgTypes.Length];
            for (int i = 0; i < bi.ArgTypes.Length; ++i)
            {
                args[i] = Default(bi.ArgTypes[i]);
            }

            InvokationBlock block = new InvokationBlock(text, BlockAttributes.Hat, bi.ArgTypes, bi.ReturnType);

            block.Args.AddRange(args, bi.ArgTypes);
            return(block);
        }
Exemple #18
0
        BlockStack makeSampleBlockStack()
        {
            InvokationBlock b1 = makeInvokationBlock("move % steps",
                                                     new DataType[] { DataType.Number },
                                                     DataType.Script,
                                                     new IBlock[] { new TextBlock("") });

            InvokationBlock b2 = makeInvokationBlock("turn % degrees right",
                                                     new DataType[] { DataType.Number },
                                                     DataType.Script,
                                                     new IBlock[] { new TextBlock("") });

            BlockStack stack = new BlockStack();

            stack.AddRange(new IBlock[] { b1, b2 });
            return(stack);
        }
Exemple #19
0
 public IBlockView ViewFromBlock(IBlock block)
 {
     if (blockViews.ContainsKey(block))
     {
         return(blockViews[block]);
     }
     if (block is BlockStack)
     {
         IBlockView ret = ViewFromBlockStack((BlockStack)block);;
         blockViews[block] = ret;
         return(ret);
     }
     if (block is VarAccessBlock || block is VarDefBlock)
     {
         IBlockView ret = new VariableView((IVarBlock)block, varb_parts, textMetrics, textFont);
         blockViews[block] = ret;
         return(ret);
     }
     if (block is TextBlock)
     {
         IBlockView ret = new TextView((TextBlock)block, ib_parts, textMetrics, textFont);
         blockViews[block] = ret;
         return(ret);
     }
     if (block is InvokationBlock)
     {
         InvokationBlock b    = (InvokationBlock)block;
         BlockAttributes attr = blockSpace.AttributeOf(b);
         IBlockView      r    = ViewFromInvokationBlock(b, attr);
         blockViews[block] = r;
         return(r);
     }
     if (block is ProcDefBlock)
     {
         ProcDefBlock    b    = (ProcDefBlock)block;
         BlockAttributes attr = blockSpace.AttributeOf(b);
         IBlockView      r    = ViewFromProcDefBlock(b);
         blockViews[block] = r;
         return(r);
     }
     throw new ArgumentException();
 }
 public InvokationBlock ToInvokationBlock(JToken json)
 {
     string name = json[0].ToString();
     string typeFingerPrint = json[1].ToString();
     string retTypeName = json[2].ToString();
     TypeCheck(name, typeFingerPrint);
     DataType[] argTypes = DataTypeNames.DecodeFingerprint(typeFingerPrint);
     DataType retType = DataTypeNames.TypeOf(retTypeName);
     List<IBlock> args = new List<IBlock>();
     for (int i = 3; i < json.Count(); ++i)
     {
         args.Add(ToBlock(json[i]));
     }
     BlockAttributes attr;
     if (!blockSpace.RegisteredMethodAttribute(name, out attr))
     {
         attr = BlockAttributes.Stack;
     }
     InvokationBlock ib = new InvokationBlock(name, attr, argTypes, retType);
     ib.Args.AddRange(args.ToArray(), argTypes.ToArray());
     return ib;
 }
Exemple #21
0
        public CBlockView(InvokationBlock model,
                          BlockAttributes attribute,
                          List <ContentView> contents,
                          IEnumerable <BlockStackView> scripts,
                          CBlockImgParts parts,
                          List <ArgumentPartition> argPartitions)
        {
            this.model     = model;
            this.attribute = attribute;
            Contents.AddRange(contents);
            Scripts.AddRange(scripts);
            this.ArgPartitions = argPartitions;
            int si = 0;

            foreach (ArgumentPartition p in argPartitions)
            {
                if (p.Type == ArgViewType.Script)
                {
                    scriptIndexes.Add(si);
                }
                si += p.N;
            }
            this.parts = parts;
            Changed   += delegate(object sender) { };

            foreach (ContentView cv in contents)
            {
                cv.Parent   = this;
                cv.Changed += new ViewChangedEvent(subView_Changed);
            }
            foreach (BlockStackView sv in scripts)
            {
                sv.Parent   = this;
                sv.Changed += new ViewChangedEvent(subView_Changed);
            }
            Reassemble();
        }
Exemple #22
0
 internal IBlock TakeoutArg(InvokationBlock parent, int i)
 {
     IBlock arg = parent.Args[i];
     parent.SetArg(i, Default(parent.ArgTypes[i]));
     return arg;
 }
Exemple #23
0
        public IBlock makeNewBlock(string text, IBlock[] args)
        {
            BlockInfo bi = blockInfos[text];

            InvokationBlock block = new InvokationBlock(text, BlockAttributes.Hat, bi.ArgTypes, bi.ReturnType);
            block.Args.AddRange(args.Select(a=>a.DeepClone()).ToArray(), bi.ArgTypes);

            return block;
        }
        public IBlockView ViewFromInvokationBlock(InvokationBlock b, BlockAttributes attribute)
        {
            string[] textParts = b.Text.SplitFuncArgs();
            Bitmap[] textBitmaps = RenderTextBits(textParts);

            if (b.ArgTypes.All(t => t != DataType.Script))
            {
                // it ain't a C block
                List<IBlockView> subContent = new List<IBlockView>();
                int i = 0;
                int currentArg = 0;
                BitArray trueArgs = new BitArray(textParts.Length);
                foreach (string s in textParts)
                {
                    if (s == "%")
                    {
                        subContent.Add(ViewFromBlock(b.Args[currentArg++]));
                        trueArgs[i] = true;
                    }
                    else
                    {
                        subContent.Add(new LabelView(textBitmaps[i]));
                        trueArgs[i] = false;
                    }
                    ++i;
                }

                NineContent imageParts = sb_parts; // dummy initial val
                switch (attribute)
                {
                    case BlockAttributes.Stack:
                        imageParts = sb_parts;
                        break;
                    case BlockAttributes.Report:
                        if (b.ReturnType == DataType.Boolean)
                            imageParts = bool_parts;
                        else
                            imageParts = fib_parts;
                        break;
                    case BlockAttributes.Cap:
                        imageParts = capb_parts;
                        break;
                    case BlockAttributes.Hat:
                        imageParts = hatb_parts;
                        break;
                }

                ContentView content = new ContentView(subContent.ToArray(), b.ArgTypes.ToArray(), trueArgs, imageParts);
                InvokationBlockView ib = new InvokationBlockView(b, attribute, content);
                b.OnArgChanged += new InvokationBlockArgChangeEvent(InvokationBlock_ArgChanged);

                return ib;

            }
            else
            {
                // it's a C block, yappari
                List<ContentView> contents = new List<ContentView>();
                List<IBlockView> subContent = new List<IBlockView>();
                List<DataType> subArgTypes = new List<DataType>();
                List<BlockStackView> scripts = new List<BlockStackView>();
                List<ArgumentPartition> argPartitions = new List<ArgumentPartition>();
                List<bool> trueArgs = new List<bool>();
                int currentArg = 0;
                int currentPartitionCount = 0;
                int i = 0;
                bool head = true;
                foreach (string s in textParts)
                {
                    if (s != "%")
                    {
                        LabelView lv = new LabelView(textBitmaps[i]);
                        subContent.Add(lv);
                        trueArgs.Add(false);
                    }
                    else
                    {
                        // It's an arg. Script or normal?
                        DataType type = b.ArgTypes[currentArg];
                        IBlock arg = b.Args[currentArg];
                        if (type != DataType.Script)
                        {
                            // Oh it's just a normal argument
                            IBlockView bv = ViewFromBlock(arg);
                            subContent.Add(bv);
                            subArgTypes.Add(type);
                            trueArgs.Add(true);
                            currentPartitionCount++;
                        }
                        else
                        {
                            // We need to split a new head or waist in the C block
                            NineContent nc;
                            if (head)
                            {
                                nc = cb_parts.Head;
                                head = false;
                            }
                            else
                            {
                                nc = cb_parts.Waist;
                            }
                            ContentView cv = new ContentView(subContent.ToArray(), subArgTypes.ToArray(), new BitArray(trueArgs.ToArray()), nc);
                            contents.Add(cv);
                            ArgumentPartition ap = new ArgumentPartition(currentPartitionCount, ArgViewType.Content);
                            argPartitions.Add(ap);
                            currentPartitionCount = 0;

                            BlockStackView side = (BlockStackView)ViewFromBlock((BlockStack)arg);
                            scripts.Add(side);
                            ap = new ArgumentPartition(1, ArgViewType.Script);
                            argPartitions.Add(ap);
                            subContent = new List<IBlockView>();
                            subArgTypes = new List<DataType>();
                            trueArgs = new List<bool>();

                        }
                        currentArg++;
                    }
                    i++;
                }
                b.OnArgChanged +=new InvokationBlockArgChangeEvent(InvokationBlock_ArgChanged);
                CBlockView cb = new CBlockView(b, attribute, contents, scripts, cb_parts, argPartitions);

                return cb;
            }
        }
Exemple #25
0
 public ArgList(InvokationBlock owner)
 {
     this.owner     = owner;
     this.ArgAdded += delegate(object sender, IBlock newArg, DataType newArgType) { };
 }
Exemple #26
0
        private TopLevelScript TakeoutBlockArgument(InvokationBlock parent, int i, Point newArgLocation)
        {
            IBlock newBlock = blockSpace.TakeoutArg(parent, i);

            return(AddTopLevel(newBlock, newArgLocation));
        }
Exemple #27
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();
            }
        }
Exemple #28
0
 private InvokationBlock makeInvokationBlock(string invokation, DataType[] types, DataType retType, IBlock[] values)
 {
     List<DataType> typesList = new List<DataType>();
     typesList.AddRange(types);
     InvokationBlock ret = new InvokationBlock(invokation, BlockAttributes.Hat, typesList, retType);
     ret.Args.AddRange(values, types);
     return ret;
 }
Exemple #29
0
        public IBlockView ViewFromInvokationBlock(InvokationBlock b, BlockAttributes attribute)
        {
            string[] textParts   = b.Text.SplitFuncArgs();
            Bitmap[] textBitmaps = RenderTextBits(textParts);

            if (b.ArgTypes.All(t => t != DataType.Script))
            {
                // it ain't a C block
                List <IBlockView> subContent = new List <IBlockView>();
                int      i          = 0;
                int      currentArg = 0;
                BitArray trueArgs   = new BitArray(textParts.Length);
                foreach (string s in textParts)
                {
                    if (s == "%")
                    {
                        subContent.Add(ViewFromBlock(b.Args[currentArg++]));
                        trueArgs[i] = true;
                    }
                    else
                    {
                        subContent.Add(new LabelView(textBitmaps[i]));
                        trueArgs[i] = false;
                    }
                    ++i;
                }


                NineContent imageParts = sb_parts; // dummy initial val
                switch (attribute)
                {
                case BlockAttributes.Stack:
                    imageParts = sb_parts;
                    break;

                case BlockAttributes.Report:
                    if (b.ReturnType == DataType.Boolean)
                    {
                        imageParts = bool_parts;
                    }
                    else
                    {
                        imageParts = fib_parts;
                    }
                    break;

                case BlockAttributes.Cap:
                    imageParts = capb_parts;
                    break;

                case BlockAttributes.Hat:
                    imageParts = hatb_parts;
                    break;
                }


                ContentView         content = new ContentView(subContent.ToArray(), b.ArgTypes.ToArray(), trueArgs, imageParts);
                InvokationBlockView ib      = new InvokationBlockView(b, attribute, content);
                b.OnArgChanged += new InvokationBlockArgChangeEvent(InvokationBlock_ArgChanged);

                return(ib);
            }
            else
            {
                // it's a C block, yappari
                List <ContentView>       contents      = new List <ContentView>();
                List <IBlockView>        subContent    = new List <IBlockView>();
                List <DataType>          subArgTypes   = new List <DataType>();
                List <BlockStackView>    scripts       = new List <BlockStackView>();
                List <ArgumentPartition> argPartitions = new List <ArgumentPartition>();
                List <bool> trueArgs              = new List <bool>();
                int         currentArg            = 0;
                int         currentPartitionCount = 0;
                int         i    = 0;
                bool        head = true;
                foreach (string s in textParts)
                {
                    if (s != "%")
                    {
                        LabelView lv = new LabelView(textBitmaps[i]);
                        subContent.Add(lv);
                        trueArgs.Add(false);
                    }
                    else
                    {
                        // It's an arg. Script or normal?
                        DataType type = b.ArgTypes[currentArg];
                        IBlock   arg  = b.Args[currentArg];
                        if (type != DataType.Script)
                        {
                            // Oh it's just a normal argument
                            IBlockView bv = ViewFromBlock(arg);
                            subContent.Add(bv);
                            subArgTypes.Add(type);
                            trueArgs.Add(true);
                            currentPartitionCount++;
                        }
                        else
                        {
                            // We need to split a new head or waist in the C block
                            NineContent nc;
                            if (head)
                            {
                                nc   = cb_parts.Head;
                                head = false;
                            }
                            else
                            {
                                nc = cb_parts.Waist;
                            }
                            ContentView cv = new ContentView(subContent.ToArray(), subArgTypes.ToArray(), new BitArray(trueArgs.ToArray()), nc);
                            contents.Add(cv);
                            ArgumentPartition ap = new ArgumentPartition(currentPartitionCount, ArgViewType.Content);
                            argPartitions.Add(ap);
                            currentPartitionCount = 0;

                            BlockStackView side = (BlockStackView)ViewFromBlock((BlockStack)arg);
                            scripts.Add(side);
                            ap = new ArgumentPartition(1, ArgViewType.Script);
                            argPartitions.Add(ap);
                            subContent  = new List <IBlockView>();
                            subArgTypes = new List <DataType>();
                            trueArgs    = new List <bool>();
                        }
                        currentArg++;
                    }
                    i++;
                }
                b.OnArgChanged += new InvokationBlockArgChangeEvent(InvokationBlock_ArgChanged);
                CBlockView cb = new CBlockView(b, attribute, contents, scripts, cb_parts, argPartitions);

                return(cb);
            }
        }
Exemple #30
0
        public IBlock makeNewBlock(string text)
        {
            BlockInfo bi = blockInfos[text];
            IBlock[] args = new IBlock[bi.ArgTypes.Length];
            for (int i = 0; i < bi.ArgTypes.Length; ++i)
            {
                args[i] = Default(bi.ArgTypes[i]);
            }

            InvokationBlock block = new InvokationBlock(text, BlockAttributes.Hat, bi.ArgTypes, bi.ReturnType);
            block.Args.AddRange(args, bi.ArgTypes);
            return block;
        }
Exemple #31
0
 public IBlock DeepClone()
 {
     InvokationBlock ret = new InvokationBlock(Text, Attributes, ArgTypes, ReturnType);
     int i = 0;
     foreach (IBlock arg in Args)
     {
         ret.SetArg(i, arg.DeepClone());
     }
     return ret;
 }
Exemple #32
0
 private TopLevelScript TakeoutBlockArgument(InvokationBlock parent, int i, Point newArgLocation)
 {
     IBlock newBlock = blockSpace.TakeoutArg(parent, i);
     return AddTopLevel(newBlock, newArgLocation);
 }