public PlainText(bool autoSize, string text, Color color, QFontAlignment alignment, float offsetX, float offsetY) { this.AutoSize = autoSize; this.text = text; this.Color = color; this.Alignment = alignment; this.offsetX = offsetX; this.offsetY = offsetY; }
/// <summary> /// Initializes a new <see cref="TextObject" /> instance. /// </summary> /// <param name="text">The initial text to set for this text object.</param> /// <param name="font">The font to use for this text object.</param> /// <param name="position">The intitial position of this text object.</param> /// <param name="alignment">The intitial alignment of the text in this text object.</param> public TextObject(string text, Font font, Point<int> position = new Point<int>(), QFontAlignment alignment = QFontAlignment.Centre) { if (font == null) throw new EngineException("Font supplied for TextObject is null!", new ArgumentNullException("font")); Text = text; Font = font; Position = position; Alignment = alignment; }
/// <summary> /// Measures the actual width and height of the block of text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <param name="alignment"></param> /// <returns></returns> public SizeF Measure(string text, SizeF maxSize, QFontAlignment alignment) { var processedText = ProcessText(text, maxSize, alignment); return(Measure(processedText)); }
public void PrintToVBO(string text, QFontAlignment alignment, Vector3 position, Color color, SizeF maxSize) { Options.Colour = color; PrintOffset = position; Print(text, maxSize, alignment); }
public void PrintToVBO(string text, Vector3 position, Color color, QFontAlignment alignment = QFontAlignment.Left) { Options.Colour = color; PrintOffset = position; PrintOrMeasure(text, alignment, false); }
/// <summary> /// Measures the actual width and height of the block of text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <param name="alignment"></param> /// <returns></returns> public SizeF Measure(string text, float maxWidth, QFontAlignment alignment) { var processedText = ProcessText(text, maxWidth, alignment); return Measure(processedText); }
public void Print(string text, Vector2 position, QFontAlignment alignment = QFontAlignment.Left) { position = TransformPositionToViewport(position); position = LockToPixel(position); GL.PushMatrix(); GL.Translate(position.X, position.Y, 0f); Print(text, alignment); GL.PopMatrix(); }
public void Print(string text, QFontAlignment alignment = QFontAlignment.Left, PointF position = default(PointF)) { position = LockToPixel(position); renderer.Begin(position); PrintOrMeasure(text, alignment, false); renderer.End(); }
public void Print(string text, Vector3 position, Color color, QFontAlignment alignment = QFontAlignment.Left) { var position2 = new Vector2(position.X, position.Y); position2 = TransformPositionToViewport(position2); position2 = LockToPixel(position2); Options.Colour = color; GL.PushMatrix(); GL.Translate(position.X, position.Y, 0f); PrintOrMeasure(text, alignment, false); GL.PopMatrix(); }
private void HandleKeyDown(object sender, KeyboardKeyEventArgs keyEventArgs) { int texmax = GL.GetInteger(GetPName.MaxTextureSize); switch (keyEventArgs.Key) { case Key.Escape: Exit(); break; case Key.Space: case Key.Right: currentDemoPage++; break; case Key.BackSpace: case Key.Left: currentDemoPage--; break; case Key.Enter: { if (currentDemoPage == 4) { boundsAnimationCnt = 0f; } break; } case Key.Up: { if (currentDemoPage == 4) { if (cycleAlignment == QFontAlignment.Justify) { cycleAlignment = QFontAlignment.Left; } else { cycleAlignment++; } } break; } case Key.Down: { if (currentDemoPage == 4) { if (cycleAlignment == QFontAlignment.Left) { cycleAlignment = QFontAlignment.Justify; } else { cycleAlignment--; } } break; } case Key.F9: break; } if (currentDemoPage > lastPage) { currentDemoPage = lastPage; } if (currentDemoPage < 0) { currentDemoPage = 0; } }
static void OnKeyPress(GlfwWindowPtr window, Key KeyCode, int Scancode, KeyAction Action, KeyModifiers Mods) { int texmax = GL.GetInteger(GetPName.MaxTextureSize); if (Action == KeyAction.Press) { switch (KeyCode) { case Key.Escape: Glfw.SetWindowShouldClose(window, true); break; case Key.Space: case Key.Right: currentDemoPage++; break; case Key.Backspace: case Key.Left: currentDemoPage--; break; case Key.Enter: { if (currentDemoPage == 4) { boundsAnimationCnt = 0f; } break; } case Key.Up: { if (currentDemoPage == 4) { if (cycleAlignment == QFontAlignment.Justify) { cycleAlignment = QFontAlignment.Left; } else { cycleAlignment++; } } break; } case Key.Down: { if (currentDemoPage == 4) { if (cycleAlignment == QFontAlignment.Left) { cycleAlignment = QFontAlignment.Justify; } else { cycleAlignment--; } } break; } } } if (currentDemoPage > lastPage) { currentDemoPage = lastPage; } if (currentDemoPage < 0) { currentDemoPage = 0; } }
/// <summary> /// Creates node list object associated with the text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <returns></returns> public static ProcessedText ProcessText(QFont font, QFontRenderOptions options, string text, SizeF maxSize, QFontAlignment alignment) { return(ProcessText(font.FontData, options, text, maxSize, alignment)); }
private SizeF PrintOrMeasure(string text, QFontAlignment alignment, bool measureOnly, Rectangle clippingRectangle = default(Rectangle)) { var maxWidth = 0f; var xOffset = 0f; var yOffset = 0f; var maxXpos = float.MinValue; var minXPos = float.MaxValue; text = text.Replace("\r\n", "\r"); #if DEBUG _DisplayText_dbg = text; #endif if (alignment == QFontAlignment.Right) { xOffset -= MeasureNextlineLength(text); } else if (alignment == QFontAlignment.Centre) { xOffset -= (int)(0.5f * MeasureNextlineLength(text)); } var lineSpacing = LineSpacing(); var isMonospacingActive = IsMonospacingActive(); for (var i = 0; i < text.Length; i++) { var c = text[i]; //newline if (c == '\r' || c == '\n') { yOffset += lineSpacing; xOffset = 0f; if (alignment == QFontAlignment.Right) { xOffset -= MeasureNextlineLength(text.Substring(i + 1)); } else if (alignment == QFontAlignment.Centre) { xOffset -= (int)(0.5f * MeasureNextlineLength(text.Substring(i + 1))); } } else { minXPos = Math.Min(xOffset, minXPos); if (c == ' ') { xOffset += isMonospacingActive ? MonoSpaceWidth() : (float)Math.Ceiling(Font.meanGlyphWidth * Options.WordSpacing); } else { QFontGlyph glyph; //normal character if (Font.CharSetMapping.TryGetValue(c, out glyph)) { if (!measureOnly) { RenderGlyph(xOffset, yOffset, c, Font, CurrentVertexRepr, ref clippingRectangle); } if (isMonospacingActive) { xOffset += MonoSpaceWidth(); } else { xOffset += (float)Math.Ceiling( glyph.rect.Width + Font.meanGlyphWidth * Options.CharacterSpacing + Font.GetKerningPairCorrection(i, text, null)); } } } maxXpos = Math.Max(xOffset, maxXpos); } } if (minXPos != float.MaxValue) { maxWidth = maxXpos - minXPos; } LastSize = new SizeF(maxWidth, yOffset + lineSpacing); return(LastSize); }
private void KeyDown(object sender, KeyboardKeyEventArgs keyEventArgs) { switch (keyEventArgs.Key) { case Key.Space: case Key.Right: currentDemoPage++; break; case Key.BackSpace: case Key.Left: currentDemoPage--; break; case Key.Enter: { if (currentDemoPage == 4) { boundsAnimationCnt = 0f; } } break; case Key.Up: { if (currentDemoPage == 4) { if (cycleAlignment == QFontAlignment.Justify) { cycleAlignment = QFontAlignment.Left; } else { cycleAlignment++; } } } break; case Key.Down: { if (currentDemoPage == 4) { if (cycleAlignment == QFontAlignment.Left) { cycleAlignment = QFontAlignment.Justify; } else { cycleAlignment--; } } } break; case Key.F9: break; } if (currentDemoPage > lastPage) { currentDemoPage = lastPage; } if (currentDemoPage < 1) { currentDemoPage = 1; } }
/// <summary> /// Measures the specified text. Helper method delegating functionality. /// </summary> /// <param name="text">The text.</param> /// <param name="maxSize">The maximum size.</param> /// <param name="alignment">The alignment.</param> /// <returns>Measured size</returns> public SizeF Measure(string text, SizeF maxSize, QFontAlignment alignment) { var test = new QFontDrawingPimitive(this); return(test.Measure(text, maxSize, alignment)); }
private SizeF PrintOrMeasure(string text, QFontAlignment alignment, bool measureOnly) { float maxWidth = 0f; float xOffset = 0f; float yOffset = 0f; var caps = new EnableCap[] { }; if (!UsingVertexBuffers) { caps = new EnableCap[] { EnableCap.Texture2D, EnableCap.Blend } } ; Helper.SafeGLEnable(caps, () => { float maxXpos = float.MinValue; float minXPos = float.MaxValue; if (!UsingVertexBuffers) { GL.Color4(1.0f, 1.0f, 1.0f, 1.0f); if (Options.UseDefaultBlendFunction) { GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); } } text = text.Replace("\r\n", "\r"); if (alignment == QFontAlignment.Right) { xOffset -= MeasureNextlineLength(text); } else if (alignment == QFontAlignment.Centre) { xOffset -= (int)(0.5f * MeasureNextlineLength(text)); } for (int i = 0; i < text.Length; i++) { char c = text[i]; //newline if (c == '\r' || c == '\n') { yOffset += LineSpacing; xOffset = 0f; if (alignment == QFontAlignment.Right) { xOffset -= MeasureNextlineLength(text.Substring(i + 1)); } else if (alignment == QFontAlignment.Centre) { xOffset -= (int)(0.5f * MeasureNextlineLength(text.Substring(i + 1))); } } else { minXPos = Math.Min(xOffset, minXPos); //normal character if (c != ' ' && fontData.CharSetMapping.ContainsKey(c)) { QFontGlyph glyph = fontData.CharSetMapping[c]; if (!measureOnly) { RenderGlyph(xOffset, yOffset, c, false); } } if (IsMonospacingActive) { xOffset += MonoSpaceWidth; } else { if (c == ' ') { xOffset += (float)Math.Ceiling(fontData.meanGlyphWidth * Options.WordSpacing); } //normal character else if (fontData.CharSetMapping.ContainsKey(c)) { QFontGlyph glyph = fontData.CharSetMapping[c]; xOffset += (float)Math.Ceiling(glyph.rect.Width + fontData.meanGlyphWidth * Options.CharacterSpacing + fontData.GetKerningPairCorrection(i, text, null)); } } maxXpos = Math.Max(xOffset, maxXpos); } } if (minXPos != float.MaxValue) { maxWidth = maxXpos - minXPos; } }); return(new SizeF(maxWidth, yOffset + LineSpacing)); }
private void PrintCommentWithLine(string comment, QFontAlignment alignment, float xOffset, ref float yOffset) { WriteCommentWithLine(mainText, comment, alignment, xOffset, ref yOffset); }
/// <summary> /// Prints the specified text with the given alignment, maximum size, colour and clipping rectangle /// </summary> /// <param name="text">The text to print</param> /// <param name="position">The text position</param> /// <param name="maxSize">The maxmimum size of the printed text</param> /// <param name="alignment">The text alignment</param> /// <param name="colour">The text colour</param> /// <param name="clippingRectangle">The clipping rectangle to scissor test the text with</param> /// <returns>The size of the printed text</returns> public SizeF Print(string text, Vector3 position, SizeF maxSize, QFontAlignment alignment, Color colour, Rectangle clippingRectangle = default(Rectangle)) { ProcessedText processedText = ProcessText(Font, Options, text, maxSize, alignment); return(Print(processedText, TransformToViewport(position), colour, clippingRectangle)); }
public SizeF Measure(string text, QFontAlignment alignment = QFontAlignment.Left) { return PrintOrMeasure(text, alignment, true); }
/// <summary> /// Measures the specified text with the given alignment and a maximum width /// (no maximum height) /// </summary> /// <param name="text">The specified text</param> /// <param name="maxWidth">The maximum width of the text</param> /// <param name="alignment">The text alignment</param> /// <returns>The size of the text</returns> public SizeF Measure(string text, float maxWidth, QFontAlignment alignment) { return(Measure(text, new SizeF(maxWidth, -1), alignment)); }
/// <summary> /// Measures the specified text. Helper method delegating functionality. /// </summary> /// <param name="text">The text.</param> /// <param name="maxWidth">The maximum width.</param> /// <param name="alignment">The alignment.</param> /// <returns> /// Measured size. /// </returns> public SizeF Measure(string text, float maxWidth, QFontAlignment alignment) { var test = new QFontDrawingPimitive(this); return test.Measure(text, maxWidth, alignment); }
/// <summary> /// Measures the actual width and height of the block of text. /// </summary> /// <param name="text">The text to measure</param> /// <param name="maxSize">The maximum size of the text</param> /// <param name="alignment">The text alignment</param> /// <returns>The size of the text</returns> public SizeF Measure(string text, SizeF maxSize, QFontAlignment alignment) { ProcessedText processedText = ProcessText(Font, Options, text, maxSize, alignment); return(Measure(processedText)); }
public void PrintToVBO(string text, Vector2 position, QFontAlignment alignment = QFontAlignment.Left) { PrintOffset = new Vector3(position.X, position.Y, 0f); PrintOrMeasure(text, alignment, false); }
/// <summary> /// Print or measure the specified text /// </summary> /// <param name="text">The text to print or measure</param> /// <param name="alignment">The text alignment</param> /// <param name="measureOnly">Whether to only measure the text</param> /// <param name="clippingRectangle">The clipping rectangle to scissor test the text with</param> /// <returns>The size of the text</returns> private SizeF PrintOrMeasure(string text, QFontAlignment alignment, bool measureOnly, Rectangle clippingRectangle = default(Rectangle)) { float maxWidth = 0f; float xOffset = 0f; float yOffset = 0f; float maxXpos = float.MinValue; float minXPos = float.MaxValue; text = text.Replace("\r\n", "\r"); #if DEBUG _DisplayText_dbg = text; #endif if (alignment == QFontAlignment.Right) { xOffset -= MeasureNextlineLength(text); } else if (alignment == QFontAlignment.Centre) { xOffset -= (int)(0.5f * MeasureNextlineLength(text)); } float maxCharHeight = 0; for (int i = 0; i < text.Length; i++) { char c = text[i]; //newline if (c == '\r' || c == '\n') { yOffset += LineSpacing; maxCharHeight = 0; xOffset = 0f; if (alignment == QFontAlignment.Right) { xOffset -= MeasureNextlineLength(text.Substring(i + 1)); } else if (alignment == QFontAlignment.Centre) { xOffset -= (int)(0.5f * MeasureNextlineLength(text.Substring(i + 1))); } } else { minXPos = Math.Min(xOffset, minXPos); //normal character if (c != ' ' && Font.FontData.CharSetMapping.ContainsKey(c)) { if (!measureOnly) { RenderGlyph(xOffset, yOffset, c, Font, CurrentVertexRepr, clippingRectangle); } } if (IsMonospacingActive) { xOffset += MonoSpaceWidth; } else { if (c == ' ') { xOffset += (float)Math.Ceiling(Font.FontData.MeanGlyphWidth * Options.WordSpacing); } //normal character else if (Font.FontData.CharSetMapping.ContainsKey(c)) { QFontGlyph glyph = Font.FontData.CharSetMapping[c]; xOffset += (float) Math.Ceiling(glyph.Rect.Width + Font.FontData.MeanGlyphWidth * Options.CharacterSpacing + Font.FontData.GetKerningPairCorrection(i, text, null)); maxCharHeight = Math.Max(maxCharHeight, glyph.Rect.Height + glyph.YOffset); } } maxXpos = Math.Max(xOffset, maxXpos); } } if (Math.Abs(minXPos - float.MaxValue) > float.Epsilon) { maxWidth = maxXpos - minXPos; } LastSize = new SizeF(maxWidth, yOffset + LineSpacing); return(LastSize); }
public SizeF Measure(string text, QFontAlignment alignment = QFontAlignment.Left) { return TransformMeasureFromViewport(PrintOrMeasure(text, alignment, true)); }
/// <summary> /// Print or measure the specified processed text /// </summary> /// <param name="processedText">The processed text</param> /// <param name="measureOnly">Whether to only measure the text</param> /// <param name="clippingRectangle">The clipping rectangle to scissor test the text with</param> /// <returns>The size of the text</returns> private SizeF PrintOrMeasure(ProcessedText processedText, bool measureOnly, Rectangle clippingRectangle = default(Rectangle)) { // init values we'll return float maxMeasuredWidth = 0f; float maxCharHeight = 0f; const float xPos = 0f; const float yPos = 0f; float xOffset = xPos; float yOffset = yPos; float maxWidth = processedText.MaxSize.Width; QFontAlignment alignment = processedText.Alignment; //TODO - use these instead of translate when rendering by position (at some point) TextNodeList nodeList = processedText.TextNodeList; for (TextNode node = nodeList.Head; node != null; node = node.Next) { node.LengthTweak = 0f; //reset tweaks } if (alignment == QFontAlignment.Right) { xOffset -= (float)Math.Ceiling(TextNodeLineLength(nodeList.Head, maxWidth) - maxWidth); } else if (alignment == QFontAlignment.Centre) { xOffset -= (float)Math.Ceiling(0.5f * TextNodeLineLength(nodeList.Head, maxWidth)); } else if (alignment == QFontAlignment.Justify) { JustifyLine(nodeList.Head, maxWidth); } bool atLeastOneNodeCosumedOnLine = false; float length = 0f; for (TextNode node = nodeList.Head; node != null; node = node.Next) { bool newLine = false; if (node.Type == TextNodeType.LineBreak) { newLine = true; } else { if (Options.WordWrap && SkipTrailingSpace(node, length, maxWidth) && atLeastOneNodeCosumedOnLine) { newLine = true; } else if (length + node.ModifiedLength <= maxWidth || !atLeastOneNodeCosumedOnLine) { atLeastOneNodeCosumedOnLine = true; if (!measureOnly) { RenderWord(xOffset + length, yOffset, node, ref clippingRectangle); } length += node.ModifiedLength; maxCharHeight = Math.Max(maxCharHeight, node.Height); maxMeasuredWidth = Math.Max(length, maxMeasuredWidth); } else if (Options.WordWrap) { newLine = true; if (node.Previous != null) { node = node.Previous; } } else { continue; // continue so we still read line breaks even if reached max width } } if (newLine) { if (processedText.MaxSize.Height > 0 && yOffset + LineSpacing - yPos >= processedText.MaxSize.Height) { break; } yOffset += LineSpacing; xOffset = xPos; length = 0f; atLeastOneNodeCosumedOnLine = false; if (node.Next != null) { if (alignment == QFontAlignment.Right) { xOffset -= (float)Math.Ceiling(TextNodeLineLength(node.Next, maxWidth) - maxWidth); } else if (alignment == QFontAlignment.Centre) { xOffset -= (float)Math.Ceiling(0.5f * TextNodeLineLength(node.Next, maxWidth)); } else if (alignment == QFontAlignment.Justify) { JustifyLine(node.Next, maxWidth); } } } } LastSize = new SizeF(maxMeasuredWidth, yOffset + LineSpacing - yPos); return(LastSize); }
/// <summary> /// Prints text inside the given bounds. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <param name="alignment"></param> public void Print(string text, SizeF maxSize, QFontAlignment alignment) { var processedText = ProcessText(text, maxSize, alignment); Print(processedText); }
private void PrintCommentWithLine(QFont font, string comment, QFontAlignment alignment, float xOffset, ref float yOffset) { GL.PushMatrix(); yOffset += 20; GL.Translate((int)xOffset, yOffset, 0f); font.Print(comment, alignment); var bounds = font.Measure(comment, Width-60, alignment); GL.Disable(EnableCap.Texture2D); GL.Begin(BeginMode.Lines); GL.Color4(1.0f, 0f, 0f, 1f); GL.Vertex2(0f, 0f); GL.Color4(1.0f, 0f, 0f, 1f); GL.Vertex2(0f, bounds.Height + 20f); GL.End(); yOffset += bounds.Height; GL.PopMatrix(); }
private SizeF PrintOrMeasure(string text, QFontAlignment alignment, bool measureOnly) { float maxWidth = 0f; float xOffset = 0f; float yOffset = 0f; var caps = new EnableCap[] { }; if(!UsingVertexBuffers) caps = new EnableCap[] { EnableCap.Texture2D, EnableCap.Blend }; Helper.SafeGLEnable(caps, () => { float maxXpos = float.MinValue; float minXPos = float.MaxValue; if (!UsingVertexBuffers) { GL.Color4(1.0f, 1.0f, 1.0f, 1.0f); if (Options.UseDefaultBlendFunction) GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); } text = text.Replace("\r\n", "\r"); if (alignment == QFontAlignment.Right) xOffset -= MeasureNextlineLength(text); else if (alignment == QFontAlignment.Centre) xOffset -= (int)(0.5f * MeasureNextlineLength(text)); for (int i = 0; i < text.Length; i++) { char c = text[i]; //newline if (c == '\r' || c == '\n') { yOffset += LineSpacing; xOffset = 0f; if (alignment == QFontAlignment.Right) xOffset -= MeasureNextlineLength(text.Substring(i + 1)); else if (alignment == QFontAlignment.Centre) xOffset -= (int)(0.5f * MeasureNextlineLength(text.Substring(i + 1))); } else { minXPos = Math.Min(xOffset, minXPos); //normal character if (c != ' ' && fontData.CharSetMapping.ContainsKey(c)) { QFontGlyph glyph = fontData.CharSetMapping[c]; if (!measureOnly) RenderGlyph(xOffset, yOffset, c, false); } if (IsMonospacingActive) xOffset += MonoSpaceWidth; else { if (c == ' ') xOffset += (float)Math.Ceiling(fontData.meanGlyphWidth * Options.WordSpacing); //normal character else if (fontData.CharSetMapping.ContainsKey(c)) { QFontGlyph glyph = fontData.CharSetMapping[c]; xOffset += (float)Math.Ceiling(glyph.rect.Width + fontData.meanGlyphWidth * Options.CharacterSpacing + fontData.GetKerningPairCorrection(i, text, null)); } } maxXpos = Math.Max(xOffset, maxXpos); } } if (minXPos != float.MaxValue) maxWidth = maxXpos - minXPos; }); return new SizeF(maxWidth, yOffset + LineSpacing); }
private void PrintWithBounds(NxFont font, string text, RectangleF bounds, QFontAlignment alignment, ref float yOffset) { // GL.Disable(EnableCap.Texture2D); // GL.Color4(1.0f, 0f, 0f, 1.0f); float maxWidth = bounds.Width; float height = font.SafeMeasure(ClientRectangle, text, maxWidth, alignment).Height; // GL.Begin(BeginMode.LineLoop); // GL.Vertex3(bounds.X, bounds.Y, 0f); // GL.Vertex3(bounds.X + bounds.Width, bounds.Y, 0f); // GL.Vertex3(bounds.X + bounds.Width, bounds.Y + height, 0f); // GL.Vertex3(bounds.X, bounds.Y + height, 0f); // GL.End(); font.PrintAt(ClientRectangle, text, maxWidth, alignment, new Vector2(bounds.X,bounds.Y)); yOffset += height; }
/// <summary> /// Measures the specified text. Helper method delegating functionality. /// </summary> /// <param name="text">The text.</param> /// <param name="maxWidth">The maximum width.</param> /// <param name="alignment">The alignment.</param> /// <returns> /// Measured size. /// </returns> public SizeF Measure(string text, float maxWidth, QFontAlignment alignment) { var test = new QFontDrawingPrimitive(this); return(test.Measure(text, maxWidth, alignment)); }
private void InitialiseKeyDown() { KeyDown += (sender, ke) => { if (ke.Key == Key.Escape) { this.Exit (); } }; KeyDown += (sender, ke) => { switch (ke.Key) { case Key.Space: useShader = !useShader; break; case Key.Right: currentDemoPage++; break; case Key.BackSpace: case Key.Left: currentDemoPage--; break; case Key.Enter: { if (currentDemoPage == 4) boundsAnimationCnt = 0f; } break; case Key.Up: { if (currentDemoPage == 4) { if (cycleAlignment == QFontAlignment.Justify) cycleAlignment = QFontAlignment.Left; else cycleAlignment++; } } break; case Key.Down: { if (currentDemoPage == 4) { if (cycleAlignment == QFontAlignment.Left) cycleAlignment = QFontAlignment.Justify; else cycleAlignment--; } } break; case Key.F9: break; } if (currentDemoPage > LAST_PAGE) currentDemoPage = LAST_PAGE; if (currentDemoPage < FIRST_PAGE) currentDemoPage = FIRST_PAGE; }; }
/// <summary> /// Measures the specified text. Helper method delegating functionality. /// </summary> /// <param name="text">The text.</param> /// <param name="alignment">The alignment.</param> /// <returns> /// Measured size. /// </returns> public SizeF Measure(string text, QFontAlignment alignment = QFontAlignment.Left) { var test = new QFontDrawingPrimitive(this); return(test.Measure(text, alignment)); }
private void WriteComment(NxFont font, string comment,QFontAlignment alignment, ref float yOffset) { //GL.PushMatrix(); yOffset += 20; var offset = new Vector3(30f, yOffset, 0f); var transform = Matrix4.CreateTranslation(offset); var mvp = Matrix4.Mult (transform, mOrthographicMatrix); font.SafePrint(mvp, ClientRectangle, comment, Width - 60, alignment); yOffset += font.SafeMeasure(ClientRectangle, comment, Width - 60, alignment).Height; //GL.PopMatrix(); }
void QuickFontControl_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Space: case Keys.Right: currentDemoPage++; break; case Keys.Backspace: case Keys.Left: currentDemoPage--; break; case Keys.Enter: { if (currentDemoPage == 4) { boundsAnimationCnt = 0f; } } break; case Keys.Up: { if (currentDemoPage == 4) { if (cycleAlignment == QFontAlignment.Justify) { cycleAlignment = QFontAlignment.Left; } else { cycleAlignment++; } } } break; case Keys.Down: { if (currentDemoPage == 4) { if (cycleAlignment == QFontAlignment.Left) { cycleAlignment = QFontAlignment.Justify; } else { cycleAlignment--; } } } break; case Keys.F9: break; } if (currentDemoPage > lastPage) { currentDemoPage = lastPage; } if (currentDemoPage < 1) { currentDemoPage = 1; } }
private void WriteCommentWithLine(NxFont font, string comment, QFontAlignment alignment, float xOffset, ref float yOffset) { //GL.PushMatrix(); yOffset += 20; var offset = new Vector3((int)xOffset, yOffset, 0f); var transform = Matrix4.CreateTranslation(offset); var mvp = Matrix4.Mult (transform, mOrthographicMatrix); font.Print(mvp, comment, alignment); var bounds = font.SafeMeasure(ClientRectangle, comment, Width-60, alignment); // GL.Disable(EnableCap.Texture2D); // GL.Begin(BeginMode.Lines); // GL.Color4(1.0f, 0f, 0f, 1f); // GL.Vertex2(0f, 0f); // GL.Color4(1.0f, 0f, 0f, 1f); // GL.Vertex2(0f, bounds.Height + 20f); // GL.End(); yOffset += bounds.Height; // GL.PopMatrix(); }
void PrintWithBounds(Graphics graphics, QFont font, string text, Rect bounds, QFontAlignment alignment, ref double yOffset) { double maxWidth = bounds.Width; double height = font.Measure(text, maxWidth, alignment).Height; bounds.Height = height; graphics.DrawRectangle(m_LinesPen, bounds - new Point(1, 0) + new Size(0, 1)); font.Print(text, maxWidth, alignment, new Alt.Sketch.Vector2(bounds.X, bounds.Y)); yOffset += height; }
public void Print(string text, float maxWidth, QFontAlignment alignment, PointF position) { position = LockToPixel(position); renderer.Begin(position); Print(text, maxWidth, alignment); renderer.End(); }
void PrintCommentWithLine(Graphics graphics, string comment, QFontAlignment alignment, double xOffset, ref double yOffset) { PrintCommentWithLine(graphics, mainText, comment, alignment, xOffset, ref yOffset); }
private SizeF PrintOrMeasure(string text, QFontAlignment alignment, bool measureOnly) { float maxXpos = float.MinValue; float minXPos = float.MaxValue; float xOffset = 0f; float yOffset = 0f; text = text.Replace("\r\n", "\r"); if (alignment == QFontAlignment.Right) xOffset -= MeasureNextlineLength(text); else if (alignment == QFontAlignment.Centre) xOffset -= (int)(0.5f * MeasureNextlineLength(text)); for(int i = 0; i < text.Length; i++) { char c = text[i]; //newline if (c == '\r' || c == '\n') { yOffset += LineSpacing; xOffset = 0f; if (alignment == QFontAlignment.Right) xOffset -= MeasureNextlineLength(text.Substring(i + 1)); else if (alignment == QFontAlignment.Centre) xOffset -= (int)(0.5f * MeasureNextlineLength(text.Substring(i + 1))); } else { minXPos = Math.Min(xOffset, minXPos); //normal character if (c != ' ' && fontData.CharSetMapping.ContainsKey(c)) { QFontGlyph glyph = fontData.CharSetMapping[c]; if(!measureOnly) RenderGlyph(xOffset, yOffset, c, false); } if (IsMonospacingActive) xOffset += MonoSpaceWidth; else { if (c == ' ') xOffset += (float)Math.Ceiling(fontData.meanGlyphWidth * Options.WordSpacing); //normal character else if (fontData.CharSetMapping.ContainsKey(c)) { QFontGlyph glyph = fontData.CharSetMapping[c]; xOffset += (float)Math.Ceiling(glyph.rect.Width + fontData.meanGlyphWidth * Options.CharacterSpacing + fontData.GetKerningPairCorrection(i, text, null)); } } maxXpos = Math.Max(xOffset, maxXpos); } } float maxWidth = 0f; if (minXPos != float.MaxValue) maxWidth = maxXpos - minXPos; return new SizeF(maxWidth, yOffset + LineSpacing); }
protected override void OnKeyDown(KeyboardKeyEventArgs keyboardKeyEventArgs) { GL.GetInteger(GetPName.MaxTextureSize); switch (keyboardKeyEventArgs.Key) { case Key.Space: case Key.Right: _currentDemoPage++; break; case Key.BackSpace: case Key.Left: _currentDemoPage--; break; case Key.Enter: { if (_currentDemoPage == 4) { _boundsAnimationCnt = 0f; } break; } case Key.Up: { if (_currentDemoPage == 4) { if (_cycleAlignment == QFontAlignment.Justify) { _cycleAlignment = QFontAlignment.Left; } else { _cycleAlignment++; } } break; } case Key.Down: { if (_currentDemoPage == 4) { if (_cycleAlignment == QFontAlignment.Left) { _cycleAlignment = QFontAlignment.Justify; } else { _cycleAlignment--; } } break; } case Key.F9: break; } if (_currentDemoPage > _lastPage) { _currentDemoPage = _lastPage; } if (_currentDemoPage < 0) { _currentDemoPage = 0; } base.OnKeyDown(keyboardKeyEventArgs); }
/// <summary> /// Measures the specified text. Helper method delegating functionality. /// </summary> /// <param name="text">The text.</param> /// <param name="alignment">The alignment.</param> /// <returns> /// Measured size. /// </returns> public SizeF Measure(string text, QFontAlignment alignment = QFontAlignment.Left) { var test = new QFontDrawingPimitive(this); return test.Measure(text, alignment); }
private void PrintCommentWithLine(string comment, QFontAlignment alignment, float xOffset, ref float yOffset) { PrintCommentWithLine(_mainText, comment, alignment, xOffset, ref yOffset, _mainTextOptions); }
public void PrintToVBO(string text, SizeF maxSize, QFontAlignment alignment, Vector2 position) { PrintOffset = new Vector3(position.X, position.Y, 0f); Print(text, maxSize, alignment); }
/// <summary> /// Prints text inside the given bounds. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <param name="alignment"></param> public void Print(string text, float maxWidth, QFontAlignment alignment) { var processedText = ProcessText(text, maxWidth, alignment); Print(processedText); }
public void Print(string text, QFontAlignment alignment) { PrintOrMeasure(text, alignment, false); }
private SizeF PrintOrMeasure(string text, QFontAlignment alignment, bool measureOnly) { var popRequired = false; if (!measureOnly && !ProjectionStack.Begun && Options.TransformToViewport != null) { GL.PushMatrix(); popRequired = true; GL.Scale(1 / fontData.scaleDueToTransformToViewport, 1 / fontData.scaleDueToTransformToViewport, 0); } float maxXpos = float.MinValue; float minXPos = float.MaxValue; if (!measureOnly) { GL.Color4(1.0f, 1.0f, 1.0f, 1.0f); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); if (Options.UseDefaultBlendFunction) { GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); } } float xOffset = 0f; float yOffset = 0f; text = text.Replace("\r\n", "\r"); if (alignment == QFontAlignment.Right) xOffset -= MeasureNextlineLength(text); else if (alignment == QFontAlignment.Centre) xOffset -= (int)(0.5f * MeasureNextlineLength(text)); for(int i = 0; i < text.Length; i++) { char c = text[i]; //newline if (c == '\r' || c == '\n') { yOffset += LineSpacing; xOffset = 0f; if (alignment == QFontAlignment.Right) xOffset -= MeasureNextlineLength(text.Substring(i + 1)); else if (alignment == QFontAlignment.Centre) xOffset -= (int)(0.5f * MeasureNextlineLength(text.Substring(i + 1))); } else { minXPos = Math.Min(xOffset, minXPos); //normal character if (c != ' ' && fontData.CharSetMapping.ContainsKey(c)) { QFontGlyph glyph = fontData.CharSetMapping[c]; if(!measureOnly) RenderGlyph(xOffset, yOffset, c, false); } if (IsMonospacingActive) xOffset += MonoSpaceWidth; else { if (c == ' ') xOffset += (float)Math.Ceiling(fontData.meanGlyphWidth * Options.WordSpacing); //normal character else if (fontData.CharSetMapping.ContainsKey(c)) { QFontGlyph glyph = fontData.CharSetMapping[c]; xOffset += (float)Math.Ceiling(glyph.rect.Width + fontData.meanGlyphWidth * Options.CharacterSpacing + fontData.GetKerningPairCorrection(i, text, null)); } } maxXpos = Math.Max(xOffset, maxXpos); } } float maxWidth = 0f; if (minXPos != float.MaxValue) maxWidth = maxXpos - minXPos; if (popRequired) GL.PopMatrix(); return new SizeF(maxWidth, yOffset + LineSpacing); }
public SizeF Measure(string text, QFontAlignment alignment) { return(TransformMeasureFromViewport(PrintOrMeasure(text, alignment, true))); }
/// <summary> /// Measures the actual width and height of the block of text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <param name="alignment"></param> /// <returns></returns> public SizeF Measure(string text, SizeF maxSize, QFontAlignment alignment) { var processedText = ProcessText(text, maxSize, alignment); return Measure(processedText); }
/// <summary> /// Measures the actual width and height of the block of text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <param name="alignment"></param> /// <returns></returns> public SizeF Measure(string text, float maxWidth, QFontAlignment alignment) { var processedText = ProcessText(text, maxWidth, alignment); return(Measure(processedText)); }
public void Print(string text, QFontAlignment alignment = QFontAlignment.Left) { PrintOrMeasure(text, alignment, false); }
private SizeF PrintOrMeasure(string text, QFontAlignment alignment, bool measureOnly) { var popRequired = false; if (!measureOnly && !ProjectionStack.Begun && Options.TransformToViewport != null) { GL.PushMatrix(); popRequired = true; GL.Scale(1 / fontData.scaleDueToTransformToViewport, 1 / fontData.scaleDueToTransformToViewport, 0); } float maxXpos = float.MinValue; float minXPos = float.MaxValue; if (!measureOnly) { GL.Color4(1.0f, 1.0f, 1.0f, 1.0f); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); if (Options.UseDefaultBlendFunction) { GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); } } float xOffset = 0f; float yOffset = 0f; text = text.Replace("\r\n", "\r"); if (alignment == QFontAlignment.Right) { xOffset -= MeasureNextlineLength(text); } else if (alignment == QFontAlignment.Centre) { xOffset -= (int)(0.5f * MeasureNextlineLength(text)); } for (int i = 0; i < text.Length; i++) { char c = text[i]; //newline if (c == '\r' || c == '\n') { yOffset += LineSpacing; xOffset = 0f; if (alignment == QFontAlignment.Right) { xOffset -= MeasureNextlineLength(text.Substring(i + 1)); } else if (alignment == QFontAlignment.Centre) { xOffset -= (int)(0.5f * MeasureNextlineLength(text.Substring(i + 1))); } } else { minXPos = Math.Min(xOffset, minXPos); //normal character if (c != ' ' && fontData.CharSetMapping.ContainsKey(c)) { QFontGlyph glyph = fontData.CharSetMapping[c]; if (!measureOnly) { RenderGlyph(xOffset, yOffset, c, false); } } if (IsMonospacingActive) { xOffset += MonoSpaceWidth; } else { if (c == ' ') { xOffset += (float)Math.Ceiling(fontData.meanGlyphWidth * Options.WordSpacing); } //normal character else if (fontData.CharSetMapping.ContainsKey(c)) { QFontGlyph glyph = fontData.CharSetMapping[c]; xOffset += (float)Math.Ceiling(glyph.rect.Width + fontData.meanGlyphWidth * Options.CharacterSpacing + fontData.GetKerningPairCorrection(i, text, null)); } } maxXpos = Math.Max(xOffset, maxXpos); } } float maxWidth = 0f; if (minXPos != float.MaxValue) { maxWidth = maxXpos - minXPos; } if (popRequired) { GL.PopMatrix(); } return(new SizeF(maxWidth, yOffset + LineSpacing)); }
/// <summary> /// Creates node list object associated with the text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <returns></returns> public static ProcessedText ProcessText(QFont font, QFontRenderOptions options, string text, SizeF maxSize, QFontAlignment alignment) { //TODO: bring justify and alignment calculations in here maxSize.Width = TransformWidthToViewport(maxSize.Width, options); var nodeList = new TextNodeList(text); nodeList.MeasureNodes(font.FontData, options); //we "crumble" words that are two long so that that can be split up var nodesToCrumble = new List <TextNode>(); foreach (TextNode node in nodeList) { if ((!options.WordWrap || node.Length >= maxSize.Width) && node.Type == TextNodeType.Word) { nodesToCrumble.Add(node); } } foreach (TextNode node in nodesToCrumble) { nodeList.Crumble(node, 1); } //need to measure crumbled words nodeList.MeasureNodes(font.FontData, options); var processedText = new ProcessedText(); processedText.textNodeList = nodeList; processedText.maxSize = maxSize; processedText.alignment = alignment; return(processedText); }
/// <summary> /// Creates node list object associated with the text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <returns></returns> public ProcessedText ProcessText(string text, SizeF maxSize, QFontAlignment alignment) { //TODO: bring justify and alignment calculations in here maxSize.Width = TransformWidthToViewport(maxSize.Width); var nodeList = new TextNodeList(text); nodeList.MeasureNodes(fontData, Options); //we "crumble" words that are two long so that that can be split up var nodesToCrumble = new List<TextNode>(); foreach (TextNode node in nodeList) if ((!Options.WordWrap || node.Length >= maxSize.Width) && node.Type == TextNodeType.Word) nodesToCrumble.Add(node); foreach (var node in nodesToCrumble) nodeList.Crumble(node, 1); //need to measure crumbled words nodeList.MeasureNodes(fontData, Options); var processedText = new ProcessedText(); processedText.textNodeList = nodeList; processedText.maxSize = maxSize; processedText.alignment = alignment; return processedText; }
public SizeF Print(string text, Vector3 position, QFontAlignment alignment, Color color, Rectangle clippingRectangle = default(Rectangle)) { this.Options.Colour = color; PrintOffset = TransformToViewport(position); return(PrintOrMeasure(text, alignment, false, clippingRectangle)); }
public static void Draw(QFont font, string text, QFontAlignment alignment, Vector2 position) { position.Y -= font.Measure(text, alignment).Height / 2; font.Options.UseDefaultBlendFunction = false; font.Print(text, alignment, position); }