Ejemplo n.º 1
0
        /// <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="baseRect">
        /// Rect 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, Rectf baseRect, 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, baseRect, finalColours, clipper, clipToDisplay);
            }
            catch (Exception)
            {
                // do nothing here, errors are non-faltal and are logged for debugging purposes.
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="colours"></param>
 public ColourRect(ColourRect colours)
 {
     d_top_left     = colours.d_top_left;
     d_top_right    = colours.d_top_right;
     d_bottom_left  = colours.d_bottom_left;
     d_bottom_right = colours.d_bottom_right;
 }
Ejemplo n.º 3
0
        /// <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);
            }
        }
 public RenderedStringTextComponent(string text, Font font)
 {
     d_text            = text;
     d_font            = font;
     d_colours         = new ColourRect(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
     d_selectionStart  = 0;
     d_selectionLength = 0;
 }
Ejemplo n.º 5
0
        /*!
        \brief
            Constructor

        \param owner
            String holding the name of the WidgetLookFeel object that contains the target section.

        \param sectionName
            String holding the name of the target section.

        \param controlPropertySource
            String holding the name of a property that will control whether
            rendering for this secion will actually occur or not.

        \param controlPropertyValue
            String holding the value to be tested for from the property named in
            controlPropertySource.  If this is empty, then controlPropertySource
            will be accessed as a boolean property, otherwise rendering will
            only occur when the value returned via controlPropertySource matches
            the value specified here.

        \param controlPropertyWidget
            String holding either a child widget name or the special value of
            '__parent__' indicating the window upon which the property named
            in controlPropertySource should be accessed.  If this is empty then
            the window itself is used as the source, rather than a child or the
            parent.

        \param cols
            Override colours to be used (modulates sections master colours).
        */
        public SectionSpecification(string owner, string sectionName,
                                string controlPropertySource,
                                string controlPropertyValue,
                                string controlPropertyWidget,
                                ColourRect cols)
        {
            throw new NotImplementedException();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Render this layer.
 /// </summary>
 /// <param name="srcWindow">
 /// Window to use when calculating pixel values from BaseDim values.
 /// </param>
 /// <param name="baseRect">
 /// Rect 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, Rectf baseRect, ColourRect modcols = null, Rectf?clipper = null, bool clipToDisplay = false)
 {
     // render all sections in this layer
     foreach (var curr in d_sections)
     {
         curr.Render(srcWindow, baseRect, modcols, clipper, clipToDisplay);
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Render imagery for this state.
 /// </summary>
 /// <param name="srcWindow">
 /// Window to use when convering BaseDim values to pixels.
 /// </param>
 /// <param name="baseRect">
 /// Rect to use when convering BaseDim values to pixels.
 /// </param>
 /// <param name="modcols"></param>
 /// <param name="clipper"></param>
 public void Render(Window srcWindow, Rectf baseRect, ColourRect modcols = null, Rectf?clipper = null)
 {
     // render all layers defined for this state
     foreach (var curr in d_layers)
     {
         curr.Render(srcWindow, baseRect, modcols, clipper, d_clipToDisplay);
     }
 }
 //! initialise the default state
 private void InitialiseDefaultState()
 {
     d_padding         = Rectf.Zero;
     d_colours         = new ColourRect(d_initialColours);
     d_fontName        = d_initialFontName;
     d_imageSize.Width = d_imageSize.Height = 0.0f;
     d_vertAlignment   = VerticalFormatting.BottomAligned;
     d_aspectLock      = false;
 }
Ejemplo n.º 9
0
 public ImageRenderSettings(Rectf destArea, Rectf?clipArea, bool isClippingEnabled,
                            ColourRect multiplicationColours, float alpha)
 {
     DestArea          = destArea;
     ClipArea          = clipArea;
     IsClippingEnabled = isClippingEnabled;
     MultiplyColours   = multiplicationColours;
     this.Alpha        = alpha;
 }
        /// <summary>
        /// Constructor.
        /// </summary>
        public BasicRenderedStringParser()
        {
            d_initialColours = new ColourRect();
            d_vertAlignment  = VerticalFormatting.BottomAligned;
            d_imageSize      = Sizef.Zero;
            d_aspectLock     = false;
            d_initialised    = false;

            InitialiseDefaultState();
        }
Ejemplo n.º 11
0
        // TODO: virtual ~FalagardComponentBase();

        /// <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="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, ColourRect modColours = null, Rectf?clipper = null, bool clipToDisplay = false)
        {
            var destRect = d_area.GetPixelRect(srcWindow);

            if (!clipper.HasValue)
            {
                clipper = destRect;
            }

            var finalClipRect = destRect.GetIntersection(clipper.Value);

            AddImageRenderGeometryToWindowImpl(srcWindow, destRect, modColours, finalClipRect, clipToDisplay);
        }
Ejemplo n.º 12
0
        /// <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));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Helper method to initialise a ColourRect with appropriate values according to the way the
 /// ImagerySection is set up.
 ///
 /// This will try and get values from multiple places:
 ///     - a property attached to \a wnd
 ///     - or the integral d_masterColours value.
 /// </summary>
 /// <param name="wnd"></param>
 /// <param name="cr"></param>
 protected void InitMasterColourRect(Window wnd, out ColourRect cr)
 {
     // if colours come via a colour property
     if (!String.IsNullOrEmpty(d_colourPropertyName))
     {
         // if property accesses a ColourRect or a colour
         cr = wnd.GetProperty <ColourRect>(d_colourPropertyName);
     }
     // use explicit ColourRect.
     else
     {
         cr = d_masterColours;
     }
 }
Ejemplo n.º 14
0
        private void CreateTexturedQuadVertices(TexturedColouredVertex[] vbuffer, ColourRect colours, ref Rectf finalRect, ref Rectf texRect)
        {
            // vertex 0
            vbuffer[0].Position = new Lunatics.Mathematics.Vector3(finalRect.Left, finalRect.Top, 0.0f);
            vbuffer[0].SetColour(colours.d_top_left);
            vbuffer[0].TextureCoordinates = new Lunatics.Mathematics.Vector2(texRect.Left, texRect.Top);

            // vertex 1
            vbuffer[1].Position = new Lunatics.Mathematics.Vector3(finalRect.Left, finalRect.Bottom, 0.0f);
            vbuffer[1].SetColour(colours.d_bottom_left);
            vbuffer[1].TextureCoordinates = new Lunatics.Mathematics.Vector2(texRect.Left, texRect.Bottom);

            // vertex 2
            vbuffer[2].Position.X = finalRect.Right;
            vbuffer[2].Position.Z = 0.0f;
            vbuffer[2].SetColour(colours.d_bottom_right);
            vbuffer[2].TextureCoordinates.X = texRect.Right;

            // Quad splitting done from top-left to bottom-right diagonal
            vbuffer[2].Position.Y           = finalRect.Bottom;
            vbuffer[2].TextureCoordinates.Y = texRect.Bottom;

            // vertex 3
            vbuffer[3].Position = new Lunatics.Mathematics.Vector3(finalRect.Right, finalRect.Top, 0.0f);
            vbuffer[3].SetColour(colours.d_top_right);
            vbuffer[3].TextureCoordinates = new Lunatics.Mathematics.Vector2(texRect.Right, texRect.Top);

            // vertex 4
            vbuffer[4].Position.X = finalRect.Left;
            vbuffer[4].Position.Z = 0.0f;
            vbuffer[4].SetColour(colours.d_top_left);
            vbuffer[4].TextureCoordinates.X = texRect.Left;

            // Quad splitting done from top-left to bottom-right diagonal
            vbuffer[4].Position.Y           = finalRect.Top;
            vbuffer[4].TextureCoordinates.Y = texRect.Top;

            // vertex 5
            vbuffer[5].Position = new Lunatics.Mathematics.Vector3(finalRect.Right, finalRect.Bottom, 0.0f);
            vbuffer[5].SetColour(colours.d_bottom_right);
            vbuffer[5].TextureCoordinates = new Lunatics.Mathematics.Vector2(texRect.Right, texRect.Bottom);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Helper method to initialise a ColourRect with appropriate values according to the way the
 /// section sepcification is set up.
 /// 
 /// This will try and get values from multiple places:
 ///     - a property attached to \a wnd
 ///     - the integral d_coloursOverride values.
 ///     - or default to colour(1,1,1,1);
 /// </summary>
 /// <param name="wnd"></param>
 /// <param name="cr"></param>
 protected void InitColourRectForOverride(Window wnd, ref ColourRect cr)
 {
     // if no override set
     if (!d_usingColourOverride)
     {
         var val = new Colour(1, 1, 1, 1);
         cr.d_top_left = val;
         cr.d_top_right = val;
         cr.d_bottom_left = val;
         cr.d_bottom_right = val;
     }
     // if override comes via a colour property
     else if (!String.IsNullOrEmpty(d_colourPropertyName))
     {
         // if property accesses a ColourRect or a colour
         cr = wnd.GetProperty<ColourRect>(d_colourPropertyName);
     }
         // override is an explicitly defined ColourRect.
     else
     {
         cr = d_coloursOverride;
     }
 }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Set the master colours to be used for this ImagerySection.
 /// </summary>
 /// <param name="cols">
 /// ColourRect describing the colours to be set as the master colours for this ImagerySection.
 /// </param>
 public void SetMasterColours(ColourRect cols)
 {
     d_masterColours = cols;
 }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        /// <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);
        }
 /// <summary>
 /// Set the colour values used when rendering this component.
 /// </summary>
 /// <param name="cr"></param>
 public void SetColours(ColourRect cr)
 {
     d_colours = cr;
 }
Ejemplo n.º 21
0
        // 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;
            }
        }
Ejemplo n.º 22
0
        // 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 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));
        }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
        // TODO: ???
        ///// <summary>
        ///// Constructor.
        ///// </summary>
        //public ImagerySection()
        //    : this(String.Empty)
        //{

        //}

        /*!
         * \brief
         *
         *
         * \param name
         *
         */

        /// <summary>
        /// ImagerySection constructor.  Name must be supplied, masterColours are set to 0xFFFFFFFF by default.
        /// </summary>
        /// <param name="name">
        /// Name of the new ImagerySection.
        /// </param>
        public ImagerySection(string name)
        {
            d_name          = name;
            d_masterColours = new ColourRect(new Colour(0xFFFFFFFF));
        }
Ejemplo n.º 26
0
        static PropertyHelper()
        {
            RegisterFunction <Boolean>(
                x => Boolean.Parse(x),
                x => ((Boolean)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Byte>(
                x => Byte.Parse(x, CultureInfo.InvariantCulture),
                x => ((Byte)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Int16>(
                x => Int16.Parse(x, CultureInfo.InvariantCulture),
                x => ((Int16)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Int32>(
                x => Int32.Parse(x, CultureInfo.InvariantCulture),
                x => ((Int32)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Int64>(
                x => Int64.Parse(x, CultureInfo.InvariantCulture),
                x => ((Int64)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <UInt16>(
                x => UInt16.Parse(x, CultureInfo.InvariantCulture),
                x => ((UInt16)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <UInt32>(
                x => UInt32.Parse(x, CultureInfo.InvariantCulture),
                x => ((UInt32)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <UInt64>(
                x => UInt64.Parse(x, CultureInfo.InvariantCulture),
                x => ((UInt64)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Char>(
                x => Char.Parse(x),
                x => ((Char)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Single>(
                x => String.IsNullOrEmpty(x) ? 0f : Single.Parse(x, CultureInfo.InvariantCulture),
                x => ((Single)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <Double>(
                x => Double.Parse(x, CultureInfo.InvariantCulture),
                x => ((Double)x).ToString(CultureInfo.InvariantCulture));

            RegisterFunction <String>(
                x => x,
                x => (string)x);

            RegisterFunction <Colour>(
                x => Colour.Parse(x),
                x => ((Colour)x).ToString());

            RegisterFunction <ColourRect>(
                x => ColourRect.Parse(x, CultureInfo.InvariantCulture),
                x => x.ToString());

            RegisterFunction <Sizef>(
                x => Sizef.Parse(x, CultureInfo.InvariantCulture),
                x => ((Sizef)x).ToString());

            RegisterFunction <Lunatics.Mathematics.Vector3>(
                x => MathematicsEx.Vector3Parse(x, CultureInfo.InvariantCulture),
                x => MathematicsEx.ToString((Lunatics.Mathematics.Vector3)x));

            RegisterFunction <Rectf>(
                x => Rectf.Parse(x, CultureInfo.InvariantCulture),
                x => ((Rectf)x).ToString());

            RegisterFunction <Lunatics.Mathematics.Quaternion>(
                x => MathematicsEx.QuaternionParse(x, CultureInfo.InvariantCulture),
                x => MathematicsEx.ToString((Lunatics.Mathematics.Quaternion)x));

            RegisterFunction <UDim>(
                x => UDim.Parse(x, CultureInfo.InvariantCulture),
                x => ((UDim)x).ToString());

            RegisterFunction <UVector2>(
                x => UVector2.Parse(x, CultureInfo.InvariantCulture),
                x => ((UVector2)x).ToString());

            RegisterFunction <USize>(
                x => USize.Parse(x, CultureInfo.InvariantCulture),
                x => ((USize)x).ToString());

            RegisterFunction <URect>(
                x => URect.Parse(x, CultureInfo.InvariantCulture),
                x => ((URect)x).ToString());

            RegisterFunction <UBox>(
                x => UBox.Parse(x, CultureInfo.InvariantCulture),
                x => ((UBox)x).ToString());

            RegisterFunction <Image>(
                x => String.IsNullOrEmpty(x) ? null : ImageManager.GetSingleton().Get(x),
                x => x != null ? ((Image)x).GetName() : String.Empty);

            RegisterFunction <Font>(
                x => String.IsNullOrEmpty(x) ? null : FontManager.GetSingleton().Get(x),
                x => x != null ? ((Font)x).GetName() : String.Empty);

            RegisterFunction <FontMetricType>(
                x => (FontMetricType)Enum.Parse(typeof(FontMetricType), x, true),
                x => ((FontMetricType)x).ToString());

            RegisterFunction <AspectMode>(
                x => (AspectMode)Enum.Parse(typeof(AspectMode), x, true),
                x => ((AspectMode)x).ToString());

            RegisterFunction <HorizontalAlignment>(
                x =>
            {
                HorizontalAlignment value;
                if (!Enum.TryParse(x, true, out value))
                {
                    switch (x.ToLowerInvariant())
                    {
                    case "leftaligned":
                        return(HorizontalAlignment.Left);

                    case "centrealigned":
                        return(HorizontalAlignment.Centre);

                    case "rightaligned":
                        return(HorizontalAlignment.Right);
                    }
                }

                return(value);
            },
                x => ((HorizontalAlignment)x).ToString());

            RegisterFunction <VerticalAlignment>(
                x =>
            {
                VerticalAlignment value;
                if (!Enum.TryParse(x, true, out value))
                {
                    switch (x.ToLowerInvariant())
                    {
                    case "topaligned":
                        return(VerticalAlignment.Top);

                    case "centrealigned":
                        return(VerticalAlignment.Centre);

                    case "bottomaligned":
                        return(VerticalAlignment.Bottom);
                    }
                }

                return(value);
            },
                x => ((VerticalAlignment)x).ToString());

            RegisterFunction <VerticalTextFormatting>(
                x => (VerticalTextFormatting)Enum.Parse(typeof(VerticalTextFormatting), x, true),
                x => ((VerticalTextFormatting)x).ToString());

            RegisterFunction <HorizontalTextFormatting>(
                x => (HorizontalTextFormatting)Enum.Parse(typeof(HorizontalTextFormatting), x, true),
                x => ((HorizontalTextFormatting)x).ToString());

            RegisterFunction <AutoScaledMode>(
                x =>
            {
                AutoScaledMode value;
                if (!Enum.TryParse(x, true, out value))
                {
                    if (x.ToLowerInvariant() == "false")
                    {
                        return(AutoScaledMode.Disabled);
                    }
                }
                return(value);
            },
                x => ((AutoScaledMode)x).ToString());

            RegisterFunction <VerticalFormatting>(
                x => (VerticalFormatting)Enum.Parse(typeof(VerticalFormatting), x, true),
                x => ((VerticalFormatting)x).ToString());

            RegisterFunction <HorizontalFormatting>(
                x => (HorizontalFormatting)Enum.Parse(typeof(HorizontalFormatting), x, true),
                x => ((HorizontalFormatting)x).ToString());

            RegisterFunction <FrameImageComponent>(
                x => (FrameImageComponent)Enum.Parse(typeof(FrameImageComponent), x, true),
                x => ((FrameImageComponent)x).ToString());

            RegisterFunction <DimensionType>(
                x => (DimensionType)Enum.Parse(typeof(DimensionType), x, true),
                x => ((DimensionType)x).ToString());

            RegisterFunction <DimensionOperator>(
                x => (DimensionOperator)Enum.Parse(typeof(DimensionOperator), x, true),
                x => ((DimensionOperator)x).ToString());

            RegisterFunction <WindowUpdateMode>(
                x => (WindowUpdateMode)Enum.Parse(typeof(WindowUpdateMode), x, true),
                x => ((WindowUpdateMode)x).ToString());

            RegisterFunction <ScrollbarDisplayMode>(
                x => (ScrollbarDisplayMode)Enum.Parse(typeof(ScrollbarDisplayMode), x, true),
                x => ((ScrollbarDisplayMode)x).ToString());

            RegisterFunction <ViewSortMode>(
                x => (ViewSortMode)Enum.Parse(typeof(ViewSortMode), x, true),
                x => ((ViewSortMode)x).ToString());

            RegisterFunction <Tuple <float, float> >(
                x => { throw new NotImplementedException(); },
                x => String.Format("min:{0} max:{1}", ((Tuple <float, float>)x).Item1, ((Tuple <float, float>)x).Item1));

            #region Types from Widgets

            RegisterFunction <ListHeaderSegment.SortDirection>(
                x => (ListHeaderSegment.SortDirection)Enum.Parse(typeof(ListHeaderSegment.SortDirection), x, true),
                x => ((ListHeaderSegment.SortDirection)x).ToString());

            RegisterFunction <MultiColumnList.SelectionMode>(
                x => (MultiColumnList.SelectionMode)Enum.Parse(typeof(MultiColumnList.SelectionMode), x, true),
                x => ((MultiColumnList.SelectionMode)x).ToString());

            RegisterFunction <ItemListBase.SortMode>(
                x => (ItemListBase.SortMode)Enum.Parse(typeof(ItemListBase.SortMode), x, true),
                x => ((ItemListBase.SortMode)x).ToString());

            RegisterFunction <Spinner.TextInputMode>(
                x => (Spinner.TextInputMode)Enum.Parse(typeof(Spinner.TextInputMode), x, true),
                x => ((Spinner.TextInputMode)x).ToString());

            RegisterFunction <GridLayoutContainer.AutoPositioning>(
                x => (GridLayoutContainer.AutoPositioning)Enum.Parse(typeof(GridLayoutContainer.AutoPositioning), x, true),
                x => ((GridLayoutContainer.AutoPositioning)x).ToString());

            #endregion
        }
Ejemplo n.º 27
0
        // 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);
        }
Ejemplo n.º 28
0
 /// <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);
Ejemplo n.º 29
0
 public ImageRenderSettings(Rectf destArea, Rectf?clipArea, bool isClippingEnabled,
                            ColourRect multiplicationColours)
     : this(destArea, clipArea, isClippingEnabled, multiplicationColours, 1f)
 {
 }
 /// <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);