/// <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); }
/// <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(); }
public override void Paint(LayoutBox box, Renderman renderer) { for (int i = 0; i < Contents.Count; i++) { Contents[i].Paint(box, renderer); } }
internal override void Layout(LayoutBox box, Renderman renderer) { for (int i = 0; i < Contents.Count; i++) { Contents[i].Layout(box, renderer); } }
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); }
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); }
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; }
/// <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); } }
public override void OnComputeBox(Renderman renderer, Css.LayoutBox box, ref bool widthUndefined, ref bool heightUndefined) { if (Context2D != null) { Context2D.UpdateDimensions(box); } }
/// <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); }
/// <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); }
/// <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); }
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; }
/// <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]); } } }
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); }
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); }
/// <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)); }
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(); } }
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; }
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(); } }
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); }
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; } }
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(); } }
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; } }
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); } } }
/// <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; }
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); }
/// <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; }
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(); } }
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); } }