void gameForm_Resize(object sender, EventArgs e) { if (grafx != null) { grafx.Dispose(); grafx = null; } grafx = context.Allocate(formGraphics, new Rectangle(0, 0, game.gameForm.Width, game.gameForm.Height)); grafx.Graphics.ResetTransform(); grafx.Graphics.ScaleTransform(game.gameForm.Width / view.width, game.gameForm.Height / view.height); game.gameForm.Refresh(); Console.WriteLine("Resized!" + game.gameForm.Width / view.width+" "+ game.gameForm.Height / view.height); }
public void Dispose() { if (SourceControlObject != null) { SourceControlObject.Resize -= new EventHandler(this.OnSourceControlResize); SourceControlObject.Paint -= new PaintEventHandler(this.OnSourceControlPaint); SourceControlObject = null; } if (GraphicsObject != null) { GraphicsObject.Dispose(); GraphicsObject = null; } if (GraphicsContextObject != null) { GraphicsContextObject.Dispose(); GraphicsContextObject = null; } }
public DrawManager(Game game_m) { game = game_m; formGraphics = game.gameForm.CreateGraphics(); game.gameForm.Resize += gameForm_Resize; Console.WriteLine(formGraphics.DpiX+" "+formGraphics.DpiY); view = new View(20, 20, 1920, 1080); context = BufferedGraphicsManager.Current; context.MaximumBuffer = new Size((int)view.width + 1, (int)view.height + 1); grafx = context.Allocate(formGraphics, new Rectangle(0, 0, game.gameForm.Width, game.gameForm.Height)); drawBrush = new SolidBrush(Color.Black); font = new System.Drawing.Font("Arial", 16); watch = new Stopwatch(); watch.Start(); fps = 0.0; last = 0; }
private void DrawAlphaBar(BufferedGraphics bg) { Graphics g = bg.Graphics; if (mLastHoverChar != -1) { g.FillRectangle(Brushes.DarkOrange, mAlphaBar); } else { g.FillRectangle(Brushes.White, mAlphaBar); } StringFormat stringFormat = new StringFormat(); stringFormat.LineAlignment = StringAlignment.Center; stringFormat.Alignment = StringAlignment.Center; stringFormat.FormatFlags = StringFormatFlags.LineLimit; stringFormat.Trimming = StringTrimming.EllipsisCharacter; int height = mAlphaBar.Height / 27; int offset = mAlphaBar.Height % 27; Rectangle rectLabel = new Rectangle(mAlphaBar.Left, mAlphaBar.Top, mAlphaWidth, height + offset); foreach (AlphabetCharItem item in AlphaCharItems) { item.Bounds = rectLabel; if (item.Focus) { g.DrawString(item.Value, mFontCharBold, Brushes.White, item.Bounds, stringFormat); } else { g.DrawString(item.Value, mFontChar, Brushes.Black, item.Bounds, stringFormat); } rectLabel.Y += item.Bounds.Height; rectLabel.Height = height; } }
private void UpdateGraphicsBuffer() { // We cannot create a bitmap if any of these values are 0 if (Size.Width > 0 && Size.Height > 0) { _bufContext.MaximumBuffer = new Size(Width + 1, Height + 1); _bufGraphics = _bufContext.Allocate(CreateGraphics(), ClientRectangle); if (_isHighQuality) { _bufGraphics.Graphics.SmoothingMode = SmoothingMode.AntiAlias; _bufGraphics.Graphics.CompositingQuality = CompositingQuality.HighQuality; _bufGraphics.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; } else { _bufGraphics.Graphics.SmoothingMode = SmoothingMode.Default; _bufGraphics.Graphics.CompositingQuality = CompositingQuality.Default; _bufGraphics.Graphics.PixelOffsetMode = PixelOffsetMode.Default; } } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.ListBox.DrawItem"/> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DrawItemEventArgs"/> that contains the event data.</param> protected override void OnDrawItem(DrawItemEventArgs e) { var newBounds = new Rectangle(0, 0, e.Bounds.Width, e.Bounds.Height); if (newBounds.Width == 0 || newBounds.Height == 0) { return; } // stacked using blocks to avoid indentation, don't need to call IDisposable.Dispose explicitly using (var currentContext = new BufferedGraphicsContext()) using (BufferedGraphics bufferedGraphics = currentContext.Allocate(e.Graphics, newBounds)) { var newArgs = new DrawItemEventArgs(bufferedGraphics.Graphics, e.Font, newBounds, e.Index, e.State, e.ForeColor, e.BackColor); // Supply the real DrawItem with the off-screen graphics context base.OnDrawItem(newArgs); NativeMethods.CopyGraphics(e.Graphics, e.Bounds, bufferedGraphics.Graphics, new Point(0, 0)); } }
private void drawMagFieldGraph() { magFieldGraphicsContext = new BufferedGraphicsContext(); magFieldGraphicsBuffer = magFieldGraphicsContext.Allocate(Graphics.FromImage(magFieldDrawingSurface), magFieldBoundsRectangle); magFieldGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; magFieldGraphicsBuffer.Graphics.Clear(SystemColors.Control); float xCenter = (float)(magFieldBoundsRectangle.Width / 2.0); float yCenter = (float)(magFieldBoundsRectangle.Height / 2.0); float xOld = xCenter + (float)(spatial.compassAxes[0].MagneticField) * magFieldCircleRadius * (float)(1 / ambientMagneticField); float yOld = yCenter + (float)(spatial.compassAxes[1].MagneticField) * magFieldCircleRadius * (float)(1 / ambientMagneticField); magFieldGraphicsBuffer.Graphics.DrawLine(magFieldXYAxisPen, xCenter, yCenter, xOld, yOld); magFieldGraphicsBuffer.Graphics.DrawEllipse(magFieldCirclePen, magFieldCircleRectangle); if (spatial.compassAxes.Count == 3) { double zOut = (spatial.compassAxes[2].MagneticField) * (float)(1 / ambientMagneticField); if (zOut > 0) { magFieldGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2), new Rectangle((int)xCenter - (int)(magFieldCircleRadius * zOut), (int)yCenter - (int)(magFieldCircleRadius * zOut), (int)(magFieldCircleDiameter * zOut), (int)(magFieldCircleDiameter * zOut))); } else { magFieldGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2), new Rectangle((int)xCenter - (int)(magFieldCircleRadius * -zOut), (int)yCenter - (int)(magFieldCircleRadius * -zOut), (int)(magFieldCircleDiameter * -zOut), (int)(magFieldCircleDiameter * -zOut))); } } magFieldGraphicsBuffer.Render(magFieldView.CreateGraphics()); magFieldGraphicsBuffer.Dispose(); magFieldGraphicsContext.Dispose(); }
private void WmPaintHeader(ref Message m) { if (!this.HaveEndHeader) { return; } // IntPtr iHandle = GISShare.Win32.API.GetWindowDC(m.HWnd); try { Graphics g = Graphics.FromHdc(iHandle); // Rectangle rectangle = this.EndHeaderRectangle; if (m_BufferedGraphics == null || this.m_CurrentCacheSize != rectangle.Size) { if (m_BufferedGraphics != null) { m_BufferedGraphics.Dispose(); } m_BufferedGraphics = this.m_BufferedGraphicsContext.Allocate(g, rectangle); this.m_CurrentCacheSize = rectangle.Size; } // this.OnPaintHeader(new PaintEventArgs(m_BufferedGraphics.Graphics, rectangle)); // if (m_BufferedGraphics != null) { m_BufferedGraphics.Render(g); } // g.Dispose(); } catch { } finally { GISShare.Win32.API.ReleaseDC(m.HWnd, iHandle); } }
private void txtHeight_ValueChanged(object sender, EventArgs e) { int NewValue = (int)txtHeight.Value; //List is getting bigger. if (OldHeight < NewValue) { for (; OldHeight < NewValue; ++OldHeight) { for (int Y = 0; Y < ListUnitSize.Count; ++Y) { ListUnitSize[Y].Insert(0, false); ListUnitSize[Y].Add(false); } } } //List is getting smaller. else if (OldHeight > NewValue) { for (int Y = 0; Y < ListUnitSize.Count; ++Y) { ListUnitSize[Y].RemoveRange(ListUnitSize[Y].Count - (OldHeight - NewValue), OldHeight - NewValue); ListUnitSize[Y].RemoveRange(0, OldHeight - NewValue); } OldHeight = NewValue; } pbUnitSize.Height = NewValue * 32; if (pbSizePreviewContext == null) { return; } this.pbSizePreviewContext.MaximumBuffer = new Size(pbUnitSize.Width, pbUnitSize.Height); this.pbSizePreviewGraphicDevice = pbSizePreviewContext.Allocate(pbDrawingSurfaceGraphics, new Rectangle(0, 0, pbUnitSize.Width, pbUnitSize.Height)); panel1.Refresh(); DrawUnitSize(); }
public static void ClearForm(BufferedGraphics preBufferedGraphics) { preBufferedGraphics.Graphics.Clear(Color.LightGray); Shape tmp = prevShape; if (tmp != null) { for (int j = 0; j < prevShape.shapeY.Length; j++) { tmp.shapeY[j] += 4; tmp.shapeX[j] -= 6; } tmp.PaintShape(preBufferedGraphics); preBufferedGraphics.Render(); for (int j = 0; j < prevShape.shapeY.Length; j++) { tmp.shapeY[j] -= 4; tmp.shapeX[j] += 6; } } }
public void Dispose() { if (backgroundGraphic != null) { backgroundGraphic.Dispose(); } backgroundGraphic = null; if (graphicsBuffer != null) { graphicsBuffer.Dispose(); } graphicsBuffer = null; if (backgroundRenderGraphic != null) { backgroundRenderGraphic.Dispose(); } backgroundRenderGraphic = null; if (backgroundMemoryBitmap != null) { GDIRender.DeleteObject(memoryBitmapHdc); backgroundMemoryBitmap.Dispose(); } backgroundMemoryBitmap = null; if (backgroundMemoryGraphic != null) { GDIRender.DeleteObject(memoryGraphicHdc); backgroundMemoryGraphic.Dispose(); } backgroundMemoryGraphic = null; if (backgroundDrawGraphic != null) { backgroundDrawGraphic.Dispose(); } backgroundDrawGraphic = null; }
/// <summary>TODO</summary> void ResizeBuffer() { var rectangle = new Rectangle(Point.Empty, ClientSize); if (ClientSize != _bufferedGraphicsContext.MaximumBuffer) { _bufferedGraphicsContext.MaximumBuffer = ClientSize; if (MapBuffer != null) { MapBuffer.Dispose(); } MapBuffer = _bufferedGraphicsContext.Allocate(this.CreateGraphics(), rectangle); if (MapSpare != null) { MapSpare.Dispose(); } MapSpare = _bufferedGraphicsContext.Allocate(this.CreateGraphics(), rectangle); } PaintBuffer(rectangle); }
public GameForm(Game game) { SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.UserPaint, true); int rndNumber = rng.Next(0, 3); currentGame = game; string[] imageFilenames = { "Images\\background1.jpg", "Images\\background2.jpg", "Images\\background3.jpg", "Images\\background4.jpg" }; backgroundImage = Image.FromFile(imageFilenames[rndNumber]); Color[] landscapeColours = { Color.FromArgb(255, 0, 0, 0), Color.FromArgb(255, 73, 58, 47), Color.FromArgb(255, 148, 116, 93), Color.FromArgb(255, 133, 119, 109) }; landscapeColour = landscapeColours[rndNumber]; InitializeComponent(); backgroundGraphics = InitBuffer(); gameplayGraphics = InitBuffer(); DrawBackground(); DrawGameplay(); NewTurn(); }
public static void Initialize(Form form) { Width = form.Width; Height = form.Height; __Context = BufferedGraphicsManager.Current; var g = form.CreateGraphics(); __Buffer = __Context.Allocate(g, new Rectangle(0, 0, Width, Height)); var timer = new Timer { Interval = __FrameTimeout }; timer.Tick += OnTimerTick; timer.Start(); __Timer = timer; form.KeyDown += OnFormKeyDown; Log?.Invoke("Выполнена инициализация"); }
/// <inheritdoc /> protected override void RenderInternal(IEnumerable <IModel> models) { // clear buffers FrameBuffers.BufferColor[0].Clear(Color.Black); FrameBuffers.BufferDepth.Clear(1); // render models RenderModels(models); // flush to screen back buffer BufferedGraphics.Graphics.DrawImage( FrameBuffers.BufferColor[0].Bitmap, new RectangleF(PointF.Empty, HostSize), new RectangleF(new PointF(-0.5f, -0.5f), BufferSize), GraphicsUnit.Pixel); // draw fps BufferedGraphics.Graphics.DrawString(FpsCounter.FpsString, FontConsolas12, Brushes.Red, 0, 0); // swap buffers BufferedGraphics.Render(GraphicsHostDeviceContext); }
private void txtWidth_ValueChanged(object sender, EventArgs e) { int NewValue = (int)txtWidth.Value; int CurrentHeight = (int)txtHeight.Value; //List is getting bigger. if (OldWidth < NewValue) { for (; OldWidth < NewValue; ++OldWidth) { List <bool> NewListbool = new List <bool>(CurrentHeight); for (int Y = 0; Y < CurrentHeight; ++Y) { NewListbool.Add(false); } ListUnitSize.Insert(0, NewListbool); NewListbool = new List <bool>(CurrentHeight); for (int Y = 0; Y < CurrentHeight; ++Y) { NewListbool.Add(false); } ListUnitSize.Add(NewListbool); } } //List is getting smaller. else if (OldWidth > NewValue) { ListUnitSize.RemoveRange(ListUnitSize.Count - (OldWidth - NewValue), OldWidth - NewValue); ListUnitSize.RemoveRange(0, OldWidth - NewValue); OldWidth = NewValue; } pbUnitSize.Width = OldWidth * 32; this.pbSizePreviewContext.MaximumBuffer = new Size(pbUnitSize.Width, pbUnitSize.Height); this.pbSizePreviewGraphicDevice = pbSizePreviewContext.Allocate(pbDrawingSurfaceGraphics, new Rectangle(0, 0, pbUnitSize.Width, pbUnitSize.Height)); panel1.Refresh(); DrawUnitSize(); }
protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); fpsRect = new Rectangle(ClientRectangle.Width - 75, 5, 75, 30); fpsPt = new Point(ClientRectangle.Width - 75, 10); gameRect = new Rectangle(0, 0, ClientRectangle.Width, ClientRectangle.Height); if (menu != null) { fpsPt.Y = 10 + menu.Height; fpsRect.Y = 5 + menu.Height; gameRect.Y = menu.Height; gameRect.Height -= menu.Height; } if (gfxBufferedContext != null) { gfxBuffer = gfxBufferedContext.Allocate(this.CreateGraphics(), this.DisplayRectangle); } }
public TDForm() { ThisForm = this; // for component and cross thread references InitializeComponent(); // read files TDResources.LoadResources(); SetupNewSession(); // setup drawing details ActionPanelGraphics = this.panelAction.CreateGraphics(); BufferedGraphicsContext context = BufferedGraphicsManager.Current; context.MaximumBuffer = new Size(this.Width + 1, this.Height + 1); bufferedGraphics = context.Allocate(this.CreateGraphics(), new Rectangle(0, 0, this.Width, this.Height)); DrawTimer.Enabled = true; DrawTimer.Tick += OnDrawTimer; DrawTimer.Interval = (1000 / MaxFPS); DrawTimer.Start(); }
internal void RawResize(Graphics g, int width, int height) { if (Context == null) { return; } // initialize the double buffer Width = width; Height = height; Context.MaximumBuffer = new Size(width + 1, height + 1); // cleanup if (Surface != null) { Surface.Dispose(); } // recreate Surface = Context.Allocate(g, new Rectangle(0, 0, width, height)); Graphics = Surface.Graphics; }
public static void Init(Form form) { Timer timer = new Timer { Interval = 100 }; timer.Start(); timer.Tick += Timer_Tick; // Графическое устройство для вывода графики Graphics g; // Предоставляет доступ к главному буферу графического контекста для текущего приложения _context = BufferedGraphicsManager.Current; g = form.CreateGraphics(); // Создаем объект (поверхность рисования) и связываем его с формой // Запоминаем размеры формы Width = form.ClientSize.Width; Height = form.ClientSize.Height; // Связываем буфер в памяти с графическим объектом, чтобы рисовать в буфере Buffer = _context.Allocate(g, new Rectangle(0, 0, Width, Height)); Load(); }
private void Form1_Load(object sender, EventArgs e) { bufferedGraphicsContext.MaximumBuffer = new Size(pictureBox1.Width + 1, pictureBox1.Height + 1); bufferedGraphics = bufferedGraphicsContext.Allocate(pictureBox1.CreateGraphics(), new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height)); CreateFont(); label1.Font = new Font(privateFont.Families[0], 18); label1.Font = new Font(privateFont.Families[0], 18); OutputLabel.Font = new Font(privateFont.Families[1], 24); florRectangles[0] = new Rectangle((x / 2 - width / 2) - width - shift[0], (y / 2 - width / 2) - width - shift[1], width * 3, width * 3); wallRectangles[0] = new Rectangle((x / 2 - width / 2) - width * 2 - shift[0], (y / 2 - width / 2) - width * 2 - shift[1], width * 5, width * 5); // #region Way //way[0] = new Rectangle(new Point((x / 2 - width / 2) - shift[0], (y / 2 - width / 2) - width * 2 - shift[1]), new Size(width, width)); //way[1] = new Rectangle(new Point((x / 2 - width / 2) - shift[0], (y / 2 - width / 2) + width * 2 - shift[1]), new Size(width, width)); //way[2] = new Rectangle(new Point((x / 2 - width / 2) - width * 2 - shift[0], (y / 2 - width / 2) - shift[1]), new Size(width, width)); //way[3] = new Rectangle(new Point((x / 2 - width / 2) + width * 2 - shift[0], (y / 2 - width / 2) - shift[1]), new Size(width, width)); #endregion // for (int i = 1; i < wallRectangles.Length; i++) { int x1, y1, x2, y2; x2 = width * random.Next(4, 11); y2 = width * random.Next(4, 11); do { x1 = width * random.Next(1, (x - x2) / width) - width / 2; y1 = width * random.Next(1, (y - y2) / width) - width / 2; }while (ContainsPoint(x1, y1)); //OutputLabel.Text += $"\n{x1},{y1},\t{x2},{y2}"; florRectangles[i] = new Rectangle(x1, y1, x2, y2); wallRectangles[i] = new Rectangle(x1 - width, y1 - width, x2 + width * 2, y2 + width * 2); } this.Focus(); CreateWay(wallRectangles); }
/// <summary> /// Main update thread. /// Read and write game memory, draw on screen. /// </summary> public void UpdateHack() { //update loop while (isRunning) { //read ReadGameMemory(); //Test Hacks //self hacks, infinite health and ammo /* * self.Health = 99999; * self.weapon.Ammo = 7331; * self.weapon.AmmoClip = 999; * self.weapon.DelayTime = 0;//rapid fire */ //players.ForEach(p => p.Velocity = new Vector3(0, 0, 15));//send everyone to the ceiling //players.ForEach(p => p.Pitch = 90); //make everyone look up //players.ForEach(p => p.Position = new Vector3(130, 130, 10)); //set everyone to same spot //players.ForEach(p => p.Health = 0);//1 hit kills on anyone //aimbot UpdateAimbot(); //draw Draw(bufferedGraphics.Graphics); Thread.Sleep(1); } //cleanup Memory.CloseProcess(); bufferedGraphics.Dispose(); bufferedGraphics = null; }
/// <summary> /// 开始游戏 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ToolStripMenuItemGameBegin_Click(object sender, EventArgs e) { // 开始接收服务器发送过来的信号 if (this.m_gameMode == GameMode.ONLINE) { m_gameControl.BeginReceiveMessage(); } // 释放画布所占用的资源 if (bufferGrap != null) { bufferGrap.Dispose(); } bufferGrap = currentContext.Allocate(this.panelPaint.CreateGraphics(), new Rectangle(0, 0, this.panelPaint.Width, this.panelPaint.Height)); m_gameControl.GameStart(this.panelPaint.Width, this.panelPaint.Height, bufferGrap); // SetMoveTimerInterval(); // timerMove.Start(); }
// draw lines, rubber band private void DrawRubberLine(Graphics g, PointF start, PointF end) { BufferedGraphicsContext context = BufferedGraphicsManager.Current; BufferedGraphics bg = context.Allocate(g, new Rectangle(0, 0, PictureBox1.Width, PictureBox1.Height)); bg.Graphics.Clear(Color.White); for (int i = 0; i < points.Count - 1; ++i) { bg.Graphics.DrawLine(SystemPens.ControlText, points[i], points[i + 1]); bg.Graphics.FillRectangle(Brushes.Black, points[i].X, points[i].Y, 4, 4); } Pen redPen = new Pen(Color.Red); for (int i = 0; i < curve.Count; i += 2) { bg.Graphics.DrawLine(redPen, curve[i], curve[i + 1]); } bg.Graphics.DrawLine(SystemPens.ControlText, start, end); bg.Graphics.FillRectangle(Brushes.Black, points.Last().X, points.Last().Y, 4, 4); bg.Render(); bg.Dispose(); }
private void InitializeOverlayWindowAttributes() { //set up window and overlay properties for drawing on top of another window Visible = true; picBoxOverlay.Visible = true; TopMost = true; //set window on top of all others FormBorderStyle = FormBorderStyle.None; //remove form controls picBoxOverlay.Dock = DockStyle.Fill; //fill window with picturebox graphics picBoxOverlay.BackColor = colorTransparencyKey; //set overlay to transparent color TransparencyKey = colorTransparencyKey; //set tranparency key SetStyle(ControlStyles.SupportsTransparentBackColor, true); //Win32API.SetLayeredWindowAttributes(this.Handle, 0, 128, 2); //initialize graphics BufferedGraphicsContext buffContext = new BufferedGraphicsContext(); bufferedGraphics = buffContext.Allocate(picBoxOverlay.CreateGraphics(), ClientRectangle); bufferedGraphics.Graphics.SmoothingMode = SmoothingMode.AntiAlias; bufferedGraphics.Graphics.CompositingQuality = CompositingQuality.HighQuality; }
// Draws the motor visualisation circle to the interface private void drawCirclePlot() { circlePlotContext = new BufferedGraphicsContext(); circlePlotBuffer = circlePlotContext.Allocate(Graphics.FromImage(circlePlotSurface), circleBounds); circlePlotBuffer.Graphics.SmoothingMode = SmoothingMode.AntiAlias; circlePlotBuffer.Graphics.Clear(SystemColors.Control); float xCenter = (float)(circleBounds.Width / 2.0); float yCenter = (float)(circleBounds.Height / 2.0); circlePlotBuffer.Graphics.DrawEllipse(outerCirclePlotPen, circleRectangles[0]); circlePlotBuffer.Graphics.DrawEllipse(circlePlotPens[0], (float)(circleRadii[0] * Math.Cos(currentPos * 2 * Math.PI / 2000.0) + xCenter) - 2, (float)(-circleRadii[0] * Math.Sin(currentPos * 2 * Math.PI / 2000.0) + yCenter) - 2, 4, 4); circlePlotBuffer.Graphics.DrawEllipse(outerCirclePlotPen, circleRectangles[1]); circlePlotBuffer.Graphics.DrawEllipse(circlePlotPens[1], (float)(circleRadii[1] * Math.Cos(desiredPos * 2 * Math.PI / 2000.0) + xCenter) - 2, (float)(-circleRadii[1] * Math.Sin(desiredPos * 2 * Math.PI / 2000.0) + yCenter) - 2, 4, 4); circlePlotBuffer.Render(circlePlotPanel.CreateGraphics()); circlePlotBuffer.Dispose(); circlePlotContext.Dispose(); }
/// <summary> /// Renders all game shapes to a back buffer /// before replacing the front buffer. /// </summary> private void DoubleBufferedRender() { using (BufferedGraphicsContext bgc = new BufferedGraphicsContext()) { using (BufferedGraphics bg = bgc.Allocate(CreateGraphics(), ClientRectangle)) { // draw level background in the top left corner _lvGameLevel.Render(bg.Graphics); // render moving shapes _lDynShapes.ForEach(ds => ds.Render(bg.Graphics)); // render walls _lWalls.ForEach(w => w.Render(bg.Graphics)); // render slow floors _lBrushes.ForEach(w => w.Render(bg.Graphics)); // render active ammo drops _lAmmoDrops.Where(a => a.IsAlive).ToList() .ForEach(a => a.Render(bg.Graphics)); // render active ammo drops _lPowerUpDrops.Where(a => a.IsAlive).ToList() .ForEach(a => a.Render(bg.Graphics)); // render active healing packs _lHealingPacks.Where(a => a.IsAlive).ToList() .ForEach(a => a.Render(bg.Graphics)); _lMinesDrops.Where(a => a.IsAlive).ToList() .ForEach(a => a.Render(bg.Graphics)); // flip back buffer to front bg.Render(); } } }
public void Allocate_SmallRectWithTargetHdc_Success() { using (var context = new BufferedGraphicsContext()) using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { try { IntPtr hdc = graphics.GetHdc(); using (BufferedGraphics bufferedGraphics = context.Allocate(hdc, new Rectangle(0, 0, context.MaximumBuffer.Width - 1, context.MaximumBuffer.Height - 1))) { Assert.NotNull(bufferedGraphics.Graphics); } context.Invalidate(); } finally { graphics.ReleaseHdc(); } } }
private void Tick(object sender, EventArgs e) { lock (device.frameBuffer) { //数据刷新 device.alpha = alpha; device.camera.eye.x = rot; //初始化bitmap并且在frameBuffer上重绘图像 device.ClearBuffer(); drawing.DrawBox(device.alpha); if (gc == null) { gc = this.CreateGraphics(); } //初始化窗体并将bitmap绘在窗体上 双缓冲区 BufferedGraphicsContext dc = new BufferedGraphicsContext(); BufferedGraphics backBufeer = dc.Allocate(gc, new Rectangle(new Point(0, 0), this.Size)); gc.Clear(System.Drawing.Color.Black); gc.DrawImage(device.frameBuffer, 0, 0); backBufeer.Render(this.CreateGraphics()); } }
public void Allocate_ValidTargetHdc_Success() { using (var context = new BufferedGraphicsContext()) using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { try { IntPtr hdc = graphics.GetHdc(); using (BufferedGraphics bufferedGraphics = context.Allocate(hdc, Rectangle.Empty)) { Assert.NotNull(bufferedGraphics.Graphics); } context.Invalidate(); } finally { graphics.ReleaseHdc(); } } }
public test(Configuration configuration, String userName, String savingPath, String testingMode) { InitializeComponent(); Cursor.Hide(); this.savingPath = savingPath; this.userName = userName; this.mtestingMode = testingMode; this.KeyDown += new KeyEventHandler(HandleEsc); this.drawGazePoints = false; mConfiguration = configuration; combineEyeGaze = new combineEyes(mConfiguration); oneEyeRight = new OneEyeRight(mConfiguration); oneEyeLeft = new OneEyeLeft(mConfiguration); mDelayFactor = mConfiguration.delayFactor; mSensitivityOfTest = mConfiguration.sensitivityOfTest; FormBorderStyle = FormBorderStyle.None; this.TopMost = true; this.WindowState = FormWindowState.Maximized; BufferedGraphicsContext context = BufferedGraphicsManager.Current; context.MaximumBuffer = new Size(this.Width + 1, this.Height + 1); bufferedGraphics = context.Allocate(this.CreateGraphics(), new Rectangle(0, 0, this.Width, this.Height)); mScreenImage = new Bitmap(this.Width, this.Height); timer.Enabled = true; timer.Tick += new EventHandler(doTesting); timer.Interval = 40; // 40 images per second. timer.Start(); }
public BufferingExample() : base() { // Configure the Form for this example. this.Text = "User double buffering"; this.MouseDown += new MouseEventHandler(this.MouseDownHandler); this.Resize += new EventHandler(this.OnResize); this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); // Configure a timer to draw graphics updates. timer1 = new System.Windows.Forms.Timer(); timer1.Interval = 200; timer1.Tick += new EventHandler(this.OnTimer); bufferingMode = 2; count = 0; // Retrieves the BufferedGraphicsContext for the // current application domain. context = BufferedGraphicsManager.Current; // Sets the maximum size for the primary graphics buffer // of the buffered graphics context for the application // domain. Any allocation requests for a buffer larger // than this will create a temporary buffered graphics // context to host the graphics buffer. context.MaximumBuffer = new Size(this.Width + 1, this.Height + 1); // Allocates a graphics buffer the size of this form // using the pixel format of the Graphics created by // the Form.CreateGraphics() method, which returns a // Graphics object that matches the pixel format of the form. grafx = context.Allocate(this.CreateGraphics(), new Rectangle(0, 0, this.Width, this.Height)); // Draw the first frame to the buffer. DrawToBuffer(grafx.Graphics); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Get the graphics2D instance. the graphics 2D shall be protected by * graphic2DMutex to support multi-threading. * @return the shared the graphics2D objects. */ private static void GetGraphics2DInstance() { lock (GRAPHICS_MUTEX) { if (SharedGraphics2D == null) { // Retrieves the BufferedGraphicsContext for the // current application domain. BufferedGraphicsContext context = BufferedGraphicsManager.Current; // Sets the maximum size for the primary graphics buffer // of the buffered graphics context for the application // domain. Any allocation requests for a buffer larger // than this will create a temporary buffered graphics // context to host the graphics buffer. context.MaximumBuffer = new Size(MapLayer.MAP_TILE_WIDTH + 1, MapLayer.MAP_TILE_WIDTH + 1); // Allocates a graphics buffer the size of this form // using the pixel format of the Graphics created by // the Form.CreateGraphics() method, which returns a // Graphics object that matches the pixel format of the form. RenderBitmap = new Bitmap(MapLayer.MAP_TILE_WIDTH, MapLayer.MAP_TILE_WIDTH); BitmapGraphics = Graphics.FromImage(RenderBitmap); SharedGraphics2D = context.Allocate(BitmapGraphics, new Rectangle(0, 0, MapLayer.MAP_TILE_WIDTH, MapLayer.MAP_TILE_WIDTH)); SharedGraphics2D.Graphics.SmoothingMode = SmoothingMode.HighQuality; SharedGraphics2D.Graphics.CompositingQuality = CompositingQuality.HighQuality; SharedGraphics2D.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias; SharedGraphics2D.Graphics.PageUnit = GraphicsUnit.Pixel; BitmapGraphics.SmoothingMode = SmoothingMode.HighQuality; BitmapGraphics.CompositingQuality = CompositingQuality.HighQuality; BitmapGraphics.TextRenderingHint = TextRenderingHint.AntiAlias; BitmapGraphics.PageUnit = GraphicsUnit.Pixel; } } }
private void VerifyGraphicsContext() { if (SourceControlObject != null) { int ClientWidth = (SourceControlObject.ClientSize.Width + 1); int ClientHeight = (SourceControlObject.ClientSize.Height + 1); bool RebuildObjectsFlag = true; if ((GraphicsContextObject != null) && (GraphicsObject != null)) { if ((GraphicsContextObject.MaximumBuffer.Width == ClientWidth) && (GraphicsContextObject.MaximumBuffer.Height == ClientHeight)) { RebuildObjectsFlag = false; } } if (RebuildObjectsFlag == true) { if (GraphicsObject != null) { GraphicsObject.Dispose(); GraphicsObject = null; } if (GraphicsContextObject != null) { GraphicsContextObject.Dispose(); GraphicsContextObject = null; } if ((ClientWidth > 1) && (ClientHeight > 1)) { GraphicsContextObject = new BufferedGraphicsContext(); GraphicsContextObject.MaximumBuffer = new Size(ClientWidth, ClientHeight); Graphics ControlGraphicsObject = SourceControlObject.CreateGraphics(); GraphicsObject = GraphicsContextObject.Allocate(ControlGraphicsObject, SourceControlObject.ClientRectangle); GraphicsObject.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; GraphicsObject.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; } } } }