Exemple #1
0
        public override ShapeProvider ToShape(SVGElement context, RenderContext renderer, out Css.Value value)
        {
            value = this;

            if (_cachedTarget == null)
            {
                string id = this[0].Hash;

                // Get the target now:
                SVGElement target = context.document.getElementById(id) as SVGElement;

                if (target == null)
                {
                    return(null);
                }

                // Get the path from the element (note that it could be a clip path):
                VectorPath path = target.GetPath(context, renderer);

                // Create a shape provider for it:
                _cachedTarget = new ShapeProvider();
                _cachedTarget.SetPath(path);
            }

            return(_cachedTarget);
        }
Exemple #2
0
 /// <summary>
 /// Draw the comment icon.
 /// </summary>
 /// <param name="group">The icon group.</param>
 protected override void drawIcon_(SVGElement group)
 {
     // Circle.
     Core.createSvgElement("circle", new Dictionary <string, object>()
     {
         { "class", "blocklyIconShape" }, { "r", "8" }, { "cx", "8" }, { "cy", "8" }
     },
                           group);
     // Can't use a real "?" text character since different browsers and operating
     // systems render it differently.
     // Body of question mark.
     Core.createSvgElement("path", new Dictionary <string, object>()
     {
         { "class", "blocklyIconSymbol" },
         { "d", "m6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405 0.607,-5.534 -3.765,-3.874v1.7c3.12,-1.657 3.698,0.118 2.336,1.25 -1.201,0.998 -1.201,1.528 -1.204,2.19z" }
     },
                           group);
     // Dot of question point.
     Core.createSvgElement("rect", new Dictionary <string, object>()
     {
         { "class", "blocklyIconSymbol" },
         { "x", "6.8" }, { "y", "10.78" }, { "height", "2" }, { "width", "2" }
     },
                           group);
 }
Exemple #3
0
        /// <summary>
        /// Create all the DOM elements required for a scrollbar.
        /// The resulting widget is not sized.
        /// </summary>
        private void createDom_()
        {
            /* Create the following DOM:
             * <g class="blocklyScrollbarHorizontal">
             * <rect class="blocklyScrollbarBackground" />
             * <rect class="blocklyScrollbarHandle" rx="8" ry="8" />
             * </g>
             */
            var className = "blocklyScrollbar" +
                            (this.horizontal_ ? "Horizontal" : "Vertical");

            this.svgGroup_ = Core.createSvgElement("g", new Dictionary <string, object>()
            {
                { "class", className }
            }, null);
            this.svgBackground_ = Core.createSvgElement("rect", new Dictionary <string, object>()
            {
                { "class", "blocklyScrollbarBackground" }
            }, this.svgGroup_);
            var radius = System.Math.Floor((Scrollbar.scrollbarThickness - 5) / 2);

            this.svgHandle_ = Core.createSvgElement("rect", new Dictionary <string, object>()
            {
                { "class", "blocklyScrollbarHandle" }, { "rx", radius }, { "ry", radius }
            },
                                                    this.svgGroup_);
            Scrollbar.insertAfter_(this.svgGroup_,
                                   this.workspace_.getBubbleCanvas());
        }
Exemple #4
0
        /// <summary>
        /// Does this icon get hidden when the block is collapsed.
        /// </summary>
        //public bool collapseHidden = false;

        /// <summary>
        /// Draw the warning icon.
        /// </summary>
        /// <param name="group">The icon group.</param>
        protected override void drawIcon_(SVGElement group)
        {
            // Triangle with rounded corners.
            Core.createSvgElement("path", new Dictionary <string, object>()
            {
                { "class", "blocklyIconShape" },
                { "d", "M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z" }
            },
                                  group);
            // Can't use a real "!" text character since different browsers and operating
            // systems render it differently.
            // Body of exclamation point.
            Core.createSvgElement("path", new Dictionary <string, object>()
            {
                { "class", "blocklyIconSymbol" },
                { "d", "m7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z" }
            },
                                  group);
            // Dot of exclamation point.
            Core.createSvgElement("rect", new Dictionary <string, object>()
            {
                { "class", "blocklyIconSymbol" },
                { "x", "7" }, { "y", "11" }, { "height", "2" }, { "width", "2" }
            },
                                  group);
        }
Exemple #5
0
 /// <summary>
 /// Class for an editable angle field.
 /// </summary>
 /// <param name="text">The initial content of the field.</param>
 /// <param name="opt_validator">An optional function that is called
 /// to validate any constraints on what the user entered.  Takes the new
 /// text as an argument and returns the accepted text or null to abort
 /// the change.</param>
 public FieldAngle(string text, Func <Field, string, object> opt_validator = null)
     : base(text, opt_validator)
 {
     // Add degree symbol: "360°" (LTR) or "°360" (RTL)
     this.symbol_ = Core.createSvgElement("tspan", new Dictionary <string, object>(), null);
     this.symbol_.AppendChild(Document.CreateTextNode("\u00B0"));
 }
Exemple #6
0
        public Element CreateElementNS(String namespaceURI, String tagName)
        {
            Element element = null;

            if (namespaceURI == Namespaces.Html)
            {
                element = HTMLElement.Factory(tagName);
            }
            else if (namespaceURI == Namespaces.Svg)
            {
                element = SVGElement.Create(tagName);
            }
            else if (namespaceURI == Namespaces.MathML)
            {
                element = MathMLElement.Create(tagName);
            }
            else if (namespaceURI == Namespaces.Xml)
            {
                element = XMLElement.Create(tagName);
            }
            else
            {
                element = new Element {
                    NamespaceURI = namespaceURI, NodeName = tagName
                }
            };

            element.OwnerDocument = this;
            return(element);
        }
Exemple #7
0
 /// <summary>
 /// Dispose of all DOM objects belonging to this text.
 /// </summary>
 public override void dispose()
 {
     goog.dom.removeNode(this.fieldGroup_);
     this.fieldGroup_   = null;
     this.imageElement_ = null;
     this.rectElement_  = null;
 }
Exemple #8
0
        /// <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));
        }
Exemple #9
0
        /// <summary>
        /// Create the icon on the block.
        /// </summary>
        internal void createIcon()
        {
            if (this.iconGroup_ != null)
            {
                // Icon already exists.
                return;
            }

            /* Here's the markup that will be generated:
             * <g class="blocklyIconGroup">
             * ...
             * </g>
             */
            this.iconGroup_ = Core.createSvgElement("g", new Dictionary <string, object>()
            {
                { "class", "blocklyIconGroup" }
            }, null);
            if (this.block_.isInFlyout)
            {
                Core.addClass_(this.iconGroup_, "blocklyIconGroupReadonly");
            }
            this.drawIcon_(this.iconGroup_);

            this.block_.getSvgRoot().AppendChild(this.iconGroup_);
            Core.bindEventWithChecks_(this.iconGroup_, "mouseup", this,
                                      new Action <MouseEvent>(this.iconClick_));
            this.updateEditable();
        }
Exemple #10
0
        /// <summary>Gets the shape that this CSS value represents.</summary>
        public virtual ShapeProvider ToShape(SVGElement context, RenderContext renderer, out Css.Value value)
        {
            // Unchanged value:
            value = this;

            // Isn't one!
            return(null);
        }
Exemple #11
0
 public void dispose()
 {
     if (this.svgGroup_ != null)
     {
         goog.dom.removeNode(this.svgGroup_);
         this.svgGroup_ = null;
     }
     this.workspace_ = null;
 }
Exemple #12
0
 /// <summary>
 /// Dispose of this icon.
 /// </summary>
 public virtual void dispose()
 {
     // Dispose of and unlink the icon.
     goog.dom.removeNode(this.iconGroup_);
     this.iconGroup_ = null;
     // Dispose of and unlink the bubble.
     this.setVisible(false);
     this.block_ = null;
 }
Exemple #13
0
 /// <summary>
 /// Dispose of this pair of scrollbars.
 /// Unlink from all DOM elements to prevent memory leaks.
 /// </summary>
 public void dispose()
 {
     goog.dom.removeNode(this.corner_);
     this.corner_         = null;
     this.workspace_      = null;
     this.oldHostMetrics_ = null;
     this.hScroll.dispose();
     this.hScroll = null;
     this.vScroll.dispose();
     this.vScroll = null;
 }
Exemple #14
0
 /// <summary>
 /// Dispose of this trash can.
 /// Unlink from all DOM elements to prevent memory leaks.
 /// </summary>
 public void dispose()
 {
     if (this.svgGroup_ != null)
     {
         goog.dom.removeNode(this.svgGroup_);
         this.svgGroup_ = null;
     }
     this.svgLid_    = null;
     this.workspace_ = null;
     goog.Timer.clear(this.lidTask_);
 }
Exemple #15
0
        public override ShapeProvider ToShape(SVGElement context, RenderContext renderer, out Css.Value value)
        {
            // Convert into an SVG rect function so it can store a cached square:
            SVGRectFunction rect = new SVGRectFunction();

            rect.Values = Values;
            value       = rect;

            Css.Value junk;
            return(value.ToShape(context, renderer, out junk));
        }
Exemple #16
0
        public override ShapeProvider ToShape(SVGElement context, RenderContext renderer, out Css.Value value)
        {
            // Convert into an SVG url function so it can store a cached square:
            SVGUrlFunction url = new SVGUrlFunction();

            url.Values = Values;
            value      = url;

            Css.Value junk;
            return(value.ToShape(context, renderer, out junk));
        }
Exemple #17
0
        /// <summary>
        /// Create the button elements.
        /// </summary>
        /// <returns>The button's SVG group.</returns>
        public SVGElement createDom()
        {
            this.svgGroup_ = Core.createSvgElement("g", new Dictionary <string, object>()
            {
                { "class", this.isLabel_ ? "blocklyFlyoutLabel" : "blocklyFlyoutButton" }
            }, this.workspace_.getCanvas());

            SVGElement shadow = null;

            if (!this.isLabel_)
            {
                // Shadow rectangle (light source does not mirror in RTL).
                shadow = Core.createSvgElement("rect", new Dictionary <string, object>()
                {
                    { "class", "blocklyFlyoutButtonShadow" },
                    { "rx", 4 }, { "ry", 4 }, { "x", 1 }, { "y", 1 }
                },
                                               this.svgGroup_);
            }
            // Background rectangle.
            var rect = Core.createSvgElement("rect", new Dictionary <string, object>()
            {
                { "class", this.isLabel_ ? "blocklyFlyoutLabelBackground" : "blocklyFlyoutButtonBackground" },
                { "rx", 4 }, { "ry", 4 }
            },
                                             this.svgGroup_);
            var svgText = Core.createSvgElement("text", new Dictionary <string, object>()
            {
                { "class", this.isLabel_ ? "blocklyFlyoutLabelText" : "blocklyText" },
                { "x", 0 }, { "y", 0 },
                { "text-anchor", "middle" }
            }, this.svgGroup_);

            svgText.TextContent = this.text_;

            this.width  = svgText.getComputedTextLength() + 2 * FlyoutButton.MARGIN;
            this.height = 20;              // Can't compute it :(

            if (!this.isLabel_)
            {
                shadow.SetAttribute("width", this.width.ToString());
                shadow.SetAttribute("height", this.height.ToString());
            }

            rect.SetAttribute("width", this.width.ToString());
            rect.SetAttribute("height", this.height.ToString());

            svgText.SetAttribute("x", (this.width / 2).ToString());
            svgText.SetAttribute("y", (this.height - FlyoutButton.MARGIN).ToString());

            this.updateTransform_();
            return(this.svgGroup_);
        }
Exemple #18
0
 /// <summary>
 /// Dispose of this bubble.
 /// </summary>
 public void dispose()
 {
     Bubble.unbindDragEvents_();
     // Dispose of and unlink the bubble.
     goog.dom.removeNode(this.bubbleGroup_);
     this.bubbleGroup_ = null;
     this.bubbleArrow_ = null;
     this.bubbleBack_  = null;
     this.resizeGroup_ = null;
     this.workspace_   = null;
     this.content_     = null;
     this.shape_       = null;
 }
Exemple #19
0
 public ScrollbarPair(WorkspaceSvg workspace)
 {
     this.workspace_ = workspace;
     this.hScroll    = new Scrollbar(workspace, true, true);
     this.vScroll    = new Scrollbar(workspace, false, true);
     this.corner_    = Core.createSvgElement("rect", new Dictionary <string, object>()
     {
         { "height", Scrollbar.scrollbarThickness },
         { "width", Scrollbar.scrollbarThickness },
         { "class", "blocklyScrollbarBackground" }
     }, null);
     Scrollbar.insertAfter_(this.corner_, workspace.getBubbleCanvas());
 }
Exemple #20
0
        /// <summary>
        /// Return the converted coordinates of the given mouse ev.
        /// The origin (0,0) is the top-left corner of the Blockly svg.
        /// </summary>
        /// <param name="e">Mouse ev.</param>
        /// <param name="svg">SVG element.</param>
        /// <param name="matrix">Inverted screen CTM to use.</param>
        /// <returns>Object with .x and .y properties.</returns>
        public static SVGPoint mouseToSvg(Event e, SVGElement svg, SVGMatrix matrix)
        {
            var svgPoint = svg.createSVGPoint();

            svgPoint.x = e.ClientX;
            svgPoint.y = e.ClientY;

            if (matrix == null)
            {
                matrix = svg.getScreenCTM().Inverse();
            }
            return(svgPoint.matrixTransform(matrix));
        }
Exemple #21
0
 /// <summary>
 /// Dispose of all DOM objects belonging to this editable field.
 /// </summary>
 public virtual void dispose()
 {
     if (this.mouseUpWrapper_ != null)
     {
         Core.unbindEvent_(this.mouseUpWrapper_);
         this.mouseUpWrapper_ = null;
     }
     this.sourceBlock_ = null;
     goog.dom.removeNode(this.fieldGroup_);
     this.fieldGroup_  = null;
     this.textElement_ = null;
     this.borderRect_  = null;
     this.validator_   = null;
 }
Exemple #22
0
        /// <summary>
        /// Dispose of this scrollbar.
        /// Unlink from all DOM elements to prevent memory leaks.
        /// </summary>
        public void dispose()
        {
            this.cleanUp_();
            Core.unbindEvent_(this.onMouseDownBarWrapper_);
            this.onMouseDownBarWrapper_ = null;
            Core.unbindEvent_(this.onMouseDownHandleWrapper_);
            this.onMouseDownHandleWrapper_ = null;

            goog.dom.removeNode(this.svgGroup_);
            this.svgGroup_      = null;
            this.svgBackground_ = null;
            this.svgHandle_     = null;
            this.workspace_     = null;
        }
Exemple #23
0
        /// <summary>
        /// Create the editor for the mutator's bubble.
        /// </summary>
        /// <returns>The top-level node of the editor.</returns>
        private SVGElement createEditor_()
        {
            /* Create the editor.  Here's the markup that will be generated:
             * <svg>
             * [Workspace]
             * </svg>
             */
            this.svgDialog_ = Core.createSvgElement("svg", new Dictionary <string, object>()
            {
                { "x", Bubble.BORDER_WIDTH }, { "y", Bubble.BORDER_WIDTH }
            },
                                                    null);
            // Convert the list of names into a list of XML objects for the flyout.
            Element quarkXml;

            if (this.quarkNames_.Length != 0)
            {
                quarkXml = (Element)goog.dom.createDom("xml");
                foreach (var quarkName in this.quarkNames_)
                {
                    var block = (Element)goog.dom.createDom("block");
                    block.SetAttribute("type", quarkName);
                    quarkXml.AppendChild(block);
                }
            }
            else
            {
                quarkXml = null;
            }
            var workspaceOptions = new Options {
                languageTree    = quarkXml,
                parentWorkspace = this.block_.workspace,
                pathToMedia     = this.block_.workspace.options.pathToMedia,
                RTL             = this.block_.RTL,
                toolboxPosition = this.block_.RTL ? Core.TOOLBOX_AT_RIGHT :
                                  Core.TOOLBOX_AT_LEFT,
                horizontalLayout = false,
                getMetrics       = new Func <Metrics>(() => this.getFlyoutMetrics_()),
                setMetrics       = null
            };

            this.workspace_           = new WorkspaceSvg(workspaceOptions);
            this.workspace_.MAX_UNDO  = 0;
            this.workspace_.isMutator = true;
            this.svgDialog_.AppendChild(
                ((WorkspaceSvg)this.workspace_).createDom("blocklyMutatorBackground"));
            return(this.svgDialog_);
        }
Exemple #24
0
        private SVGElement createEditor_()
        {
            /* Create the editor.  Here's the markup that will be generated:
             * <foreignObject x="8" y="8" width="164" height="164">
             *      <body xmlns="http://www.w3.org/1999/xhtml" class="blocklyMinimalBody">
             *        <textarea xmlns="http://www.w3.org/1999/xhtml"
             *                class="blocklyCommentTextarea"
             *                style="height: 164px; width: 164px;"></textarea>
             *      </body>
             * </foreignObject>
             */
            this.foreignObject_ = Core.createSvgElement("foreignObject", new Dictionary <string, object>()
            {
                { "x", Bubble.BORDER_WIDTH }, { "y", Bubble.BORDER_WIDTH }
            },
                                                        null);
            var body = Document.CreateElementNS <HTMLBodyElement>(Core.HTML_NS, "body");

            body.SetAttribute("xmlns", Core.HTML_NS);
            body.ClassName = "blocklyMinimalBody";
            var textarea = Document.CreateElementNS <HTMLTextAreaElement>(Core.HTML_NS, "textarea");

            textarea.ClassName = "blocklyCommentTextarea";
            textarea.SetAttribute("dir", this.block_.RTL ? "RTL" : "LTR");
            body.AppendChild(textarea);
            this.textarea_ = textarea;
            this.foreignObject_.AppendChild(body);
            Core.bindEventWithChecks_(textarea, "mouseup", this, new Action <Event>(this.textareaFocus_));
            // Don't zoom with mousewheel.
            Core.bindEventWithChecks_(textarea, "wheel", null, new Action <Event>((e) => {
                e.StopPropagation();
            }));
            Core.bindEventWithChecks_(textarea, "change", null, new Action <Event>((e) => {
                if (this.text_ != textarea.Value)
                {
                    Events.fire(new Events.Change(
                                    this.block_, "comment", null, this.text_, textarea.Value));
                    this.text_ = textarea.Value;
                }
            }));
            Window.SetTimeout(() => {
                textarea.Focus();
            }, 0);
            return(this.foreignObject_);
        }
Exemple #25
0
        /// <summary>
        /// Insert a node after a reference node.
        /// Contrast with node.insertBefore function.
        /// </summary>
        /// <param name="newNode">New element to insert.</param>
        /// <param name="refNode">Existing element to precede new node.</param>
        internal static void insertAfter_(SVGElement newNode, SVGElement refNode)
        {
            var siblingNode = refNode.NextSibling;
            var parentNode  = refNode.ParentNode;

            if (parentNode == null)
            {
                throw new Exception("Reference node has no parent.");
            }
            if (siblingNode != null)
            {
                parentNode.InsertBefore(newNode, siblingNode);
            }
            else
            {
                parentNode.AppendChild(newNode);
            }
        }
Exemple #26
0
        /// <summary>
        /// Class for UI bubble.
        /// </summary>
        /// <param name="workspace">The workspace on which to draw the
        /// bubble.</param>
        /// <param name="content">SVG content for the bubble.</param>
        /// <param name="shape">SVG element to avoid eclipsing.</param>
        /// <param name="anchorXY">Absolute position of bubble's anchor
        /// point.</param>
        /// <param name="bubbleWidth">Width of bubble, or null if not resizable.</param>
        /// <param name="bubbleHeight">Height of bubble, or null if not resizable.</param>
        public Bubble(WorkspaceSvg workspace, SVGElement content, SVGElement shape,
                      goog.math.Coordinate anchorXY, double bubbleWidth, double bubbleHeight)
        {
            this.workspace_ = workspace;
            this.content_   = content;
            this.shape_     = shape;

            var angle = Bubble.ARROW_ANGLE;

            if (this.workspace_.RTL)
            {
                angle = -angle;
            }
            this.arrow_radians_ = goog.math.toRadians(angle);

            var canvas = workspace.getBubbleCanvas();

            canvas.AppendChild(this.createDom_(content, !(bubbleWidth != 0.0 && bubbleHeight != 0.0)));

            this.setAnchorLocation(anchorXY);
            if (bubbleWidth == 0.0 || bubbleHeight == 0.0)
            {
                var bBox = /** @type {SVGLocatable} */ (this.content_).getBBox();
                bubbleWidth  = bBox.width + 2 * Bubble.BORDER_WIDTH;
                bubbleHeight = bBox.height + 2 * Bubble.BORDER_WIDTH;
            }
            this.setBubbleSize(bubbleWidth, bubbleHeight);

            // Render the bubble.
            this.positionBubble_();
            this.renderArrow_();
            this.rendered_ = true;

            if (!workspace.options.readOnly)
            {
                Core.bindEventWithChecks_(this.bubbleBack_, "mousedown", this,
                                          new Action <MouseEvent>(this.bubbleMouseDown_));
                if (this.resizeGroup_ != null)
                {
                    Core.bindEventWithChecks_(this.resizeGroup_, "mousedown", this,
                                              new Action <MouseEvent>(this.resizeMouseDown_));
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// Show or hide the comment bubble.
        /// </summary>
        /// <param name="visible">True if the bubble should be visible.</param>
        internal override void setVisible(bool visible)
        {
            if (visible == this.isVisible())
            {
                // No change.
                return;
            }
            Events.fire(
                new Events.Ui(this.block_, "commentOpen", (!visible).ToString(), visible.ToString()));
            if ((!this.block_.isEditable() && this.textarea_ == null) || goog.userAgent.IE)
            {
                // Steal the code from warnings to make an uneditable text bubble.
                // MSIE does not support foreignobject; textareas are impossible.
                // http://msdn.microsoft.com/en-us/library/hh834675%28v=vs.85%29.aspx
                // Always treat comments in IE as uneditable.
                // TODO:Warning.prototype.setVisible.call(this, visible);
                return;
            }
            // Save the bubble stats before the visibility switch.
            var text = this.getText();
            var size = this.getBubbleSize();

            if (visible)
            {
                // Create the bubble.
                this.bubble_ = new Bubble((WorkspaceSvg)this.block_.workspace,
                                          this.createEditor_(), ((BlockSvg)this.block_).svgPath_,
                                          this.iconXY_, this.width_, this.height_);
                this.bubble_.registerResizeEvent(new Action(this.resizeBubble_));
                this.updateColour();
            }
            else
            {
                // Dispose of the bubble.
                this.bubble_.dispose();
                this.bubble_        = null;
                this.textarea_      = null;
                this.foreignObject_ = null;
            }
            // Restore the bubble stats after the visibility switch.
            this.setText(text);
            this.setBubbleSize(size.width, size.height);
        }
Exemple #28
0
        /// <summary>
        /// Install this image on a block.
        /// </summary>
        public override void init()
        {
            if (this.fieldGroup_ != null)
            {
                // Image has already been initialized once.
                return;
            }
            // Build the DOM.
            /** @type {SVGElement} */
            this.fieldGroup_ = Core.createSvgElement("g", new Dictionary <string, object>(), null);
            if (!this.visible_)
            {
                this.fieldGroup_.style.Display = Display.None;
            }
            /** @type {SVGElement} */
            this.imageElement_ = Core.createSvgElement("image", new Dictionary <string, object>()
            {
                { "height", this.height_ + "px" },
                { "width", this.width_ + "px" }
            }, this.fieldGroup_);
            this.setValue(this.src_);
            if (goog.userAgent.GECKO)
            {
                /**
                 * Due to a Firefox bug which eats mouse events on image elements,
                 * a transparent rectangle needs to be placed on top of the image.
                 * @type {SVGElement}
                 */
                this.rectElement_ = Core.createSvgElement("rect", new Dictionary <string, object>()
                {
                    { "height", this.height_ + "px" },
                    { "width", this.width_ + "px" },
                    { "fill-opacity", 0 }
                }, this.fieldGroup_);
            }
            this.sourceBlock_.getSvgRoot().AppendChild(this.fieldGroup_);

            // Configure the field to be transparent with respect to tooltips.
            var topElement = this.rectElement_ ?? this.imageElement_;

            topElement.tooltip = this.sourceBlock_;
            Tooltip.bindMouseEvents(topElement);
        }
Exemple #29
0
        /// <summary>
        /// Install this dropdown on a block.
        /// </summary>
        public override void init()
        {
            if (this.fieldGroup_ != null)
            {
                // Dropdown has already been initialized once.
                return;
            }
            // Add dropdown arrow: "option ▾" (LTR) or "▾ אופציה" (RTL)
            this.arrow_ = Core.createSvgElement("tspan", new Dictionary <string, object>(), null);
            this.arrow_.AppendChild(Document.CreateTextNode(
                                        this.sourceBlock_.RTL ? FieldDropdown.ARROW_CHAR + " " :
                                        ' ' + FieldDropdown.ARROW_CHAR));

            base.init();
            // Force a reset of the text to add the arrow.
            var text = this.text_;

            this.text_ = null;
            this.setText(text);
        }
Exemple #30
0
        public override ShapeProvider ToShape(SVGElement context, RenderContext renderer, out Css.Value value)
        {
            value = this;

            if (_cachedShape == null)
            {
                // Create a rectangle:
                RectangleProvider rect = new RectangleProvider();

                // Apply width/height/position to it:
                rect.X      = this[0];
                rect.Y      = this[1];
                rect.Width  = this[2];
                rect.Height = this[3];

                // Cached:
                _cachedShape = rect;
            }

            return(_cachedShape);
        }
    // Parse the file specified by the path parameter
    public void importSVG(string path)
    {
        SVGElement element = new SVGElement();
        TextAsset svgTextAsset = (TextAsset)Resources.Load("SVG/"+path); //load svg file as textasset
        string SVGData = svgTextAsset.text;

        // Remove superfluos characters
        SVGData = cleanString (SVGData);

        // Extract individual elements
        string[] SVGElements = SVGData.Split('<');
        // Parse each element according to its type
        for (int i = 0; i < SVGElements.Length - 1; i++)
        {
            // Extract element type
            string e = SVGElements[i].Split (' ')[0];
            // Ignore empty strings and end tags
            if(e.Length > 0 && e[0] == '/')
                continue;

            switch(e)
            {
            case "polygon":
                element = new SVGPolygon(SVGElements[i]);
                type = SVGType.polygon;
                break;
                //Not supported in sample
            /*case "path":
                element = new SVGPath(SVGElements[i]);
                type = SVGType.path;
                break;
            case "circle":
                element = new SVGCircle(SVGElements[i]);
                type = SVGType.circle;
                break;
            case "ellipse":
                element = new SVGEllipse(SVGElements[i]);
                type = SVGType.ellipse;
                break;
            case "rect":
                element = new SVGRect(SVGElements[i]);
                type = SVGType.rect;
                break;
            case "line":
                element = new SVGLine(SVGElements[i]);
                type = SVGType.line;
                break;
            case "text":
                element = new SVGText(SVGElements[i]);
                type = SVGType.text;
                break;*/
            default:
                if (!(String.IsNullOrEmpty(e) || e != "svg")) break;
                    Debug.Log ("Element '" + SVGElements[i] + "' not recognised");
                break;
            }

            // Access element points
            List<Vector2> points = element.points;

            // Move on if there is no mesh to generate
            if ((points.Count == 0 && type != SVGType.text) || type == SVGType.none)
            {
                continue;
            }

            // Call mesh creation functions

            // Text mesh
            if(type == SVGType.text)
            {
                createText (element.id, element.singlePoint, element.fill, element.opacity, element.textString, element.fontSize, element.fontType, i);
            }
            // Line mesh
            else if(type == SVGType.line)
            {
                createMesh (element.strokePoints, element.stroke, element.opacity, i, element.id);
            }
            // All others
            else
            {
                // Create primary mesh
                createMesh (element.points, element.fill, element.opacity, i+1, element.id);
                // Create stroke mesh only if there are enough points
                if(element.strokePoints.Count > 2)
                    createMesh (element.strokePoints, element.stroke, element.opacity, i, element.id);
            }
            // reset type to default
            type = SVGType.none;
        }
    }