예제 #1
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));
        }
예제 #2
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());
 }
예제 #3
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_));
                }
            }
        }