diff options
author | Marc-André Moreau <marcandre.moreau@gmail.com> | 2011-03-30 06:10:09 +0400 |
---|---|---|
committer | Marc-André Moreau <marcandre.moreau@gmail.com> | 2011-03-30 06:10:09 +0400 |
commit | dff5f1d3bdb52feac65aacd4855597dd620ae459 (patch) | |
tree | d83a7728ed004735ea3376848c87e340de38cfb3 | |
parent | abe821c200eb66e26266f698e8b04ebd5907f622 (diff) |
Added Ellipse() testing view
-rw-r--r-- | GdiTest/BitBltDrawingArea.cs | 35 | ||||
-rw-r--r-- | GdiTest/EllipseDrawingArea.cs | 69 | ||||
-rw-r--r-- | GdiTest/FreeRDPGDI.cs | 10 | ||||
-rw-r--r-- | GdiTest/GDI.cs | 2 | ||||
-rw-r--r-- | GdiTest/GdiTest.csproj | 1 | ||||
-rw-r--r-- | GdiTest/LineToDrawingArea.cs | 31 | ||||
-rw-r--r-- | GdiTest/MainWindow.cs | 14 | ||||
-rw-r--r-- | GdiTest/TestDrawingArea.cs | 27 | ||||
-rw-r--r-- | GdiTest/Win32GDI.cs | 22 | ||||
-rw-r--r-- | GdiTest/gtk-gui/MainWindow.cs | 1 | ||||
-rw-r--r-- | GdiTest/gtk-gui/gui.stetic | 3 |
11 files changed, 149 insertions, 66 deletions
diff --git a/GdiTest/BitBltDrawingArea.cs b/GdiTest/BitBltDrawingArea.cs index 8ccb5a8..6c61180 100644 --- a/GdiTest/BitBltDrawingArea.cs +++ b/GdiTest/BitBltDrawingArea.cs @@ -36,13 +36,13 @@ namespace GdiTest drawBitmap(hdc, 32, 0, bmp_PAT); dumpText += "unsigned char bmp_SRC[" + bmp_SRC.Width * bmp_SRC.Height + "] = \n"; - dumpText += this.dump(hdc, 0, 0, bmp_SRC.Width, bmp_SRC.Height) + "\n"; + dumpText += dumpPixelArea(GDI_Win32, hdc, 0, 0, bmp_SRC.Width, bmp_SRC.Height) + "\n"; dumpText += "unsigned char bmp_DST[" + bmp_DST.Width * bmp_DST.Height + "] = \n"; - dumpText += this.dump(hdc, 16, 0, bmp_DST.Width, bmp_DST.Height) + "\n"; + dumpText += dumpPixelArea(GDI_Win32, hdc, 16, 0, bmp_DST.Width, bmp_DST.Height) + "\n"; dumpText += "unsigned char bmp_PAT[" + bmp_PAT.Width * bmp_PAT.Height + "] = \n"; - dumpText += this.dump(hdc, 32, 0, bmp_PAT.Width, bmp_PAT.Height) + "\n"; + dumpText += dumpPixelArea(GDI_Win32, hdc, 32, 0, bmp_PAT.Width, bmp_PAT.Height) + "\n"; //GDI_Win32.BitBlt(dc, 70, 0, 60, 60, dc, 0, 0, GDI.SRCCOPY); } @@ -71,35 +71,6 @@ namespace GdiTest } } - public String dump(IntPtr hdc, int X, int Y, int W, int H) - { - String text = ""; - - Win32GDI GDI_Win32 = Win32GDI.getInstance(); - - if (GDI_Win32.isAvailable()) - { - text += "{\n"; - for (int y = Y; y < Y + H; y++) - { - text += "\t\""; - for (int x = X; x < X + W; x++) - { - int p = GDI_Win32.GetPixel(hdc, x, y); - - if (p == 0) - text += "\\x00"; - else - text += "\\xFF"; - } - text += "\"\n"; - } - text += "};\n"; - } - - return text; - } - public override String getDumpText () { return dumpText; diff --git a/GdiTest/EllipseDrawingArea.cs b/GdiTest/EllipseDrawingArea.cs new file mode 100644 index 0000000..60ae5ac --- /dev/null +++ b/GdiTest/EllipseDrawingArea.cs @@ -0,0 +1,69 @@ +using Gtk; +using Cairo; +using System; +using System.Drawing; + +namespace GdiTest +{ + public class EllipseDrawingArea : TestDrawingArea + { + String dumpText; + + public EllipseDrawingArea () + { + dumpText = ""; + } + + protected override bool OnExposeEvent (Gdk.EventExpose args) + { + using (Context cg = Gdk.CairoHelper.Create (args.Window)) + { + Win32GDI GDI_Win32 = Win32GDI.getInstance(); + + if (GDI_Win32.isAvailable()) + { + System.Drawing.Graphics wg = Gtk.DotNet.Graphics.FromDrawable(this.GdkWindow, true); + IntPtr hdc = wg.GetHdc(); + + int i = 0; + int n = 1; + int w = 16; + int h = 16; + + Area[] areas = new Area[n]; + + areas[i].X = 0; + areas[i].Y = 0; + areas[i].W = w; + areas[i].H = h; + i++; + + /* Fill Area with White */ + cg.Color = new Cairo.Color(255,255,255); + Cairo.Rectangle rect = new Cairo.Rectangle(0, 0, n * w, h); + cg.Rectangle(rect); + cg.Fill(); + cg.Stroke(); + + IntPtr blackSolidBrush = GDI_Win32.CreateSolidBrush(0); + IntPtr oldBrush = GDI_Win32.SelectObject(hdc, blackSolidBrush); + + for (i = 0; i < n; i++) + { + GDI_Win32.Ellipse(hdc, areas[i].X, areas[i].Y, areas[i].W, areas[i].H); + + dumpText += "unsigned char ellipse_case_" + (i + 1) + "[" + w * h + "] = \n"; + dumpText += dumpPixelArea(GDI_Win32, hdc, i * w, 0, w, h) + "\n"; + } + } + } + return true; + } + + public override string getDumpText () + { + return dumpText; + } + } +} + diff --git a/GdiTest/FreeRDPGDI.cs b/GdiTest/FreeRDPGDI.cs index ab3bd4a..89e8403 100644 --- a/GdiTest/FreeRDPGDI.cs +++ b/GdiTest/FreeRDPGDI.cs @@ -102,6 +102,16 @@ namespace GdiTest return (IntPtr) null; } + public override IntPtr CreateSolidBrush(int crColor) + { + return (IntPtr) null; + } + + public override bool Ellipse(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect) + { + return false; + } + public override 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/GDI.cs b/GdiTest/GDI.cs index 9272bb9..fe3136c 100644 --- a/GdiTest/GDI.cs +++ b/GdiTest/GDI.cs @@ -38,6 +38,8 @@ namespace GdiTest public abstract bool MoveToEx(IntPtr hdc, int X, int Y, IntPtr lpPoint); public abstract bool LineTo(IntPtr hdc, int nXEnd, int nYEnd); public abstract IntPtr CreatePen(int fnPenStyle, int nWidth, int crColor); + public abstract IntPtr CreateSolidBrush(int crColor); + public abstract bool Ellipse(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect); 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/GdiTest.csproj b/GdiTest/GdiTest.csproj index e1e5b34..669c01c 100644 --- a/GdiTest/GdiTest.csproj +++ b/GdiTest/GdiTest.csproj @@ -61,6 +61,7 @@ <Compile Include="FreeRDPGDI.cs" /> <Compile Include="LineToDrawingArea.cs" /> <Compile Include="TestDrawingArea.cs" /> + <Compile Include="EllipseDrawingArea.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup> diff --git a/GdiTest/LineToDrawingArea.cs b/GdiTest/LineToDrawingArea.cs index d98f932..d1a94b9 100644 --- a/GdiTest/LineToDrawingArea.cs +++ b/GdiTest/LineToDrawingArea.cs @@ -166,7 +166,7 @@ namespace GdiTest GDI_Win32.LineTo(hdc, endp[i].X, endp[i].Y); dumpText += "unsigned char line_to_case_" + (i + 1) + "[" + areas[i].W * areas[i].H + "] = \n"; - dumpText += this.dump(hdc, areas[i].X, areas[i].Y, areas[i].W, areas[i].H) + "\n"; + dumpText += dumpPixelArea(GDI_Win32, hdc, areas[i].X, areas[i].Y, areas[i].W, areas[i].H) + "\n"; } } } @@ -174,35 +174,6 @@ namespace GdiTest return true; } - public String dump(IntPtr hdc, int X, int Y, int W, int H) - { - String text = ""; - - Win32GDI GDI_Win32 = Win32GDI.getInstance(); - - if (GDI_Win32.isAvailable()) - { - text += "{\n"; - for (int y = Y; y < Y + H; y++) - { - text += "\t\""; - for (int x = X; x < X + W; x++) - { - int p = GDI_Win32.GetPixel(hdc, x, y); - - if (p == 0) - text += "\\x00"; - else - text += "\\xFF"; - } - text += "\"\n"; - } - text += "};\n"; - } - - return text; - } - public override String getDumpText() { return dumpText; diff --git a/GdiTest/MainWindow.cs b/GdiTest/MainWindow.cs index c153b1d..891b9d2 100644 --- a/GdiTest/MainWindow.cs +++ b/GdiTest/MainWindow.cs @@ -9,12 +9,14 @@ public partial class MainWindow : Gtk.Window TestDrawingArea testDrawingArea; TestDrawingArea lineToDrawingArea; TestDrawingArea bitBltDrawingArea; + TestDrawingArea ellipseDrawingArea; public MainWindow () : base(Gtk.WindowType.Toplevel) { Build (); - lineToDrawingArea = new LineToDrawingArea (); - bitBltDrawingArea = new BitBltDrawingArea (); + lineToDrawingArea = new LineToDrawingArea(); + bitBltDrawingArea = new BitBltDrawingArea(); + ellipseDrawingArea = new EllipseDrawingArea(); testDrawingArea = lineToDrawingArea; testFrame.Add(testDrawingArea); @@ -23,7 +25,7 @@ public partial class MainWindow : Gtk.Window protected void OnDeleteEvent (object sender, DeleteEventArgs a) { - Application.Quit (); + Application.Quit(); a.RetVal = true; } @@ -50,6 +52,12 @@ public partial class MainWindow : Gtk.Window testFrame.Add(testDrawingArea); testFrame.ShowAll(); } + else if (testSuiteName.Equals("Ellipse")) + { + testDrawingArea = ellipseDrawingArea; + testFrame.Add(testDrawingArea); + testFrame.ShowAll(); + } } protected virtual void OnDumpButtonClicked (object sender, System.EventArgs e) { diff --git a/GdiTest/TestDrawingArea.cs b/GdiTest/TestDrawingArea.cs index f32ddd2..8b36e32 100644 --- a/GdiTest/TestDrawingArea.cs +++ b/GdiTest/TestDrawingArea.cs @@ -19,6 +19,33 @@ namespace GdiTest } abstract public String getDumpText(); + + public String dumpPixelArea(GDI gdi, IntPtr hdc, int X, int Y, int W, int H) + { + String text = ""; + + if (gdi.isAvailable()) + { + text += "{\n"; + for (int y = Y; y < Y + H; y++) + { + text += "\t\""; + for (int x = X; x < X + W; x++) + { + int p = gdi.GetPixel(hdc, x, y); + + if (p == 0) + text += "\\x00"; + else + text += "\\xFF"; + } + text += "\"\n"; + } + text += "};\n"; + } + + return text; + } } } diff --git a/GdiTest/Win32GDI.cs b/GdiTest/Win32GDI.cs index 0e788f9..a6f8fd7 100644 --- a/GdiTest/Win32GDI.cs +++ b/GdiTest/Win32GDI.cs @@ -38,6 +38,12 @@ namespace GdiTest [DllImport("gdi32")] public static extern IntPtr CreatePen(int fnPenStyle, int nWidth, int crColor); + [DllImport("gdi32")] + public static extern IntPtr CreateSolidBrush(int crColor); + + [DllImport("gdi32")] + public static extern bool Ellipse(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect); + [DllImport("gdi32.dll")] public static extern int BitBlt( IntPtr hdcDest, @@ -165,6 +171,22 @@ namespace GdiTest return (IntPtr) null; } + public override bool Ellipse(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect) + { + if (available) + return Callbacks.Ellipse(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect); + else + return false; + } + + public override IntPtr CreateSolidBrush(int crColor) + { + if (available) + return Callbacks.CreateSolidBrush(crColor); + else + return (IntPtr) null; + } + public override 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/gtk-gui/MainWindow.cs b/GdiTest/gtk-gui/MainWindow.cs index a996874..312714e 100644 --- a/GdiTest/gtk-gui/MainWindow.cs +++ b/GdiTest/gtk-gui/MainWindow.cs @@ -73,6 +73,7 @@ public partial class MainWindow this.testComboBox = global::Gtk.ComboBox.NewText (); this.testComboBox.AppendText (global::Mono.Unix.Catalog.GetString ("LineTo")); this.testComboBox.AppendText (global::Mono.Unix.Catalog.GetString ("BitBlt")); + this.testComboBox.AppendText (global::Mono.Unix.Catalog.GetString ("Ellipse")); this.testComboBox.Name = "testComboBox"; this.testComboBox.Active = 0; this.mainFixedContainer.Add (this.testComboBox); diff --git a/GdiTest/gtk-gui/gui.stetic b/GdiTest/gtk-gui/gui.stetic index 2691faa..fcfc064 100644 --- a/GdiTest/gtk-gui/gui.stetic +++ b/GdiTest/gtk-gui/gui.stetic @@ -93,7 +93,8 @@ <property name="MemberName" /> <property name="IsTextCombo">True</property> <property name="Items" translatable="yes">LineTo -BitBlt</property> +BitBlt +Ellipse</property> <property name="Active">0</property> <signal name="Changed" handler="OnTestComboBoxChanged" /> </widget> |