/// <summary> /// Init this widget. /// </summary> public override void Initialize() { base.Initialize(); TextureAtlas imageset = AtlasManager.Instance.GetTextureAtlas(ImagesetName); topLeft = imageset.GetTextureInfo(TopLeftFrameImageName); topRight = imageset.GetTextureInfo(TopRightFrameImageName); bottomLeft = imageset.GetTextureInfo(BottomLeftFrameImageName); bottomRight = imageset.GetTextureInfo(BottomRightFrameImageName); left = imageset.GetTextureInfo(LeftFrameImageName); right = imageset.GetTextureInfo(RightFrameImageName); top = imageset.GetTextureInfo(TopFrameImageName); bottom = imageset.GetTextureInfo(BottomFrameImageName); background = imageset.GetTextureInfo(BackgroundImageName); colors = new ColorRect(ColorEx.White); // StoreFrameSizes(); }
protected override void DrawSelf(float z) { if (lines.Count == 0) { // add an empty line TextRange range = new TextRange(); range.start = 0; range.end = 0; lines.Add(range); } base.DrawSelf(z); Rect clipRect = this.PixelRect; // Draw the caret PointF pt = GetOffset(caretIndex); Vector3 drawPos = new Vector3(pt.X, pt.Y, z); float zOffset = (int)frameStrata * GuiZFrameStrataStep + (int)layerLevel * GuiZLayerLevelStep + (int)frameLevel * GuiZFrameLevelStep; float maxOffset = (int)FrameStrata.Maximum * GuiZFrameStrataStep; float curOffset = maxOffset - zOffset; drawPos.z = drawPos.z + curOffset - (int)SubLevel.Caret * GuiZSubLevelStep; if (drawPos.x < clipRect.Left) { drawPos.x = clipRect.Left; } else if (drawPos.x + caret.Width > clipRect.Right) { drawPos.x = clipRect.Right - caret.Width; } SizeF caretSize = new SizeF(caret.Width, this.Font.LineSpacing); ColorRect caretColorRect = new ColorRect(ColorEx.White); caret.Draw(drawPos, caretSize, clipRect, caretColorRect); }
/// <summary> /// Init this widget. /// </summary> public override void Initialize() { base.Initialize(); colors = new ColorRect(ColorEx.WhiteSmoke); TextureAtlas atlas = AtlasManager.Instance.GetTextureAtlas(ImagesetName); topLeft = atlas.GetTextureInfo(TopLeftBubbleImageName); topRight = atlas.GetTextureInfo(TopRightBubbleImageName); bottomLeft = atlas.GetTextureInfo(BottomLeftBubbleImageName); bottomRight = atlas.GetTextureInfo(BottomRightBubbleImageName); left = atlas.GetTextureInfo(LeftBubbleImageName); right = atlas.GetTextureInfo(RightBubbleImageName); top = atlas.GetTextureInfo(TopBubbleImageName); bottom = atlas.GetTextureInfo(BottomBubbleImageName); background = atlas.GetTextureInfo(BackgroundImageName); bottomCenter = atlas.GetTextureInfo(TailBubbleImageName); textWidget.HorizontalFormat = HorizontalTextFormat.WordWrapCentered; textWidget.VerticalFormat = VerticalTextFormat.Bottom; textWidget.NormalTextStyle = new TextStyle(); textWidget.NormalTextStyle.textColor = ColorEx.Black; }
public void SetImageColors(ColorRect colors) { imageColors = colors; // RequestRedraw(); }
public void Draw(Vector3 pos, SizeF target, ColorRect colors) { this.Draw(pos, target, null, colors); }
public void DrawTextLine(string text, int offset, int count, Vector3 pos, Rect clip, ColorRect colors) { }
/// <summary> /// This is the basic method to draw text. /// It does not do word or line wrapping. /// </summary> /// <param name="text">the string to write</param> /// <param name="pos">the position to start the draw</param> /// <param name="clip">the rectangle used to clip the draw calls or null to avoid clipping</param> /// <param name="colors">the color to use for the text</param> public void DrawTextLine(string text, Vector3 pos, Rect clip, ColorRect colors) { DrawTextLine(text, 0, text.Length, pos, clip, colors); }
public static ColorRect ReadGradient(XmlNode node) { ColorEx minColor = new ColorEx(); ColorEx maxColor = new ColorEx(); bool minColorSet = false; bool maxColorSet = false; bool horizontal = true; if (node.Attributes["orientation"] != null && node.Attributes["orientation"].Value == "VERTICAL") horizontal = false; foreach (XmlNode childNode in node.ChildNodes) { switch (childNode.Name) { case "MinColor": minColor = ReadColor(childNode); minColorSet = true; break; case "MaxColor": maxColor = ReadColor(childNode); maxColorSet = true; break; default: break; } } Debug.Assert(minColorSet && maxColorSet, "Got Gradient node without MinColor and MaxColor child"); ColorRect rv = new ColorRect(); if (horizontal) { rv.TopLeft = minColor; rv.TopRight = maxColor; rv.BottomLeft = minColor; rv.BottomRight = maxColor; } else { rv.TopLeft = minColor; rv.TopRight = minColor; rv.BottomLeft = maxColor; rv.BottomRight = maxColor; } return rv; }
/// <summary> /// This is a fairly basic method to draw text. /// It does not do word or line wrapping. /// </summary> /// <param name="text">the string to write</param> /// <param name="offset">number of characters from str that should be ignored</param> /// <param name="count">number of characters from text that should be considered</param> /// <param name="pos">the position to start the draw</param> /// <param name="clip">the rectangle used to clip the draw calls or null to avoid clipping</param> /// <param name="colors">the color to use for the text</param> public void DrawTextLine(string text, int offset, int count, Vector3 pos, Rect clip, ColorRect colors) { Vector3 currentPos = pos; for (int i = offset; i < offset + count; i++) { char c = text[i]; if (!IsCharacterAvailable(c)) { log.InfoFormat("Character '{0}' not present in font {1}", c, this.font); continue; } int glyphIndex = glyphMap[c]; TextureInfo glyphImage = glyphData[glyphIndex].TextureInfo; // log.DebugFormat("Drawing character {0} from texture atlas {1}", c, glyphImage.Atlas.Name); if (!leftToRight) currentPos.x -= glyphData[glyphIndex].HorizontalAdvance; glyphImage.Draw(currentPos, clip, colors); if (leftToRight) currentPos.x += glyphData[glyphIndex].HorizontalAdvance; } }
/// <summary> /// Draw text into a specified area of the display. /// </summary> /// <param name="text">The text to be drawn.</param> /// <param name="area"> /// Rect object describing the area of the display where the text is to be rendered. The text is not clipped to this Rect, but is formatted /// using this Rect depending upon the option specified in <paramref name="format"/>. /// </param> /// <param name="z">float value specifying the z co-ordinate for the drawn text.</param> /// <param name="clip">Rect object describing the clipping area for the drawing. No drawing will occur outside this Rect.</param> /// <param name="format">The text formatting required.</param> /// <param name="colors"> /// ColorRect object describing the colors to be applied when drawing the text. /// The colors specified in here are applied to each glyph, rather than the text as a whole. /// </param> /// <returns>The number of lines output. This does not consider clipping, so if all text was clipped, this would still return >=1.</returns> public int DrawText(string text, List<TextRange> lines, Rect area, float z, Rect clip, HorizontalTextFormat horzFormat, VerticalTextFormat vertFormat, ColorRect colors) { foreach (TextRange line in lines) { PointF offset = GetOffset(text, lines, line.start, horzFormat, vertFormat, area.Width, area.Height, leftToRight); DrawTextLine(text, line.start, line.Length, new Vector3(area.Left + offset.X, area.Top + offset.Y, z), clip, colors); } return lines.Count; }
/// <summary> /// Draw text into a specified area of the display. /// </summary> /// <param name="text">The text to be drawn.</param> /// <param name="area"> /// Rect object describing the area of the display where the text is to be rendered. The text is not clipped to this Rect, but is formatted /// using this Rect depending upon the option specified in <paramref name="format"/>. /// </param> /// <param name="z">float value specifying the z co-ordinate for the drawn text.</param> /// <param name="clip">Rect object describing the clipping area for the drawing. No drawing will occur outside this Rect.</param> /// <param name="format">The text formatting required.</param> /// <param name="colors"> /// ColorRect object describing the colors to be applied when drawing the text. /// The colors specified in here are applied to each glyph, rather than the text as a whole. /// </param> /// <returns>The number of lines output. This does not consider clipping, so if all text was clipped, this would still return >=1.</returns> public int DrawText(string text, Rect area, float z, Rect clip, HorizontalTextFormat horzFormat, VerticalTextFormat vertFormat, ColorRect colors) { List<TextRange> lines = GetLines(text, area.Width, horzFormat, false); return DrawText(text, lines, area, z, clip, horzFormat, vertFormat, colors); }
public ColorRect Clone() { ColorRect rv = new ColorRect(); rv.TopLeft = this.TopLeft; rv.TopRight = this.TopRight; rv.BottomLeft = this.BottomLeft; rv.BottomRight = this.BottomRight; return rv; }
public static bool CompareTo(ColorRect c1, ColorRect c2) { if (c1 == null && c2 == null) return true; if (c1 == null || c2 == null) return false; for (int i=0; i<4; i++) { ColorEx color1 = c1.colors[i]; ColorEx color2 = c2.colors[i]; if (color1 == null && color2 == null) continue; if (color1 == null || color2 == null) return false; if (color1.CompareTo(color2) != 0) return false; } return true; }
/// <summary> /// Init this widget. /// </summary> public override void Initialize() { base.Initialize(); colors = new ColorRect(ColorEx.Red); textWidget.SetTextColor(ColorEx.Cyan); textWidget.HorizontalFormat = HorizontalTextFormat.Centered; }
/// <summary> /// Init this widget. /// </summary> public override void Initialize() { base.Initialize (); TextureAtlas imageset = AtlasManager.Instance.GetTextureAtlas(ImagesetName); topLeft = imageset.GetTextureInfo(TopLeftFrameImageName); topRight = imageset.GetTextureInfo(TopRightFrameImageName); bottomLeft = imageset.GetTextureInfo(BottomLeftFrameImageName); bottomRight = imageset.GetTextureInfo(BottomRightFrameImageName); left = imageset.GetTextureInfo(LeftFrameImageName); right = imageset.GetTextureInfo(RightFrameImageName); top = imageset.GetTextureInfo(TopFrameImageName); bottom = imageset.GetTextureInfo(BottomFrameImageName); background = imageset.GetTextureInfo(BackgroundImageName); colors = new ColorRect(ColorEx.White); // StoreFrameSizes(); }
private void DrawText(string text, int offset, int count, Vector3 drawPos, Rect clipRect, TextStyle style) { if (log.IsDebugEnabled) log.DebugFormat("Drawing '{0}' at [{1},{2}] clipped by {3}", text.Substring(offset, count), drawPos.x, drawPos.y, clipRect); float textZ = drawPos.z - (int)SubLevel.Normal * GuiZSubLevelStep; float shadowZ = drawPos.z - (int)SubLevel.Shadow * GuiZSubLevelStep; float bgZ = drawPos.z - (int)SubLevel.Background * GuiZSubLevelStep; SimpleFont textFont = this.Font; float x = textFont.GetTextExtent(text, offset, count); float y = textFont.LineSpacing; if (clipRect != null) { if (drawPos.x > clipRect.Right || drawPos.x + x < clipRect.Left || drawPos.y > clipRect.Bottom || drawPos.y + y < clipRect.Top) { // this line is entirely out of bounds - technically, the drop shadow // could extend outside this area (as could the font), but I think // that if we wouldn't have drawn the background for the text, we don't // need to draw the text. log.DebugFormat("text with dimensions ({4},{5}) fully clipped by rect [{0},{1} - {2},{3}]", clipRect.Left, clipRect.Top, clipRect.Right, clipRect.Bottom, x, y); return; } } // Draw these on integer boundaries drawPos.x = (int)drawPos.x; drawPos.y = (int)drawPos.y; drawPos.z = textZ; ColorRect colorRect; if (style.bgEnabled) { colorRect = new ColorRect(style.bgColor); colorRect.SetAlpha(this.EffectiveAlpha); Rect bgRect = new Rect(drawPos.x, drawPos.x + x, drawPos.y, drawPos.y + y); bgImage.Draw(bgRect, bgZ, clipRect, colorRect); } colorRect = new ColorRect(style.textColor); colorRect.SetAlpha(this.EffectiveAlpha); textFont.DrawTextLine(text, offset, count, drawPos, clipRect, colorRect); if (style.shadowEnabled) { drawPos.x += shadowOffset.X; drawPos.y += shadowOffset.Y; drawPos.z = shadowZ; colorRect = new ColorRect(style.shadowColor); colorRect.SetAlpha(this.EffectiveAlpha); textFont.DrawTextLine(text, offset, count, drawPos, clipRect, colorRect); } }
//public void Draw() { // Point[] destPoints = new Point[4]; // destPoints[0] = new Point(target.Left, target.Top); // destPoints[1] = new Point(target.Left + target.Width, target.Top); // destPoints[2] = new Point(target.Left, target.Top + target.Height); // destPoints[3] = new Point(target.Left + target.Width, target.Top + target.Height); // Renderer.Instance.AddQuad(destPoints, 0, null, this.Texture, this.uvArray, null); //} public void Draw(Rect target, float z, Rect clip, ColorRect colors) { PointF[] destPoints = new PointF[4]; destPoints[0] = new PointF(target.Left, target.Top); destPoints[1] = new PointF(target.Left + target.Width, target.Top); destPoints[2] = new PointF(target.Left, target.Top + target.Height); destPoints[3] = new PointF(target.Left + target.Width, target.Top + target.Height); if (colors == null) colors = new ColorRect(ColorEx.White); Renderer.Instance.AddQuad(destPoints, z, clip, this.Texture, this.uvArray, colors); }
/// <summary> /// Draw text into a specified area of the display. /// </summary> /// <param name="text">The text to be drawn.</param> /// <param name="area"> /// Rect object describing the area of the display where the text is to be rendered. The text is not clipped to this Rect, but is formatted /// using this Rect depending upon the option specified in <paramref name="format"/>. /// </param> /// <param name="z">float value specifying the z co-ordinate for the drawn text.</param> /// <param name="clip">Rect object describing the clipping area for the drawing. No drawing will occur outside this Rect.</param> /// <param name="format">The text formatting required.</param> /// <param name="colors"> /// ColorRect object describing the colors to be applied when drawing the text. /// The colors specified in here are applied to each glyph, rather than the text as a whole. /// </param> /// <returns>The number of lines output. This does not consider clipping, so if all text was clipped, this would still return >=1.</returns> public int DrawText(string text, List <TextRange> lines, Rect area, float z, Rect clip, HorizontalTextFormat horzFormat, VerticalTextFormat vertFormat, ColorRect colors) { foreach (TextRange line in lines) { PointF offset = GetOffset(text, lines, line.start, horzFormat, vertFormat, area.Width, area.Height, leftToRight); DrawTextLine(text, line.start, line.Length, new Vector3(area.Left + offset.X, area.Top + offset.Y, z), clip, colors); } return(lines.Count); }
public void Draw(Vector3 pos, SizeF target, Rect clip, ColorRect colors) { PointF[] destPoints = new PointF[4]; destPoints[0] = new PointF(pos.x, pos.y); destPoints[1] = new PointF(pos.x + target.Width, pos.y); destPoints[2] = new PointF(pos.x, pos.y + target.Height); destPoints[3] = new PointF(pos.x + target.Width, pos.y + target.Height); if (colors == null) colors = new ColorRect(ColorEx.White); Renderer.Instance.AddQuad(destPoints, pos.z, clip, this.Texture, this.uvArray, colors); }
/// <summary> /// This is a fairly basic method to draw text. /// It does not do word or line wrapping. /// </summary> /// <param name="text">the string to write</param> /// <param name="offset">number of characters from str that should be ignored</param> /// <param name="count">number of characters from text that should be considered</param> /// <param name="pos">the position to start the draw</param> /// <param name="clip">the rectangle used to clip the draw calls or null to avoid clipping</param> /// <param name="colors">the color to use for the text</param> public void DrawTextLine(string text, int offset, int count, Vector3 pos, Rect clip, ColorRect colors) { Vector3 currentPos = pos; for (int i = offset; i < offset + count; i++) { char c = text[i]; if (!IsCharacterAvailable(c)) { log.InfoFormat("Character '{0}' not present in font {1}", c, this.font); continue; } int glyphIndex = glyphMap[c]; TextureInfo glyphImage = glyphData[glyphIndex].TextureInfo; // log.DebugFormat("Drawing character {0} from texture atlas {1}", c, glyphImage.Atlas.Name); if (!leftToRight) { currentPos.x -= glyphData[glyphIndex].HorizontalAdvance; } glyphImage.Draw(currentPos, clip, colors); if (leftToRight) { currentPos.x += glyphData[glyphIndex].HorizontalAdvance; } } }
public void Draw(Vector3 pos, Rect clip, ColorRect colors) { this.Draw(pos, this.size, clip, colors); }
public void SetTextColor(ColorEx color) { textColors = new ColorRect(color); }