Example #1
0
        public ContentView(IBlockView[] argViews, DataType[] argTypes, BitArray trueArgs, NineContent abc)
        {
            foreach (bool b in trueArgs)
            {
                this.trueArgs.Add(b);
            }
            this.ArgTypes.AddRange(argTypes);
            this.abc = abc;
            Changed += delegate(object sender) {};
            int i   = 0;
            int arg = 0;

            foreach (IBlockView v in argViews)
            {
                if (trueArgs[i])
                {
                    AddSubView(v, argTypes[arg++], i, false);
                }
                else
                {
                    AddSubView(v, DataType.Invalid, i, false);
                }
                i++;
            }
            Reassemble();
        }
Example #2
0
        public void FromBitmapCutting(Bitmap fullBmp, Color mark)
        {
            fullBmp.MakeTransparent(fullBmp.GetPixel(0, 0));
            Bitmap[] vertPieces = fullBmp.SplitVerticalByCol0(mark);
            vertPieces = vertPieces.Select(b => b.TrimTrailingRight(Color.Transparent)).ToArray();

            /*
             * for (int i = 0; i < vertPieces.Length; ++i)
             *  vertPieces[i].Save("vertPiece" + i + ".png");
             */

            Head = new NineContent();
            Head.FromBitmapCutting(vertPieces[0], mark);

            Side = new A1A2A3();
            Side.FromBitmapCutting(vertPieces[1].SliceX(1).SplitHorizontaByRow0(Color.Red)[0], mark);

            Waist = new NineContent();

            Waist.FromBitmapCutting(vertPieces[2], mark);

            FootCap = new ABC();
            FootCap.FromBitmapCutting(vertPieces[3].SliceX(2), mark);

            FootStack = new ABC();
            FootStack.FromBitmapCutting(vertPieces[4].SliceX(2), mark);
        }
Example #3
0
        public void FromBitmapCutting(Bitmap fullBmp, Color mark)
        {
            fullBmp.MakeTransparent(fullBmp.GetPixel(0, 0));
            Bitmap[] vertPieces = fullBmp.SplitVerticalByCol0(mark);
            vertPieces = vertPieces.Select(b => b.TrimTrailingRight(Color.Transparent)).ToArray();

            /*
            for (int i = 0; i < vertPieces.Length; ++i)
                vertPieces[i].Save("vertPiece" + i + ".png");
             */

            Head = new NineContent();
            Head.FromBitmapCutting(vertPieces[0], mark);

            Side = new A1A2A3();
            Side.FromBitmapCutting(vertPieces[1].SliceX(1).SplitHorizontaByRow0(Color.Red)[0], mark);

            Waist = new NineContent();

            Waist.FromBitmapCutting(vertPieces[2], mark);

            FootCap = new ABC();
            FootCap.FromBitmapCutting(vertPieces[3].SliceX(2), mark);

            FootStack = new ABC();
            FootStack.FromBitmapCutting(vertPieces[4].SliceX(2), mark);
        }
Example #4
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);
            }
        }