OSDN Git Service

描写を固定サイズで行うようにした
authorkonekoneko <jbh03215@hotmail.co.jp>
Sun, 28 Oct 2012 22:36:54 +0000 (07:36 +0900)
committerkonekoneko <jbh03215@hotmail.co.jp>
Sun, 28 Oct 2012 22:36:54 +0000 (07:36 +0900)
D2DBench/Direct2D.cs
D2DBench/Form1.cs
D2DBench/GDI.cs
D2DBench/IRender.cs
D2DBench/Method2.cs
D2DBench/Method3.cs
D2DBench/Method5.cs

index 29a8b2f..e1bcf8b 100644 (file)
@@ -107,14 +107,6 @@ namespace D2DBench
             render.DrawTextLayout(new Point(x,y), layout, colors[colorno]);
         }
 
-        public void DrawLine(int x, int y,int tox,int toy, int colorno)
-        {
-            var fore = colors[colorno];
-            Point from = new Point(x,y);
-            Point to = new Point(tox,toy);
-            render.DrawLine(from, to, fore, 1.0f);
-        }
-
         public void DrawEllipse(int x, int y, int radiusX, int radiusY, int colorno)
         {
             var fore = colors[colorno];
@@ -125,6 +117,17 @@ namespace D2DBench
             render.DrawEllipse(ellipse, fore);
         }
 
+        public void DrawRectangle(int left, int top, int right, int bottom, int colorno)
+        {
+            var fore = colors[colorno];
+            SharpDX.RectangleF rect = new SharpDX.RectangleF();
+            rect.Left = left;
+            rect.Top = top;
+            rect.Right = right;
+            rect.Bottom = bottom;
+            render.DrawRectangle(rect, fore);
+        }
+
         public void FillRectangle(int left, int top, int right, int bottom, int colorno)
         {
             var fore = colors[colorno];
index cdc28a0..0a05595 100644 (file)
@@ -23,12 +23,12 @@ namespace D2DBench
                 this.comboBox3.SelectedIndex = 1;\r
         }\r
 \r
-        public const int ExecuteCountPerOneset = 50;\r
+        public const int FigureHeight = 256;\r
 \r
         private void button1_Click(object sender, EventArgs e)\r
         {\r
             int maxcount = Int32.Parse(this.comboBox1.SelectedItem.ToString());\r
-            int loopCountAtOneLoop = ExecuteCountPerOneset;\r
+            int loopCountAtOneLoop = 50;\r
             if(this.comboBox2.SelectedItem != null)\r
                 loopCountAtOneLoop = Int32.Parse(this.comboBox2.SelectedItem.ToString());\r
 \r
index ce0d166..5d33410 100644 (file)
@@ -205,13 +205,11 @@ namespace D2DBench
         static extern bool DeleteObject(IntPtr hObject);\r
         [DllImport("gdi32.dll", EntryPoint = "GetTextExtentExPointW"), SuppressUnmanagedCodeSecurity]\r
         static extern bool GetTextExtentExPoint(IntPtr hdc, [MarshalAs(UnmanagedType.LPWStr)] string lpszStr, int cchString, int nMaxExtent, out int lpnFit, int[] alpDx, out SIZE lpSize);\r
+        [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity]\r
+        static extern bool Rectangle(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);\r
         [DllImport("gdi32.dll", EntryPoint = "ExtTextOutW"), SuppressUnmanagedCodeSecurity]\r
         static extern bool ExtTextOut(IntPtr hdc, int X, int Y, uint fuOptions, [In] ref RECT lprc, [MarshalAs(UnmanagedType.LPWStr)] string lpString, uint cbCount, [In] int[] lpDx);\r
         [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity]\r
-        static extern bool LineTo(IntPtr hdc, int nXEnd, int nYEnd);\r
-        [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity]\r
-        static extern bool MoveToEx(IntPtr hdc, int X, int Y, IntPtr lpPoint);\r
-        [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity]\r
         static extern IntPtr CreatePen(PenStyle fnPenStyle, int nWidth, uint crColor);\r
         [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity]\r
         static extern IntPtr CreateFont(int nHeight, int nWidth, int nEscapement, int nOrientation, FontWeight fnWeight, uint fdwItalic, uint fdwUnderline, uint fdwStrikeOut, FontCharSet fdwCharSet, FontPrecision fdwOutputPrecision, FontClipPrecision fdwClipPrecision, FontQuality fdwQuality, FontPitchAndFamily fdwPitchAndFamily, string lpszFace);\r
@@ -322,18 +320,18 @@ namespace D2DBench
             SelectObject(backdc, oldpen);\r
         }\r
 \r
-        public void DrawLine(int x, int y, int tox, int toy, int colorno)\r
+        public void DrawRectangle(int left, int top, int right, int bottom, int colorno)\r
         {\r
             PenStyle style = PenStyle.PS_SOLID;\r
             IntPtr pen = CreatePen(style, 1, (uint)ColorTranslator.ToWin32(this.colors[colorno]));\r
 \r
             IntPtr oldpen = SelectObject(backdc, pen);\r
 \r
-            MoveToEx(backdc, x, y, IntPtr.Zero);\r
-            LineTo(backdc, tox, toy);\r
-            \r
+            Rectangle(backdc, left, top, right, bottom);\r
+\r
             DeleteObject(pen);\r
             SelectObject(backdc, oldpen);\r
+\r
         }\r
 \r
         const string showStr = "D2DBenchMark";\r
index 4c5e470..95e5a25 100644 (file)
@@ -7,7 +7,7 @@ namespace D2DBench
         int ColorCount { get; }
         void Dispose();
         void DrawBitmap(IBitmap bmp, int left, int top, int right, int bottom);
-        void DrawLine(int x, int y, int tox, int toy, int colorno);
+        void DrawRectangle(int left, int top, int right, int bottom, int colorno);
         void DrawString(int x, int y, int colorno);
         void EndDraw();
         void FillRectangle(int left, int top, int right, int bottom, int colorno);
index a7e5acf..29d32bf 100644 (file)
@@ -5,6 +5,7 @@ using System.Windows.Forms;
 using SharpDX;\r
 using SharpDX.Direct2D1;\r
 using SharpDX.DirectWrite;\r
+using D2DBench.Properties;\r
 \r
 using D2D = SharpDX.Direct2D1;\r
 using DW = SharpDX.DirectWrite;\r
@@ -15,11 +16,12 @@ namespace D2DBench
     class Method2: IBench\r
     {\r
         public int fillAreaSize { get { return 0; } }\r
-        public string methodName { get { return ""; } }\r
+        public string methodName { get { return "四角形"; } }\r
         public int loopCount { get; set; }\r
 \r
         IRender d2d;\r
         Drawing.Size ClientSize;\r
+        const int Height = 256;\r
         Random rnd;\r
 \r
         public void Init(Control ctrl, bool antialias, RenderMethod method)\r
@@ -37,10 +39,12 @@ namespace D2DBench
             this.d2d.BeginDraw();\r
             for (int i = 0; i < this.loopCount; i++)\r
             {\r
-                this.d2d.DrawLine(rnd.Next(ClientSize.Width),\r
-                    rnd.Next(ClientSize.Height),\r
-                    rnd.Next(ClientSize.Width),\r
-                    rnd.Next(ClientSize.Height),\r
+                int left = rnd.Next(ClientSize.Width);\r
+                int top = rnd.Next(ClientSize.Height);\r
+                this.d2d.DrawRectangle(left,\r
+                    top,\r
+                    left + Form1.FigureHeight,\r
+                    top + Form1.FigureHeight,\r
                     rnd.Next(this.d2d.ColorCount - 1));\r
             }\r
             this.d2d.EndDraw();\r
index cc9858f..4d69638 100644 (file)
@@ -39,11 +39,13 @@ namespace D2DBench
             this.d2d.BeginDraw();\r
             for (int i = 0; i < this.loopCount; i++)\r
             {\r
+                int left = rnd.Next(ClientSize.Width);\r
+                int top = rnd.Next(ClientSize.Height);\r
                 this.d2d.FillRectangle(\r
-                    rnd.Next(ClientSize.Width),\r
-                    rnd.Next(ClientSize.Height),\r
-                    rnd.Next(ClientSize.Width),\r
-                    rnd.Next(ClientSize.Height),\r
+                    left,\r
+                    top,\r
+                    left + Form1.FigureHeight,\r
+                    top + Form1.FigureHeight,\r
                     rnd.Next(this.d2d.ColorCount - 1));\r
             }\r
             this.d2d.EndDraw();\r
index db481d4..eca855f 100644 (file)
@@ -42,10 +42,11 @@ namespace D2DBench
 
         public void Exec()
         {
+            int radius = Form1.FigureHeight/2;
             this.d2d.BeginDraw();
             for (int i = 0; i < this.loopCount; i++)
             {
-                this.d2d.DrawEllipse(rnd.Next(ClientSize.Width), rnd.Next(ClientSize.Height), 25,25,rnd.Next(this.d2d.ColorCount - 1));
+                this.d2d.DrawEllipse(rnd.Next(ClientSize.Width), rnd.Next(ClientSize.Height), radius, radius, rnd.Next(this.d2d.ColorCount - 1));
             }
             this.d2d.EndDraw();
         }