public override void OnPaint(IGUIContext ctx, RectangleF bounds) { base.OnPaint(ctx, bounds); RectangleF paddingBounds = PaddingBounds; float y = paddingBounds.Top + (paddingBounds.Height / 2f); //ctx.DrawLine (Theme.Pens.Red, paddingBounds.Left, y, paddingBounds.Right, y); Point p = BoxAlignment.AlignBoxes(paddingBounds, bounds, Format, Font.Ascender, Font.Descender); y = p.Y; ctx.DrawLine(Theme.Pens.Red, paddingBounds.Left, y, paddingBounds.Right, y); ctx.DrawString(Text, Font, Style.ForeColorBrush, bounds, Format); }
public void PrintTextLine(uint[] glyphs, RectangleF bounds, Color foreColor) { if (glyphs == null) { return; } GL.Color3(foreColor); RectangleF rContent; PointF presult; rContent = new RectangleF(0, 0, bounds.Width, Height); presult = BoxAlignment.AlignBoxes(rContent, bounds, FontFormat.DefaultSingleLine, Ascender, Descender); GL.Translate(Math.Floor(bounds.X + presult.X), -Math.Ceiling(Ascender - Descender + YOffsetScaled + bounds.Y + presult.Y), 0f); GL.CallLists(glyphs.Length, ListNameType.Int, glyphs); }
public SizeF Print(string text, RectangleF bounds, FontFormat format, Color color = default(Color)) { if (this.IsDisposed || string.IsNullOrEmpty(text)) { return(SizeF.Empty); } try { RectangleF rContent; PointF presult; // Abkürzung, häufigster Fall if (format.HAlign == Alignment.Near && !format.HasFlag(FontFormatFlags.WrapText)) { rContent = new RectangleF(0, 0, bounds.Width, bounds.Height); float y = 0; if (bounds.Height > this.Height) { switch (format.VAlign) { case Alignment.Near: y = 0; break; case Alignment.Center: y = (bounds.Height - Height) / 2; break; case Alignment.Baseline: y = (bounds.Height - (Height + Descender)) / 2; break; case Alignment.Far: y = bounds.Height - Height; break; } } //presult = new Point (0, (int)(y + 0.5f)); presult = new Point(0, y.Ceil()); } else { SizeF contentSize; if (format.HasFlag(FontFormatFlags.WrapText)) { contentSize = Measure(text, bounds.Width, format); } else if (format.HasFlag(FontFormatFlags.Mnemonics)) { contentSize = MeasureMnemonicString(text); } else { contentSize = Measure(text); } rContent = new RectangleF(0, 0, contentSize.Width, contentSize.Height); presult = BoxAlignment.AlignBoxes(rContent, bounds, format, Ascender, Descender); } if (color != Color.Empty) { GL.Color3(color.R, color.G, color.B); } else { GL.Color3(Theme.Colors.Base03); } GL.Translate(Math.Floor(bounds.X + presult.X), -Math.Ceiling(Ascender - Descender + YOffsetScaled + bounds.Y + presult.Y), 0f); if (format.HasFlag(FontFormatFlags.Elipsis) || format.HasFlag(FontFormatFlags.Underline)) { return(PrintElipsisString(text, bounds.Width, format)); } else if (format.HasFlag(FontFormatFlags.Mnemonics)) { return(PrintMenomicString(text, bounds, ModifierKeys.AltPressed)); } else if (format.HasFlag(FontFormatFlags.WrapText)) { return(PrintMultiline(text, bounds.Width)); } else { return(PrintInternal(text)); } } catch (Exception ex) { ex.LogError(); return(SizeF.Empty); } }
public SizeF PrintSelectedString(string text, int selStart, int selLength, RectangleF bounds, float offsetX, FontFormat format, Color foreColor, Color selectionBackColor, Color selectionForeColor) { if (string.IsNullOrEmpty(text)) { return(SizeF.Empty); } RectangleF rContent; PointF presult; SizeF contentSize; if (format.Flags.HasFlag(FontFormatFlags.WrapText)) { contentSize = Measure(text, bounds.Width, format); } else { contentSize = Measure(text); } rContent = new RectangleF(0, 0, contentSize.Width, contentSize.Height); presult = BoxAlignment.AlignBoxes(rContent, bounds, format, Ascender, Descender); GL.Color3(foreColor); GL.Translate(Math.Floor(bounds.X + presult.X + offsetX), -Math.Ceiling(Ascender - Descender + YOffsetScaled + bounds.Y + presult.Y), 0f); int[] textbytes; float w = 0; if (selLength == 0) { selStart = 0; } else { if (selStart > 0) { textbytes = new int[selStart]; for (int i = 0; i < selStart; i++) { GlyphInfo gi; if (GetGlyphIndex(text [i], out gi)) { w += gi.Width; textbytes [i] = gi.ListID; } } GL.CallLists(selStart, ListNameType.Int, textbytes); //GL.Translate (w, 0, 0); } selLength = Math.Min(selLength, text.Length - selStart); if (selLength > 0) { textbytes = new int[selLength]; float wStart = w; for (int i = selStart; i < selStart + selLength; i++) { GlyphInfo gi; if (GetGlyphIndex(text [i], out gi)) { w += gi.Width; textbytes [i - selStart] = gi.ListID; } } using (new PaintWrapper(RenderingFlags.HighQuality)) { GL.Color4(selectionBackColor); GL.Rect(bounds.Left + wStart + offsetX, bounds.Top, bounds.Left + w + offsetX, bounds.Bottom); } //GL.ListBase(m_ListBase); GL.Enable(EnableCap.Texture2D); // doesn't work on windows computers with ATI card //GL.Enable(EnableCap.TextureRectangle); GL.Color3(selectionForeColor); GL.CallLists(selLength, ListNameType.Int, textbytes); } } int start = selStart + selLength; int len = text.Length - start; if (len > 0) { textbytes = new int[len]; for (int i = start; i < text.Length; i++) { GlyphInfo gi; if (GetGlyphIndex(text [i], out gi)) { textbytes [i - start] = gi.ListID; } } GL.Color3(foreColor); GL.CallLists(len, ListNameType.Int, textbytes); } return(new SizeF(w, Height)); }