private bool CalculateTextureAndRenderAreas(Rectf renderSettingDestArea, ref Rectf?clippingArea, out Rectf finalRect, ref Rectf texRect) { var dest = (renderSettingDestArea); // apply rendering offset to the destination Rect dest.Offset(d_scaledOffset); // get the rect area that we will actually draw to (i.e. perform clipping) finalRect = clippingArea.HasValue ? dest.GetIntersection(clippingArea.Value) : dest; // check if rect was totally clipped if ((finalRect.Width == 0) || (finalRect.Height == 0)) { return(true); } // Obtain correct scale values from the texture var texelScale = _texture.GetTexelScaling(); var texPerPix = new Lunatics.Mathematics.Vector2(d_imageArea.Width / dest.Width, d_imageArea.Height / dest.Height); // calculate final, clipped, texture co-ordinates texRect = new Rectf((d_imageArea.d_min + ((finalRect.d_min - dest.d_min) * texPerPix)) * texelScale, (d_imageArea.d_max + ((finalRect.d_max - dest.d_max) * texPerPix)) * texelScale); // TODO: This is clearly not optimal but the only way to go with the current // Font rendering system. Distance field rendering would allow us to ignore the // pixel alignment. finalRect.d_min.X = CoordConverter.AlignToPixels(finalRect.d_min.X); finalRect.d_min.Y = CoordConverter.AlignToPixels(finalRect.d_min.Y); finalRect.d_max.X = CoordConverter.AlignToPixels(finalRect.d_max.X); finalRect.d_max.Y = CoordConverter.AlignToPixels(finalRect.d_max.Y); return(false); }
/// <summary> /// Render the section specified by this SectionSpecification. /// </summary> /// <param name="srcWindow"> /// Window object to be used when calculating pixel values from BaseDim values. /// </param> /// <param name="modcols"></param> /// <param name="clipper"></param> /// <param name="clipToDisplay"></param> public void Render(Window srcWindow, ColourRect modcols = null, Rectf? clipper = null, bool clipToDisplay = false) { // see if we need to bother rendering if (!ShouldBeDrawn(srcWindow)) return; try { // get the imagery section object with the name we're set up to use var sect = WidgetLookManager.GetSingleton().GetWidgetLook(d_owner).GetImagerySection(d_sectionName); // decide what colours are to be used var finalColours =new ColourRect(); InitColourRectForOverride(srcWindow, ref finalColours); finalColours.ModulateAlpha(srcWindow.GetEffectiveAlpha()); if (modcols!=null) finalColours *= modcols; // render the imagery section sect.Render(srcWindow, finalColours, clipper, clipToDisplay); } catch (Exception) { // do nothing here, errors are non-faltal and are logged for debugging purposes. } }
/// <summary> /// Render the ImagerySection. /// </summary> /// <param name="srcWindow"> /// Window object to be used when calculating pixel values from BaseDim values. /// </param> /// <param name="modColours"> /// ColourRect specifying colours to be modulated with the ImagerySection's master colours. May be 0. /// </param> /// <param name="clipper"></param> /// <param name="clipToDisplay"></param> public void Render(Window srcWindow, ColourRect modColours = null, Rectf?clipper = null, bool clipToDisplay = false) { // decide what to do as far as colours go ColourRect finalCols; InitMasterColourRect(srcWindow, out finalCols); if (modColours != null) { finalCols *= modColours; } var finalColsPtr = (finalCols.IsMonochromatic() && finalCols.d_top_left.ToAlphaRGB() == 0xFFFFFFFF) ? null : finalCols; // render all frame components in this section foreach (var frame in d_frames) { frame.CreateRenderGeometryAndAddToWindow(srcWindow, finalColsPtr, clipper, clipToDisplay); } // render all image components in this section foreach (var image in d_images) { image.CreateRenderGeometryAndAddToWindow(srcWindow, finalColsPtr, clipper, clipToDisplay); } // render all text components in this section foreach (var text in d_texts) { text.CreateRenderGeometryAndAddToWindow(srcWindow, finalColsPtr, clipper, clipToDisplay); } }
/// <summary> /// Render this layer. /// </summary> /// <param name="srcWindow"> /// Window to use when calculating pixel values from BaseDim values. /// </param> /// <param name="modcols"></param> /// <param name="clipper"></param> /// <param name="clipToDisplay"></param> public void Render(Window srcWindow, ColourRect modcols = null, Rectf?clipper = null, bool clipToDisplay = false) { // render all sections in this layer foreach (var curr in d_sections) { curr.Render(srcWindow, modcols, clipper, clipToDisplay); } }
/// <summary> /// Render imagery for this state. /// </summary> /// <param name="srcWindow"> /// Window to use when convering BaseDim values to pixels. /// </param> /// <param name="modcols"></param> /// <param name="clipper"></param> public void Render(Window srcWindow, ColourRect modcols = null, Rectf?clipper = null) { // render all layers defined for this state foreach (var curr in d_layers) { curr.Render(srcWindow, modcols, clipper, d_clipToDisplay); } }
public ImageRenderSettings(Rectf destArea, Rectf?clipArea, bool isClippingEnabled, ColourRect multiplicationColours, float alpha) { DestArea = destArea; ClipArea = clipArea; IsClippingEnabled = isClippingEnabled; MultiplyColours = multiplicationColours; this.Alpha = alpha; }
/// <summary> /// Create render geometry for the text that should be rendered into a /// specified area of the display. /// </summary> /// <param name="buffer"> /// GeometryBuffer object where the geometry for the text be queued. /// </param> /// <param name="text"> /// String object containing the text to be drawn. /// </param> /// <param name="position"> /// Reference to a Vector2 object describing the location at which the text /// is to be drawn. /// </param> /// <param name="clipRect"> /// Rect object describing the clipping area for the drawing. /// No drawing will occur outside this Rect. /// </param> /// <param name="clippingEnabled"></param> /// <param name="colours"> /// ColourRect object describing the colours to be applied when drawing the /// text. NB: The colours specified in here are applied to each glyph, /// rather than the text as a whole. /// </param> /// <param name="spaceExtra"> /// Number of additional pixels of spacing to be added to space characters. /// </param> /// <param name="xScale"> /// Scaling factor to be applied to each glyph's x axis, where 1.0f is /// considered to be 'normal'. /// </param> /// <param name="yScale"> /// Scaling factor to be applied to each glyph's y axis, where 1.0f is /// considered to be 'normal'. /// </param> /// <returns> /// Returns a list of GeometryBuffers representing the render geometry of the text. /// </returns> public List <GeometryBuffer> CreateRenderGeometryForText(string text, Lunatics.Mathematics.Vector2 position, Rectf?clipRect, bool clippingEnabled, ColourRect colours, float spaceExtra = 0.0f, float xScale = 1.0f, float yScale = 1.0f) { float nextGlyphPos; return(CreateRenderGeometryForText(text, out nextGlyphPos, position, clipRect, clippingEnabled, colours, spaceExtra, xScale, yScale)); }
/// <summary> /// Set the area that the mouse cursor is constrained to. /// </summary> /// <param name="area"> /// Pointer to a Rect object that describes the area of the display that the mouse is allowed to occupy. /// The given area will be clipped to the current Renderer screen area - it is never possible for the /// mouse to leave this area. If this parameter is NULL, the constraint is set to the size of the current /// Renderer screen area. /// </param> public void SetConstraintArea(Rectf?area) { var rendererArea = new Rectf(Vector2f.Zero, System.GetSingleton().GetRenderer().GetDisplaySize()); if (!area.HasValue) { d_constraints.d_min.d_x = UDim.Relative(rendererArea.d_min.d_x / rendererArea.Width); d_constraints.d_min.d_y = UDim.Relative(rendererArea.d_min.d_y / rendererArea.Height); d_constraints.d_max.d_x = UDim.Relative(rendererArea.d_max.d_x / rendererArea.Width); d_constraints.d_max.d_y = UDim.Relative(rendererArea.d_max.d_y / rendererArea.Height); } else { var finalArea = area.Value.GetIntersection(rendererArea); d_constraints.d_min.d_x = UDim.Relative(finalArea.d_min.d_x / rendererArea.Width); d_constraints.d_min.d_y = UDim.Relative(finalArea.d_min.d_y / rendererArea.Height); d_constraints.d_max.d_x = UDim.Relative(finalArea.d_max.d_x / rendererArea.Width); d_constraints.d_max.d_y = UDim.Relative(finalArea.d_max.d_y / rendererArea.Height); } ConstrainPosition(); }
public override List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Vector2 position, ColourRect modColours, Rectf?clipRect, float verticalSpace, float spaceExtra) { var window = GetEffectiveWindow(refWnd); if (window == null) { return(new List <GeometryBuffer>()); } var geomBuffers = new List <GeometryBuffer>(); // HACK: re-adjust for inner-rect of parent float xAdj = 0, yAdj = 0; var parent = window.GetParent(); if (parent != null) { var outer = parent.GetUnclippedOuterRect().Get(); var inner = parent.GetUnclippedInnerRect().Get(); xAdj = inner.d_min.X - outer.d_min.X; yAdj = inner.d_min.Y - outer.d_min.Y; } // HACK: re-adjust for inner-rect of parent (Ends) var finalPos = position; // handle formatting options switch (d_verticalFormatting) { case VerticalFormatting.BottomAligned: finalPos.Y += verticalSpace - GetPixelSize(refWnd).Height; break; case VerticalFormatting.Stretched: case VerticalFormatting.CentreAligned: if (d_verticalFormatting == VerticalFormatting.Stretched) { System.GetSingleton().Logger.LogEvent("RenderedStringWidgetComponent::draw: " + "VerticalFormatting.Stretched specified but is unsupported for Widget types; " + "defaulting to VerticalFormatting.CentreAligned instead."); } finalPos.Y += (verticalSpace - GetPixelSize(refWnd).Height) / 2; break; case VerticalFormatting.TopAligned: // nothing additional to do for this formatting option. break; default: throw new InvalidRequestException("unknown VerticalFormatting option specified."); } // render the selection if needed if (d_selectionImage != null && d_selected) { var selectArea = new Rectf(position, GetPixelSize(refWnd)); var imgRenderSettings = new ImageRenderSettings(selectArea, clipRect, true, new ColourRect(0xFF002FFF)); geomBuffers.AddRange(d_selectionImage.CreateRenderGeometry(imgRenderSettings)); } // we do not actually draw the widget, we just move it into position. var wpos = new UVector2(new UDim(0, finalPos.X + d_padding.d_min.X - xAdj), new UDim(0, finalPos.Y + d_padding.d_min.Y - yAdj)); window.SetPosition(wpos); return(geomBuffers); }
public override void AddToRenderGeometry(GeometryBuffer geomBuffer, ref Rectf renderArea, ref Rectf?clipArea, ColourRect colours) { Rectf texRect = Rectf.Zero, finalRect; var isFullClipped = CalculateTextureAndRenderAreas(renderArea, ref clipArea, out finalRect, ref texRect); if (isFullClipped) { return; } var vbuffer = new TexturedColouredVertex[6]; CreateTexturedQuadVertices(vbuffer, colours, ref finalRect, ref texRect); geomBuffer.AppendGeometry(vbuffer); }
public override List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Vector2 position, ColourRect modColours, Rectf?clipRect, float verticalSpace, float spaceExtra) { throw new global::System.NotImplementedException(); }
// implemets abstract from base protected override void AddImageRenderGeometryToWindowImpl(Window srcWindow, Rectf destRect, ColourRect modColours, Rectf?clipper, bool clipToDisplay) { var backgroundRect = destRect; Sizef imageSize; Lunatics.Mathematics.Vector2 imageOffsets; float leftfactor, rightfactor, topfactor, bottomfactor; bool calcColoursPerImage; // vars we use to track what to do with the side pieces. float topOffset = 0, bottomOffset = 0, leftOffset = 0, rightOffset = 0; float topWidth, bottomWidth, leftHeight, rightHeight; topWidth = bottomWidth = destRect.Width; leftHeight = rightHeight = destRect.Height; // calculate final overall colours to be used ColourRect renderSettingFinalColours; InitColoursRect(srcWindow, modColours, out renderSettingFinalColours); var renderSettings = new ImageRenderSettings(Rectf.Zero, clipper, !clipToDisplay, renderSettingFinalColours); //var renderSettingDestArea = renderSettings.destArea; //var renderSettingMultiplyColours = renderSettings.multiplyColours; calcColoursPerImage = !renderSettingFinalColours.IsMonochromatic(); // top-left image var componentImage = GetImage(FrameImageComponent.TopLeftCorner, srcWindow); if (componentImage != null) { // calculate final destination area imageSize = componentImage.GetRenderedSize(); imageOffsets = componentImage.GetRenderedOffset(); renderSettings.DestArea.d_min = destRect.d_min; renderSettings.DestArea.Size = imageSize; renderSettings.DestArea = destRect.GetIntersection(renderSettings.DestArea); // update adjustments required to edges do to presence of this element. topOffset += imageSize.Width + imageOffsets.X; leftOffset += imageSize.Height + imageOffsets.Y; topWidth -= topOffset; leftHeight -= leftOffset; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (renderSettings.DestArea.Left + imageOffsets.X) / destRect.Width; rightfactor = leftfactor + renderSettings.DestArea.Width / destRect.Width; topfactor = (renderSettings.DestArea.Top + imageOffsets.Y) / destRect.Height; bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height; renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // create render geometry for this element and append it to the Window's geometry var imageGeomBuffers = componentImage.CreateRenderGeometry(renderSettings); srcWindow.AppendGeometryBuffers(imageGeomBuffers); } // top-right image componentImage = GetImage(FrameImageComponent.TopRightCorner, srcWindow); if (componentImage != null) { // calculate final destination area imageSize = componentImage.GetRenderedSize(); imageOffsets = componentImage.GetRenderedOffset(); renderSettings.DestArea.Left = destRect.Right - imageSize.Width; renderSettings.DestArea.Top = destRect.Top; renderSettings.DestArea.Size = imageSize; renderSettings.DestArea = destRect.GetIntersection(renderSettings.DestArea); // update adjustments required to edges do to presence of this element. rightOffset += imageSize.Height + imageOffsets.Y; topWidth -= imageSize.Width - imageOffsets.X; rightHeight -= rightOffset; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (renderSettings.DestArea.Left + imageOffsets.X) / destRect.Width; rightfactor = leftfactor + renderSettings.DestArea.Width / destRect.Width; topfactor = (renderSettings.DestArea.Top + imageOffsets.Y) / destRect.Height; bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height; renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // create render geometry for this element and append it to the Window's geometry var imageGeomBuffers = componentImage.CreateRenderGeometry(renderSettings); srcWindow.AppendGeometryBuffers(imageGeomBuffers); } // bottom-left image componentImage = GetImage(FrameImageComponent.BottomLeftCorner, srcWindow); if (componentImage != null) { // calculate final destination area imageSize = componentImage.GetRenderedSize(); imageOffsets = componentImage.GetRenderedOffset(); renderSettings.DestArea.Left = destRect.Left; renderSettings.DestArea.Top = destRect.Bottom - imageSize.Height; renderSettings.DestArea.Size = imageSize; renderSettings.DestArea = destRect.GetIntersection(renderSettings.DestArea); // update adjustments required to edges do to presence of this element. bottomOffset += imageSize.Width + imageOffsets.X; bottomWidth -= bottomOffset; leftHeight -= imageSize.Height - imageOffsets.Y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (renderSettings.DestArea.Left + imageOffsets.X) / destRect.Width; rightfactor = leftfactor + renderSettings.DestArea.Width / destRect.Width; topfactor = (renderSettings.DestArea.Top + imageOffsets.Y) / destRect.Height; bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height; renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // create render geometry for this element and append it to the Window's geometry var imageGeomBuffers = componentImage.CreateRenderGeometry(renderSettings); srcWindow.AppendGeometryBuffers(imageGeomBuffers); } // bottom-right image componentImage = GetImage(FrameImageComponent.BottomRightCorner, srcWindow); if (componentImage != null) { // calculate final destination area imageSize = componentImage.GetRenderedSize(); imageOffsets = componentImage.GetRenderedOffset(); renderSettings.DestArea.Left = destRect.Right - imageSize.Width; renderSettings.DestArea.Top = destRect.Bottom - imageSize.Height; renderSettings.DestArea.Size = imageSize; renderSettings.DestArea = destRect.GetIntersection(renderSettings.DestArea); // update adjustments required to edges do to presence of this element. bottomWidth -= imageSize.Width - imageOffsets.X; rightHeight -= imageSize.Height - imageOffsets.Y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (renderSettings.DestArea.Left + componentImage.GetRenderedOffset().X) / destRect.Width; rightfactor = leftfactor + renderSettings.DestArea.Width / destRect.Width; topfactor = (renderSettings.DestArea.Top + componentImage.GetRenderedOffset().Y) / destRect.Height; bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height; renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // create render geometry for this element and append it to the Window's geometry var imageGeomBuffers = componentImage.CreateRenderGeometry(renderSettings); srcWindow.AppendGeometryBuffers(imageGeomBuffers); } // top image componentImage = GetImage(FrameImageComponent.TopEdge, srcWindow); if (componentImage != null) { // calculate final destination area imageSize = componentImage.GetRenderedSize(); renderSettings.DestArea.Left = destRect.Left + topOffset; renderSettings.DestArea.Right = (renderSettings.DestArea.Left + topWidth); renderSettings.DestArea.Top = destRect.Top; renderSettings.DestArea.Bottom = renderSettings.DestArea.Top + imageSize.Height; renderSettings.DestArea = destRect.GetIntersection(renderSettings.DestArea); // adjust background area to miss this edge backgroundRect.d_min.Y += imageSize.Height + componentImage.GetRenderedOffset().Y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (renderSettings.DestArea.Left + componentImage.GetRenderedOffset().X) / destRect.Width; rightfactor = leftfactor + renderSettings.DestArea.Width / destRect.Width; topfactor = (renderSettings.DestArea.Top + componentImage.GetRenderedOffset().Y) / destRect.Height; bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height; renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // create render geometry for this image and append it to the Window's geometry var imageGeomBuffers = CreateRenderGeometryForImage(componentImage, VerticalFormatting.TopAligned, TopEdgeFormatting.Get(srcWindow), renderSettings.DestArea, renderSettings.MultiplyColours, clipper, clipToDisplay); srcWindow.AppendGeometryBuffers(imageGeomBuffers); } // bottom image componentImage = GetImage(FrameImageComponent.BottomEdge, srcWindow); if (componentImage != null) { // calculate final destination area imageSize = componentImage.GetRenderedSize(); renderSettings.DestArea.Left = destRect.Left + bottomOffset; renderSettings.DestArea.Right = renderSettings.DestArea.Left + bottomWidth; renderSettings.DestArea.Bottom = destRect.Bottom; renderSettings.DestArea.Top = renderSettings.DestArea.Bottom - imageSize.Height; renderSettings.DestArea = destRect.GetIntersection(renderSettings.DestArea); // adjust background area to miss this edge backgroundRect.d_max.Y -= imageSize.Height - componentImage.GetRenderedOffset().Y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (renderSettings.DestArea.Left + componentImage.GetRenderedOffset().X) / destRect.Width; rightfactor = leftfactor + renderSettings.DestArea.Width / destRect.Width; topfactor = (renderSettings.DestArea.Top + componentImage.GetRenderedOffset().Y) / destRect.Height; bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height; renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // create render geometry for this image and append it to the Window's geometry var imageGeomBuffers = CreateRenderGeometryForImage(componentImage, VerticalFormatting.BottomAligned, BottomEdgeFormatting.Get(srcWindow), renderSettings.DestArea, renderSettings.MultiplyColours, clipper, clipToDisplay); srcWindow.AppendGeometryBuffers(imageGeomBuffers); } // left image componentImage = GetImage(FrameImageComponent.LeftEdge, srcWindow); if (componentImage != null) { // calculate final destination area imageSize = componentImage.GetRenderedSize(); renderSettings.DestArea.Left = destRect.Left; renderSettings.DestArea.Right = renderSettings.DestArea.Left + imageSize.Width; renderSettings.DestArea.Top = destRect.Top + leftOffset; renderSettings.DestArea.Bottom = renderSettings.DestArea.Top + leftHeight; renderSettings.DestArea = destRect.GetIntersection(renderSettings.DestArea); // adjust background area to miss this edge backgroundRect.d_min.X += imageSize.Width + componentImage.GetRenderedOffset().X; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (renderSettings.DestArea.Left + componentImage.GetRenderedOffset().X) / destRect.Width; rightfactor = leftfactor + renderSettings.DestArea.Width / destRect.Width; topfactor = (renderSettings.DestArea.Top + componentImage.GetRenderedOffset().Y) / destRect.Height; bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height; renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // create render geometry for this image and append it to the Window's geometry var imageGeomBuffers = CreateRenderGeometryForImage(componentImage, LeftEdgeFormatting.Get(srcWindow), HorizontalFormatting.LeftAligned, renderSettings.DestArea, renderSettings.MultiplyColours, clipper, clipToDisplay); srcWindow.AppendGeometryBuffers(imageGeomBuffers); } // right image componentImage = GetImage(FrameImageComponent.RightEdge, srcWindow); if (componentImage != null) { // calculate final destination area imageSize = componentImage.GetRenderedSize(); renderSettings.DestArea.Top = destRect.Top + rightOffset; renderSettings.DestArea.Bottom = renderSettings.DestArea.Top + rightHeight; renderSettings.DestArea.Right = destRect.Right; renderSettings.DestArea.Left = renderSettings.DestArea.Right - imageSize.Width; renderSettings.DestArea = destRect.GetIntersection(renderSettings.DestArea); // adjust background area to miss this edge backgroundRect.d_max.X -= imageSize.Width - componentImage.GetRenderedOffset().X; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (renderSettings.DestArea.Left + componentImage.GetRenderedOffset().X) / destRect.Width; rightfactor = leftfactor + renderSettings.DestArea.Width / destRect.Width; topfactor = (renderSettings.DestArea.Top + componentImage.GetRenderedOffset().Y) / destRect.Height; bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height; renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // create render geometry for this image and append it to the Window's geometry var imageGeomBuffers = CreateRenderGeometryForImage(componentImage, RightEdgeFormatting.Get(srcWindow), HorizontalFormatting.RightAligned, renderSettings.DestArea, renderSettings.MultiplyColours, clipper, clipToDisplay); srcWindow.AppendGeometryBuffers(imageGeomBuffers); } componentImage = GetImage(FrameImageComponent.Background, srcWindow); if (componentImage != null) { // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (backgroundRect.Left + componentImage.GetRenderedOffset().X) / destRect.Width; rightfactor = leftfactor + backgroundRect.Width / destRect.Width; topfactor = (backgroundRect.Top + componentImage.GetRenderedOffset().Y) / destRect.Height; bottomfactor = topfactor + backgroundRect.Height / destRect.Height; renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } var horzFormatting = BackgroundHorzFormatting.Get(srcWindow); var vertFormatting = BackgroundVertFormatting.Get(srcWindow); var imageGeomBuffers = CreateRenderGeometryForImage(componentImage, vertFormatting, horzFormatting, backgroundRect, renderSettings.MultiplyColours, clipper, clipToDisplay); srcWindow.AppendGeometryBuffers(imageGeomBuffers); } }
public void CreateRenderGeometryAndAddToItemView(ItemView view, RenderedString renderedString, Rectf drawRect, Font font, Rectf?itemClipper, bool isSelected) { if (view.GetSelectionBrushImage() != null && isSelected) { var renderSettings = new ImageRenderSettings(drawRect, itemClipper, true, view.GetSelectionColourRect()); var brushGeomBuffers = view.GetSelectionBrushImage().CreateRenderGeometry(renderSettings); view.AppendGeometryBuffers(brushGeomBuffers); } var drawPos = drawRect.Position; for (var i = 0; i < renderedString.GetLineCount(); ++i) { drawPos.Y += CoordConverter.AlignToPixels((font.GetLineSpacing() - font.GetFontHeight()) * 0.5f); var stringGeomBuffers = renderedString.CreateRenderGeometry(view, i, drawPos, null, itemClipper, 0.0f); view.AppendGeometryBuffers(stringGeomBuffers); drawPos.Y += renderedString.GetPixelSize(view, i).Height; } }
public abstract List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Lunatics.Mathematics.Vector2 position, ColourRect modColours, Rectf?clipRect);
public override List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Lunatics.Mathematics.Vector2 position, ColourRect modColours, Rectf?clipRect) { var drawPos = position; var geomBuffers = new List <GeometryBuffer>(); for (var i = 0; i < d_renderedString.GetLineCount(); ++i) { geomBuffers.AddRange(d_renderedString.CreateRenderGeometry(refWnd, i, drawPos, modColours, clipRect, SpaceExtras[i])); drawPos.Y += d_renderedString.GetPixelSize(refWnd, i).Height; } return(geomBuffers); }
/// <summary> /// Creates the render geometry for this component and adds it to the Window /// </summary> /// <param name="srcWindow"> /// Window to use as the base for translating the component's ComponentArea /// into pixel values. /// </param> /// <param name="baseRect"> /// Rect to use as the base for translating the component's ComponentArea /// into pixel values. /// </param> /// <param name="modColours"> /// ColourRect describing colours that are to be modulated with the /// component's stored colour values to calculate a set of 'final' colour /// values to be used. May be 0. /// </param> /// <param name="clipper"></param> /// <param name="clipToDisplay"></param> public void CreateRenderGeometryAndAddToWindow(Window srcWindow, Rectf baseRect, ColourRect modColours = null, Rectf?clipper = null, bool clipToDisplay = false) { var destRect = d_area.GetPixelRect(srcWindow, baseRect); if (clipper == null) { clipper = destRect; } var finalClipRect = destRect.GetIntersection(clipper.Value); AddImageRenderGeometryToWindowImpl(srcWindow, destRect, modColours, finalClipRect, clipToDisplay); }
/// <summary> /// Appends additional render geometry for this image to an GeometryBuffers. /// The GeometryBuffer must be created beforehand and must feature render /// settings that allow adding this image geometry into the same render batch. /// Batching compatibility has to be ensured before this call. /// </summary> /// <param name="geomBuffer"> /// The existing GeometryBuffers to which the new render geometry will be appended. /// </param> /// <param name="renderArea"> /// The target area at which the image should be rendered. /// </param> /// <param name="clipAreaColourRect"> /// </param> /// <param name="colours"> /// Multiplicative colours to be applied to the text. /// </param> public abstract void AddToRenderGeometry(GeometryBuffer geomBuffer, ref Rectf renderArea, ref Rectf?clipAreaColourRect, ColourRect colours);
public override List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Vector2 position, ColourRect modColours, Rectf?clipRect, float verticalSpace, float spaceExtra) { var fnt = GetEffectiveFont(refWnd); if (fnt == null) { return(new List <GeometryBuffer>()); } var finalPos = position; var yScale = 1.0f; // handle formatting options switch (d_verticalFormatting) { case VerticalFormatting.BottomAligned: finalPos.Y += verticalSpace - GetPixelSize(refWnd).Height; break; case VerticalFormatting.CentreAligned: finalPos.Y += (verticalSpace - GetPixelSize(refWnd).Height) / 2; break; case VerticalFormatting.Stretched: yScale = verticalSpace / GetPixelSize(refWnd).Height; break; case VerticalFormatting.TopAligned: // nothing additional to do for this formatting option. break; default: throw new InvalidRequestException("unknown VerticalFormatting option specified."); } // apply padding to position: finalPos += d_padding.Position; // apply modulative colours if needed. var finalCols = d_colours; if (modColours != null) { finalCols *= modColours; } // render selection if (d_selectionImage != null && d_selectionLength != 0) { float selStartExtent = 0f, selEndExtent = 0f; if (d_selectionStart > 0) { selStartExtent = fnt.GetTextExtent(d_text.CEGuiSubstring(0, d_selectionStart)); } selEndExtent = fnt.GetTextExtent(d_text.CEGuiSubstring(0, d_selectionStart + d_selectionLength)); var selRect = new Rectf(position.X + selStartExtent, position.Y, position.X + selEndExtent, position.Y + verticalSpace); var imgRenderSetting = new ImageRenderSettings(selRect, clipRect, true, new ColourRect(0xFF002FFF)); d_selectionImage.CreateRenderGeometry(imgRenderSetting); } // draw the text string. return(fnt.CreateRenderGeometryForText(d_text, finalPos, clipRect, true, finalCols, spaceExtra, 1.0f, yScale)); }
// implemets abstract from base protected override void AddImageRenderGeometryToWindowImpl(Window srcWindow, Rectf destRect, ColourRect modColours, Rectf?clipper, bool clipToDisplay) { UpdateFormatting(srcWindow, destRect.Size); // Get total formatted height. var textHeight = _formattedRenderedString.GetVerticalExtent(srcWindow); // handle dest area adjustments for vertical formatting. var vertFormatting = _vertFormatting.Get(srcWindow); switch (vertFormatting) { case VerticalTextFormatting.CentreAligned: destRect.d_min.Y += (destRect.Height - textHeight) * 0.5f; break; case VerticalTextFormatting.BottomAligned: destRect.d_min.Y = destRect.d_max.Y - textHeight; break; } // calculate final colours to be used ColourRect finalColours; InitColoursRect(srcWindow, modColours, out finalColours); // add geometry for text to the target window. var geomBuffers = _formattedRenderedString.CreateRenderGeometry(srcWindow, destRect.Position, finalColours, clipper); srcWindow.AppendGeometryBuffers(geomBuffers); }
public override List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Lunatics.Mathematics.Vector2 position, ColourRect modColours, Rectf?clipRect) { var linePos = position; var geomBuffers = new List <GeometryBuffer>(); foreach (var i in Lines) { geomBuffers.AddRange(i.CreateRenderGeometry(refWnd, linePos, modColours, clipRect)); linePos.Y += i.GetVerticalExtent(refWnd); } return(geomBuffers); }
/// <summary> /// draw the component. /// </summary> /// <param name="refWnd"></param> /// <param name="position"></param> /// <param name="modColours"></param> /// <param name="clipRect"></param> /// <param name="verticalSpace"></param> /// <param name="spaceExtra"></param> public abstract List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Lunatics.Mathematics.Vector2 position, ColourRect modColours, Rectf?clipRect, float verticalSpace, float spaceExtra);
/// <summary> /// Draw the list box item in its current state /// </summary> /// <param name="targetRect"></param> /// <param name="alpha"> /// Alpha value to be used when rendering the item (between 0.0f and 1.0f). /// </param> /// <param name="clipper"> /// Rect object describing the clipping rectangle for the draw operation. /// </param> public abstract List <GeometryBuffer> CreateRenderGeometry(Rectf targetRect, float alpha, Rectf?clipper);
// TODO: Copy constructor. //public RenderedString(const RenderedString& other) //{ // cloneComponentList(other.d_components); // d_lines = other.d_lines; //} // TODO: Assignment. //RenderedString operator=(RenderedString rhs) //{ // cloneComponentList(rhs.d_components); // d_lines = rhs.d_lines; // return *this; //} // TODO: Destructor. //virtual ~RenderedString(); /// <summary> /// Draw the string to a GeometryBuffer. /// </summary> /// <param name="refWnd"> /// A pointer to a reference Window used to retrieve certain attributes if needed. /// </param> /// <param name="line"> /// The line of the RenderedString to draw. /// </param> /// <param name="position"> /// Vector2 describing the position where the RenderedString is to be drawn. /// Note that this is not the final onscreen position, but the position as /// offset from the top-left corner of the entity represented by the /// GeometryBuffer. /// </param> /// <param name="modColours"> /// Pointer to a ColourRect describing colour values that are to be /// modulated with the any stored colour values to calculate the final /// colour values to be used. This may be 0 if no modulated colours are /// required. NB: Each specific component will decide if and how it will /// apply the modulated colours. /// </param> /// <param name="clipRect"> /// Pointer to a Rect object that describes a clipping rectangle that should /// be used when drawing the RenderedString. This may be 0 if no clipping /// is required. /// </param> /// <param name="spaceExtra"> /// float value indicating additional padding value to be applied to space /// characters in the string. /// </param> /// <exception cref="InvalidRequestException"> /// thrown if \a line is out of range. /// </exception> public List <GeometryBuffer> CreateRenderGeometry(Window refWnd, int line, Lunatics.Mathematics.Vector2 position, ColourRect modColours, Rectf?clipRect, float spaceExtra) { if (line >= GetLineCount()) { throw new InvalidRequestException("line number specified is invalid."); } var renderHeight = GetPixelSize(refWnd, line).Height; var compPos = position; var geomBuffers = new List <GeometryBuffer>(); var endComponent = d_lines[line].First + d_lines[line].Second; for (var i = d_lines[line].First; i < endComponent; ++i) { var currentRenderGeometry = d_components[i].CreateRenderGeometry(refWnd, compPos, modColours, clipRect, renderHeight, spaceExtra); geomBuffers.AddRange(currentRenderGeometry); compPos.X += d_components[i].GetPixelSize(refWnd).Width; } return(geomBuffers); }
public ImageRenderSettings(Rectf destArea, Rectf?clipArea, bool isClippingEnabled) : this(destArea, clipArea, isClippingEnabled, new ColourRect(0XFFFFFFFF), 1f) { }
// implemets abstract from base protected override void AddImageRenderGeometryToWindowImpl(Window srcWindow, Rectf destRect, ColourRect modColours, Rectf?clipper, bool clipToDisplay) { // get final image to use. var img = IsImageFetchedFromProperty() ? srcWindow.GetProperty <Image>(ImagePropertyName) : Image; // do not draw anything if image is not set. if (img == null) { return; } var horzFormatting = HorizontalFormatting.Get(srcWindow); var vertFormatting = VerticalFormatting.Get(srcWindow); int horzTiles, vertTiles; float xpos, ypos; var imgSz = img.GetRenderedSize(); // calculate final colours to be used ColourRect finalColours; InitColoursRect(srcWindow, modColours, out finalColours); // calculate initial x co-ordinate and horizontal tile count according to formatting options switch (horzFormatting) { case Base.HorizontalFormatting.Stretched: imgSz.Width = destRect.Width; xpos = destRect.Left; horzTiles = 1; break; case Base.HorizontalFormatting.Tiled: xpos = destRect.Left; horzTiles = Math.Abs((int)((destRect.Width + (imgSz.Width - 1)) / imgSz.Width)); break; case Base.HorizontalFormatting.LeftAligned: xpos = destRect.Left; horzTiles = 1; break; case Base.HorizontalFormatting.CentreAligned: xpos = destRect.Left + CoordConverter.AlignToPixels((destRect.Width - imgSz.Width) * 0.5f); horzTiles = 1; break; case Base.HorizontalFormatting.RightAligned: xpos = destRect.Right - imgSz.Width; horzTiles = 1; break; default: throw new InvalidRequestException("An unknown HorizontalFormatting value was specified."); } // calculate initial y co-ordinate and vertical tile count according to formatting options switch (vertFormatting) { case Base.VerticalFormatting.Stretched: imgSz.Height = destRect.Height; ypos = destRect.Top; vertTiles = 1; break; case Base.VerticalFormatting.Tiled: ypos = destRect.Top; vertTiles = Math.Abs((int)((destRect.Height + (imgSz.Height - 1)) / imgSz.Height)); break; case Base.VerticalFormatting.TopAligned: ypos = destRect.Top; vertTiles = 1; break; case Base.VerticalFormatting.CentreAligned: ypos = destRect.Top + CoordConverter.AlignToPixels((destRect.Height - imgSz.Height) * 0.5f); vertTiles = 1; break; case Base.VerticalFormatting.BottomAligned: ypos = destRect.Bottom - imgSz.Height; vertTiles = 1; break; default: throw new InvalidRequestException("An unknown VerticalFormatting value was specified."); } // perform final rendering (actually is now a caching of the images which will be drawn) var imgRenderSettings = new ImageRenderSettings(Rectf.Zero, null, !clipToDisplay, finalColours); imgRenderSettings.DestArea.Top = ypos; imgRenderSettings.DestArea.Bottom = ypos + imgSz.Height; for (uint row = 0; row < vertTiles; ++row) { imgRenderSettings.DestArea.Left = xpos; imgRenderSettings.DestArea.Right = xpos + imgSz.Width; for (uint col = 0; col < horzTiles; ++col) { // use custom clipping for right and bottom edges when tiling the imagery if (((vertFormatting == Base.VerticalFormatting.Tiled) && row == vertTiles - 1) || ((horzFormatting == Base.HorizontalFormatting.Tiled) && col == horzTiles - 1)) { imgRenderSettings.ClipArea = clipper.HasValue ? clipper.Value.GetIntersection(destRect) : destRect; } // not tiliing, or not on far edges, just used passed in clipper (if any). else { imgRenderSettings.ClipArea = clipper; } // add geometry for image to the target window. var geomBuffers = img.CreateRenderGeometry(imgRenderSettings); srcWindow.AppendGeometryBuffers(geomBuffers); imgRenderSettings.DestArea.d_min.X += imgSz.Width; imgRenderSettings.DestArea.d_max.X += imgSz.Width; } imgRenderSettings.DestArea.d_min.Y += imgSz.Height; imgRenderSettings.DestArea.d_max.Y += imgSz.Height; } }
public ImageRenderSettings(Rectf destArea, Rectf?clipArea, bool isClippingEnabled, ColourRect multiplicationColours) : this(destArea, clipArea, isClippingEnabled, multiplicationColours, 1f) { }
/// <summary> /// /// </summary> /// <param name="text"></param> /// <param name="nextGlyphPosX"> /// The x-coordinate where subsequent text should be rendered to ensure correct /// positioning (which is not possible to determine accurately by using the /// extent measurement functions).</param> /// <param name="position"></param> /// <param name="clipRect"></param> /// <param name="clippingEnabled"></param> /// <param name="colours"></param> /// <param name="spaceExtra"></param> /// <param name="xScale"></param> /// <param name="yScale"></param> /// <returns> /// Returns a list of GeometryBuffers representing the render geometry of the text. /// </returns> public List <GeometryBuffer> CreateRenderGeometryForText(string text, out float nextGlyphPosX, Lunatics.Mathematics.Vector2 position, Rectf?clipRect, bool clippingEnabled, ColourRect colours, float spaceExtra = 0.0f, float xScale = 1.0f, float yScale = 1.0f) { var baseY = position.Y + GetBaseline(yScale); var glyphPos = position; var lastChar = (char)0; var geomBuffers = new List <GeometryBuffer>(); GeometryBuffer textGeometryBuffer = null; var imgRenderSettings = new ImageRenderSettings(Rectf.Zero, clipRect, clippingEnabled, colours); foreach (var c in text) { var glyph = GetGlyphData(c); if (glyph != null) { var img = glyph.GetImage(); glyphPos.X += GetKerningAmount(lastChar, c); glyphPos.Y = baseY - (img.GetRenderedOffset().Y - img.GetRenderedOffset().Y *yScale); imgRenderSettings.DestArea = new Rectf(glyphPos, glyph.GetSize(xScale, yScale)); if (textGeometryBuffer == null) { var currentGeombuffs = img.CreateRenderGeometry(imgRenderSettings); Debug.Assert(currentGeombuffs.Count <= 1, "Glyphs are expected to be built from a single GeometryBuffer (or none)"); if (currentGeombuffs.Count == 1) { textGeometryBuffer = currentGeombuffs[0]; } } else { // Else we add geometry to the rendering batch of the existing geometry img.AddToRenderGeometry(textGeometryBuffer, ref imgRenderSettings.DestArea, ref clipRect, colours); } glyphPos.X += glyph.GetAdvance(xScale); // apply extra spacing to space chars if (c == ' ') { glyphPos.X += spaceExtra; } } lastChar = c; } if (textGeometryBuffer != null) { geomBuffers.Add(textGeometryBuffer); } nextGlyphPosX = glyphPos.X; // Adding a single geometry buffer containing the batched glyphs return(geomBuffers); }
public override List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Lunatics.Mathematics.Vector2 position, ColourRect modColours, Rectf?clipRect) { Lunatics.Mathematics.Vector2 drawPos; var geomBuffers = new List <GeometryBuffer>(); drawPos.Y = position.Y; for (var i = 0; i < d_renderedString.GetLineCount(); ++i) { drawPos.X = position.X + _offsets[i]; var currentRenderGeometry = d_renderedString.CreateRenderGeometry(refWnd, i, drawPos, modColours, clipRect, 0.0f); geomBuffers.AddRange(currentRenderGeometry); drawPos.Y += d_renderedString.GetPixelSize(refWnd, i).Height; } return(geomBuffers); }
/// <summary> /// Function to do main render caching work. /// </summary> /// <param name="srcWindow"></param> /// <param name="destRect"></param> /// <param name="modColours"></param> /// <param name="clipper"></param> /// <param name="clipToDisplay"></param> protected abstract void AddImageRenderGeometryToWindowImpl(Window srcWindow, Rectf destRect, ColourRect modColours, Rectf?clipper, bool clipToDisplay);
protected List <GeometryBuffer> CreateRenderGeometryForImage(Image image, VerticalFormatting vertFmt, HorizontalFormatting horzFmt, Rectf destRect, ColourRect colours, Rectf?clipper, bool clipToDisplay) { int horzTiles, vertTiles; float xpos, ypos; var imgSz = image.GetRenderedSize(); // calculate initial x co-ordinate and horizontal tile count according to formatting options switch (horzFmt) { case HorizontalFormatting.Stretched: imgSz.Width = destRect.Width; xpos = destRect.Left; horzTiles = 1; break; case HorizontalFormatting.Tiled: xpos = destRect.Left; horzTiles = Math.Abs((int)((destRect.Width + (imgSz.Width - 1)) / imgSz.Width)); break; case HorizontalFormatting.LeftAligned: xpos = destRect.Left; horzTiles = 1; break; case HorizontalFormatting.CentreAligned: xpos = destRect.Left + CoordConverter.AlignToPixels((destRect.Width - imgSz.Width) * 0.5f); horzTiles = 1; break; case HorizontalFormatting.RightAligned: xpos = destRect.Right - imgSz.Width; horzTiles = 1; break; default: throw new InvalidRequestException("An unknown HorizontalFormatting value was specified."); } // calculate initial y co-ordinate and vertical tile count according to formatting options switch (vertFmt) { case VerticalFormatting.Stretched: imgSz.Height = destRect.Height; ypos = destRect.Top; vertTiles = 1; break; case VerticalFormatting.Tiled: ypos = destRect.Top; vertTiles = Math.Abs((int)((destRect.Height + (imgSz.Height - 1)) / imgSz.Height)); break; case VerticalFormatting.TopAligned: ypos = destRect.Top; vertTiles = 1; break; case VerticalFormatting.CentreAligned: ypos = destRect.Top + CoordConverter.AlignToPixels((destRect.Height - imgSz.Height) * 0.5f); vertTiles = 1; break; case VerticalFormatting.BottomAligned: ypos = destRect.Bottom - imgSz.Height; vertTiles = 1; break; default: throw new InvalidRequestException("An unknown VerticalFormatting value was specified."); } // Create the render geometry var geomBuffers = new List <GeometryBuffer>(); var renderSettings = new ImageRenderSettings(Rectf.Zero, null, !clipToDisplay, colours); renderSettings.DestArea.d_min.Y = ypos; renderSettings.DestArea.d_max.Y = ypos + imgSz.Height; for (uint row = 0; row < vertTiles; ++row) { renderSettings.DestArea.d_min.X = xpos; renderSettings.DestArea.d_max.X = xpos + imgSz.Width; for (uint col = 0; col < horzTiles; ++col) { // use custom clipping for right and bottom edges when tiling the imagery if (((vertFmt == VerticalFormatting.Tiled) && row == vertTiles - 1) || ((horzFmt == HorizontalFormatting.Tiled) && col == horzTiles - 1)) { renderSettings.ClipArea = clipper.HasValue ? clipper.Value.GetIntersection(destRect) : destRect; } else { // not tiling, or not on far edges, just used passed in clipper (if any). renderSettings.ClipArea = clipper; } geomBuffers.AddRange(image.CreateRenderGeometry(renderSettings)); renderSettings.DestArea.d_min.X += imgSz.Width; renderSettings.DestArea.d_max.X += imgSz.Width; } renderSettings.DestArea.d_min.Y += imgSz.Height; renderSettings.DestArea.d_max.Y += imgSz.Height; } return(geomBuffers); }