OSDN Git Service

123
[psychlops/silverlight.git] / dev4 / psychlops / core / graphic / module.cs
1 using System;\r
2 using System.Windows;\r
3 \r
4 \r
5 namespace Psychlops\r
6 {\r
7 \r
8         public partial struct Point\r
9         {\r
10                 public double x, y, z;\r
11                 public Point(double dx, double dy, double dz = 0.0)\r
12                 {\r
13                         x = dx;\r
14                         y = dy;\r
15                         z = dz;\r
16                 }\r
17                 public Point set(double dx, double dy, double dz = 0.0)\r
18                 {\r
19                         x = dx;\r
20                         y = dy;\r
21                         z = dz;\r
22                         return this;\r
23                 }\r
24 \r
25                 public static Point operator +(Point lhs, Point rhs)\r
26                 {\r
27                         return new Point(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);\r
28                 }\r
29                 public static Point operator -(Point lhs, Point rhs)\r
30                 {\r
31                         return new Point(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);\r
32                 }\r
33                 public override string ToString()\r
34                 {\r
35                         return "X:"+ x.ToString() + " Y:"+ y.ToString() + " Z:"+ z.ToString();\r
36                 }\r
37         }\r
38 \r
39 \r
40         public partial struct Color\r
41         {\r
42                 public double r, g, b, a;\r
43                 public Color(double lum)\r
44                 {\r
45                         r = g = b = lum;\r
46                         a = 1.0;\r
47                 }\r
48                 public Color(double red, double green, double blue, double alpha = 1.0)\r
49                 {\r
50                         r = red;\r
51                         g = green;\r
52                         b = blue;\r
53                         a = alpha;\r
54                 }\r
55                 public void set(double lum)\r
56                 {\r
57                         r = g = b = lum;\r
58                         a = 1.0;\r
59                 }\r
60                 public void set(double red, double green, double blue, double alpha = 1.0)\r
61                 {\r
62                         r = red;\r
63                         g = green;\r
64                         b = blue;\r
65                         a = alpha;\r
66                 }\r
67 \r
68                 public override string ToString()\r
69                 {\r
70                         return "R:" + r.ToString() + " G:" + g.ToString() + " B:" + b.ToString() + " A:" + a.ToString();\r
71                 }\r
72 \r
73                 public static readonly Color\r
74                         black = new Color(0, 0, 0, 1),\r
75                         red = new Color(1, 0, 0, 1),\r
76                         green = new Color(0, 1, 0, 1),\r
77                         blue = new Color(0, 0, 1, 1),\r
78                         yellow = new Color(1, 1, 0, 1),\r
79                         magenta = new Color(1, 0, 1, 1),\r
80                         cyan = new Color(0, 1, 1, 1),\r
81                         white = new Color(1, 1, 1, 1),\r
82                         gray = new Color(.5, .5, .5, 1),\r
83                         null_color = new Color(0, 0, 0, 0);\r
84 \r
85         }\r
86 \r
87 \r
88         public interface Drawable\r
89         {\r
90                 Point getCenter();\r
91                 void clear(Color col);\r
92                 void pix(int x, int y, Color col);\r
93                 void line(Line drawee);\r
94                 void rect(Rectangle drawee);\r
95                 void ellipse(Ellipse drawee);\r
96                 void polygon(Polygon drawee);\r
97                 void letters(Letters drawee);\r
98                 void image(Image drawee);\r
99                 void msg(string s, double x, double y, Color c);\r
100         }\r
101 \r
102 \r
103 \r
104         public interface Figure\r
105         {\r
106                 Point datum { get; set; }\r
107                 Figure shift(Point p);\r
108                 Figure centering(Point p);\r
109                 void draw();\r
110         }\r
111         public static class FigureExtention\r
112         {\r
113                 public static Point getDatum(this Figure target)\r
114                 {\r
115                         return target.datum;\r
116                 }\r
117                 public static Point setDatum(this Figure target, Point p)\r
118                 {\r
119                         target.datum = p;\r
120                         return target.datum;\r
121                 }\r
122                 public static Figure shift(this Figure target, double x, double y, double z = 0.0)\r
123                 {\r
124                         return target.shift(new Point(x, y, z));\r
125                 }\r
126                 public static Figure centering(this Figure target)\r
127                 {\r
128                         return target.centering(Main.drawable.getCenter());\r
129                 }\r
130                 public static Figure centering(this Figure target, double x, double y, double z = 0.0)\r
131                 {\r
132                         return target.centering(new Point(x, y, z));\r
133                 }\r
134         }\r
135 \r
136         namespace Internal\r
137         {\r
138                 public interface PrimitiveFigure : Figure\r
139                 {\r
140                         UIElement toNative();\r
141                 }\r
142         }\r
143 }