コード例 #1
0
        /// <summary>Gets a box from the pool or creates one.</summary>
        public LayoutBox PooledBox()
        {
            if (FirstBoxPool == null)
            {
                return(new LayoutBox());
            }

            LayoutBox front = FirstBoxPool;

            FirstBoxPool = front.NextInElement;

            if (LastBoxPool == front)
            {
                // Clear end:
                LastBoxPool = null;
            }

            // Clear all hierarchy values:
            front.NextInElement = null;
            front.NextLineStart = null;
            front.NextOnLine    = null;
            front.FirstChild    = null;
            front.Parent        = null;

            front.ParentOffsetTop  = 0f;
            front.ParentOffsetLeft = 0f;
            front.OrdinaryInline   = true;
            front.Baseline         = 0f;

            return(front);
        }
コード例 #2
0
ファイル: BackgroundOverlay.cs プロジェクト: ru-ace/spark
        /// <summary>Lays out this background.</summary>
        internal void Layout(LayoutBox box, Renderman renderer)
        {
            if (Image == null || !Image.Loaded)
            {
                // Reject the visibility state change.
                ImageLocation = null;
                Text.Include();
                return;
            }

            // Tell the image that the box has likely changed - this allows it to redraw (e.g. SVGs):
            float trueImageWidth;
            float trueImageHeight;

            Image.Contents.OnLayout(Text.RenderData, box, out trueImageWidth, out trueImageHeight);

            if (ImageLocation == null)
            {
                // Tell it that it's going on screen:
                Image.GoingOnDisplay(Text.RenderData);

                // Create an isolated location:
                ImageLocation = new AtlasLocation(trueImageWidth, trueImageHeight);
            }

            // Isolate the text:
            Text.Isolate();
        }
コード例 #3
0
 public override void Paint(LayoutBox box, Renderman renderer)
 {
     for (int i = 0; i < Contents.Count; i++)
     {
         Contents[i].Paint(box, renderer);
     }
 }
コード例 #4
0
 internal override void Layout(LayoutBox box, Renderman renderer)
 {
     for (int i = 0; i < Contents.Count; i++)
     {
         Contents[i].Layout(box, renderer);
     }
 }
コード例 #5
0
        public override void OnComputeBox(Renderman renderer, Css.LayoutBox box, ref bool widthUndefined, ref bool heightUndefined)
        {
            if (document is SVGDocument)
            {
                return;
            }

            // Occurs on inline SVG's.

            // Set the size:
            Context.SetSize((int)box.InnerWidth, (int)box.InnerHeight);

            UnityEngine.Texture tex = Context.Texture;

            if (tex == null)
            {
                return;
            }

            // Update the background raw image:
            BackgroundImage img = RenderData.BGImage;

            if (img == null)
            {
                img = new Css.BackgroundImage(RenderData);
                RenderData.BGImage = img;
            }

            // Update the bg image:
            img.UpdateImage(tex);
        }
コード例 #6
0
        public override bool Render(bool first, LayoutBox box, Renderman renderer)
        {
            base.Render(first, box, renderer);

            // PostProcess required if this has Resets (i.e. after the element has done all of its kids):
            return(Resets != null);
        }
コード例 #7
0
ファイル: img.cs プロジェクト: HippoAR/DemoPowerUI
        public override void OnComputeBox(Renderman renderer, Css.LayoutBox box, ref bool widthUndefined, ref bool heightUndefined)
        {
            // Replaced:
            box.OrdinaryInline = false;

            if (widthUndefined)
            {
                if (heightUndefined)
                {
                    // Both undefined - use the base:
                    box.InnerWidth  = RawWidth;
                    box.InnerHeight = RawHeight;
                }
                else
                {
                    // Apply width from the height:
                    box.InnerWidth = box.InnerHeight * AspectRatio;
                }
            }
            else if (heightUndefined)
            {
                // Apply height from the width:
                box.InnerHeight = box.InnerWidth * InverseAspectRatio;
            }

            // They're always defined by the end of this:
            widthUndefined  = false;
            heightUndefined = false;
        }
コード例 #8
0
        /// <summary>Renders round corners.</summary>
        public void RenderCorners(LayoutBox box, Renderman renderer)
        {
            // Get the co-ord of the top edge:
            float top  = box.Y;
            float left = box.X;

            // And the dimensions of the lines:
            float boxWidth  = box.PaddedWidth + box.Border.Left + box.Border.Right;
            float boxHeight = box.PaddedHeight + box.Border.Top + box.Border.Bottom;

            if (TopLeft != null)
            {
                // Got a top left corner - render it now:
                TopLeft.Render(box, renderer, left, top);
            }

            if (TopRight != null)
            {
                // Got a top left corner - render it now:
                TopRight.Render(box, renderer, left + boxWidth, top);
            }

            if (BottomRight != null)
            {
                // Got a top left corner - render it now:
                BottomRight.Render(box, renderer, left + boxWidth, top + boxHeight);
            }

            if (BottomLeft != null)
            {
                // Got a top left corner - render it now:
                BottomLeft.Render(box, renderer, left, top + boxHeight);
            }
        }
コード例 #9
0
 public override void OnComputeBox(Renderman renderer, Css.LayoutBox box, ref bool widthUndefined, ref bool heightUndefined)
 {
     if (Context2D != null)
     {
         Context2D.UpdateDimensions(box);
     }
 }
コード例 #10
0
        /// <summary>Calculates where the transformation origin should go in screen space.</summary>
        /// <param name="relativeTo">The computed style of the element that the origin will be
        /// relative to if the origin position is 'Relative'</param>
        private Vector3 CalculateOrigin(ComputedStyle relativeTo, LayoutBox box)
        {
            // We need to figure out where the origin is and then apply the parent transformation to it.

            Vector3 origin;

            if (_OriginOffset == null)
            {
                // Default (50%,50%,0):
                origin = new Vector3(0.5f * box.Width, 0.5f * box.Height, 0f);
            }
            else if (_OriginOffset is CssFunction)
            {
                RenderableData rd = relativeTo.RenderData;

                origin = new Vector3(
                    _OriginOffset.GetDecimal(rd, ValueAxis.X),
                    _OriginOffset.GetDecimal(rd, ValueAxis.Y),
                    0f
                    );
            }
            else
            {
                float          z  = 0f;
                RenderableData rd = relativeTo.RenderData;

                if (_OriginOffset.Count == 3)
                {
                    z = _OriginOffset[2].GetDecimal(rd, ValueAxis.X);
                }

                origin = new Vector3(
                    _OriginOffset[0].GetDecimal(rd, ValueAxis.X),
                    _OriginOffset[1].GetDecimal(rd, ValueAxis.Y),
                    z
                    );
            }

            if (_OriginPosition == PositionMode.Relative)
            {
                origin.x += box.X;
                origin.y += box.Y;
            }

            // Map origin to world space:
            Renderman renderer = (relativeTo.Element.document as PowerUI.HtmlDocument).Renderer;

            origin = renderer.PixelToWorldUnit(origin.x, origin.y, relativeTo.ZIndex);

            if (Parent != null)
            {
                origin = Parent.Apply(origin);
            }

            return(origin);
        }
コード例 #11
0
        /// <summary>Make this property visible by forcing it to redraw.</summary>
        public virtual bool Render(bool first, LayoutBox box, Renderman renderer)
        {
            if (first)
            {
                ClearBlocks();
            }

            Layout(box, renderer);
            return(false);
        }
コード例 #12
0
        /// <summary>Transforms all the blocks that this property has allocated. Note that transformations are a post process.
        /// Special case for borders as it may also internally transform its corners.</summary>
        /// <param name="topTransform">The transform that should be applied to this property.</param>
        public override void PostProcess(LayoutBox box, Renderman renderer)
        {
            if (Corners == null)
            {
                return;
            }

            // Render them:
            Corners.RenderCorners(box, renderer);
        }
コード例 #13
0
        public override void OnComputeBox(Renderman renderer, Css.LayoutBox box, ref bool widthUndefined, ref bool heightUndefined)
        {
            // Update viewport:
            if (ContentDocument == null)
            {
                return;
            }

            ContentDocument.Viewport.Height = box.InnerHeight;
            ContentDocument.Viewport.Width  = box.InnerWidth;
        }
コード例 #14
0
 /// <summary>Transforms all the blocks that this property has allocated. Note that transformations are a post process.
 /// Special case for borders as it may also internally transform its corners.</summary>
 /// <param name="topTransform">The transform that should be applied to this property.</param>
 public override void PostProcess(LayoutBox box, Renderman renderer)
 {
     if (Resets != null)
     {
         // Pop all of the counters:
         for (int i = 0; i < Resets.Count; i++)
         {
             // Pop it:
             renderer.PopCounter(Resets[i]);
         }
     }
 }
コード例 #15
0
        public override bool Render(bool first, LayoutBox box, Renderman renderer)
        {
            if (first)
            {
                ClearBlocks();
            }

            Layout(box, renderer);

            // Return true if we've got border-radius corners - that'll trigger a PostProcess event:
            return(Corners != null);
        }
コード例 #16
0
        public override void Paint(LayoutBox box, Renderman renderer)
        {
            MeshBlock block = GetFirstBlock(renderer);

            if (block == null)
            {
                // This can happen if an animation is requesting that a now offscreen element gets painted only.
                return;
            }

            block.PaintColour(BaseColour * renderer.ColorOverlay);
        }
コード例 #17
0
        /// <summary>Gets the horizontal position in pixels of the numbered letter.</summary>
        /// <param name="letterID">The letter to get.</param>
        /// <returns>The position of the left edge of the numbered letter in pixels, relative to the left edge of the UI.</returns>
        public float PositionOf(int letterID)
        {
            LayoutBox box = RenderData.FirstBox;

            if (box == null)
            {
                // Not run yet
                return(0f);
            }

            float width = box.X + box.StyleOffsetLeft;

            return(width + LocalPositionOf(letterID));
        }
コード例 #18
0
ファイル: rectangle.cs プロジェクト: HippoAR/DemoPowerUI
        public override void OnComputeBox(Renderman renderer, Css.LayoutBox box, ref bool widthUndefined, ref bool heightUndefined)
        {
            RectangleProvider rect = Rectangle;

            // Check to see if w/h was updated via CSS:
            Css.Value newWidth  = Width;
            Css.Value newHeight = Height;

            if (rect.Width != newWidth || rect.Height != newHeight)
            {
                rect.Width  = newWidth;
                rect.Height = newHeight;
                RebuildPath();
            }
        }
コード例 #19
0
        public override void OnComputeBox(Renderman renderer, Css.LayoutBox box, ref bool widthUndefined, ref bool heightUndefined)
        {
            // Replaced:
            box.OrdinaryInline = false;

            if (widthUndefined)
            {
                if (heightUndefined)
                {
                    // Both undefined - establish which we'll be primarily clipping by.

                    if (Style.Computed.ShouldClipHeight())
                    {
                        // Height priority. Clip by min/max-height:
                        box.InnerHeight = Style.Computed.ClipHeight(
                            box.DisplayMode, RawHeight * Style.Computed.RenderData.ValueScale
                            );

                        // Derive height from the aspect ratio:
                        box.InnerWidth = box.InnerHeight * AspectRatio;
                    }
                    else
                    {
                        // Width priority. Clip by min/max-width:
                        box.InnerWidth = Style.Computed.ClipWidth(
                            box.DisplayMode, RawWidth * Style.Computed.RenderData.ValueScale
                            );

                        // Derive height from the aspect ratio:
                        box.InnerHeight = box.InnerWidth * InverseAspectRatio;
                    }
                }
                else
                {
                    // Apply width from the height:
                    box.InnerWidth = box.InnerHeight * AspectRatio;
                }
            }
            else if (heightUndefined)
            {
                // Apply height from the width:
                box.InnerHeight = box.InnerWidth * InverseAspectRatio;
            }

            // They're always defined by the end of this:
            widthUndefined  = false;
            heightUndefined = false;
        }
コード例 #20
0
        public override void Paint(LayoutBox box, Renderman renderer)
        {
            Color colour = Colour * renderer.ColorOverlay;

            MeshBlock block = GetFirstBlock(renderer);

            // For each block..
            for (int i = 0; i < BlockCount; i++)
            {
                // Paint the colour:
                block.PaintColour(colour);

                // Go to next block:
                block.Next();
            }
        }
コード例 #21
0
ファイル: br.cs プロジェクト: Viktoriahwang/GallagherUnity
        public override void OnComputeBox(Renderman renderer, Css.LayoutBox box, ref bool widthUndefined, ref bool heightUndefined)
        {
            // Get meta:
            LineBoxMeta lbm = renderer.TopOfStackSafe;

            // If the line is empty, set some height:
            if (lbm.FirstOnLine == null)
            {
                heightUndefined = false;
                box.InnerHeight = Style.Computed.FontSizeX;
                box.Height      = box.InnerHeight;
            }

            // Implicit line break:
            lbm.CompleteLine(LineBreakMode.Normal | LineBreakMode.Last);
        }
コード例 #22
0
ファイル: scrollthumb.cs プロジェクト: HippoAR/DemoPowerUI
 public override void OnComputeBox(Renderman renderer, Css.LayoutBox thumbBox, ref bool widthUndefined, ref bool heightUndefined)
 {
     if (IsVertical)
     {
         if (thumbBox.Position.Top == float.MaxValue)
         {
             // Initial push over the first arrow:
             thumbBox.Position.Top = StartArrowSize;
         }
     }
     else if (thumbBox.Position.Left == float.MaxValue)
     {
         // Initial push over the first arrow:
         thumbBox.Position.Left = StartArrowSize;
     }
 }
コード例 #23
0
ファイル: BackgroundImage.cs プロジェクト: ru-ace/spark
        public override void Paint(LayoutBox box, Renderman renderer)
        {
            // Any meshes in this elements queue should now change colour:
            Color colour = renderer.ColorOverlay;

            MeshBlock block = GetFirstBlock(renderer);

            // For each block..
            for (int i = 0; i < BlockCount; i++)
            {
                // Paint the colour:
                block.PaintColour(colour);

                // Go to next block:
                block.Next();
            }
        }
コード例 #24
0
        public override void Paint(LayoutBox box, Renderman renderer)
        {
            // Any meshes in my queue should now change colour:
            MeshBlock block = GetFirstBlock(renderer);

            if (BaseColour == null || BaseColour.Count == 1)
            {
                // Most common case. This is a single colour border.

                // Get the default colour - that's the same as the text colour:
                Color colour = Color.black;

                // Does this border have a colour?
                if (BaseColour == null)
                {
                    // Grab the text colour if there is one:
                    if (RenderData.Text != null)
                    {
                        // It's the same as the font colour:
                        colour = RenderData.Text.BaseColour * renderer.ColorOverlay;
                    }
                    else
                    {
                        // Nope - We need to set alpha:
                        colour.a = renderer.ColorOverlay.a;
                    }
                }
                else
                {
                    colour = BaseColour[0].GetColour(RenderData, Css.Properties.BorderColor.GlobalProperty) * renderer.ColorOverlay;
                }

                // For each block..
                for (int i = 0; i < BlockCount; i++)
                {
                    // Paint the colour:
                    block.PaintColour(colour);

                    // Go to next block:
                    block.Next();
                }

                return;
            }
        }
コード例 #25
0
        internal override void Layout(LayoutBox box, Renderman renderer)
        {
            // Get the top left inner corner (inside margin and border):
            float width  = box.PaddedWidth;
            float height = box.PaddedHeight;
            float top    = box.Y + box.Border.Top;
            float left   = box.X + box.Border.Left;

            // Is it clipped?
            if (renderer.IsInvisible(left, top, width, height))
            {
                // Totally not visible.
                return;
            }

            // Ensure we have a batch (doesn't change graphics or font thus both nulls):
            renderer.SetupBatch(this, null, null);

            // Get the transform:
            Transformation transform = renderer.Transform;

            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    // Add it:
                    MeshBlock block = Add(renderer);

                    // Set the UV to that of the solid block colour pixel:
                    block.SetSolidColourUV();

                    // Set the colour - here we set it unevenly to trigger gradients.
                    // block.SetColour(BackingColour * renderer.ColorOverlay);

                    // BoxRegion clipZone=new BoxRegion(left,top,width,height);

                    // Set the verts too:
                    // block.SetClipped(renderer.ClippingBoundary,clipZone,renderer,box.ZIndex-0.006f);

                    block.Done(transform);
                }
            }
        }
コード例 #26
0
        /// <summary>Updates the FlatWorldUI so it builds the mesh for this element.</summary>
        private void UpdateRenderer(LayoutBox box, float width, float height)
        {
            // - Set w/h to width and height:
            int w = (int)width;
            int h = (int)height;

            // Resize the renderer (which will emit a changed image event):
            Renderer.SetDimensions(w, h);

            // Temporarily set the positioning of 'box' such that it's at the origin:
            int      _pos      = box.PositionMode;
            BoxStyle _position = box.Position;

            // Clear:
            box.Position     = new BoxStyle(0f, float.MaxValue, float.MaxValue, 0f);
            box.PositionMode = PositionMode.Fixed;

            // Put the RenderData in the render only queue of *Renderer* and ask it to layout now:
            RenderableData _next     = RenderData.Next;
            UpdateMode     _mode     = RenderData.NextUpdateMode;
            RenderableData _ancestor = RenderData.Ancestor;

            // Clear:
            RenderData.Next           = null;
            RenderData.NextUpdateMode = UpdateMode.Render;
            RenderData.Ancestor       = null;

            // Queue:
            Renderer.Renderer.StylesToUpdate    = RenderData;
            Renderer.Renderer.HighestUpdateMode = UpdateMode.Render;

            // Draw now!
            Renderer.Renderer.Update();

            // Restore (box):
            box.Position     = _position;
            box.PositionMode = _pos;

            // Restore (queue):
            RenderData.Next           = _next;
            RenderData.NextUpdateMode = _mode;
            RenderData.Ancestor       = _ancestor;
        }
コード例 #27
0
        public override void Paint(LayoutBox box, Renderman renderer)
        {
            // Does the given renderer belong to the worldUI?
            if (Renderer != null && renderer == Renderer.Renderer)
            {
                // Yes! We're actually drawing the element. Do nothing.
                return;
            }

            MeshBlock block = GetFirstBlock(renderer);

            if (block == null)
            {
                // This can happen if an animation is requesting that a now offscreen element gets painted only.
                return;
            }

            block.PaintColour(renderer.ColorOverlay);
        }
コード例 #28
0
        /// <summary>Adds a linked list of boxes to the box pool.</summary>
        public void PoolBoxes(LayoutBox firstBox, LayoutBox lastBox)
        {
            if (firstBox == null)
            {
                return;
            }

            if (LastBoxPool == null)
            {
                FirstBoxPool = firstBox;
                LastBoxPool  = lastBox;
            }
            else
            {
                LastBoxPool.NextInElement = firstBox;
                LastBoxPool = lastBox;
            }

            lastBox.NextInElement = null;
        }
コード例 #29
0
        public override void Paint(LayoutBox box, Renderman renderer)
        {
            // Resolve colour:
            BaseColour = RenderData.computedStyle.Resolve(Css.Properties.ColorProperty.GlobalProperty)
                         .GetColour(RenderData, Css.Properties.ColorProperty.GlobalProperty);

            Color colour = BaseColour * renderer.ColorOverlay;

            MeshBlock block = GetFirstBlock(renderer);

            // For each block..
            for (int i = 0; i < BlockCount; i++)
            {
                // Paint the colour:
                block.PaintColour(colour);

                // Go to next block:
                block.Next();
            }
        }
コード例 #30
0
        public override void OnComputeBox(Renderman renderer, Css.LayoutBox box, ref bool widthUndefined, ref bool heightUndefined)
        {
            // Locate the caret if we need to:
            if (Locate)
            {
                Locate = false;

                RenderableTextNode htn = TextHolder;
                Vector2            position;

                if (htn == null)
                {
                    // Just at 0,0:
                    position = Vector2.zero;
                }
                else
                {
                    // Clip:
                    if (Index >= htn.length)
                    {
                        Index = htn.length;
                    }

                    // Get the position of the given letter:
                    position = htn.GetPosition(Index);
                }

                // Scroll it if position is out of range:
                ScrollIfBeyond(ref position);

                // Set it in for this pass:
                box.Position.Top  = position.y;
                box.Position.Left = position.x;

                // Write it out:
                Style.Computed.ChangeTagProperty("left", new Css.Units.DecimalUnit(position.x), false);
                Style.Computed.ChangeTagProperty("top", new Css.Units.DecimalUnit(position.y), false);
            }
        }