public MultiLineTextBox(string name, IWidgetStyle style) : base(name, Docking.Fill, style) { m_Font = SummerGUIWindow.CurrentContext.FontManager.MonoFont; RowManager = new MultiLineTextManager(this, SpecialCharacterFlags.All); UndoRedoManager = new UndoRedoStack(this, 100); CursorOptions = CursorFlags.Default; CanFocus = true; HideSelection = true; AutoScroll = true; ScrollBars = ScrollBars.Vertical; VScrollBar.SetColorScheme(ScrollBarColorSchemes.Dark); Padding = new Padding(Font.Height, Font.LineHeight / 2); CursorPen = new Pen(Theme.Colors.White, 1.5f); BreakWidthRulerVisible = true; RowManager.LoadingCompleted += delegate { RowManager.MoveHome(); ScrollOffsetX = 0; ScrollOffsetY = 0; IsLoading = false; OnEnabledChanged(); RowManager.Paragraphs.UpdateCompleted += delegate { try { EnsureCurrentRowVisible(); Invalidate(1); } catch (Exception ex) { ex.LogError(); } }; }; }
public void ParseString(string line, IGUIFont font, SpecialCharacterFlags flags) { if (font == null) { this.LogError("ParseString: font must not be null"); return; } if (line != null) { for (int i = 0; i < line.Length; i++) { char c = line [i]; if (c != '\n') { AppendChar(c, font, flags); } } } // Ensure that we end up with a line-break, no matter what the string is AppendChar('\n', font, flags); if (BreakWidth > font.Height * 2) { WordWrap(); } }
public TextWidget(string name, Docking dock, IWidgetStyle style, string text, IGUIFont font) : base(name, dock, style) { this.m_Padding = new Padding(3); this.HAlign = Alignment.Near; this.VAlign = Alignment.Center; if (text == null) { m_Text = String.Empty; } else { m_Text = text; } if (font == null) { m_Font = SummerGUIWindow.CurrentContext.FontManager.DefaultFont; } else { m_Font = font; } m_IconFont = SummerGUIWindow.CurrentContext.FontManager.SmallIcons; Format = FontFormat.DefaultSingleLineCentered; CanFocus = false; }
protected override void OnParentChanged() { if (!IsDisposed) { if (Parent != null) { if (Font == null && ReflectionUtils.HasProperty(Parent.GetType(), "Font")) { Font = ReflectionUtils.GetPropertyValue(Parent.GetType(), "Font") as IGUIFont; } if (IconFont == null && ReflectionUtils.HasProperty(Parent.GetType(), "IconFont")) { IconFont = ReflectionUtils.GetPropertyValue(Parent.GetType(), "IconFont") as IGUIFont; } } if (Font == null) { this.SetFontByTag(CommonFontTags.Default); } if (IconFont == null) { this.SetIconFontByTag(CommonFontTags.SmallIcons); } } base.OnParentChanged(); }
const int minextra = 31; // minimum extra space to reserve /// <summary> /// This will reserve some extra free space for fast subsequent appends /// </summary> /// <returns><c>true</c>, if char was appended, <c>false</c> otherwise.</returns> /// <param name="c">The character to append</param> /// <param name="font">Font.</param> /// <param name="flags">Flags.</param> public int Append(char c, IGUIFont font, SpecialCharacterFlags flags = SpecialCharacterFlags.None) { if (c == '\r' || font == null) { return(0); } GlyphChar g = font.GetGlyph(c, flags); if (g.Glyph > 0) { try { int idx = 0; if (Length == 0) { m_Glyphs = new GlyphChar[++Length]; } else { idx = Length++; if (idx >= m_Glyphs.Length) { Array.Resize(ref m_Glyphs, idx + Math.Max(minextra, Length / 3)); } } Glyphs[idx] = g; Width += g.Width; return(1); } catch (Exception ex) { ex.LogError(); } } return(0); }
public void ParseString(string text, IGUIFont font, SpecialCharacterFlags flags = SpecialCharacterFlags.None) { Length = 0; GlyphChar[] tmp = null; if (!String.IsNullOrEmpty(text) && font != null) { tmp = new GlyphChar[text.Length]; int w = 0; for (int i = 0; i < text.Length; i++) { GlyphChar g = font.GetGlyph(text [i], flags); w += g.Width; tmp [i] = g; } Width = w; Length = text.Length; } if (tmp == null) { tmp = new GlyphChar[0]; } if (m_Glyphs == null) // called from constructor { m_Glyphs = tmp; } else { Concurrency.LockFreeUpdate(ref m_Glyphs, tmp); } }
public Graph2DPlotter(string name) : base(name, Docking.Fill, new Graph2DPlotterStyle()) { // this.Cursor = Cursors.Cross; Font = SummerGUIWindow.CurrentContext.FontManager.DefaultFont; m_CenterPoint.X = 0; m_CenterPoint.Y = 0; PlotMargin = 8; PointRadius = 6f; DefaultCurveWidth = 3f; AxisWidth = 1.5f; xRange = 20; yRange = 20; ZoomX = 1.0; ZoomY = 1.0; Graphs = new GraphList(); CanFocus = true; //timer_catch = new System.Windows.Forms.Timer(); //timer_catch.Interval = 50; //timer_catch.Tick += new EventHandler(timer_catch_Tick); //Thread caretThread = new Thread(new ThreadStart(ShowCaret)); //caretThread.Start(); }
public void InitFont(GUIFontConfiguration config) { if (config == null) { throw new ArgumentNullException("config"); } if (String.IsNullOrEmpty(config.Tag)) { throw new ArgumentException("config.Tag must not be null or empty."); } if (Fonts.ContainsKey(config.Tag)) { this.LogWarning("Font was already loaded: {0}", config.Tag); return; } config.ScaleFactor = Owner.ScaleFactor; IGUIFont font = null; if (!String.IsNullOrEmpty(config.Path)) { font = FontManager.CreateFont(config); if (font == null) { this.LogWarning("Failed to load font: {0}", config.Tag); } } // Add even when font is null, which means: loading failed Fonts.Add(config.Tag, font); }
public ComponentToolBar(string name, IGuiMenu menu) : base(name, menu, new ComponentToolBarStyle()) { Font = SummerGUIWindow.CurrentContext.FontManager.DefaultFont; Margin = Padding.Empty; Padding = new Padding(5, 1, 5, 1); }
public override void OnPaint(IGUIContext ctx, RectangleF bounds) { base.OnPaint(ctx, bounds); bounds.Offset(Padding.Left, Padding.Top); int lineHeight = RowManager.LineHeight; int offsetY = (int)ScrollOffsetY; int rowIndex = RowManager.FirstParagraphOnScreen; IGUIFont font = RowManager.Font; try { while (rowIndex < RowManager.Paragraphs.Count) { Paragraph para = RowManager.Paragraphs[rowIndex]; Rectangle rowBounds = new Rectangle((int)bounds.Left + (int)ScrollOffsetX, (int)(bounds.Top + para.Top + offsetY), (int)bounds.Width, lineHeight); var glyphLines = para.ToGlyphs(); foreach (var line in glyphLines) { if (rowBounds.Bottom > bounds.Top) { font.Begin(ctx); font.PrintTextLine(line.Select(g => g.Glyph).ToArray(), rowBounds, Style.ForeColorBrush.Color); font.End(); } rowBounds.Offset(0, lineHeight); if (rowBounds.Top > bounds.Bottom) { break; } } if (rowBounds.Top > bounds.Bottom) { break; } rowIndex++; } if (CursorOn && CursorVisible) { RectangleF CursorRectangle = RowManager.CalcCursorRectangle(); int x = Math.Max((int)bounds.Left + 1, (int)(CursorRectangle.X + bounds.Left + ScrollOffsetX + 0.5f)); float y1 = CursorRectangle.Top + bounds.Top + ScrollOffsetY + 2; float y2 = y1 + CursorRectangle.Height - 4; ctx.DrawLine(CursorPen, x, y1, x, y2); } } catch (Exception ex) { ex.LogError(); } }
public int Insert(int index, string text, IGUIFont font, SpecialCharacterFlags flags = SpecialCharacterFlags.None) { if (String.IsNullOrEmpty(text)) { return(0); } // we must handle 3 cases: // (1) insert at index 0, same implementation as (2) would lead to array-copy errors // (2) insert in the middle // (3) append at the end, same as with (1) if (index >= Length) { return(Append(text, font, flags)); } List <GlyphChar> glyphs = new List <GlyphChar> (text.Length); for (int i = 0; i < text.Length; i++) { GlyphChar g = font.GetGlyph(text [i], flags); if (g.Glyph != 0) { glyphs.Add(g); } } if (glyphs.Count == 0) { return(0); } GlyphChar[] source = glyphs.ToArray(); int sourceLen = source.Length; int newLen = Glyphs.Length + sourceLen + 1; GlyphChar[] arr = new GlyphChar[newLen]; if (index <= 0) { Array.Copy(source, arr, sourceLen); Array.Copy(Glyphs, 0, arr, sourceLen, Length); } else { Array.Copy(Glyphs, 0, arr, 0, index); Array.Copy(source, index, arr, 0, sourceLen); Array.Copy(Glyphs, index + sourceLen, arr, index, Length - index); } Length += sourceLen; Width += source.Sum(p => p.Width); return(sourceLen); }
public CircleSlider(string name, ColorContexts context) : base(name, Docking.Fill, new CircleSliderWidgetStyle()) { ColorContext = context; Styles.SetStyle(new CircleSliderDisabledWidgetStyle(), WidgetStates.Disabled); Font = SummerGUIWindow.CurrentContext.FontManager.DefaultFont; Radius = 48; //Padding = new Padding (3); }
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 int Append(string text, IGUIFont font, SpecialCharacterFlags flags = SpecialCharacterFlags.None) { int result = 0; for (int i = 0; i < text.Length; i++) { result += Append(text [i], font, flags); } return(result); }
public SizeF MeasureMnemonicString(string fontTag, string text) { IGUIFont font = FontByTag(fontTag); if (font == null) { return(SizeF.Empty); } return(font.MeasureMnemonicString(text)); }
public SizeF Measure(string fontTag, string text, int start = 0, int len = -1) { IGUIFont font = FontByTag(fontTag); if (font == null) { return(SizeF.Empty); } return(font.Measure(text, start, len)); }
public void RefreshGlyphs(IGUIFont font, SpecialCharacterFlags flags) { GlyphList glyphs = new GlyphList(); foreach (GlyphChar g in Glyphs) { glyphs.AddLast(font.GetGlyph(g.Char, flags)); } Concurrency.LockFreeUpdate(ref m_Glyphs, glyphs); NeedsWordWrap = true; }
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 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, }); }
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 int Insert(int index, char c, IGUIFont font, SpecialCharacterFlags flags = SpecialCharacterFlags.None) { if (c == '\r' || font == null) { return(0); } // we must handle 3 cases: // (1) insert at index 0, same implementation as (2) would lead to array-copy errors // (2) insert in the middle // (3) append at the end, same as with (1) if (index >= Length) { return(Append(c, font, flags)); } // first see, if we get a valid Glyph GlyphChar glyph = font.GetGlyph(c, flags); if (glyph.Glyph == 0) { return(0); } int newLen = Glyphs.Length; if (Length + 1 >= newLen) { newLen += minextra; } GlyphChar[] arr = new GlyphChar[newLen]; if (index <= 0) { Array.Copy(Glyphs, arr, 1); Glyphs [0] = glyph; } else { Array.Copy(Glyphs, 0, arr, 0, index); Glyphs [index] = glyph; Array.Copy(Glyphs, index + 1, arr, index, Length - index); } Length++; Width += glyph.Width; return(1); }
public bool InsertChar(int pos, char c, IGUIFont font, SpecialCharacterFlags flags) { GlyphChar g = font.GetGlyph(c, flags); if (g.Glyph > 0) { try { Glyphs.InsertAt(pos, g); NeedsWordWrap = true; return(true); } catch (Exception ex) { ex.LogError(); } } return(false); }
public bool AppendChar(char c, IGUIFont font, SpecialCharacterFlags flags) { GlyphChar g = font.GetGlyph(c, flags); if (g.Glyph > 0) { try { Glyphs.AddLast(g); NeedsWordWrap = true; return(true); } catch (Exception ex) { ex.LogError(); } } return(false); }
public IGUIFont FontByTag(string tag) { IGUIFont font = null; while (font == null) { if (String.IsNullOrEmpty(tag)) { tag = CommonFontTags.Default.ToString(); } if (Fonts.TryGetValue(tag, out font)) { if (font == null) { GUIFontConfiguration config; if (FontConfigs.TryGetValue(tag, out config)) { tag = config.FallbackTag; } } } else { GUIFontConfiguration config; if (FontConfigs.TryGetValue(tag, out config)) { try { InitFont(config); } catch (Exception ex) { ex.LogError(); if (tag == CommonFontTags.Default.ToString()) { break; } tag = null; } } else { tag = null; } } } return(font); }
public override void Flush() { if (Count > 0) { using (new PaintWrapper(RenderingFlags.HighQuality)) { IGUIFont lastInitializedFont = null; //GL.Scale ((float)GFX.OriginalWidth / GFX.Width, (float)GFX.OriginalHeight / GFX.Height, 1); //foreach (StringDrawingBufferRow row in this) { while (Count > 0) { StringDrawingBufferRow row = Queue.Dequeue(); if (row.Font != null) { if (row.Font != lastInitializedFont) { if (lastInitializedFont != null) { lastInitializedFont.End(); } row.Font.Begin(GFX); lastInitializedFont = row.Font; } /*** * GL.PushMatrix(); * GL.Translate(row.Rect.Left, row.Rect.Top, 0); * row.Font.Print(row.Text, row.Rect, FontFormat.DefaultSingleLine); * GL.PopMatrix(); ***/ row.Font.Print(row.Text, row.Rect, FontFormat.DefaultSingleLine); } } if (lastInitializedFont != null) { lastInitializedFont.End(); } } } }
public void PrintTextLine(IGUIContext ctx, string fontTag, uint[] glyphs, RectangleF bounds, Color foreColor) { IGUIFont font = FontByTag(fontTag); if (font == null) { return; } font.Begin(ctx); try { font.PrintTextLine(glyphs, bounds, foreColor); } catch (Exception ex) { ex.LogError(); } 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(); } }
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 MenuBar(string name, IGuiMenu menu) : base(name, Docking.Top, new MenuBarStyle()) { IsMenu = true; Menu = menu; Dock = Docking.Top; ZIndex = 5000; Padding = new Padding(8, 3, 8, 3); Styles.SetStyle(new MenuBarActiveStyle(), WidgetStates.Active); Styles.SetStyle(new MenuBarDisabledStyle(), WidgetStates.Disabled); Styles.SetStyle(new MenuBarSelectedStyle(), WidgetStates.Selected); //Font = SummerGUIWindow.CurrentContext.FontManager.DefaultFont; Font = SummerGUIWindow.CurrentContext.FontManager.StatusFont; IconFont = SummerGUIWindow.CurrentContext.FontManager.SmallIcons; CanFocus = false; TabIndex = -1; }
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); }