/*** * public MultiLineTextWidget (string name, string text = null) * : this(name, text, new DefaultTextWidgetStyle()) * { * } ***/ public MultiLineTextWidget(string name, string text = null, IWidgetStyle style = null) : base(name, Docking.Fill, style) { Text = text; this.SetFontByTag(CommonFontTags.Default); m_Format = FontFormat.DefaultMultiLine; }
public SizeF Measure(string fontTag, string text, float width, FontFormat format) { IGUIFont font = FontByTag(fontTag); if (font == null) { return(SizeF.Empty); } return(font.Measure(text, width, format)); }
public UrlTextWidget(string name, string url) : base(name, Docking.Fill, new UrlTextWidgetStyle(), null, null) { Text = url; m_Url = url; Format = new FontFormat(Alignment.Near, Alignment.Center, FontFormatFlags.Elipsis); Styles.SetStyle(new DisabledTextWidgetStyle(), WidgetStates.Disabled); Styles.SetStyle(new UrlTextWidgetPressedStyle(), WidgetStates.Pressed); CanFocus = true; }
public override void OnMouseEnter(IGUIContext ctx) { if (Enabled) { Format = new FontFormat(Alignment.Near, Alignment.Center, FontFormatFlags.Elipsis | FontFormatFlags.Underline); } else { Format = new FontFormat(Alignment.Near, Alignment.Center, FontFormatFlags.Elipsis); } base.OnMouseEnter(ctx); }
public FontAlignmentTestWidget() : base("test", Docking.Fill, new WidgetStyle()) { Style.BackColorBrush.Color = Color.Lime; Text = "AbcdefghijklmnOPQrstUVwxyz"; Margin = Padding.Empty; Padding = Padding.Empty; //Padding = new Padding(16); Font = SummerGUIWindow.CurrentContext.FontManager.DefaultFont; Format = new FontFormat(Alignment.Center, Alignment.Center, FontFormatFlags.None); }
/// <summary> /// Return the upper-left corner /// </summary> /// <returns>The boxes.</returns> /// <param name="rContent">R content.</param> /// <param name="rBoundingBox">R bounding box.</param> /// <param name="SF">S.</param> /// <param name="Ascender">Ascender.</param> /// <param name="Descender">Descender.</param> public static Point AlignBoxes(RectangleF rContent, RectangleF rBoundingBox, FontFormat SF, float Ascender, float Descender) { if (rContent.Equals(Rectangle.Empty) || rBoundingBox.Equals(Rectangle.Empty)) { return(Point.Empty); } float x = 0; float y = 0; switch (SF.HAlign) { case Alignment.Near: //x = 0; break; case Alignment.Center: x = Math.Max(0, (rBoundingBox.Width - rContent.Width) / 2f); break; case Alignment.Far: x = rBoundingBox.Width - rContent.Width; break; } switch (SF.VAlign) { case Alignment.Near: //y = 0; break; case Alignment.Center: y = Math.Max(0, (rBoundingBox.Height - rContent.Height) / 2); break; case Alignment.Baseline: y = Math.Max(0, (rBoundingBox.Height - (rContent.Height + Descender)) / 2); break; case Alignment.Far: y = rBoundingBox.Height - rContent.Height; break; } //return new Point ((int)(x + 0.5f), (int)(y + 0.5f)); return(new Point(x.Ceil(), y.Ceil())); }
public MonthCalendar(string name, IGUIFont dayFont, IGUIFont titleFont) : base(name, Docking.Fill, new MonthCalendarStyle()) { m_Weekdays = new string[7]; for (int i = 0; i < 7; i++) { m_Weekdays [i] = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedDayName((DayOfWeek)i); } DayFont = dayFont; TitleFont = titleFont; this.SetIconFontByTag(CommonFontTags.SmallIcons); Format = new FontFormat(Alignment.Center, Alignment.Center, FontFormatFlags.Elipsis); this.Padding = new Padding(8); Timer = new TaskTimer(150, TimerAction, 500); MinCircleRadius = DayFont.Measure("0").Height * 0.75f; MaxCircleRadius = MinCircleRadius * 1.5f; ShowDate(); }
public override SizeF PreferredSize(IGUIContext ctx, SizeF proposedSize) { if (CachedPreferredSize == SizeF.Empty) { if (Font == null || Text == null) { return(base.PreferredSize(ctx, proposedSize)); } else { //SizeF sz = Font.Measure (Text, proposedSize.Width - Padding.Width, FontFormat.DefaultMultiLine); if (!formatUserSet) { m_Format = new FontFormat(HAlign, VAlign, FontFormatFlags.WrapText); } SizeF sz = Font.Measure(Text, proposedSize.Width - Padding.Width, Format); CachedPreferredSize = new SizeF(sz.Width + Padding.Width, sz.Height + Padding.Height); } } return(CachedPreferredSize); }
public static SizeF DrawSelectedString(this IGUIContext ctx, string text, IGUIFont font, int selStart, int selLength, RectangleF rect, float offsetX, FontFormat format, Color foreColor, Color selectionBackColor, Color selectionForeColor) { if (ctx == null || text == null) { return(SizeF.Empty); } SizeF retVal; font.Begin(ctx); retVal = font.PrintSelectedString(text, selStart, selLength, rect, offsetX, format, foreColor, selectionBackColor, selectionForeColor); font.End(); return(retVal); }
public static SizeF DrawString(this IGUIContext ctx, string text, IGUIFont font, Brush brush, RectangleF rect, FontFormat format) { if (ctx == null || text == null) { return(SizeF.Empty); } SizeF retVal; Color c = Color.Empty; if (brush != null) { c = brush.Color; } font.Begin(ctx); retVal = font.Print(text, rect, format, c); font.End(); return(retVal); }
public static SizeF DrawSelectedString(this IGUIContext ctx, string text, string fontTag, int selStart, int selLength, RectangleF bounds, float offsetX, FontFormat format, Color foreColor, Color selectionBackColor, Color selectionForeColor) { return(ctx.FontManager.PrintSelectedString(ctx, fontTag, text, selStart, selLength, bounds, offsetX, format, foreColor, selectionBackColor, selectionForeColor)); }
public static SizeF DrawString(this IGUIContext ctx, string text, IGUIFont font, Brush brush, float x, float y, FontFormat format) { if (ctx == null) { return(SizeF.Empty); } SizeF contentSize = font.Measure(text); switch (format.HAlign) { case Alignment.Near: break; case Alignment.Center: x -= contentSize.Width / 2f; break; case Alignment.Far: x -= contentSize.Width; break; } // ToDo: Was soll das hier noch ? switch (format.VAlign) { case Alignment.Near: y -= contentSize.Height / 2f; break; case Alignment.Center: y += contentSize.Height / 2f; break; case Alignment.Far: case Alignment.Baseline: y += contentSize.Height / 2; break; } SizeF retVal; font.Begin(ctx); Color c = Color.Empty; if (brush != null) { c = brush.Color; } retVal = font.Print(text, new RectangleF(x, y, contentSize.Width, contentSize.Height), format, c); font.End(); return(retVal); }
/*** ***/ public static SizeF DrawString(this IGUIContext ctx, string text, string fontTag, Color color, RectangleF bounds, FontFormat format) { return(ctx.FontManager.Print(ctx, fontTag, text, bounds, format, color)); }
public static SizeF DrawString(this IGUIContext ctx, string text, string fontTag, Brush brush, PointF point, FontFormat format) { Color c = Color.Empty; if (brush != null) { c = brush.Color; } return(ctx.FontManager.Print(ctx, text, fontTag.ToString(), new RectangleF(point, SizeF.Empty), format, c)); }
public static SizeF DrawString(this IGUIContext ctx, string text, IGUIFont font, Brush brush, PointF point, FontFormat format) { return(DrawString(ctx, text, font, brush, point.X, point.Y, format)); }
public void AddString(string text, IGUIFont font, Brush brush, System.Drawing.Rectangle rect, FontFormat sf) { //System.Drawing.SizeF contentSize = font.Measure( text, (float)rect.Width, FontFormat.DefaultSingleLine); //System.Drawing.RectangleF rContent = new System.Drawing.RectangleF (0, 0, contentSize.Width, contentSize.Height); //System.Drawing.PointF presult = BoxAlignment.AlignBoxes (rContent, rect, sf); Queue.Enqueue(new StringDrawingBufferRow { Font = font, Brush = brush, Text = text, Rect = rect, }); }
private SizeF PrintElipsisString(string text, float width, FontFormat format) { if (String.IsNullOrEmpty(text)) { return(SizeF.Empty); } const int rightDotDistance = 2; int[] textbytes = new int[text.Length]; float adv = 0; int i; int len = text.Length; for (i = 0; i < len; i++) { GlyphInfo gi; if (GetGlyphIndex(text [i], out gi)) { if (adv + gi.Width > width && i > 0) { try { // add ellipsis character to where it fits float desiredSpace = m_EllipsisGlyphIndex.Width + (rightDotDistance * ScaleFactor); i--; while (i > 1 && adv + desiredSpace > width) { if (GetGlyphIndex(text [i], out gi)) { adv -= gi.Width; } i--; } textbytes [i] = m_EllipsisGlyphIndex.ListID; adv += m_EllipsisGlyphIndex.Width; i++; } catch (Exception ex) { ex.LogError(); } break; } adv += gi.Width; textbytes [i] = gi.ListID; } } GL.CallLists(i, ListNameType.Int, textbytes); if (format.HasFlag(FontFormatFlags.Underline)) { float y = -3f * ScaleFactor; // ToDo: DPI Scaling GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.Texture1D); GL.Disable(EnableCap.TextureRectangle); GL.LineWidth(1f * ScaleFactor); // ToDo: DPI Scaling GL.Begin(PrimitiveType.Lines); GL.Vertex2(0, y); GL.Vertex2(-adv + 0.5f, y); GL.End(); } if (i < len) { return(new SizeF(width + 1, Height)); } else { return(new SizeF(adv, Height)); } }
public SizeF Print(IGUIContext ctx, CommonFontTags fontTag, string text, RectangleF bounds, FontFormat format, Color color = default(Color)) { return(Print(ctx, fontTag.ToString(), text, bounds, format, color)); }
public static SizeF MeasureString(this IGUIContext ctx, string text, string fontTag, RectangleF rect, FontFormat format) { return(ctx.FontManager.Measure(fontTag, text, rect.Width, format)); }
public override void OnMouseLeave(IGUIContext ctx) { Format = new FontFormat(Alignment.Near, Alignment.Center, FontFormatFlags.Elipsis); base.OnMouseLeave(ctx); }
public SizeF Measure(CommonFontTags fontTag, string text, float width, FontFormat format) { return(Measure(fontTag.ToString(), text, width, format)); }
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 Measure(string text, float width, FontFormat sf) { if (String.IsNullOrEmpty(text)) { return(SizeF.Empty); } float adv = 0; float maxAdv = 0; int lines = 1; GlyphInfo gi; int lastStopChar = 0; int maxStop = text.Length - 1; int i; int start = 0; for (i = start; i < text.Length; i++) { bool breakFlag = false; char c = text [i]; if (c == '\n') { breakFlag = true; lastStopChar = i; } else { if (IsBreakChar(c) && i < maxStop) { lastStopChar = i; } if (GetGlyphIndex(c, out gi)) { float a = gi.Width; if (adv + a > width && i > 0) { breakFlag = true; if (lastStopChar <= start) { adv = a; } } else { adv += a; } } } if (breakFlag) { maxAdv = Math.Max(maxAdv, adv); if (lastStopChar > start) { i = lastStopChar; start = i + 1; adv = 0; } else { start = i; } lastStopChar = 0; lines++; } } if (lines > 1) { return(new SizeF(Math.Max(maxAdv, adv), Height + (LineHeight * (lines - 1)))); } //return new SizeF (Math.Max (maxAdv, adv), LineHeight * lines); return(new SizeF(adv, Height)); }
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)); }
public static SizeF MeasureString(this IGUIContext ctx, string text, IGUIFont font, RectangleF rect, FontFormat format) { return(font.Measure(text, rect.Width, format)); }
public SizeF PrintSelectedString(IGUIContext ctx, CommonFontTags fontTag, string text, int selStart, int selLength, RectangleF bounds, float offsetX, FontFormat format, Color foreColor, Color selectionBackColor, Color selectionForeColor) { return(PrintSelectedString(ctx, fontTag.ToString(), text, selStart, selLength, bounds, offsetX, format, foreColor, selectionBackColor, selectionForeColor)); }
public SizeF Print(IGUIContext ctx, string fontTag, string text, RectangleF bounds, FontFormat format, Color color = default(Color)) { IGUIFont font = FontByTag(fontTag); if (font == null) { return(SizeF.Empty); } font.Begin(ctx); try { return(font.Print(text, bounds, format, color)); } catch (Exception ex) { ex.LogError(); return(SizeF.Empty); } finally { font.End(); } }
public SizeF PrintSelectedString(IGUIContext ctx, string fontTag, string text, int selStart, int selLength, RectangleF bounds, float offsetX, FontFormat format, Color foreColor, Color selectionBackColor, Color selectionForeColor) { IGUIFont font = FontByTag(fontTag); if (font == null) { return(SizeF.Empty); } font.Begin(ctx); try { return(font.PrintSelectedString(text, selStart, selLength, bounds, offsetX, format, foreColor, selectionBackColor, selectionForeColor)); } catch (Exception ex) { ex.LogError(); return(SizeF.Empty); } finally { font.End(); } }