Ejemplo n.º 1
0
        /// <summary>
        /// Handle a mouse-down on bubble's resize corner.
        /// </summary>
        /// <param name="e">Mouse down event.</param>
        private void resizeMouseDown_(MouseEvent e)
        {
            this.promote_();
            Bubble.unbindDragEvents_();
            if (Core.isRightButton(e))
            {
                // No right-click.
                e.StopPropagation();
                return;
            }
            // Left-click (or middle click)
            Css.setCursor(Css.Cursor.CLOSED);

            this.workspace_.startDrag(e, new goog.math.Coordinate(
                                          this.workspace_.RTL ? -this.width_ : this.width_, this.height_));

            Bubble.onMouseUpWrapper_ = Core.bindEventWithChecks_(Document.Instance,
                                                                 "mouseup", null, new Action <MouseEvent>(Bubble.bubbleMouseUp_));
            Bubble.onMouseMoveWrapper_ = Core.bindEventWithChecks_(Document.Instance,
                                                                   "mousemove", this, new Action <MouseEvent>(this.resizeMouseMove_));
            Core.hideChaff();
            // This event has been handled.  No need to bubble up to the document.
            e.StopPropagation();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create the SVG image.
        /// </summary>
        /// <param name="container">Containing element.</param>
        /// <param name="options">Dictionary of options.</param>
        /// <returns>Newly created SVG image.</returns>
        private static SVGElement createDom_(Element container, Options options)
        {
            // Sadly browsers (Chrome vs Firefox) are currently inconsistent in laying
            // out content in RTL mode.  Therefore Blockly forces the use of LTR,
            // then manually positions content in RTL as needed.
            container.SetAttribute("dir", "LTR");
            // Closure can be trusted to create HTML widgets with the proper direction.
            goog.ui.Component.setDefaultRightToLeft(options.RTL);

            // Load CSS.
            Css.inject(options.hasCss, options.pathToMedia);
#if false
            // Build the SVG DOM.

            /*
             * <svg
             * xmlns="http://www.w3.org/2000/svg"
             * xmlns:html="http://www.w3.org/1999/xhtml"
             * xmlns:xlink="http://www.w3.org/1999/xlink"
             * version="1.1"
             * class="blocklySvg">
             * ...
             * </svg>
             */
            var svg = Core.createSvgElement("svg", new Dictionary <string, object>()
            {
                { "xmlns", "http://www.w3.org/2000/svg" },
                { "xmlns:html", "http://www.w3.org/1999/xhtml" },
                { "xmlns:xlink", "http://www.w3.org/1999/xlink" },
                { "version", "1.1" },
                { "class", "blocklySvg" }
            }, container);

            /*
             * <defs>
             * ... filters go here ...
             * </defs>
             */
            var defs = Core.createSvgElement("defs", new Dictionary <string, object>(), svg);
            var rnd  = Script.Random().ToString().Substring(2);

            /*
             * <filter id="blocklyEmbossFilter837493">
             *      <feGaussianBlur in="SourceAlpha" stdDeviation="1" result="blur"/>
             *      <feSpecularLighting in="blur" surfaceScale="1" specularConstant="0.5"
             *                                              specularExponent="10" lighting-color="white"
             *                                              result="specOut">
             *        <fePointLight x="-5000" y="-10000" z="20000"/>
             *      </feSpecularLighting>
             *      <feComposite in="specOut" in2="SourceAlpha" operator="in"
             *                               result="specOut"/>
             *      <feComposite in="SourceGraphic" in2="specOut" operator="arithmetic"
             *                               k1="0" k2="1" k3="1" k4="0"/>
             * </filter>
             */
            var embossFilter = Core.createSvgElement("filter", new Dictionary <string, object>()
            {
                { "id", "blocklyEmbossFilter" + rnd }
            }, defs);
            Core.createSvgElement("feGaussianBlur", new Dictionary <string, object>()
            {
                { "in", "SourceAlpha" }, { "stdDeviation", 1 }, { "result", "blur" }
            }, embossFilter);
            var feSpecularLighting = Core.createSvgElement("feSpecularLighting", new Dictionary <string, object>()
            {
                { "in", "blur" }, { "surfaceScale", 1 }, { "specularConstant", 0.5 },
                { "specularExponent", 10 }, { "lighting-color", "white" }, { "result", "specOut" }
            },
                                                           embossFilter);
            Core.createSvgElement("fePointLight", new Dictionary <string, object>()
            {
                { "x", -5000 }, { "y", -10000 }, { "z", 20000 }
            }, feSpecularLighting);
            Core.createSvgElement("feComposite", new Dictionary <string, object>()
            {
                { "in", "specOut" }, { "in2", "SourceAlpha" }, { "operator", "in" },
                { "result", "specOut" }
            }, embossFilter);
            Core.createSvgElement("feComposite", new Dictionary <string, object>()
            {
                { "in", "SourceGraphic" }, { "in2", "specOut" }, { "operator", "arithmetic" },
                { "k1", 0 }, { "k2", 1 }, { "k3", 1 }, { "k4", 0 }
            }, embossFilter);
            options.embossFilterId = embossFilter.Id;

            /*
             * <pattern id="blocklyDisabledPattern837493" patternUnits="userSpaceOnUse"
             *                 width="10" height="10">
             *      <rect width="10" height="10" fill="#aaa" />
             *      <path d="M 0 0 L 10 10 M 10 0 L 0 10" stroke="#cc0" />
             * </pattern>
             */
            var disabledPattern = Core.createSvgElement("pattern", new Dictionary <string, object>()
            {
                { "id", "blocklyDisabledPattern" + rnd },
                { "patternUnits", "userSpaceOnUse" },
                { "width", 10 }, { "height", 10 }
            }, defs);
            Core.createSvgElement("rect", new Dictionary <string, object>()
            {
                { "width", 10 }, { "height", 10 }, { "fill", "#aaa" }
            }, disabledPattern);
            Core.createSvgElement("path", new Dictionary <string, object>()
            {
                { "d", "M 0 0 L 10 10 M 10 0 L 0 10" }, { "stroke", "#cc0" }
            }, disabledPattern);
            options.disabledPatternId = disabledPattern.Id;

            /*
             * <pattern id="blocklyGridPattern837493" patternUnits="userSpaceOnUse">
             *      <rect stroke="#888" />
             *      <rect stroke="#888" />
             * </pattern>
             */
            var gridPattern = Core.createSvgElement("pattern", new Dictionary <string, object>()
            {
                { "id", "blocklyGridPattern" + rnd },
                { "patternUnits", "userSpaceOnUse" }
            }, defs);
            if (options.gridOptions.length > 0 && options.gridOptions.spacing > 0)
            {
                Core.createSvgElement("line", new Dictionary <string, object>()
                {
                    { "stroke", options.gridOptions.colour }
                },
                                      gridPattern);
                if (options.gridOptions.length > 1)
                {
                    Core.createSvgElement("line", new Dictionary <string, object>()
                    {
                        { "stroke", options.gridOptions.colour }
                    },
                                          gridPattern);
                }
                // x1, y1, x1, x2 properties will be set later in updateGridPattern_.
            }
            options.gridPattern = gridPattern;
#else
            var opt         = Script.NewObject();
            var gridOptions = Script.NewObject();
            Script.Set(gridOptions, "spacing", options.gridOptions.spacing);
            Script.Set(gridOptions, "colour", options.gridOptions.colour);
            Script.Set(gridOptions, "length", options.gridOptions.length);
            Script.Set(gridOptions, "snap", options.gridOptions.snap);
            Script.Set(opt, "gridOptions", gridOptions);
            var svg = SVGElement.Create(Script.CreateSvgDom(container.Instance, opt));
            options.embossFilterId    = (string)Script.Get(opt, "embossFilterId");
            options.disabledPatternId = (string)Script.Get(opt, "disabledPatternId");
            options.gridPattern       = SVGElement.Create(Script.Get(opt, "gridPattern"));
#endif
            return(svg);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Handle a mouse-up event while dragging a bubble's border or resize handle.
 /// </summary>
 /// <param name="e">Mouse up event.</param>
 private static void bubbleMouseUp_(MouseEvent e)
 {
     Touch.clearTouchIdentifier();
     Css.setCursor(Css.Cursor.OPEN);
     Bubble.unbindDragEvents_();
 }