Exemplo n.º 1
0
        public void Load(string json)
        {
            blockSpace.Clear();
            BlockDeserializer ds     = new BlockDeserializer();
            BlockSpace        bspace = ds.LoadBlockSpace(json, blockSpace, blockSpace.GetSystemMethods(), (proc) => DefineNewProcFromFile(proc, "My blocks"));

            blockSpace.AddDummyEvents();
            ResetBlockSpace();
        }
Exemplo n.º 2
0
 internal void AddTool(BlockSpace blockSpace, ToolPrototype spec)
 {
     AddNewTool(blockSpace, spec);
     LayoutTools(currentCategory);
     if (currentCategory == spec.category)
     {
         UpdateBitmap(currentCategory, tabWidth, tabHeight);
     }
 }
Exemplo n.º 3
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();
     }
 }
Exemplo n.º 4
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();
     }
 }
Exemplo n.º 5
0
        private void AddNewTool(BlockSpace blockSpace, ToolPrototype spec)
        {
            string[] parts = spec.tool.Split("|".ToCharArray());
            //string fileName = Path.Combine(filePrefix, parts[0]) + ".bmp";
            string funcName = parts[1];
            // Bitmap tbBmp = (Bitmap)Bitmap.FromFile(fileName);
            Bitmap tbBmp = dummyFactory.ViewFromBlock(blockSpace.makeNewBlock(funcName, spec.defaultArgs))
                           .Assemble();

            //tbBmp.MakeTransparent(tbBmp.GetPixel(0, 0));
            tools.Add(new ToolSpec(tbBmp, funcName, spec.category, spec.defaultArgs));
            categories.Add(spec.category);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 public BlockViewFactory(Graphics textMetrics,
     Font textFont, 
     BlockSpace blockSpace,
     Dictionary<IBlock, IBlockView> blockViews,
     Action modified)
 {
     this.modified = modified;
     this.textMetrics = textMetrics;
     this.textFont = textFont;
     boldFont = new Font(textFont, FontStyle.Bold);
     this.blockSpace = blockSpace;
     this.blockViews = blockViews;
     InitImageParts();
 }
Exemplo n.º 8
0
 public BlockViewFactory(Graphics textMetrics,
                         Font textFont,
                         BlockSpace blockSpace,
                         Dictionary <IBlock, IBlockView> blockViews,
                         Action modified)
 {
     this.modified    = modified;
     this.textMetrics = textMetrics;
     this.textFont    = textFont;
     boldFont         = new Font(textFont, FontStyle.Bold);
     this.blockSpace  = blockSpace;
     this.blockViews  = blockViews;
     InitImageParts();
 }
Exemplo n.º 9
0
        public void Init(IEnumerable <ToolPrototype> toolSpecs, string filePrefix, string initialCategory,
                         BlockSpace blockSpace)
        {
            this.currentCategory = initialCategory;
            this.toolSpecs       = toolSpecs;
            this.filePrefix      = filePrefix;
            tools.Clear();


            dummyFactory = new BlockViewFactory(textMetrics, textFont,
                                                blockSpace, new Dictionary <IBlock, IBlockView>(), delegate() { });
            foreach (ToolPrototype spec in toolSpecs)
            {
                AddNewTool(blockSpace, spec);
            }
        }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
0
        public BlockController(Graphics textMetrics, Font textFont, Size canvasSize, Func<TextBox> textBoxMaker)
        {
            this.Modified += delegate(object sender) { };
            blockSpace = new BlockSpace();
            blockSpace.OnTopLevelAdded += new TopLevelEvent(blockSpace_OnTopLevelAdded);
            blockSpace.OnTopLevelDeleted += new TopLevelEvent(blockSpace_OnTopLevelDeleted);
            blockSpace.OnTopLevelMoved += new TopLevelEvent(blockSpace_OnTopLevelMoved);

            palette = new Palette(new Size(canvasSize.Width - 20, 60), textMetrics, textFont);
            palette.Modified += new PaletteModifiedEvent(palette_Modified);

            canvasView = new CanvasView(textMetrics, canvasSize, allViews, DropRegions, textFont, palette);
            this.canvasSize = canvasSize;
            state = CanvasState.Ready;
            viewFactory = new BlockViewFactory(textMetrics, textFont, blockSpace, blockViews,
                ()=>Modified(this));

            this.textBoxMaker = textBoxMaker;
        }
Exemplo n.º 12
0
        public BlockController(Graphics textMetrics, Font textFont, Size canvasSize, Func <TextBox> textBoxMaker)
        {
            this.Modified += delegate(object sender) { };
            blockSpace     = new BlockSpace();
            blockSpace.OnTopLevelAdded   += new TopLevelEvent(blockSpace_OnTopLevelAdded);
            blockSpace.OnTopLevelDeleted += new TopLevelEvent(blockSpace_OnTopLevelDeleted);
            blockSpace.OnTopLevelMoved   += new TopLevelEvent(blockSpace_OnTopLevelMoved);

            palette           = new Palette(new Size(canvasSize.Width - 20, 60), textMetrics, textFont);
            palette.Modified += new PaletteModifiedEvent(palette_Modified);

            canvasView      = new CanvasView(textMetrics, canvasSize, allViews, DropRegions, textFont, palette);
            this.canvasSize = canvasSize;
            state           = CanvasState.Ready;
            viewFactory     = new BlockViewFactory(textMetrics, textFont, blockSpace, blockViews,
                                                   () => Modified(this));

            this.textBoxMaker = textBoxMaker;
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
 public TopLevelScript(Point Location, IBlock Block, BlockSpace owner)
 {
     this._Location = Location;
     this.Block = Block;
     this.owner = owner;
 }
Exemplo n.º 15
0
 internal void AddTool(BlockSpace blockSpace, ToolPrototype spec)
 {
     AddNewTool(blockSpace, spec);
     LayoutTools(currentCategory);
     if (currentCategory == spec.category)
         UpdateBitmap(currentCategory, tabWidth, tabHeight);
 }
Exemplo n.º 16
0
 internal void ResetBlockSpace(BlockSpace blockSpace)
 {
     this.blockSpace = blockSpace;
 }
Exemplo n.º 17
0
 public TopLevelScript(Point Location, IBlock Block, BlockSpace owner)
 {
     this._Location = Location;
     this.Block     = Block;
     this.owner     = owner;
 }
Exemplo n.º 18
0
 private void AddNewTool(BlockSpace blockSpace, ToolPrototype spec)
 {
     string[] parts = spec.tool.Split("|".ToCharArray());
     //string fileName = Path.Combine(filePrefix, parts[0]) + ".bmp";
     string funcName = parts[1];
     // Bitmap tbBmp = (Bitmap)Bitmap.FromFile(fileName);
     Bitmap tbBmp = dummyFactory.ViewFromBlock(blockSpace.makeNewBlock(funcName, spec.defaultArgs))
         .Assemble();
     //tbBmp.MakeTransparent(tbBmp.GetPixel(0, 0));
     tools.Add(new ToolSpec(tbBmp, funcName, spec.category, spec.defaultArgs));
     categories.Add(spec.category);
 }
Exemplo n.º 19
0
        public void Init(IEnumerable<ToolPrototype> toolSpecs, string filePrefix, string initialCategory,
            BlockSpace blockSpace)
        {
            this.currentCategory = initialCategory;
            this.toolSpecs = toolSpecs;
            this.filePrefix = filePrefix;
            tools.Clear();

            dummyFactory = new BlockViewFactory(textMetrics, textFont,
                blockSpace, new Dictionary<IBlock, IBlockView>(), delegate() { });
            foreach (ToolPrototype spec in toolSpecs)
            {
                AddNewTool(blockSpace, spec);
            }
        }
Exemplo n.º 20
0
 internal void ResetBlockSpace(BlockSpace blockSpace)
 {
     this.blockSpace = blockSpace;
 }
Exemplo n.º 21
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;
 }