Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FreeRDP/GdiTest.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Moreau <marcandre.moreau@gmail.com>2011-03-27 23:40:39 +0400
committerMarc-André Moreau <marcandre.moreau@gmail.com>2011-03-27 23:40:39 +0400
commit51f9edb1729be4b7cac9ee64c9a1d7790f71a836 (patch)
tree13c2a95bc74b27ede3ddc773ba851c2697e2a953
parent40d99b0fb12a3b415fc787d87fc136b9dc6cebae (diff)
Refactoring of Win32 GDI wrapper class
-rw-r--r--GdiTest.userprefs6
-rw-r--r--GdiTest/BitBltDrawingArea.cs6
-rw-r--r--GdiTest/Gdi.cs40
-rw-r--r--GdiTest/Gdi32.cs123
-rw-r--r--GdiTest/GdiTest.csproj3
-rw-r--r--GdiTest/GdiTest.pidbbin12029 -> 12101 bytes
-rw-r--r--GdiTest/Main.cs1
-rw-r--r--GdiTest/Win32Gdi.cs114
8 files changed, 165 insertions, 128 deletions
diff --git a/GdiTest.userprefs b/GdiTest.userprefs
index 95fb57a..232e216 100644
--- a/GdiTest.userprefs
+++ b/GdiTest.userprefs
@@ -1,6 +1,10 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
- <MonoDevelop.Ide.Workbench />
+ <MonoDevelop.Ide.Workbench ActiveDocument="GdiTest/BitBltDrawingArea.cs">
+ <Files>
+ <File FileName="GdiTest/BitBltDrawingArea.cs" Line="31" Column="39" />
+ </Files>
+ </MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
diff --git a/GdiTest/BitBltDrawingArea.cs b/GdiTest/BitBltDrawingArea.cs
index 5f1af9d..2b13aa0 100644
--- a/GdiTest/BitBltDrawingArea.cs
+++ b/GdiTest/BitBltDrawingArea.cs
@@ -33,12 +33,14 @@ namespace GdiTest
cg.LineTo (110, 110);
cg.Stroke ();
- if (Gdi32.getWin32())
+ Win32Gdi win32Gdi = Win32Gdi.getInstance();
+
+ if (win32Gdi.isAvailable())
{
System.Drawing.Graphics wg = Gtk.DotNet.Graphics.FromDrawable(this.GdkWindow, true);
IntPtr dc = wg.GetHdc();
- Gdi32.BitBlt(dc, 70, 0, 60, 60, dc, 0, 0, Gdi32.SRCCOPY);
+ win32Gdi.BitBlt(dc, 70, 0, 60, 60, dc, 0, 0, Gdi.SRCCOPY);
}
}
return true;
diff --git a/GdiTest/Gdi.cs b/GdiTest/Gdi.cs
new file mode 100644
index 0000000..dcfc602
--- /dev/null
+++ b/GdiTest/Gdi.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace GdiTest
+{
+ public abstract class Gdi
+ {
+ public static System.Int32 SRCCOPY = 0x00CC0020; /* D = S */
+ public static System.Int32 SRCPAINT = 0x00EE0086; /* D = S | D */
+ public static System.Int32 SRCAND = 0x008800C6; /* D = S & D */
+ public static System.Int32 SRCINVERT = 0x00660046; /* D = S ^ D */
+ public static System.Int32 SRCERASE = 0x00440328; /* D = S & ~D */
+ public static System.Int32 NOTSRCCOPY = 0x00330008; /* D = ~S */
+ public static System.Int32 NOTSRCERASE = 0x001100A6; /* D = ~S & ~D */
+ public static System.Int32 MERGECOPY = 0x00C000CA; /* D = S & P */
+ public static System.Int32 MERGEPAINT = 0x00BB0226; /* D = ~S | D */
+ public static System.Int32 PATCOPY = 0x00F00021; /* D = P */
+ public static System.Int32 PATPAINT = 0x00FB0A09; /* D = D | (P | ~S) */
+ public static System.Int32 PATINVERT = 0x005A0049; /* D = P ^ D */
+ public static System.Int32 DSTINVERT = 0x00550009; /* D = ~D */
+ public static System.Int32 BLACKNESS = 0x00000042; /* D = 0 */
+ public static System.Int32 WHITENESS = 0x00FF0062; /* D = 1 */
+ public static System.Int32 DSPDxax = 0x00E20746; /* D = (S & P) | (~S & D) */
+ public static System.Int32 SPna = 0x000C0324; /* D = S & ~P */
+
+ public Gdi ()
+ {
+ }
+
+ public abstract void init();
+ public abstract bool isAvailable();
+ public abstract IntPtr GetDC(IntPtr hWnd);
+ public abstract int ReleaseDC(IntPtr hWnd, IntPtr hDC);
+ public abstract int GetPixel(IntPtr hdc, int X, int Y);
+ public abstract int SetPixel(IntPtr hdc, int X, int Y, int crColor);
+ public abstract int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
+ IntPtr hdcSrc, int nXSrc, int nYSrc, System.Int32 dwRop);
+ }
+}
+
diff --git a/GdiTest/Gdi32.cs b/GdiTest/Gdi32.cs
deleted file mode 100644
index e461ca2..0000000
--- a/GdiTest/Gdi32.cs
+++ /dev/null
@@ -1,123 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-
-namespace GdiTest
-{
- public class Gdi32
- {
- public static System.Int32 SRCCOPY = 0x00CC0020; /* D = S */
- public static System.Int32 SRCPAINT = 0x00EE0086; /* D = S | D */
- public static System.Int32 SRCAND = 0x008800C6; /* D = S & D */
- public static System.Int32 SRCINVERT = 0x00660046; /* D = S ^ D */
- public static System.Int32 SRCERASE = 0x00440328; /* D = S & ~D */
- public static System.Int32 NOTSRCCOPY = 0x00330008; /* D = ~S */
- public static System.Int32 NOTSRCERASE = 0x001100A6; /* D = ~S & ~D */
- public static System.Int32 MERGECOPY = 0x00C000CA; /* D = S & P */
- public static System.Int32 MERGEPAINT = 0x00BB0226; /* D = ~S | D */
- public static System.Int32 PATCOPY = 0x00F00021; /* D = P */
- public static System.Int32 PATPAINT = 0x00FB0A09; /* D = D | (P | ~S) */
- public static System.Int32 PATINVERT = 0x005A0049; /* D = P ^ D */
- public static System.Int32 DSTINVERT = 0x00550009; /* D = ~D */
- public static System.Int32 BLACKNESS = 0x00000042; /* D = 0 */
- public static System.Int32 WHITENESS = 0x00FF0062; /* D = 1 */
- public static System.Int32 DSPDxax = 0x00E20746; /* D = (S & P) | (~S & D) */
- public static System.Int32 SPna = 0x000C0324; /* D = S & ~P */
-
- public class NativeGdi32
- {
- [DllImport("user32.dll")]
- public static extern IntPtr GetDC(IntPtr hWnd);
-
- [DllImport("user32.dll")]
- public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
-
- [DllImport("gdi32.dll")]
- public static extern int GetPixel(IntPtr hdc, int X, int Y);
-
- [DllImport("gdi32.dll")]
- public static extern int SetPixel(IntPtr hdc, int X, int Y, int crColor);
-
- [DllImport("gdi32.dll")]
- public static extern int BitBlt(
- IntPtr hdcDest,
- int nXDest,
- int nYDest,
- int nWidth,
- int nHeight,
- IntPtr hdcSrc,
- int nXSrc,
- int nYSrc,
- System.Int32 dwRop
- );
- }
-
- static bool win32 = false;
-
- public Gdi32 ()
- {
- }
-
- public static void init()
- {
- int p = (int) Environment.OSVersion.Platform;
-
- if ((p == 4) || (p == 6) || (p == 128)) {
- win32 = false;
- } else {
- win32 = true;
- }
- }
-
- public static void setWin32(bool pWin32)
- {
- win32 = pWin32;
- }
-
- public static bool getWin32()
- {
- return win32;
- }
-
- public static IntPtr GetDC(IntPtr hWnd)
- {
- if (win32)
- return NativeGdi32.GetDC(hWnd);
- else
- return (IntPtr) null;
- }
-
- public static int ReleaseDC(IntPtr hWnd, IntPtr hDC)
- {
- if (win32)
- return NativeGdi32.ReleaseDC(hWnd, hDC);
- else
- return 0;
- }
-
- public static int GetPixel(IntPtr hdc, int X, int Y)
- {
- if (win32)
- return NativeGdi32.GetPixel(hdc, X, Y);
- else
- return 0;
- }
-
- public static int SetPixel(IntPtr hdc, int X, int Y, int crColor)
- {
- if (win32)
- return NativeGdi32.SetPixel(hdc, X, Y, crColor);
- else
- return 0;
- }
-
- public static int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
- IntPtr hdcSrc, int nXSrc, int nYSrc, System.Int32 dwRop)
- {
- if (win32)
- return NativeGdi32.BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop);
- else
- return 0;
- }
- }
-}
-
diff --git a/GdiTest/GdiTest.csproj b/GdiTest/GdiTest.csproj
index 68489c4..f4a91af 100644
--- a/GdiTest/GdiTest.csproj
+++ b/GdiTest/GdiTest.csproj
@@ -57,8 +57,9 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="LineDrawingArea.cs" />
<Compile Include="BitBltDrawingArea.cs" />
- <Compile Include="Gdi32.cs" />
<Compile Include="TestData.cs" />
+ <Compile Include="Win32Gdi.cs" />
+ <Compile Include="Gdi.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project> \ No newline at end of file
diff --git a/GdiTest/GdiTest.pidb b/GdiTest/GdiTest.pidb
index f29b539..0595485 100644
--- a/GdiTest/GdiTest.pidb
+++ b/GdiTest/GdiTest.pidb
Binary files differ
diff --git a/GdiTest/Main.cs b/GdiTest/Main.cs
index 1d24365..180a4e4 100644
--- a/GdiTest/Main.cs
+++ b/GdiTest/Main.cs
@@ -8,7 +8,6 @@ namespace GdiTest
{
public static void Main (string[] args)
{
- Gdi32.init();
Application.Init ();
MainWindow w = new MainWindow ();
diff --git a/GdiTest/Win32Gdi.cs b/GdiTest/Win32Gdi.cs
new file mode 100644
index 0000000..23fdede
--- /dev/null
+++ b/GdiTest/Win32Gdi.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace GdiTest
+{
+ public class Win32Gdi : Gdi
+ {
+ static bool available = false;
+ static bool initialized = false;
+ static Win32Gdi instance = null;
+
+ public class NativeGdi
+ {
+ [DllImport("user32.dll")]
+ public static extern IntPtr GetDC(IntPtr hWnd);
+
+ [DllImport("user32.dll")]
+ public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
+
+ [DllImport("gdi32.dll")]
+ public static extern int GetPixel(IntPtr hdc, int X, int Y);
+
+ [DllImport("gdi32.dll")]
+ public static extern int SetPixel(IntPtr hdc, int X, int Y, int crColor);
+
+ [DllImport("gdi32.dll")]
+ public static extern int BitBlt(
+ IntPtr hdcDest,
+ int nXDest,
+ int nYDest,
+ int nWidth,
+ int nHeight,
+ IntPtr hdcSrc,
+ int nXSrc,
+ int nYSrc,
+ System.Int32 dwRop
+ );
+ }
+
+ public Win32Gdi ()
+ {
+ this.init();
+ }
+
+ public static Win32Gdi getInstance()
+ {
+ if (!initialized)
+ {
+ instance = new Win32Gdi();
+ initialized = true;
+ }
+
+ return instance;
+ }
+
+ public override void init()
+ {
+ int p = (int) Environment.OSVersion.Platform;
+
+ if ((p == 4) || (p == 6) || (p == 128)) {
+ available = false;
+ } else {
+ available = true;
+ }
+ }
+
+ public override bool isAvailable()
+ {
+ return available;
+ }
+
+ public override IntPtr GetDC(IntPtr hWnd)
+ {
+ if (available)
+ return NativeGdi.GetDC(hWnd);
+ else
+ return (IntPtr) null;
+ }
+
+ public override int ReleaseDC(IntPtr hWnd, IntPtr hDC)
+ {
+ if (available)
+ return NativeGdi.ReleaseDC(hWnd, hDC);
+ else
+ return 0;
+ }
+
+ public override int GetPixel(IntPtr hdc, int X, int Y)
+ {
+ if (available)
+ return NativeGdi.GetPixel(hdc, X, Y);
+ else
+ return 0;
+ }
+
+ public override int SetPixel(IntPtr hdc, int X, int Y, int crColor)
+ {
+ if (available)
+ return NativeGdi.SetPixel(hdc, X, Y, crColor);
+ else
+ return 0;
+ }
+
+ public override int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
+ IntPtr hdcSrc, int nXSrc, int nYSrc, System.Int32 dwRop)
+ {
+ if (available)
+ return NativeGdi.BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop);
+ else
+ return 0;
+ }
+ }
+}
+