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 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; }
void ResetCachedData() { Concurrency.LockFreeUpdate(ref m_SortedVisibleColumns, Columns.SortedVisibleColumns.ToArray()); var lst = new BinarySortedList <float> (); float offset = 0; Columns.Where(col => col.Visible).ForEach(col => { lst.AddLast(offset); offset += col.Width; }); Concurrency.LockFreeUpdate(ref m_ColumnOffsets, lst); }
public void LoadTextAsync(string value, float breakWidth) { BreakWidth = breakWidth; if (value == null) { value = String.Empty; } Task.Factory.StartNew(() => { Stopwatch sw = Stopwatch.StartNew(); int index = 0; Paragraphs.Clear(); ParagraphList paragraphs = new ParagraphList(LineHeight, BreakWidth); char splitChar = AutoDetectLineBreakChar(value); if (!GroupParagraphs) { Strings.Split(value, splitChar).ForEach(line => paragraphs.AddLast(new Paragraph(index++, BreakWidth, line, Font, Flags)) ); } else { const string splitStr = "\r\n\r\n"; Strings.Split(value, splitStr).ForEach(line => { paragraphs.AddLast(new Paragraph(index++, BreakWidth, line.Replace("\n", " ") + "\n", Font, Flags)); paragraphs.AddLast(new Paragraph(index++, BreakWidth, "\n", Font, Flags)); }); } paragraphs.OnUpdate(); Concurrency.LockFreeUpdate(ref m_Paragraphs, paragraphs); this.LogVerbose("{0} characters of text in {1} paragraphs loaded into the editor in {2} ms.", value.Length.ToString("n0"), Paragraphs.Count.ToString("n0"), sw.ElapsedMilliseconds.ToString("n0")); }).ContinueWith((t) => { if (t.Status == TaskStatus.RanToCompletion) { if (Paragraphs.BreakWidth != BreakWidth) { Paragraphs.OnUpdateBreakWidthAsync(BreakWidth); } } }).ContinueWith((t) => { Owner.UndoRedoManager.Clear(); if (LoadingCompleted != null) { LoadingCompleted(this, EventArgs.Empty); } }); }
public void InvertSelection() { int rowCount = RowCount; HashSet <int> sel = new HashSet <int> (); for (int i = 0; i < rowCount; i++) { if (!m_SelectedRowIndices.Contains(i)) { sel.Add(i); } } Concurrency.LockFreeUpdate(ref m_SelectedRowIndices, sel); OnSelectionChanged(); }
public override void OnLayout(IGUIContext ctx, RectangleF bounds) { base.OnLayout(ctx, bounds); if (MenuDirtyFlag) { MenuDirtyFlag = false; Tree = null; var q = new Queue <IGuiMenuItem> (); Menu.ForEach(m => QueueDraw(m, 0, q)); //Queue = q; Concurrency.LockFreeUpdate(ref Queue, q); ItemCount = q.Count; } this.SetSize(Bounds.Width, ItemCount * LineHeight); }
public override void ApplySort() { CancelSort(); TokenSource = new CancellationTokenSource(); Root.SendMessage(this, "ShowStatus", false, "Sorting Contacts..", true); try { Task <BalancedOrderStatisticTree <Contact> > .Factory.StartNew(() => new BalancedOrderStatisticTree <Contact>(Contacts, Contacts.Comparer) , TokenSource.Token, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default) .ContinueWith((t) => { if (t.Status == TaskStatus.RanToCompletion && t.Result != null) { Concurrency.LockFreeUpdate(ref m_Contacts, t.Result); } Root.SendMessage(this, "ClearStatus"); }); } catch (Exception ex) { ex.LogWarning(); Root.SendMessage(this, "ClearStatus"); } }
public void WordWrap(float breakWidth) { // ToDo: Still not perfect: // * Lines with ending NewLine may hang over // (the non-printable NewLine character is right above breakwidth) // * Lines without any break-chars may hang one character over breakwidth lock (SyncObject) { if (!NeedsWordWrap && BreakWidth == breakWidth) { return; } BreakWidth = breakWidth; NeedsWordWrap = false; // Since here, we completely work with temporary local variables // and set final values once finished. GlyphList.Node curr = Glyphs.Head; GlyphList.Node prev = curr; BreakList lineBreaks = new BreakList(); float currentWidth = 0; float totalWidth = 0; float maxWidth = 0; int pos = 0; int prevBreakCharPos = 0; while (curr != null) { currentWidth += curr.Value.Width; totalWidth += currentWidth; if (currentWidth > BreakWidth && curr.Next != null) { if (prevBreakCharPos == 0) { lineBreaks.AddLast(pos); currentWidth = curr.Value.Width; prev = curr; } else { lineBreaks.AddLast(prevBreakCharPos); prevBreakCharPos = 0; currentWidth = 0; while (prev != curr) { currentWidth += prev.Value.Width; prev = prev.Next; } } } else if (IsSpaceWrapCharacter(curr.Value.Char) || (IsWrapCharacter(curr.Value.Char) && curr.Next != null && !IsSpaceWrapCharacter(curr.Next.Value.Char))) { prevBreakCharPos = pos + 1; prev = curr; } maxWidth = Math.Max(maxWidth, currentWidth); curr = curr.Next; pos++; } // Update final values Concurrency.LockFreeUpdate(ref m_Breaks, lineBreaks); Width = maxWidth.Ceil(); TotalGlyphWidth = totalWidth; } }