Example #1
0
        /// <summary>
        /// Parse the user-specified zoom options, using reasonable defaults where
        /// behaviour is unspecified.  See zoom documentation:
        /// https://developers.google.com/blockly/guides/configure/web/zoom
        /// </summary>
        /// <param name="options">Dictionary of options.</param>
        /// <returns>A dictionary of normalized options.</returns>
        private static ZoomOptions parseZoomOptions_(Dictionary <string, object> options)
        {
            var zoom        = options.ContainsKey("zoom") ? (Dictionary <string, object>)options["zoom"] : new Dictionary <string, object>();
            var zoomOptions = new ZoomOptions();

            if (!zoom.ContainsKey("controls"))
            {
                zoomOptions.controls = false;
            }
            else
            {
                zoomOptions.controls = (bool)zoom["controls"];
            }
            if (!zoom.ContainsKey("wheel"))
            {
                zoomOptions.wheel = false;
            }
            else
            {
                zoomOptions.wheel = (bool)zoom["wheel"];
            }
            if (!zoom.ContainsKey("startScale"))
            {
                zoomOptions.startScale = 1;
            }
            else
            {
                zoomOptions.startScale = Script.ParseFloat(zoom["startScale"].ToString());
            }
            if (!zoom.ContainsKey("maxScale"))
            {
                zoomOptions.maxScale = 3;
            }
            else
            {
                zoomOptions.maxScale = Script.ParseFloat(zoom["maxScale"].ToString());
            }
            if (!zoom.ContainsKey("minScale"))
            {
                zoomOptions.minScale = 0.3;
            }
            else
            {
                zoomOptions.minScale = Script.ParseFloat(zoom["minScale"].ToString());
            }
            if (!zoom.ContainsKey("scaleSpeed"))
            {
                zoomOptions.scaleSpeed = 1.2;
            }
            else
            {
                zoomOptions.scaleSpeed = Script.ParseFloat(zoom["scaleSpeed"].ToString());
            }
            return(zoomOptions);
        }
Example #2
0
        public Options(Dictionary <string, object> options = null)
        {
            if (options == null)
            {
                options = new Dictionary <string, object>();
            }

            var     readOnly      = options.ContainsKey("readOnly") ? (bool)options["readOnly"] : false;
            Element languageTree  = null;
            var     hasCategories = false;
            var     hasTrashcan   = false;
            var     hasCollapse   = false;
            var     hasComments   = false;
            var     hasDisable    = false;
            var     hasSounds     = false;

            if (!readOnly)
            {
                languageTree  = options.ContainsKey("toolbox") ? Options.parseToolboxTree(new Union <string, Element>(options["toolbox"])) : null;
                hasCategories = languageTree != null &&
                                languageTree.GetElementsByTagName("category").Length != 0;
                if (options.ContainsKey("trashcan"))
                {
                    hasTrashcan = (bool)options["trashcan"];
                }
                else
                {
                    hasTrashcan = hasCategories;
                }
                if (options.ContainsKey("collapse"))
                {
                    hasCollapse = (bool)options["collapse"];
                }
                else
                {
                    hasCollapse = hasCategories;
                }
                if (options.ContainsKey("comments"))
                {
                    hasComments = (bool)options["comments"];
                }
                else
                {
                    hasComments = hasCategories;
                }
                if (options.ContainsKey("disable"))
                {
                    hasDisable = (bool)options["disable"];
                }
                else
                {
                    hasDisable = hasCategories;
                }
                if (options.ContainsKey("sounds"))
                {
                    hasSounds = (bool)options["sounds"];
                }
                else
                {
                    hasSounds = true;
                }
            }
            var  rtl = options.ContainsKey("rtl") ? (bool)options["rtl"] : false;
            bool horizontalLayout;

            if (options.ContainsKey("horizontalLayout"))
            {
                horizontalLayout = (bool)options["horizontalLayout"];
            }
            else
            {
                horizontalLayout = false;
            }
            bool toolboxAtStart = true;

            if (options.ContainsKey("toolboxPosition"))
            {
                if (options["toolboxPosition"].ToString() == "end")
                {
                    toolboxAtStart = false;
                }
            }

            int toolboxPosition;

            if (horizontalLayout)
            {
                toolboxPosition = toolboxAtStart ?
                                  Core.TOOLBOX_AT_TOP : Core.TOOLBOX_AT_BOTTOM;
            }
            else
            {
                toolboxPosition = (toolboxAtStart == rtl) ?
                                  Core.TOOLBOX_AT_RIGHT : Core.TOOLBOX_AT_LEFT;
            }

            bool hasScrollbars;

            if (options.ContainsKey("scrollbars"))
            {
                hasScrollbars = (bool)options["scrollbars"];
            }
            else
            {
                hasScrollbars = hasCategories;
            }
            bool hasCss;

            if (options.ContainsKey("css"))
            {
                hasCss = (bool)options["css"];
            }
            else
            {
                hasCss = true;
            }
            var pathToMedia = "https://blockly-demo.appspot.com/static/media/";

            if (options.ContainsKey("media"))
            {
                pathToMedia = options["media"].ToString();
            }
            else if (options.ContainsKey("path"))
            {
                // "path" is a deprecated option which has been replaced by "media".
                pathToMedia = options["path"] + "media/";
            }
            var oneBasedIndex = true;

            if (options.ContainsKey("oneBasedIndex"))
            {
                oneBasedIndex = (bool)options["oneBasedIndex"];
            }

            this.RTL              = rtl;
            this.oneBasedIndex    = oneBasedIndex;
            this.collapse         = hasCollapse;
            this.comments         = hasComments;
            this.disable          = hasDisable;
            this.readOnly         = readOnly;
            this.maxBlocks        = options.ContainsKey("maxBlocks") ? (int)options["maxBlocks"] : int.MaxValue;
            this.pathToMedia      = pathToMedia;
            this.hasCategories    = hasCategories;
            this.hasScrollbars    = hasScrollbars;
            this.hasTrashcan      = hasTrashcan;
            this.hasSounds        = hasSounds;
            this.hasCss           = hasCss;
            this.horizontalLayout = horizontalLayout;
            this.languageTree     = languageTree;
            this.gridOptions      = Options.parseGridOptions_(options);
            this.zoomOptions      = Options.parseZoomOptions_(options);
            this.toolboxPosition  = toolboxPosition;
        }