OSDN Git Service

321
[psychlops/silverlight.git] / dev3 / psychlops / core / graphic / canvas.cs
index 8dd4753..4414a24 100644 (file)
@@ -15,9 +15,9 @@ namespace Psychlops
 \r
        public class Canvas : Drawable\r
        {\r
-               public static System.Windows.Controls.Image default_instance;\r
+               public static System.Windows.Controls.Image default_buffer_frame;\r
                public static System.Windows.Controls.UserControl default_panel;\r
-               public static WriteableBitmap default_buffer; \r
+               public static WriteableBitmap default_buffer;\r
                System.Windows.Controls.Image instance;\r
                System.Windows.Controls.UserControl panel; \r
                WriteableBitmap buffer;\r
@@ -25,27 +25,20 @@ namespace Psychlops
                public Canvas(int wid, int hei)\r
                {\r
                        panel = default_panel;\r
-                       instance = default_instance;\r
-                       instance.Width = wid;\r
-                       instance.Height = hei;\r
-                       buffer = new WriteableBitmap((int)instance.Width, (int)instance.Height);\r
-                       instance.Source = buffer;\r
-                       instance.MouseMove += Mouse.Canvas_MousePos;\r
-                       instance.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
-                       instance.MouseLeftButtonUp += Mouse.Canvas_LUp;\r
-                       instance.MouseWheel += Mouse.Canvas_MouseWheel;\r
-                       Mouse._prime = instance;\r
-                       Main.drawable = this;\r
-                       default_buffer = buffer;\r
+                       instance = default_buffer_frame;\r
+                       initialize(wid, hei);\r
                }\r
                public Canvas(int wid, int hei, System.Windows.Controls.Image target, System.Windows.Controls.UserControl system)\r
                {\r
                        panel = system;\r
                        instance = target;\r
+                       initialize(wid, hei);\r
+               }\r
+               protected void initialize(int wid, int hei)\r
+               {\r
                        instance.Width = wid;\r
                        instance.Height = hei;\r
                        buffer = new WriteableBitmap((int)instance.Width, (int)instance.Height);\r
-                       instance = target;\r
                        instance.Source = buffer;\r
                        instance.MouseMove += Mouse.Canvas_MousePos;\r
                        instance.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
@@ -53,6 +46,7 @@ namespace Psychlops
                        instance.MouseWheel += Mouse.Canvas_MouseWheel;\r
                        Mouse._prime = instance;\r
                        Main.drawable = this;\r
+                       default_buffer = buffer;\r
                }\r
                public Point getCenter()\r
                {\r
@@ -73,6 +67,29 @@ namespace Psychlops
                        buffer.SetPixel(x, y, col);\r
                }\r
 \r
+               static System.Windows.Shapes.Line api_line;\r
+               static System.Windows.Shapes.Path api_curve;\r
+               static System.Windows.Shapes.Rectangle api_rect;\r
+               static System.Windows.Shapes.Ellipse api_ellipse;\r
+               static System.Windows.Shapes.Polygon api_polygon;\r
+               static System.Windows.Shapes.Polyline api_polyline;\r
+               static System.Windows.Media.Color api_color;\r
+               static System.Windows.Media.SolidColorBrush api_fill;\r
+               static System.Windows.Media.SolidColorBrush api_stroke;\r
+               static System.Windows.Media.TranslateTransform api_translation;\r
+               static Canvas()\r
+               {\r
+                       api_line     = new System.Windows.Shapes.Line();\r
+                       api_curve    = new System.Windows.Shapes.Path();\r
+                       api_rect     = new System.Windows.Shapes.Rectangle();\r
+                       api_ellipse  = new System.Windows.Shapes.Ellipse();\r
+                       api_polygon  = new System.Windows.Shapes.Polygon();\r
+                       api_polyline = new System.Windows.Shapes.Polyline();\r
+                       api_color       = new System.Windows.Media.Color();\r
+                       api_fill        = new System.Windows.Media.SolidColorBrush();\r
+                       api_stroke      = new System.Windows.Media.SolidColorBrush();\r
+                       api_translation = new System.Windows.Media.TranslateTransform();\r
+               }\r
 \r
                public void line(Line drawee, Color col)\r
                {\r
@@ -80,7 +97,14 @@ namespace Psychlops
                }\r
                public void rect(Rectangle drawee, Color col)\r
                {\r
-                       buffer.DrawRectangle((int)drawee.v1.x, (int)drawee.v1.y, (int)drawee.v2.x, (int)drawee.v2.y, col);\r
+                       //buffer.DrawRectangle((int)drawee.v1.x, (int)drawee.v1.y, (int)drawee.v2.x, (int)drawee.v2.y, col);\r
+                       api_rect.Width = drawee.width;\r
+                       api_rect.Height = drawee.height;\r
+                       api_fill.Color = col;\r
+                       api_rect.Fill = api_fill;\r
+                       api_translation.X = drawee.left;\r
+                       api_translation.Y = drawee.top;\r
+                       buffer.Render(api_rect, api_translation);\r
                }\r
                public void ellipse(Ellipse drawee, Color col)\r
                {\r
@@ -103,9 +127,11 @@ namespace Psychlops
                }\r
 \r
 \r
+               public int frame;\r
                public void flip()\r
                {\r
                        buffer.Invalidate();\r
+                       frame++;\r
                }\r
        }\r
 \r