protected override void Dispose(bool disposing) { if (!this.IsDisposed) { Console.WriteLine("Stopping renderer"); running = false; renderThread.Join(); renderThread2.Join(); rbmp?.Dispose(); gpuRenderer?.Dispose(); foreach (var obj in ScreenObjects) { obj.Dispose(); } } try { base.Dispose(disposing); } catch (InvalidOperationException) { } }
void renderLoop() { gpuRenderer.Init(); while (running) { if (redraw || fullredraw || targetTransform != null) { if (lockDraw) { waiting = true; continue; } try { Matrix3x3 mat = transform; if (targetTransform != null) { targetT += .03f; if (targetT < 1) { mat = Matrix3x3.Slerp(transform, targetTransform, -(float)Math.Cos(targetT * Math.PI) * .5f + .5f); } else { fullredraw = true; transform = mat = targetTransform; targetTransform = null; } if (Configuration.RefreshOnTransform) { fullredraw = true; } } Matrix3x3 tMat = mat.Clone(); Matrix3x3 dMat = (stableTransform.GetInverse() * mat).Clone(); waiting = false; redraw = false; //if (this.Height <= 0 || this.Width <= 0) return; int vW = (int)(this.Width * BufferSize); int vH = (int)(this.Height * BufferSize); if (rbmp == null || vW != gpuRenderer.Width || vH != gpuRenderer.Height) { gpuRenderer.Resize(new Size(vW, vH)); rbmp?.Dispose(); rbmp = gpuRenderer.CreateRenderTarget(); } if (!gpuRenderer.Begin(Style.Default.Background)) { return; } SizeF pSize = page.Format.GetPixelSize(); if (fullredraw) { stableTransform = transform; dMat = new Matrix3x3(); rbmp.Begin(); fullredraw = false; gpuRenderer.SetRenderTarget(rbmp); gpuRenderer.Begin(SystemColors.ControlDark); gpuRenderer.ResetTransform(); gpuRenderer.Transform(tMat); if (page.OriginalPage == null) { if (page.BackgroundImage == null) { gpuRenderer.FillRectangle(Util.ApplyFilter(Color.White, Page.Filter), new RectangleF( 0, 0, pSize.Width, pSize.Height)); } else { gpuRenderer.DrawImage(page.BackgroundImage, new RectangleF(0, 0, pSize.Width, pSize.Height)); } } else { gpuRenderer.FillRectangle(Color.White, new RectangleF( 0, 0, pSize.Width, pSize.Height)); } page.DrawBackground(gpuRenderer); if (page.OriginalPage != null && page.BackgroundImage != null) { gpuRenderer.DrawImage(page.BackgroundImage, new RectangleF(0, 0, pSize.Width, pSize.Height)); } page.Draw(gpuRenderer); rbmp.End(); gpuRenderer.SetRenderTarget(null); tmpLine = null; } gpuRenderer.ResetTransform(); gpuRenderer.Transform(dMat); gpuRenderer.DrawRenderBitmap(rbmp); gpuRenderer.ResetTransform(); gpuRenderer.Transform(tMat); gpuRenderer.DrawRect(Color.Black, 1, new RectangleF(0, 0, pSize.Width, pSize.Height)); if (tmpLine != null) { tmpLine.Render(gpuRenderer); } if (line != null) { line.Render(gpuRenderer); } if (selections != null) { lock (selections) { PointF[] pts = selections.ToArray(); transform.GetInverse().Transform(pts); gpuRenderer.DrawDashPolygon(pts); } } // Screen Objects foreach (BaseScreenObject bso in ScreenObjects) { gpuRenderer.ResetTransform(); bso.Draw(gpuRenderer, this.Width, this.Height); } gpuRenderer.ResetTransform(); gpuRenderer.Transform(Matrix3x3.Translation(0, 0)); gpuRenderer.DrawLine(Color.Black, 3, new PointF(0, 0), new PointF(this.Width, 0)); Renderer.Effects.DrawShadow(gpuRenderer, new RectangleF(0, 0, Width, 16)); if (Configuration.LeftHanded) { gpuRenderer.DrawLine(Color.Black, 3, new PointF(this.Width, 0), new PointF(this.Width, this.Height)); gpuRenderer.Transform(Matrix3x3.RotateD(-90)); gpuRenderer.Transform(Matrix3x3.Translation(Width, 0)); Renderer.Effects.DrawShadow(gpuRenderer, new RectangleF(0, 0, Height, 16)); gpuRenderer.ResetTransform(); } else { gpuRenderer.DrawLine(Color.Black, 3, new PointF(0, 0), new PointF(0, this.Height)); gpuRenderer.Transform(Matrix3x3.RotateD(90)); Renderer.Effects.DrawShadow(gpuRenderer, new RectangleF(0, 0, -Height, 16)); gpuRenderer.ResetTransform(); } Control _p = Parent; Form _parentForm; while (!(_p is Form)) { _p = _p.Parent; } _parentForm = (Form)_p; if (_parentForm.FormBorderStyle == FormBorderStyle.None) { string fullscreenInfo = ""; if (Configuration.ShowBattery) { fullscreenInfo += Language.GetText("Overlay.battery") + ": " + (int)(SystemInformation.PowerStatus.BatteryLifePercent * 100) + "%\n"; } if (Configuration.ShowTime) { fullscreenInfo += Language.GetText("Overlay.time") + ": " + DateTime.Now.ToShortTimeString() + "\n"; } if (Configuration.ShowDate) { fullscreenInfo += Language.GetText("Overlay.date") + ": " + DateTime.Now.ToShortDateString() + "\n"; } if (fullscreenInfo.Length > 1) { SizeF size = CreateGraphics().MeasureString(fullscreenInfo, new Font("Calibri", Util.MmToPoint(5))); RectangleF rect = new RectangleF(Width - size.Width - 16, Height - size.Height - 16, size.Width, size.Height); gpuRenderer.FillRectangle(Color.Black, rect); gpuRenderer.DrawText(fullscreenInfo, new PointF(Util.PointToMm(rect.X), Util.PointToMm(rect.Y)), 5, Color.White); } } if (rBounds.Equals(RectangleF.Empty)) { gpuRenderer.End(); } else { gpuRenderer.End(rBounds); } } catch (InvalidOperationException e) { Console.WriteLine(e.Message); } catch (FieldAccessException) { gpuRenderer.End(); } } Thread.Sleep(10); } gpuRenderer.Dispose(); }