Skip to content

Commit 9911e51

Browse files
Add files via upload
1 parent 42e65ac commit 9911e51

14 files changed

+4795
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using System.Drawing;
3+
4+
namespace GDIDB
5+
{
6+
/// <summary>
7+
/// Class to implement Double Buffering
8+
/// Author: NT Almond
9+
/// 24 July 2003
10+
/// Used by the Graph class to update the display graphs.
11+
/// </summary>
12+
///
13+
public class DBGraphics
14+
{
15+
private Graphics graphics;
16+
private Bitmap memoryBitmap;
17+
private int width;
18+
private int height;
19+
20+
/// <summary>
21+
/// Default constructor
22+
/// </summary>
23+
public DBGraphics()
24+
{
25+
width = 0;
26+
height = 0;
27+
}
28+
29+
/// <summary>
30+
/// Creates double buffer object
31+
/// </summary>
32+
/// <param name="g">Window forms Graphics Object</param>
33+
/// <param name="width">width of paint area</param>
34+
/// <param name="height">height of paint area</param>
35+
/// <returns>true/false if double buffer is created</returns>
36+
public bool CreateDoubleBuffer(Graphics g, int width, int height)
37+
{
38+
39+
if (memoryBitmap != null)
40+
{
41+
memoryBitmap.Dispose();
42+
memoryBitmap = null;
43+
}
44+
45+
if (graphics != null)
46+
{
47+
graphics.Dispose();
48+
graphics = null;
49+
}
50+
51+
if (width == 0 || height == 0)
52+
return false;
53+
54+
55+
if ((width != this.width) || (height != this.height))
56+
{
57+
this.width = width;
58+
this.height = height;
59+
60+
memoryBitmap = new Bitmap(width, height);
61+
graphics = Graphics.FromImage(memoryBitmap);
62+
}
63+
64+
return true;
65+
}
66+
67+
68+
/// <summary>
69+
/// Renders the double buffer to the screen
70+
/// </summary>
71+
/// <param name="g">Window forms Graphics Object</param>
72+
public void Render(Graphics g)
73+
{
74+
if (memoryBitmap != null)
75+
g.DrawImage(memoryBitmap, new Rectangle(0,0, width, height),0,0, width, height, GraphicsUnit.Pixel);
76+
}
77+
78+
/// <summary>
79+
///
80+
/// </summary>
81+
/// <returns>true if double buffering can be achieved</returns>
82+
public bool CanDoubleBuffer()
83+
{
84+
return graphics != null;
85+
}
86+
87+
/// <summary>
88+
/// Accessor for memory graphics object
89+
/// </summary>
90+
public Graphics g
91+
{
92+
get
93+
{
94+
return graphics;
95+
}
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)