/// <param name="needDetach">whether remove current context from render buffer</param> private async Task _UpdateAsync(GLVisual visual, bool needDetach = false) { if (visual.TryEnterUpdate()) { if (needDetach) { _DetachVisual(visual); // remove current context from render buffer but not clear itself (for hittest) } await visual.UpdateAsync(); // context has been swapped visual.BackContext?.Clear(); // so we clear back context // has been deleted when updating ? if (!visual.IsDeleted) // not deleted { _AttachVisual(visual); // add current context to render buffer if (!visual.TryExitUpdate()) { await _UpdateAsync(visual, true); } } else // has been deleted { visual.Reset(); // reset visual visual.Panel = null; // disconnect from panel visual.ExitUpdate(); // endup updating !!!!! if (visual.NeedDispose) { visual.Dispose(); } } } }
/// <param name="needDetach">whether remove current context from render buffer</param> private void _Update(GLVisual visual, bool needDetach = false) { if (needDetach) { _DetachVisual(visual); } visual.Update(); // context has been swapped visual.BackContext.Clear(); // so we clear back context _AttachVisual(visual); }
public void Dispose() { if (_isDisposed) { return; } _isDisposed = true; _Clear(); _transform.Dispose(); _primitives = null; _visual = null; }
private void _DetachVisual(GLVisual visual) { if (_resourceMode == ResourceMode.Normal) { visual.DetachData(); } else { var drawContext = visual.CurrentContext; visual.Detach(drawContext); } }
public void MoveToBottom(GLVisual visual, bool refresh = false) { if (_resourceMode == ResourceMode.Normal) { _visuals.Remove(visual); _visuals.Insert(0, visual); if (refresh) { _Refresh(); } } }
public void MoveToTop(GLVisual visual, bool refresh = false) { if (_resourceMode == ResourceMode.Normal) { _visuals.Remove(visual); _visuals.Add(visual); if (refresh) { _Refresh(); } } }
public void MoveOnBottom(GLVisual source, GLVisual target, bool refresh = false) { if (_resourceMode == ResourceMode.Normal) { _visuals.Remove(source); var index = _visuals.IndexOf(target); _visuals.Insert(index, source); if (refresh) { _Refresh(); } } }
/// <summary> /// Remove a visual /// </summary> /// <param name="visual">The visual to remove</param> /// <param name="refresh">Whether to refresh the frame buffer immediately</param> public void RemoveVisual(GLVisual visual, bool refresh = true) { MakeSureCurrentContext(_context); if (visual.Panel != this) { throw new InvalidOperationException("Logical parent error!"); } _DetachVisual(visual); _RemoveVisual(visual); if (!visual.IsUpdating) { visual.Reset(); visual.Panel = null; } if (refresh) { _Refresh(); } }
/// <summary> /// Update viausl /// </summary> /// <param name="visual">The visual to update</param> /// <param name="refresh">Whether to refresh the frame buffer immediately</param> public async Task UpdateAsync(GLVisual visual, bool refresh = false) { MakeSureCurrentContext(_context); if (visual.IsDeleted) { return; } if (_renderMode == RenderMode.Sync) { _Update(visual, true); } else { await _UpdateAsync(visual, true); } if (refresh || _renderMode == RenderMode.Async) { _Refresh(); } }
private void _AttachVisual(GLVisual visual) { if (_resourceMode == ResourceMode.Normal) { visual.AttachData(); visual.EndInitModels(); } else { var drawContext = visual.CurrentContext; MakeSureCurrentContext(_context); foreach (var primitive in drawContext.Primitives) { if (!primitive.Pen.IsNULL || primitive.Type == PrimitiveType.ComplexGeometry) { _AttachModel(primitive, primitive.Pen); } if (primitive.Filled) { if (primitive.Type == PrimitiveType.ComplexGeometry) { _AttachStreamModel(primitive); } else if (primitive.Type == PrimitiveType.Arrow) { _AttachArrowModels(primitive); } else if (primitive.Type == PrimitiveType.Point) { _AttachPointModels(primitive); } else { _AttachFillModels(primitive); } } } } }
/// <summary> /// Add a visual /// </summary> /// <param name="visual">The visual to add</param> /// <param name="refresh">Whether to refresh the frame buffer immediately</param> public void AddVisual(GLVisual visual, bool refresh = false) { MakeSureCurrentContext(_context); if (!visual.IsDeleted) { if (visual.Panel != this) { throw new InvalidOperationException("Visual has already a logical parent!"); } else { throw new InvalidOperationException("Visual has already been added"); } } _AddVisual(visual); _Update(visual); if (refresh) { _Refresh(); } }
internal GLDrawContext(GLVisual visual) { _visual = visual; _primitives = new List <IPrimitive>(); _transform = new StackTransform(); }
private void _RemoveVisual(GLVisual visual) { visual.IsDeleted = true; _visuals.Remove(visual); }
private void _AddVisual(GLVisual visual) { visual.IsDeleted = false; visual.Panel = this; _visuals.Add(visual); }