コード例 #1
0
ファイル: Blockly.cs プロジェクト: h7ga40/BlockFactory
        /// <summary>
        /// Size the SVG image to completely fill its container. Call this when the view
        /// actually changes sizes (e.g. on a window resize/device orientation change).
        /// See Blockly.resizeSvgContents to resize the workspace when the contents
        /// change (e.g. when a block is added or removed).
        /// Record the height/width of the SVG image.
        /// </summary>
        /// <param name="workspace">Any workspace in the SVG.</param>
        public static void svgResize(WorkspaceSvg workspace)
        {
            var mainWorkspace = workspace;

            while (mainWorkspace.options.parentWorkspace != null)
            {
                mainWorkspace = (WorkspaceSvg)mainWorkspace.options.parentWorkspace;
            }
            var svg = mainWorkspace.getParentSvg();
            var div = (HTMLDivElement)svg.ParentNode;

            if (div == null)
            {
                // Workspace deleted, or something.
                return;
            }
            var width  = div.OffsetWidth;
            var height = div.OffsetHeight;

            if ((double?)svg["cachedWidth_"] != width)
            {
                svg.SetAttribute("width", width + "px");
                svg["cachedWidth_"] = width;
            }
            if ((double?)svg["cachedHeight_"] != height)
            {
                svg.SetAttribute("height", height + "px");
                svg["cachedHeight_"] = height;
            }
            mainWorkspace.resize();
        }
コード例 #2
0
ファイル: Utils.cs プロジェクト: h7ga40/BlockFactory
        /// <summary>
        /// Return the absolute coordinates of the top-left corner of this element,
        /// scales that after canvas SVG element, if it's a descendant.
        /// The origin (0,0) is the top-left corner of the Blockly SVG.
        /// </summary>
        /// <param name="element">Element to find the coordinates of.</param>
        /// <param name="workspace">Element must be in this workspace.</param>
        /// <returns>Object with .x and .y properties.</returns>
        internal static goog.math.Coordinate getSvgXY_(SVGElement element,
                                                       WorkspaceSvg workspace)
        {
            var x     = 0.0;
            var y     = 0.0;
            var scale = 1.0;

            if (goog.dom.contains(workspace.getCanvas(), element) ||
                goog.dom.contains(workspace.getBubbleCanvas(), element))
            {
                // Before the SVG canvas, scale the coordinates.
                scale = workspace.scale;
            }
            do
            {
                // Loop through this block and every parent.
                var xy = Core.getRelativeXY_(element);
                if (element == workspace.getCanvas() ||
                    element == workspace.getBubbleCanvas())
                {
                    // After the SVG canvas, don't scale the coordinates.
                    scale = 1;
                }
                x      += xy.x * scale;
                y      += xy.y * scale;
                element = element.ParentNode as SVGElement;
            } while (element != null && element != workspace.getParentSvg());
            return(new goog.math.Coordinate(x, y));
        }
コード例 #3
0
ファイル: Inject.cs プロジェクト: h7ga40/BlockFactory
        /// <summary>
        /// Initialize Blockly with various handlers.
        /// </summary>
        /// <param name="mainWorkspace">Newly created main workspace.</param>
        private static void init_(WorkspaceSvg mainWorkspace)
        {
            var options = mainWorkspace.options;
            var svg     = mainWorkspace.getParentSvg();

            // Supress the browser's context menu.
            Core.bindEventWithChecks_(svg, "contextmenu", null,
                                      new Action <Event>((e) => {
                if (!Core.isTargetInput_(e))
                {
                    e.PreventDefault();
                }
            }));

            var workspaceResizeHandler = Core.bindEventWithChecks_(new Node(Window.Instance.instance), "resize",
                                                                   null,
                                                                   new Action <Event>((e) => {
                Core.hideChaff(true);
                Core.svgResize(mainWorkspace);
            }));

            mainWorkspace.setResizeHandlerWrapper(workspaceResizeHandler);

            Core.inject_bindDocumentEvents_();

            if (options.languageTree != null)
            {
                if (mainWorkspace.toolbox_ != null)
                {
                    mainWorkspace.toolbox_.init(/*mainWorkspace*/);
                }
                else if (mainWorkspace.flyout_ != null)
                {
                    // Build a fixed flyout with the root blocks.
                    mainWorkspace.flyout_.init(mainWorkspace);
                    mainWorkspace.flyout_.show(options.languageTree.ChildNodes);
                    mainWorkspace.flyout_.scrollToStart();
                    // Translate the workspace sideways to avoid the fixed flyout.
                    mainWorkspace.scrollX = mainWorkspace.flyout_.width_;
                    if (options.toolboxPosition == Core.TOOLBOX_AT_RIGHT)
                    {
                        mainWorkspace.scrollX *= -1;
                    }
                    mainWorkspace.translate(mainWorkspace.scrollX, 0);
                }
            }

            if (options.hasScrollbars)
            {
                mainWorkspace.scrollbar = new ScrollbarPair(mainWorkspace);
                mainWorkspace.scrollbar.resize();
            }

            // Load the sounds.
            if (options.hasSounds)
            {
                Core.inject_loadSounds_(options.pathToMedia, mainWorkspace);
            }
        }