diff options
author | Marc-André Moreau <marcandre.moreau@gmail.com> | 2011-03-29 09:02:04 +0400 |
---|---|---|
committer | Marc-André Moreau <marcandre.moreau@gmail.com> | 2011-03-29 09:02:04 +0400 |
commit | 9773a2f6780cd62d6e3c000b710f789469b075fd (patch) | |
tree | 6810e36fa87fe7ad7d4b5d9b037957c4dbf5ffd2 | |
parent | bb79aa303c67ed270a3fb470897442d53adb2b0d (diff) |
Added "dump" button, started trying to properly dump test data
-rw-r--r-- | GdiTest/BitBltDrawingArea.cs | 27 | ||||
-rw-r--r-- | GdiTest/FreeRDPGDI.cs | 4 | ||||
-rw-r--r-- | GdiTest/GDI.cs | 4 | ||||
-rw-r--r-- | GdiTest/GdiTest.csproj | 1 | ||||
-rw-r--r-- | GdiTest/LineToDrawingArea.cs | 59 | ||||
-rw-r--r-- | GdiTest/MainWindow.cs | 13 | ||||
-rw-r--r-- | GdiTest/TestDrawingArea.cs | 16 | ||||
-rw-r--r-- | GdiTest/Win32GDI.cs | 19 | ||||
-rw-r--r-- | GdiTest/gtk-gui/MainWindow.cs | 49 | ||||
-rw-r--r-- | GdiTest/gtk-gui/gui.stetic | 58 |
10 files changed, 200 insertions, 50 deletions
diff --git a/GdiTest/BitBltDrawingArea.cs b/GdiTest/BitBltDrawingArea.cs index 1a42802..a5e3de9 100644 --- a/GdiTest/BitBltDrawingArea.cs +++ b/GdiTest/BitBltDrawingArea.cs @@ -5,7 +5,7 @@ using System.Drawing; namespace GdiTest { - public class BitBltDrawingArea : DrawingArea + public class BitBltDrawingArea : TestDrawingArea { public BitBltDrawingArea () { @@ -52,6 +52,31 @@ namespace GdiTest } return true; } + + public override String dump() + { + String text = ""; + + Win32GDI GDI_Win32 = Win32GDI.getInstance(); + + if (GDI_Win32.isAvailable()) + { + System.Drawing.Graphics wg = Gtk.DotNet.Graphics.FromDrawable(this.GdkWindow, true); + IntPtr hdc = wg.GetHdc(); + + for (int y = 0; y < 16; y++) + { + for (int x = 0; x < 16; x++) + { + System.Drawing.Color color = GDI_Win32.GetPixelColor(x, y); + text += String.Format("0x{0:X}, ", color.ToArgb()); + } + text += "\n"; + } + } + + return text; + } } } diff --git a/GdiTest/FreeRDPGDI.cs b/GdiTest/FreeRDPGDI.cs index ab3bd4a..a38b5f7 100644 --- a/GdiTest/FreeRDPGDI.cs +++ b/GdiTest/FreeRDPGDI.cs @@ -77,12 +77,12 @@ namespace GdiTest return false; } - public override int GetPixel(IntPtr hdc, int X, int Y) + public override uint GetPixel(IntPtr hdc, int X, int Y) { return 0; } - public override int SetPixel(IntPtr hdc, int X, int Y, int crColor) + public override uint SetPixel(IntPtr hdc, int X, int Y, int crColor) { return 0; } diff --git a/GdiTest/GDI.cs b/GdiTest/GDI.cs index 9272bb9..8aa8351 100644 --- a/GdiTest/GDI.cs +++ b/GdiTest/GDI.cs @@ -33,8 +33,8 @@ namespace GdiTest public abstract int ReleaseDC(IntPtr hWnd, IntPtr hDC); public abstract IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj); public abstract bool DeleteObject(IntPtr hObject); - public abstract int GetPixel(IntPtr hdc, int X, int Y); - public abstract int SetPixel(IntPtr hdc, int X, int Y, int crColor); + public abstract uint GetPixel(IntPtr hdc, int X, int Y); + public abstract uint SetPixel(IntPtr hdc, int X, int Y, int crColor); 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); diff --git a/GdiTest/GdiTest.csproj b/GdiTest/GdiTest.csproj index 127f976..6fdfac3 100644 --- a/GdiTest/GdiTest.csproj +++ b/GdiTest/GdiTest.csproj @@ -61,6 +61,7 @@ <Compile Include="Win32GDI.cs" /> <Compile Include="FreeRDPGDI.cs" /> <Compile Include="LineToDrawingArea.cs" /> + <Compile Include="TestDrawingArea.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file diff --git a/GdiTest/LineToDrawingArea.cs b/GdiTest/LineToDrawingArea.cs index bd644ad..0144258 100644 --- a/GdiTest/LineToDrawingArea.cs +++ b/GdiTest/LineToDrawingArea.cs @@ -4,7 +4,7 @@ using Gtk; namespace GdiTest { - public class LineToDrawingArea : DrawingArea + public class LineToDrawingArea : TestDrawingArea { public struct Area { @@ -14,23 +14,26 @@ namespace GdiTest public int H; } + private bool rendered; + public LineToDrawingArea() { + rendered = false; } protected override bool OnExposeEvent (Gdk.EventExpose args) { using (Context g = Gdk.CairoHelper.Create (args.Window)) { - g.Antialias = Antialias.None; g.LineWidth = 1; + g.Antialias = Antialias.None; Win32GDI GDI_Win32 = Win32GDI.getInstance(); if (GDI_Win32.isAvailable()) - { + { System.Drawing.Graphics wg = Gtk.DotNet.Graphics.FromDrawable(this.GdkWindow, true); - IntPtr dc = wg.GetHdc(); + IntPtr hdc = wg.GetHdc(); int i = 0; int n = 10; @@ -153,23 +156,51 @@ namespace GdiTest for (i = 0; i < n; i++) { - /* Fill Area with White */ - g.Color = new Color(255,255,255); - Rectangle rect = new Rectangle(areas[i].X, areas[i].Y, areas[i].W, areas[i].H); - g.Rectangle(rect); - g.Fill(); - g.Stroke(); - + if (!rendered) + { + /* Fill Area with White */ + g.Color = new Color(255,255,255); + Rectangle rect = new Rectangle(areas[i].X, areas[i].Y, areas[i].W, areas[i].H); + g.Rectangle(rect); + g.Fill(); + g.Stroke(); + } + /* Render Test Case */ IntPtr pen = GDI_Win32.CreatePen(1, 1, 0); - IntPtr oldPen = GDI_Win32.SelectObject(dc, pen); - GDI_Win32.MoveToEx(dc, startp[i].X, startp[i].Y, IntPtr.Zero); - GDI_Win32.LineTo(dc, endp[i].X, endp[i].Y); + IntPtr oldPen = GDI_Win32.SelectObject(hdc, pen); + GDI_Win32.MoveToEx(hdc, startp[i].X, startp[i].Y, IntPtr.Zero); + GDI_Win32.LineTo(hdc, endp[i].X, endp[i].Y); } } } return true; } + + public override String dump() + { + String text = ""; + + Win32GDI GDI_Win32 = Win32GDI.getInstance(); + + if (GDI_Win32.isAvailable()) + { + System.Drawing.Graphics wg = Gtk.DotNet.Graphics.FromDrawable(this.GdkWindow, true); + IntPtr hdc = wg.GetHdc(); + + for (int y = 0; y < 16; y++) + { + for (int x = 0; x < 16; x++) + { + System.Drawing.Color color = GDI_Win32.GetPixelColor(x, y); + text += String.Format("0x{0:X}, ", color.ToArgb()); + } + text += "\n"; + } + } + + return text; + } } } diff --git a/GdiTest/MainWindow.cs b/GdiTest/MainWindow.cs index 58eb657..214c593 100644 --- a/GdiTest/MainWindow.cs +++ b/GdiTest/MainWindow.cs @@ -6,9 +6,9 @@ using GdiTest; public partial class MainWindow : Gtk.Window { - DrawingArea testDrawingArea; - DrawingArea lineToDrawingArea; - DrawingArea bitBltDrawingArea; + TestDrawingArea testDrawingArea; + TestDrawingArea lineToDrawingArea; + TestDrawingArea bitBltDrawingArea; public MainWindow () : base(Gtk.WindowType.Toplevel) { @@ -50,4 +50,11 @@ public partial class MainWindow : Gtk.Window testFrame.ShowAll(); } } + protected virtual void OnDumpButtonClicked (object sender, System.EventArgs e) + { + String dumpText = testDrawingArea.dump(); + dumpTextView.Buffer.Text = dumpText; + } + + } diff --git a/GdiTest/TestDrawingArea.cs b/GdiTest/TestDrawingArea.cs new file mode 100644 index 0000000..27e9d24 --- /dev/null +++ b/GdiTest/TestDrawingArea.cs @@ -0,0 +1,16 @@ +using System; +using Cairo; +using Gtk; + +namespace GdiTest +{ + public abstract class TestDrawingArea : DrawingArea + { + public TestDrawingArea () + { + } + + abstract public String dump(); + } +} + diff --git a/GdiTest/Win32GDI.cs b/GdiTest/Win32GDI.cs index be620eb..0fd19c4 100644 --- a/GdiTest/Win32GDI.cs +++ b/GdiTest/Win32GDI.cs @@ -24,10 +24,10 @@ namespace GdiTest public static extern bool DeleteObject(IntPtr hObject); [DllImport("gdi32.dll")] - public static extern int GetPixel(IntPtr hdc, int X, int Y); + public static extern uint GetPixel(IntPtr hdc, int X, int Y); [DllImport("gdi32.dll")] - public static extern int SetPixel(IntPtr hdc, int X, int Y, int crColor); + public static extern uint SetPixel(IntPtr hdc, int X, int Y, int crColor); [DllImport("gdi32")] public static extern bool MoveToEx(IntPtr hdc, int X, int Y, IntPtr lpPoint); @@ -116,7 +116,7 @@ namespace GdiTest return false; } - public override int GetPixel(IntPtr hdc, int X, int Y) + public override uint GetPixel(IntPtr hdc, int X, int Y) { if (available) return Callbacks.GetPixel(hdc, X, Y); @@ -124,7 +124,7 @@ namespace GdiTest return 0; } - public override int SetPixel(IntPtr hdc, int X, int Y, int crColor) + public override uint SetPixel(IntPtr hdc, int X, int Y, int crColor) { if (available) return Callbacks.SetPixel(hdc, X, Y, crColor); @@ -132,6 +132,17 @@ namespace GdiTest return 0; } + public System.Drawing.Color GetPixelColor(int x, int y) + { + IntPtr hdc = GetDC(IntPtr.Zero); + uint pixel = Callbacks.GetPixel(hdc, x, y); + ReleaseDC(IntPtr.Zero, hdc); + System.Drawing.Color color = System.Drawing.Color.FromArgb((int)(pixel & 0x000000FF), + (int)(pixel & 0x0000FF00) >> 8, + (int)(pixel & 0x00FF0000) >> 16); + return color; + } + public override bool MoveToEx(IntPtr hdc, int X, int Y, IntPtr lpPoint) { if (available) diff --git a/GdiTest/gtk-gui/MainWindow.cs b/GdiTest/gtk-gui/MainWindow.cs index f82e313..a996874 100644 --- a/GdiTest/gtk-gui/MainWindow.cs +++ b/GdiTest/gtk-gui/MainWindow.cs @@ -9,12 +9,16 @@ public partial class MainWindow private global::Gtk.ScrolledWindow GtkScrolledWindow; + private global::Gtk.TextView dumpTextView; + private global::Gtk.Frame testFrame; private global::Gtk.Label drawingAreaLabel; private global::Gtk.ComboBox testComboBox; + private global::Gtk.Button dumpButton; + protected virtual void Build () { global::Stetic.Gui.Initialize (this); @@ -36,18 +40,24 @@ public partial class MainWindow w1.Y = 31; // Container child mainFixedContainer.Gtk.Fixed+FixedChild this.GtkScrolledWindow = new global::Gtk.ScrolledWindow (); - this.GtkScrolledWindow.WidthRequest = 600; - this.GtkScrolledWindow.HeightRequest = 100; this.GtkScrolledWindow.Name = "GtkScrolledWindow"; this.GtkScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1)); + // Container child GtkScrolledWindow.Gtk.Container+ContainerChild + this.dumpTextView = new global::Gtk.TextView (); + this.dumpTextView.WidthRequest = 600; + this.dumpTextView.HeightRequest = 200; + this.dumpTextView.CanFocus = true; + this.dumpTextView.Name = "dumpTextView"; + this.dumpTextView.Editable = false; + this.GtkScrolledWindow.Add (this.dumpTextView); this.mainFixedContainer.Add (this.GtkScrolledWindow); - global::Gtk.Fixed.FixedChild w2 = ((global::Gtk.Fixed.FixedChild)(this.mainFixedContainer[this.GtkScrolledWindow])); - w2.X = 9; - w2.Y = 520; + global::Gtk.Fixed.FixedChild w3 = ((global::Gtk.Fixed.FixedChild)(this.mainFixedContainer[this.GtkScrolledWindow])); + w3.X = 14; + w3.Y = 286; // Container child mainFixedContainer.Gtk.Fixed+FixedChild this.testFrame = new global::Gtk.Frame (); this.testFrame.WidthRequest = 600; - this.testFrame.HeightRequest = 400; + this.testFrame.HeightRequest = 200; this.testFrame.Name = "testFrame"; this.testFrame.ShadowType = ((global::Gtk.ShadowType)(0)); this.drawingAreaLabel = new global::Gtk.Label (); @@ -56,9 +66,9 @@ public partial class MainWindow this.drawingAreaLabel.UseMarkup = true; this.testFrame.LabelWidget = this.drawingAreaLabel; this.mainFixedContainer.Add (this.testFrame); - global::Gtk.Fixed.FixedChild w3 = ((global::Gtk.Fixed.FixedChild)(this.mainFixedContainer[this.testFrame])); - w3.X = 7; - w3.Y = 75; + global::Gtk.Fixed.FixedChild w4 = ((global::Gtk.Fixed.FixedChild)(this.mainFixedContainer[this.testFrame])); + w4.X = 21; + w4.Y = 76; // Container child mainFixedContainer.Gtk.Fixed+FixedChild this.testComboBox = global::Gtk.ComboBox.NewText (); this.testComboBox.AppendText (global::Mono.Unix.Catalog.GetString ("LineTo")); @@ -66,17 +76,28 @@ public partial class MainWindow this.testComboBox.Name = "testComboBox"; this.testComboBox.Active = 0; this.mainFixedContainer.Add (this.testComboBox); - global::Gtk.Fixed.FixedChild w4 = ((global::Gtk.Fixed.FixedChild)(this.mainFixedContainer[this.testComboBox])); - w4.X = 70; - w4.Y = 18; + global::Gtk.Fixed.FixedChild w5 = ((global::Gtk.Fixed.FixedChild)(this.mainFixedContainer[this.testComboBox])); + w5.X = 74; + w5.Y = 27; + // Container child mainFixedContainer.Gtk.Fixed+FixedChild + this.dumpButton = new global::Gtk.Button (); + this.dumpButton.CanFocus = true; + this.dumpButton.Name = "dumpButton"; + this.dumpButton.UseUnderline = true; + this.dumpButton.Label = global::Mono.Unix.Catalog.GetString ("Dump"); + this.mainFixedContainer.Add (this.dumpButton); + global::Gtk.Fixed.FixedChild w6 = ((global::Gtk.Fixed.FixedChild)(this.mainFixedContainer[this.dumpButton])); + w6.X = 156; + w6.Y = 26; this.Add (this.mainFixedContainer); if ((this.Child != null)) { this.Child.ShowAll (); } - this.DefaultWidth = 632; - this.DefaultHeight = 663; + this.DefaultWidth = 664; + this.DefaultHeight = 562; this.Show (); this.DeleteEvent += new global::Gtk.DeleteEventHandler (this.OnDeleteEvent); this.testComboBox.Changed += new global::System.EventHandler (this.OnTestComboBoxChanged); + this.dumpButton.Clicked += new global::System.EventHandler (this.OnDumpButtonClicked); } } diff --git a/GdiTest/gtk-gui/gui.stetic b/GdiTest/gtk-gui/gui.stetic index 7cb4568..2691faa 100644 --- a/GdiTest/gtk-gui/gui.stetic +++ b/GdiTest/gtk-gui/gui.stetic @@ -8,7 +8,7 @@ <widget-library name="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" /> <widget-library name="..\bin\Debug\GdiTest.exe" internal="true" /> </import> - <widget class="Gtk.Window" id="MainWindow" design-size="632 663"> + <widget class="Gtk.Window" id="MainWindow" design-size="664 562"> <property name="MemberName" /> <property name="Title" translatable="yes">MainWindow</property> <property name="WindowPosition">CenterOnParent</property> @@ -28,22 +28,46 @@ </packing> </child> <child> + <placeholder /> + </child> + <child> + <placeholder /> + </child> + <child> + <placeholder /> + </child> + <child> + <placeholder /> + </child> + <child> + <placeholder /> + </child> + <child> <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow"> <property name="MemberName" /> - <property name="WidthRequest">600</property> - <property name="HeightRequest">100</property> <property name="ShadowType">In</property> + <child> + <widget class="Gtk.TextView" id="dumpTextView"> + <property name="MemberName" /> + <property name="WidthRequest">600</property> + <property name="HeightRequest">200</property> + <property name="CanFocus">True</property> + <property name="ShowScrollbars">True</property> + <property name="Editable">False</property> + <property name="Text" translatable="yes" /> + </widget> + </child> </widget> <packing> - <property name="X">9</property> - <property name="Y">520</property> + <property name="X">14</property> + <property name="Y">286</property> </packing> </child> <child> <widget class="Gtk.Frame" id="testFrame"> <property name="MemberName" /> <property name="WidthRequest">600</property> - <property name="HeightRequest">400</property> + <property name="HeightRequest">200</property> <property name="ShadowType">None</property> <child> <placeholder /> @@ -60,8 +84,8 @@ </child> </widget> <packing> - <property name="X">7</property> - <property name="Y">75</property> + <property name="X">21</property> + <property name="Y">76</property> </packing> </child> <child> @@ -74,8 +98,22 @@ BitBlt</property> <signal name="Changed" handler="OnTestComboBoxChanged" /> </widget> <packing> - <property name="X">70</property> - <property name="Y">18</property> + <property name="X">74</property> + <property name="Y">27</property> + </packing> + </child> + <child> + <widget class="Gtk.Button" id="dumpButton"> + <property name="MemberName" /> + <property name="CanFocus">True</property> + <property name="Type">TextOnly</property> + <property name="Label" translatable="yes">Dump</property> + <property name="UseUnderline">True</property> + <signal name="Clicked" handler="OnDumpButtonClicked" /> + </widget> + <packing> + <property name="X">156</property> + <property name="Y">26</property> </packing> </child> </widget> |