当前位置: 首页>>代码示例>>C#>>正文


C# RenderState.NextElement方法代码示例

本文整理汇总了C#中RenderState.NextElement方法的典型用法代码示例。如果您正苦于以下问题:C# RenderState.NextElement方法的具体用法?C# RenderState.NextElement怎么用?C# RenderState.NextElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RenderState的用法示例。


在下文中一共展示了RenderState.NextElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateVertexCache

        private void ValidateVertexCache()
        {
            if (this.vertTextCache != null &&
                this.vertIconsCache != null &&
                this.vertCountCache != null &&
                this.metricsCache != null &&
                !this.updateVertexCache)
            {
                // No need to update.
                return;
            }
            this.updateVertexCache = false;

            int fontNum = this.fonts != null ? this.fonts.Length : 0;

            // Setting up buffers
            {
                int countCacheLen = 1 + fontNum;
                if (this.vertCountCache == null || this.vertCountCache.Length != countCacheLen)
                    this.vertCountCache = new int[countCacheLen];

                int iconVertCount = this.iconCount * 4;
                if (this.vertIconsCache == null || this.vertIconsCache.Length < iconVertCount)
                    this.vertIconsCache = new VertexC1P3T2[iconVertCount];
                this.vertCountCache[0] = iconVertCount;

                if (this.vertTextCache == null || this.vertTextCache.Length != fontNum)
                    this.vertTextCache = new VertexC1P3T2[fontNum][];
                for (int i = 0; i < this.vertTextCache.Length; i++)
                {
                    int textVertCount = this.fontGlyphCount.Length > i ? this.fontGlyphCount[i] * 4 : 0;
                    this.vertCountCache[i + 1] = textVertCount;
                    if (this.vertTextCache[i] == null || this.vertTextCache[i].Length < textVertCount)
                        this.vertTextCache[i] = new VertexC1P3T2[textVertCount];
                }
            }

            // Rendering
            {
                RenderState state = new RenderState(this);
                Element elem;
                int[] vertTextLen = new int[fontNum];
                int vertIconLen = 0;
                while ((elem = state.NextElement()) != null)
                {
                    if (elem is TextElement && state.Font != null)
                    {
                        TextElement textElem = elem as TextElement;
                        VertexC1P3T2[] textElemVert = null;
                        int count = state.Font.EmitTextVertices(
                            state.CurrentElemText,
                            ref textElemVert,
                            state.CurrentElemOffset.X,
                            state.CurrentElemOffset.Y + state.LineBaseLine - state.Font.BaseLine,
                            state.Color);
                        Array.Copy(textElemVert, 0, this.vertTextCache[state.FontIndex], state.CurrentElemTextVertexIndex, count);
                        vertTextLen[state.FontIndex] = state.CurrentElemTextVertexIndex + count;
                    }
                    else if (elem is IconElement)
                    {
                        IconElement iconElem = elem as IconElement;
                        Icon icon = iconElem.IconIndex >= 0 && iconElem.IconIndex < this.icons.Length ? this.icons[iconElem.IconIndex] : new Icon();
                        Vector2 iconOffset = icon.offset;
                        Vector2 iconSize = icon.size;
                        Rect iconUvRect = icon.uvRect;

                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Pos.X = state.CurrentElemOffset.X + iconOffset.X;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine - iconSize.Y + iconOffset.Y;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Pos.Z = 0;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Color = state.Color;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].TexCoord = iconUvRect.TopLeft;

                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Pos.X = state.CurrentElemOffset.X + iconSize.X + iconOffset.X;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine - iconSize.Y + iconOffset.Y;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Pos.Z = 0;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Color = state.Color;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].TexCoord = iconUvRect.TopRight;

                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Pos.X = state.CurrentElemOffset.X + iconSize.X + iconOffset.X;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine + iconOffset.Y;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Pos.Z = 0;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Color = state.Color;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].TexCoord = iconUvRect.BottomRight;

                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Pos.X = state.CurrentElemOffset.X + iconOffset.X;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine + iconOffset.Y;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Pos.Z = 0;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Color = state.Color;
                        this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].TexCoord = iconUvRect.BottomLeft;

                        vertIconLen = state.CurrentElemIconVertexIndex + 4;
                    }
                }

                this.vertCountCache[0] = vertIconLen;
                for (int i = 0; i < fontNum; i++)
                    this.vertCountCache[i + 1] = vertTextLen[i];
            }

            // Updating the metrics cache
//.........这里部分代码省略.........
开发者ID:ninja2003,项目名称:duality,代码行数:101,代码来源:FormattedText.cs

示例2: RenderToBitmap

        /// <summary>
        /// Renders a text to the specified target Image.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="target"></param>
        public void RenderToBitmap(string text, PixelData target, float x = 0.0f, float y = 0.0f, PixelData icons = null)
        {
            // Rendering
            int fontNum = this.fonts != null ? this.fonts.Length : 0;
            RenderState state = new RenderState(this);
            Element elem;
            while ((elem = state.NextElement()) != null)
            {
                if (elem is TextElement && state.Font != null)
                {
                    TextElement textElem = elem as TextElement;
                    state.Font.RenderToBitmap(
                        state.CurrentElemText,
                        target,
                        x + state.CurrentElemOffset.X,
                        y + state.CurrentElemOffset.Y + state.LineBaseLine - state.Font.BaseLine,
                        state.Color);
                }
                else if (elem is IconElement)
                {
                    IconElement iconElem = elem as IconElement;
                    Icon icon = iconElem.IconIndex >= 0 && iconElem.IconIndex < this.icons.Length ? this.icons[iconElem.IconIndex] : new Icon();
                    Vector2 iconSize = icon.size;
                    Vector2 iconOffset = icon.offset;
                    Rect iconUvRect = icon.uvRect;
                    Vector2 dataCoord = iconUvRect.Pos * new Vector2(icons.Width, icons.Height);
                    Vector2 dataSize = iconUvRect.Size * new Vector2(icons.Width, icons.Height);

                    PixelData iconLayer = icons.CloneSubImage(
                        MathF.RoundToInt(dataCoord.X),
                        MathF.RoundToInt(dataCoord.Y),
                        MathF.RoundToInt(dataSize.X),
                        MathF.RoundToInt(dataSize.Y));
                    iconLayer.Rescale(
                        MathF.RoundToInt(iconSize.X),
                        MathF.RoundToInt(iconSize.Y));
                    iconLayer.DrawOnto(target,
                        BlendMode.Alpha,
                        MathF.RoundToInt(x + state.CurrentElemOffset.X + iconOffset.X),
                        MathF.RoundToInt(y + state.CurrentElemOffset.Y + state.LineBaseLine - iconSize.Y + iconOffset.Y),
                        iconLayer.Width,
                        iconLayer.Height,
                        0,
                        0,
                        state.Color);

                }
            }
        }
开发者ID:ninja2003,项目名称:duality,代码行数:54,代码来源:FormattedText.cs

示例3: Measure

		/// <summary>
		/// Measures the formatted text block.
		/// </summary>
		/// <returns>A <see cref="Metrics"/> object that describes this FormattedText.</returns>
		public Metrics Measure()
		{
			Vector2 size = Vector2.Zero;
			List<Rect> lineBounds = new List<Rect>();
			List<Rect> elementBounds = new List<Rect>();

			RenderState state = new RenderState(this);
			Element elem;
			Vector2 elemSize;
			Vector2 elemOffset;
			int lastElemIndex = -1;
			int lastLineIndex = 0;
			bool elemIndexChanged = true;
			bool lineChanged = true;
			bool hasBounds;
			while ((elem = state.NextElement()) != null)
			{
				if (elem is TextElement && state.Font != null)
				{
					TextElement textElem = elem as TextElement;
					elemSize = state.Font.MeasureText(state.CurrentElemText);
					elemOffset = new Vector2(state.CurrentElemOffset.X, state.CurrentElemOffset.Y/* + state.LineBaseLine - state.Font.Ascent*/);
					//if (elemSize.Y != 0.0f) elemSize.Y -= state.LineBaseLine - state.Font.Ascent;
				}
				else if (elem is IconElement && this.icons != null)
				{
					IconElement iconElem = elem as IconElement;
					bool iconValid = iconElem.IconIndex > 0 && iconElem.IconIndex < this.icons.Length;
					elemSize = iconValid ? this.icons[iconElem.IconIndex].size : Vector2.Zero;
					elemOffset = new Vector2(state.CurrentElemOffset.X, state.CurrentElemOffset.Y/* + state.LineBaseLine - elemSize.Y*/);
					//if (elemSize.Y != 0.0f) elemSize.Y -= state.LineBaseLine - elemSize.Y;
				}
				else
				{
					elemSize = Vector2.Zero;
					elemOffset = Vector2.Zero;
				}
				hasBounds = elemSize != Vector2.Zero;

				if (elemIndexChanged) elementBounds.Add(Rect.Empty);
				if (hasBounds && elementBounds[elementBounds.Count - 1] == Rect.Empty)
					elementBounds[elementBounds.Count - 1] = new Rect(elemOffset.X, elemOffset.Y, elemSize.X, elemSize.Y);
				else if (hasBounds)
					elementBounds[elementBounds.Count - 1] = elementBounds[elementBounds.Count - 1].ExpandToContain(elemOffset.X, elemOffset.Y, elemSize.X, elemSize.Y);
				
				if (lineChanged) lineBounds.Add(Rect.Empty);
				if (hasBounds && lineBounds[lineBounds.Count - 1] == Rect.Empty)
					lineBounds[lineBounds.Count - 1] = new Rect(elemOffset.X, elemOffset.Y, elemSize.X, elemSize.Y);
				else if (hasBounds)
					lineBounds[lineBounds.Count - 1] = lineBounds[lineBounds.Count - 1].ExpandToContain(elemOffset.X, elemOffset.Y, elemSize.X, elemSize.Y);

				size.X = Math.Max(size.X, elemOffset.X + elemSize.X);
				size.Y = Math.Max(size.Y, elemOffset.Y + elemSize.Y);

				elemIndexChanged = lastElemIndex != state.CurrentElemIndex;
				lineChanged = lastLineIndex != state.CurrentLineIndex;
				lastElemIndex = state.CurrentElemIndex;
				lastLineIndex = state.CurrentLineIndex;
			}

			return new Metrics(size, lineBounds, elementBounds);
		}
开发者ID:Terracorrupt,项目名称:duality,代码行数:66,代码来源:FormattedText.cs

示例4: RenderToBitmap

        /// <summary>
        /// Renders a text to the specified target Image.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="target"></param>
        public void RenderToBitmap(string text, System.Drawing.Image target, float x = 0.0f, float y = 0.0f, System.Drawing.Image icons = null)
        {
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(target))
            {
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                // Rendering
                int fontNum = this.fonts != null ? this.fonts.Length : 0;
                RenderState state = new RenderState(this);
                Element elem;
                while ((elem = state.NextElement()) != null)
                {
                    if (elem is TextElement && state.Font != null)
                    {
                        TextElement textElem = elem as TextElement;
                        state.Font.RenderToBitmap(
                            state.CurrentElemText,
                            target,
                            x + state.CurrentElemOffset.X,
                            y + state.CurrentElemOffset.Y + state.LineBaseLine - state.Font.BaseLine,
                            state.Color);
                    }
                    else if (elem is IconElement)
                    {
                        IconElement iconElem = elem as IconElement;
                        Icon icon = iconElem.IconIndex >= 0 && iconElem.IconIndex < this.icons.Length ? this.icons[iconElem.IconIndex] : new Icon();
                        Vector2 iconSize = icon.size;
                        Vector2 iconOffset = icon.offset;
                        Rect iconUvRect = icon.uvRect;
                        Vector2 dataCoord = iconUvRect.Pos * new Vector2(icons.Width, icons.Height);
                        Vector2 dataSize = iconUvRect.Size * new Vector2(icons.Width, icons.Height);

                        var attrib = new System.Drawing.Imaging.ImageAttributes();
                        attrib.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(new[] {
                            new[] {state.Color.R / 255.0f, 0, 0, 0},
                            new[] {0, state.Color.G / 255.0f, 0, 0},
                            new[] {0, 0, state.Color.B / 255.0f, 0},
                            new[] {0, 0, 0, state.Color.A / 255.0f} }));
                        g.DrawImage(icons,
                            new System.Drawing.Rectangle(
                                MathF.RoundToInt(x + state.CurrentElemOffset.X + iconOffset.X),
                                MathF.RoundToInt(y + state.CurrentElemOffset.Y + state.LineBaseLine - iconSize.Y + iconOffset.Y),
                                MathF.RoundToInt(iconSize.X),
                                MathF.RoundToInt(iconSize.Y)),
                            dataCoord.X, dataCoord.Y, dataSize.X, dataSize.Y,
                            System.Drawing.GraphicsUnit.Pixel,
                            attrib);
                    }
                }
            }
        }
开发者ID:gitMaxim,项目名称:duality,代码行数:57,代码来源:FormattedText.cs

示例5: ValidateVertexCache

		private void ValidateVertexCache()
		{
			if (this.vertTextCache != null && this.vertIconsCache != null && !this.updateVertexCache) return;
			this.updateVertexCache = false;

			int fontNum = this.fonts != null ? this.fonts.Length : 0;

			// Setting up vertex buffers
			if (this.vertIconsCache == null || this.vertIconsCache.Length != this.iconCount * 4)
				this.vertIconsCache = new VertexC1P3T2[this.iconCount * 4];
			if (this.vertTextCache == null || this.vertTextCache.Length != fontNum) 
				this.vertTextCache = new VertexC1P3T2[fontNum][];
			for (int i = 0; i < this.vertTextCache.Length; i++)
				if (this.vertTextCache[i] == null || this.vertTextCache[i].Length != (this.fontGlyphCount.Length > i ? this.fontGlyphCount[i] * 4 : 0)) 
					this.vertTextCache[i] = new VertexC1P3T2[this.fontGlyphCount.Length > i ? this.fontGlyphCount[i] * 4 : 0];

			// Rendering
			RenderState state = new RenderState(this);
			Element elem;
			int[] vertTextLen = new int[fontNum];
			int vertIconLen = 0;
			while ((elem = state.NextElement()) != null)
			{
				if (elem is TextElement && state.Font != null)
				{
					TextElement textElem = elem as TextElement;
					VertexC1P3T2[] textElemVert = null;
					state.Font.EmitTextVertices(
						state.CurrentElemText, 
						ref textElemVert, 
						state.CurrentElemOffset.X, 
						state.CurrentElemOffset.Y + state.LineBaseLine - state.Font.BaseLine, 
						state.Color);
					Array.Copy(textElemVert, 0, this.vertTextCache[state.FontIndex], state.CurrentElemTextVertexIndex, textElemVert.Length);
					vertTextLen[state.FontIndex] = state.CurrentElemTextVertexIndex + textElemVert.Length;
				}
				else if (elem is IconElement)
				{
					IconElement iconElem = elem as IconElement;
					Icon icon = iconElem.IconIndex >= 0 && iconElem.IconIndex < this.icons.Length ? this.icons[iconElem.IconIndex] : new Icon();
					Vector2 iconSize = icon.size;
					Rect iconUvRect = icon.uvRect;

					this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Pos.X = state.CurrentElemOffset.X;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine - iconSize.Y;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Pos.Z = 0;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Color = state.Color;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].TexCoord = iconUvRect.TopLeft;

					this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Pos.X = state.CurrentElemOffset.X + iconSize.X;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine - iconSize.Y;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Pos.Z = 0;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Color = state.Color;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].TexCoord = iconUvRect.TopRight;

					this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Pos.X = state.CurrentElemOffset.X + iconSize.X;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Pos.Z = 0;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Color = state.Color;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].TexCoord = iconUvRect.BottomRight;

					this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Pos.X = state.CurrentElemOffset.X;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Pos.Z = 0;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Color = state.Color;
					this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].TexCoord = iconUvRect.BottomLeft;

					vertIconLen = state.CurrentElemIconVertexIndex + 4;
				}
			}

			for (int i = 0; i < fontNum; i++)
			{
				if (this.vertTextCache[i].Length > vertTextLen[i])
					Array.Resize(ref this.vertTextCache[i], vertTextLen[i]);
			}
			if (this.vertIconsCache.Length > vertIconLen)
				Array.Resize(ref this.vertIconsCache, vertIconLen);
		}
开发者ID:Terracorrupt,项目名称:duality,代码行数:79,代码来源:FormattedText.cs


注:本文中的RenderState.NextElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。