void blockstack_OnInsert(object sender, int i, IBlock b) { IBlockView v = ViewFromBlock(b); BlockStackView parent = (BlockStackView)ViewFromBlock((IBlock)sender); parent.InsertView(i, v); modified(); }
public IBlockView ViewFromBlockStack(BlockStack blocks) { IEnumerable <IBlockView> stack = blocks.Select(b => ViewFromBlock(b)); BlockStackView ret = new BlockStackView(blocks, stack); blocks.OnInsert += new BlockStackInsertEvent(blockstack_OnInsert); return(ret); }
public IBlockView ViewFromBlockStack(BlockStack blocks) { IEnumerable<IBlockView> stack = blocks.Select(b => ViewFromBlock(b)); BlockStackView ret = new BlockStackView(blocks, stack); blocks.OnInsert += new BlockStackInsertEvent(blockstack_OnInsert); return ret; }
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); } }