public void DrawNodeLabel(string text, Font font, Color color, RectangleF rect, NodeModel node, int depth) { QFont qfont = GetQFont(font); float height = LabelHeight; if (Model.ViewLayout == LayoutType.TreeMap) { height = depth * LevelSize + GetNodeHeight(node); // put over call lines } if (SelectionMode != SelectionModes.None) { SelectionMap[node.ID] = node; color = Color.FromArgb((255 << 24) | node.ID); var textArea = qfont.Measure(text, rect.Size, QFontAlignment.Left); var normal = new Vector3(0, 1, 0); var v1 = new Vector3(rect.X, height, rect.Y); var v2 = new Vector3(rect.X, height, rect.Y + textArea.Height); var v3 = new Vector3(rect.X + textArea.Width, height, rect.Y + textArea.Height); var v4 = new Vector3(rect.X + textArea.Width, height, rect.Y); Nodes.AddVerticies(color, normal, v1, v2, v3, v1, v3, v4); } else { qfont.PrintToVBO(text, QFontAlignment.Left, new Vector3(rect.X, rect.Y, -height), color, rect.Size); } }
public static void DrawText(string text, QFont font, RectangleF bounds, StringAlignment vAlign, StringAlignment hAlign, QFontRenderOptions options) { if (!Freetype6Loaded) { return; } var textSize = font.Measure(text, bounds.Size, QFontAlignment.Left); textSize.Height += 2; var textPos = Vector2.Zero; switch (hAlign) { case StringAlignment.Near: textPos.X = bounds.X; break; case StringAlignment.Far: textPos.X = bounds.Right - textSize.Width; break; case StringAlignment.Center: textPos.X = bounds.Left + ((bounds.Width - textSize.Width) / 2f); break; } switch (vAlign) { case StringAlignment.Near: textPos.Y = bounds.Y; break; case StringAlignment.Far: textPos.Y = bounds.Y + bounds.Height - textSize.Height; break; case StringAlignment.Center: textPos.Y = bounds.Y + ((bounds.Height - textSize.Height) / 2f); break; } textPos.Y = ViewSize.Y - textPos.Y; var dp = new QFontDrawingPrimitive(font, options); dp.Print(text, new Vector3(textPos.X, textPos.Y, 0f), bounds.Size, QFontAlignment.Left); TextRenderer.DrawingPrimitives.Add(dp); }
void PrintCode(Graphics graphics, string code, ref double yOffset) { GraphicsState state = graphics.Save(); yOffset += 20; graphics.TranslateTransform(50f, yOffset); codeText.Print(code, Width - 50, QFontAlignment.Left); yOffset += codeText.Measure(code, Width - 50, QFontAlignment.Left).Height; graphics.Restore(state); }
void PrintComment(Graphics graphics, QFont font, string comment, QFontAlignment alignment, ref double yOffset) { GraphicsState state = graphics.Save(); yOffset += 20; graphics.TranslateTransform(30, yOffset); font.Print(comment, Width - 60, alignment); yOffset += font.Measure(comment, Width - 60, alignment).Height; graphics.Restore(state); }
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 override Point MeasureText(Font font, string text) { QFont sysQFont = font.RendererData as QFont; if (sysQFont == null || Math.Abs(font.RealSize - font.Size * Scale) > 2) { Debug.WriteLine("Refreshing font object"); FreeFont(font); LoadFont(font); sysQFont = font.RendererData as QFont; } var extra = sysQFont.MaxLineHeight - sysQFont.MaxGlyphHeight; if (extra < 0) { extra = 0; } bool found = false; QFontDrawingPrimitive qdp = null; Point s = Point.Empty; if (m_StringCache.Contains(text, font)) { found = true; //Debug.WriteLine("Measure Text Cache Hit"); qdp = m_StringCache.First(text, font); s = new Point((int)Math.Ceiling(qdp.LastSize.Width), (int)Math.Ceiling(qdp.LastSize.Height + extra)); } else { found = m_StringCache.GetMeasurement(text, font, out s); } if (found) { return(s); } SizeF size = sysQFont.Measure(text); Debug.WriteLine("Measure Text Cache Miss"); ////SizeF TabSize = m_Graphics.MeasureString("....", sysFont); //Spaces are not being picked up, let's just use .'s. ////m_StringFormat.SetTabStops(0f, new float[] { TabSize.Width }); s = new Point((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height + extra)); m_StringCache.AddMeasurement(text, font, s); return(Point.Empty); }
public static void DrawText(string text, QFont font, Color color, RectangleF bounds, StringAlignment vAlign = StringAlignment.Near, StringAlignment hAlign = StringAlignment.Near) { var textSize = font.Measure(text, bounds.Size, QFontAlignment.Left); textSize.Height += 2; var textPos = Vector2.Zero; switch (hAlign) { case StringAlignment.Near: textPos.X = bounds.X; break; case StringAlignment.Far: textPos.X = bounds.Right - textSize.Width; break; case StringAlignment.Center: textPos.X = bounds.Left + ((bounds.Width - textSize.Width) / 2f); break; } switch (vAlign) { case StringAlignment.Near: textPos.Y = bounds.Y; break; case StringAlignment.Far: textPos.Y = bounds.Y + bounds.Height - textSize.Height; break; case StringAlignment.Center: textPos.Y = bounds.Y + ((bounds.Height - textSize.Height) / 2f); break; } textPos.Y = ViewSize.Y - textPos.Y; var dp = new QFontDrawingPrimitive(font, new QFontRenderOptions() { Colour = color, LockToPixel = true }); dp.Print(text, new Vector3(textPos.X, textPos.Y, 0f), bounds.Size, QFontAlignment.Left); TextRenderer.DrawingPrimitives.Add(dp); }
void PrintCommentWithLine(Graphics graphics, QFont font, string comment, QFontAlignment alignment, double xOffset, ref double yOffset) { GraphicsState state = graphics.Save(); yOffset += 20; graphics.TranslateTransform((int)xOffset, yOffset); font.Print(comment, alignment); Size bounds = font.Measure(comment, Width - 60, alignment); graphics.DrawLine(m_LinesPen, 0, 0, 0, bounds.Height + 20); yOffset += bounds.Height; graphics.Restore(state); }
private void PrintWithBounds(QFont font, string text, RectangleF bounds, QFontAlignment alignment, ref float yOffset) { float maxWidth = bounds.Width; float height = font.Measure(text, new SizeF(maxWidth, -1), 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(); drawing.Print(font, text, new Vector3(bounds.X, Height - yOffset, 0), new SizeF(maxWidth, float.MaxValue), alignment); yOffset += height; }
static void PrintCommentWithLine(QFont font, string comment, QFontAlignment alignment, float xOffset, ref float yOffset, QFontRenderOptions opts) { yOffset += 20; var dp = new QFontDrawingPimitive(font, opts); //if (doSpacing) // dp.Options.CharacterSpacing = 0.05f; dp.Print(comment, new Vector3(xOffset, Height - yOffset, 0f), new SizeF(Width - 60, -1), alignment); drawing.DrawingPimitiveses.Add(dp); var bounds = font.Measure(comment, new SizeF(Width - 60, float.MaxValue), 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; }
/// <summary> /// Called when it is time to render the next frame. Add your rendering code here. /// </summary> /// <param name="e">Contains timing information.</param> void QuickFontControl_Paint(object sender, PaintEventArgs e) { Graphics graphics = e.Graphics; GraphicsState state; switch (currentDemoPage) { case 1: { double yOffset = 0; QFont.Begin(); state = graphics.Save(); graphics.TranslateTransform(Width * 0.5f, yOffset + 10); heading1.Print("AltGUI QuickFont", QFontAlignment.Centre); yOffset += heading1.Measure("QuickFont").Height; graphics.Restore(state); state = graphics.Save(); graphics.TranslateTransform(20f, yOffset); heading2.Print("Introduction", QFontAlignment.Left); yOffset += heading2.Measure("Introduction").Height; graphics.Restore(state); state = graphics.Save(); graphics.TranslateTransform(30f, yOffset + 20); mainText.Print(introduction, Width - 60, QFontAlignment.Justify); graphics.Restore(state); QFont.End(); } break; case 2: { double yOffset = 20; QFont.Begin(); state = graphics.Save(); graphics.TranslateTransform(20f, yOffset); heading2.Print("Easy as ABC!", QFontAlignment.Left); yOffset += heading2.Measure("Easy as ABC!").Height; graphics.Restore(state); PrintComment(graphics, usingQuickFontIsSuperEasy, ref yOffset); PrintCode(graphics, loadingAFont1, ref yOffset); PrintComment(graphics, andPrintWithIt, ref yOffset); PrintCode(graphics, printWithFont1, ref yOffset); PrintComment(graphics, itIsAlsoEasyToMeasure, ref yOffset); PrintCode(graphics, measureText1, ref yOffset); PrintComment(graphics, oneOfTheFirstGotchas, ref yOffset); PrintCode(graphics, loadingAFont2, ref yOffset); QFont.End(); } break; case 3: { double yOffset = 20; QFont.Begin(); state = graphics.Save(); graphics.TranslateTransform(20f, yOffset); heading2.Print("Alignment", QFontAlignment.Left); yOffset += heading2.Measure("Easy as ABC!").Height; graphics.Restore(state); PrintCommentWithLine(graphics, whenPrintingText, QFontAlignment.Left, Width * 0.5f, ref yOffset); PrintCode(graphics, printWithFont2, ref yOffset); PrintCommentWithLine(graphics, righAlignedText, QFontAlignment.Right, Width * 0.5f, ref yOffset); yOffset += 10f; PrintCommentWithLine(graphics, centredTextAsYou, QFontAlignment.Centre, Width * 0.5f, ref yOffset); QFont.End(); } break; case 4: { double yOffset = 20; QFont.Begin(); state = graphics.Save(); graphics.TranslateTransform(20f, yOffset); heading2.Print("Bounds and Justify", QFontAlignment.Left); yOffset += heading2.Measure("Easy as ABC!").Height; graphics.Restore(state); state = graphics.Save(); yOffset += 20; graphics.TranslateTransform((int)(Width * 0.5), yOffset); controlsText.Options.Colour = Color.Yellow; controlsText.Print("Press [Up], [Down] or [Enter]!", QFontAlignment.Centre); yOffset += controlsText.Measure("[]").Height; graphics.Restore(state); double boundShrink = (int)(350 * (1 - Math.Cos(boundsAnimationCnt * Math.PI * 2))); yOffset += 15; PrintWithBounds(graphics, mainText, ofCourseItsNot, new Rect(30f + boundShrink * 0.5f, yOffset, Width - 60 - boundShrink, 350f), cycleAlignment, ref yOffset); string printWithBounds = "myFont.Print(text, 400f, QFontAlignment." + cycleAlignment + ");"; yOffset += 15f; PrintCode(graphics, printWithBounds, ref yOffset); QFont.End(); } break; case 5: { double yOffset = 20; QFont.Begin(); state = graphics.Save(); graphics.TranslateTransform(20f, yOffset); heading2.Print("Your own Texture Fonts", QFontAlignment.Left); yOffset += heading2.Measure("T").Height; graphics.Restore(state); PrintComment(graphics, anotherCoolFeature, ref yOffset); PrintCode(graphics, textureFontCode1, ref yOffset); PrintComment(graphics, thisWillHaveCreated, ref yOffset); QFont.End(); } break; case 6: { double yOffset = 20; QFont.Begin(); state = graphics.Save(); graphics.TranslateTransform(20f, yOffset); heading2.Print("Your own Texture Fonts", QFontAlignment.Left); yOffset += heading2.Measure("T").Height; graphics.Restore(state); PrintComment(graphics, ifYouDoIntend, ref yOffset); PrintCode(graphics, textureFontCode2, ref yOffset); PrintComment(graphics, actuallyTexturing, ref yOffset); PrintCode(graphics, textureFontCode3, ref yOffset); QFont.End(); } break; case 7: { double yOffset = 20; QFont.Begin(); heading2.Options.DropShadowOffset = new Alt.Sketch.Vector2(0.1f + 0.2f * (float)Math.Sin(cnt), 0.1f + 0.2f * (float)Math.Cos(cnt)); state = graphics.Save(); graphics.TranslateTransform(20f, yOffset); heading2.Print("Drop Shadows", QFontAlignment.Left); yOffset += heading2.Measure("T").Height; graphics.Restore(state); heading2.Options.DropShadowOffset = new Alt.Sketch.Vector2(0.16f, 0.16f); //back to default mainText.Options.DropShadowActive = true; mainText.Options.DropShadowOpacity = 0.7f; mainText.Options.DropShadowOffset = new Alt.Sketch.Vector2(0.1f + 0.2f * (float)Math.Sin(cnt), 0.1f + 0.2f * (float)Math.Cos(cnt)); PrintComment(graphics, asIhaveleant, ref yOffset); PrintCode(graphics, dropShadowCode1, ref yOffset); PrintComment(graphics, thisWorksFine, ref yOffset); PrintCode(graphics, dropShadowCode2, ref yOffset); PrintComment(graphics, onceAFont, ref yOffset); mainText.Options.DropShadowActive = false; QFont.End(); } break; case 8: { double yOffset = 20; QFont.Begin(); monoSpaced.Options.CharacterSpacing = 0.05f; state = graphics.Save(); graphics.TranslateTransform(20f, yOffset); heading2.Print("Monospaced Fonts", QFontAlignment.Left); yOffset += heading2.Measure("T").Height; graphics.Restore(state); PrintComment(graphics, monoSpaced, hereIsSomeMono, QFontAlignment.Left, ref yOffset); PrintCode(graphics, monoCode1, ref yOffset); PrintComment(graphics, monoSpaced, theDefaultMono, QFontAlignment.Left, ref yOffset); PrintCommentWithLine(graphics, monoSpaced, mono, QFontAlignment.Left, Width * 0.5f, ref yOffset); yOffset += 2f; PrintCommentWithLine(graphics, monoSpaced, mono, QFontAlignment.Right, Width * 0.5f, ref yOffset); yOffset += 2f; PrintCommentWithLine(graphics, monoSpaced, mono, QFontAlignment.Centre, Width * 0.5f, ref yOffset); yOffset += 2f; monoSpaced.Options.CharacterSpacing = 0.5f; PrintComment(graphics, monoSpaced, "As usual, you can adjust character spacing with myFont.Options.CharacterSpacing.", QFontAlignment.Left, ref yOffset); QFont.End(); } break; case 9: { double yOffset = 20; QFont.Begin(); state = graphics.Save(); graphics.TranslateTransform(20f, yOffset); heading2.Print("In Conclusion", QFontAlignment.Left); yOffset += heading2.Measure("T").Height; graphics.Restore(state); PrintComment(graphics, thereAreActually, ref yOffset); QFont.End(); } break; } QFont.Begin(); Color pressColor = new ColorR(0.8, 0.2, 0.2);// new ColorR(0.8, 0.1, 0.1); if (currentDemoPage != lastPage) { state = graphics.Save(); graphics.TranslateTransform(Width - 15 - 16 * (float)(1 + Math.Sin(cnt * 4)), Height - controlsText.Measure("P").Height - 17); controlsText.Options.Colour = pressColor; controlsText.Print("Press [Right] ->", QFontAlignment.Right); graphics.Restore(state); } if (currentDemoPage != 1) { state = graphics.Save(); graphics.TranslateTransform(15 + 16 * (float)(1 + Math.Sin(cnt * 4)), Height - controlsText.Measure("P").Height - 17); controlsText.Options.Colour = pressColor; controlsText.Print("<- Press [Left]", QFontAlignment.Left); graphics.Restore(state); } QFont.End(); }