OSDN Git Service

clock interval
[psychlops/silverlight.git] / dev3 / psychlops / core / graphic / shape.cs
index ffefeea..f92e989 100644 (file)
@@ -12,26 +12,70 @@ using System.Windows.Shapes;
 \r
 namespace Psychlops{\r
 \r
-       public interface Shape : Figure\r
+       public interface Shape : Internal.PrimitiveFigure\r
        {\r
+               Color fill { get; set; }\r
+               Stroke stroke { get; set; }\r
        }\r
        public static class ShapeExtention\r
        {\r
-               /*\r
-               public static void draw(this Shape drawee)\r
+               public static void draw(this Shape drawee, Color c)\r
                {\r
-                       drawee.draw(Color.white);\r
+                       Color tmp_col = drawee.fill;\r
+                       Stroke tmp_strk = drawee.stroke;\r
+                       drawee.fill = c;\r
+                       drawee.stroke = new Stroke();\r
+                       drawee.draw();\r
+                       drawee.fill = tmp_col;\r
+                       drawee.stroke = tmp_strk;\r
+               }\r
+               public static void draw(this Shape drawee, Stroke strk)\r
+               {\r
+                       Color tmp_col = drawee.fill;\r
+                       Stroke tmp_strk = drawee.stroke;\r
+                       drawee.fill = new Color(0,0,1,1);\r
+                       drawee.stroke = strk;\r
+                       drawee.draw();\r
+                       drawee.fill = tmp_col;\r
+                       drawee.stroke = tmp_strk;\r
                }\r
-               */\r
        }\r
 \r
+       public partial struct Stroke\r
+       {\r
+               public double thick;\r
+               public Color color;\r
+               public Stroke(Color c, double t)\r
+               {\r
+                       color = c;\r
+                       thick = t;\r
+               }\r
+               public void set(Color c, double t)\r
+               {\r
+                       color = c;\r
+                       thick = t;\r
+               }\r
+       }\r
 \r
-       public class Line : Shape\r
+       public partial class Line : Shape\r
        {\r
                public Point begin, end;\r
 \r
+               public Line(double x1, double y1, double x2, double y2)\r
+               {\r
+                       set(x1, y1, x2, y2);\r
+               }\r
                public Line(Point v1, Point v2)\r
                {\r
+                       set(v1, v2);\r
+               }\r
+               public void set(double x1, double y1, double x2, double y2)\r
+               {\r
+                       begin.set(x1, y1);\r
+                       end.set(x2, y2);\r
+               }\r
+               public void set(Point v1, Point v2)\r
+               {\r
                        begin = v1;\r
                        end   = v2;\r
                }\r
@@ -52,31 +96,24 @@ namespace Psychlops{
                        return this;\r
                }\r
 \r
-               public void draw(Color c)\r
-               {\r
-                       Main.drawable.line(this, c);\r
-               }\r
                public void draw()\r
                {\r
-                       Main.drawable.line(this, Color.white);\r
+                       Main.drawable.line(this);\r
                }\r
 \r
+               public double left { get { return begin.x < end.x ? begin.x : end.x; } }\r
+               public double top { get { return begin.y < end.y ? begin.y : end.y; ; } }\r
+               public double right { get { return begin.x > end.x ? begin.x : end.x; ; } }\r
+               public double bottom { get { return begin.y > end.y ? begin.y : end.y; ; } }\r
                public double width { get { return Math.abs(begin.x - end.x); } }\r
                public double height { get { return Math.abs(begin.y - end.y); } }\r
 \r
-               public static implicit operator System.Windows.Shapes.Line(Line d)\r
-               {\r
-                       var tmp = new System.Windows.Shapes.Line();\r
-                       tmp.X1 = d.begin.x;\r
-                       tmp.Y1 = d.begin.y;\r
-                       tmp.X2 = d.end.x;\r
-                       tmp.Y2 = d.end.y;\r
-                       return tmp;\r
-               }\r
+               public Color fill { get; set; }\r
+               public Stroke stroke { get; set; }\r
        }\r
 \r
 \r
-       public class Rectangle : Shape\r
+       public partial class Rectangle : Shape\r
        {\r
                public Point v1, v2;\r
 \r
@@ -112,13 +149,9 @@ namespace Psychlops{
                        return this;\r
                }\r
 \r
-               public void draw(Color c)\r
-               {\r
-                       Main.drawable.rect(this, c);\r
-               }\r
                public void draw()\r
                {\r
-                       Main.drawable.rect(this, Color.white);\r
+                       Main.drawable.rect(this);\r
                }\r
 \r
                public double left   { get { return v1.x; } }\r
@@ -129,19 +162,36 @@ namespace Psychlops{
                public double height { get { return Math.abs(v1.y - v2.y); } }\r
 \r
 \r
-               public static implicit operator System.Windows.Rect(Rectangle d)\r
+               public Color fill { get; set; }\r
+               public Stroke stroke { get; set; }\r
+\r
+               public override string ToString()\r
                {\r
-                       return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);\r
+                       return "Left:" + left.ToString() + " Top:" + top.ToString() + " Right:" + right.ToString() + " Bottom:" + bottom.ToString();\r
                }\r
-\r
        }\r
 \r
 \r
-       public class Ellipse : Shape\r
+       public partial class Ellipse : Shape\r
        {\r
                public Point datum;\r
                public double xdiameter, ydiameter;\r
 \r
+               public Ellipse()\r
+               {\r
+                       set(0,0);\r
+               }\r
+               public Ellipse(double wid, double hei)\r
+               {\r
+                       set(wid, hei);\r
+               }\r
+\r
+               public Ellipse set(double wid, double hei)\r
+               {\r
+                       xdiameter = wid;\r
+                       ydiameter = hei;\r
+                       return this;\r
+               }\r
                public Figure shift(Point p)\r
                {\r
                        datum += p;\r
@@ -153,18 +203,24 @@ namespace Psychlops{
                        return this;\r
                }\r
 \r
-               public void draw(Color c)\r
-               {\r
-                       Main.drawable.ellipse(this, c);\r
-               }\r
                public void draw()\r
                {\r
-                       Main.drawable.ellipse(this, Color.white);\r
+                       Main.drawable.ellipse(this);\r
                }\r
+\r
+               public double left { get { return datum.x - xdiameter/2.0; } }\r
+               public double top { get { return datum.y - ydiameter / 2.0; } }\r
+               public double right { get { return datum.x + xdiameter / 2.0; } }\r
+               public double bottom { get { return datum.y + ydiameter / 2.0; } }\r
+               public double width { get { return Math.abs(xdiameter); } }\r
+               public double height { get { return Math.abs(ydiameter); } }\r
+\r
+               public Color fill { get; set; }\r
+               public Stroke stroke { get; set; }\r
        }\r
 \r
 \r
-       public class Polygon : Shape\r
+       public partial class Polygon : Shape\r
        {\r
                public Point datum;\r
                public System.Collections.Generic.List<Point> vertices;\r
@@ -173,6 +229,24 @@ namespace Psychlops{
                {\r
                        vertices = new System.Collections.Generic.List<Point>();\r
                }\r
+               public Polygon(double[] verts)\r
+               {\r
+                       vertices = new System.Collections.Generic.List<Point>();\r
+                       for (int i=0; i < verts.Length; i+=2)\r
+                       {\r
+                               vertices.Add(new Point(verts[i], verts[i+1]));\r
+                       }\r
+\r
+               }\r
+               public Polygon(Point[] verts)\r
+               {\r
+                       vertices = new System.Collections.Generic.List<Point>();\r
+                       foreach (Point p in verts)\r
+                       {\r
+                               vertices.Add(p);\r
+                       }\r
+\r
+               }\r
                public Polygon append(Point p) { vertices.Add(p); return this; }\r
                public Polygon append(double x, double y) { return append(new Point(x, y, 0.0)); }\r
                public Polygon append(double x, double y, double z) { return append(new Point(x, y, z)); }\r
@@ -189,14 +263,13 @@ namespace Psychlops{
                        return this;\r
                }\r
 \r
-               public void draw(Color c)\r
-               {\r
-                       Main.drawable.polygon(this, c);\r
-               }\r
                public void draw()\r
                {\r
-                       Main.drawable.polygon(this, Color.white);\r
+                       Main.drawable.polygon(this);\r
                }\r
+\r
+               public Color fill { get; set; }\r
+               public Stroke stroke { get; set; }\r
        }\r
 \r
 }
\ No newline at end of file