Region.jvm.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. using System;
  2. using System.Drawing.Drawing2D;
  3. using System.Runtime.InteropServices;
  4. using awt = java.awt;
  5. using geom = java.awt.geom;
  6. namespace System.Drawing
  7. {
  8. [ComVisible (false)]
  9. public sealed class Region : BasicShape
  10. {
  11. #region Member Vars
  12. internal static readonly Region InfiniteRegion = new Region(new Rectangle(-0x400000, -0x400000, 0x800000, 0x800000));
  13. #endregion
  14. #region Internals
  15. internal geom.Area NativeObject
  16. {
  17. get
  18. {
  19. return (geom.Area)Shape;
  20. }
  21. }
  22. #endregion
  23. #region Ctors. and Dtor
  24. public Region ()
  25. : this ((geom.Area) InfiniteRegion.NativeObject.MemberwiseClone ())
  26. {
  27. }
  28. internal Region(geom.Area native) : base(native)
  29. {
  30. }
  31. public Region (GraphicsPath path) : this(new geom.Area(path.NativeObject))
  32. {
  33. }
  34. public Region (Rectangle rect) : this(new geom.Area(rect.NativeObject))
  35. {
  36. }
  37. public Region (RectangleF rect) : this(new geom.Area(rect.NativeObject))
  38. {
  39. }
  40. [MonoTODO]
  41. public Region (RegionData region_data) : this((geom.Area)null)
  42. {
  43. throw new NotImplementedException ();
  44. }
  45. #endregion
  46. #region Union
  47. public void Union (GraphicsPath path)
  48. {
  49. if (path == null)
  50. throw new ArgumentNullException("path");
  51. NativeObject.add(new geom.Area(path.NativeObject));
  52. }
  53. public void Union (Rectangle rect)
  54. {
  55. NativeObject.add(new geom.Area(rect.NativeObject));
  56. }
  57. public void Union (RectangleF rect)
  58. {
  59. NativeObject.add(new geom.Area(rect.NativeObject));
  60. }
  61. public void Union (Region region)
  62. {
  63. if (region == null)
  64. throw new ArgumentNullException("region");
  65. NativeObject.add(region.NativeObject);
  66. }
  67. #endregion
  68. #region Intersect
  69. //
  70. public void Intersect (GraphicsPath path)
  71. {
  72. if (path == null)
  73. throw new ArgumentNullException("path");
  74. NativeObject.intersect(new geom.Area(path.NativeObject));
  75. }
  76. public void Intersect (Rectangle rect)
  77. {
  78. NativeObject.intersect(new geom.Area(rect.NativeObject));
  79. }
  80. public void Intersect (RectangleF rect)
  81. {
  82. NativeObject.intersect(new geom.Area(rect.NativeObject));
  83. }
  84. public void Intersect (Region region)
  85. {
  86. if (region == null)
  87. throw new ArgumentNullException("region");
  88. NativeObject.intersect(region.NativeObject);
  89. }
  90. #endregion
  91. #region Complement
  92. //
  93. public void Complement (GraphicsPath path)
  94. {
  95. if (path == null)
  96. throw new ArgumentNullException("path");
  97. geom.Area a = new geom.Area(path.NativeObject);
  98. a.subtract(NativeObject);
  99. Shape = a;
  100. }
  101. public void Complement (Rectangle rect)
  102. {
  103. geom.Area a = new geom.Area(rect.NativeObject);
  104. a.subtract(NativeObject);
  105. Shape = a;
  106. }
  107. public void Complement (RectangleF rect)
  108. {
  109. geom.Area a = new geom.Area(rect.NativeObject);
  110. a.subtract(NativeObject);
  111. Shape = a;
  112. }
  113. public void Complement (Region region)
  114. {
  115. if (region == null)
  116. throw new ArgumentNullException("region");
  117. geom.Area a = (geom.Area) region.NativeObject.MemberwiseClone ();
  118. a.subtract(NativeObject);
  119. Shape = a;
  120. }
  121. #endregion
  122. #region Exclude
  123. //
  124. public void Exclude (GraphicsPath path)
  125. {
  126. if (path == null)
  127. throw new ArgumentNullException("path");
  128. NativeObject.subtract(new geom.Area(path.NativeObject));
  129. }
  130. public void Exclude (Rectangle rect)
  131. {
  132. NativeObject.subtract(new geom.Area(rect.NativeObject));
  133. }
  134. public void Exclude (RectangleF rect)
  135. {
  136. NativeObject.subtract(new geom.Area(rect.NativeObject));
  137. }
  138. public void Exclude (Region region)
  139. {
  140. if (region == null)
  141. throw new ArgumentNullException("region");
  142. NativeObject.subtract(region.NativeObject);
  143. }
  144. #endregion
  145. #region Xor
  146. //
  147. public void Xor (GraphicsPath path)
  148. {
  149. if (path == null)
  150. throw new ArgumentNullException("path");
  151. NativeObject.exclusiveOr(new geom.Area(path.NativeObject));
  152. }
  153. public void Xor (Rectangle rect)
  154. {
  155. NativeObject.exclusiveOr(new geom.Area(rect.NativeObject));
  156. }
  157. public void Xor (RectangleF rect)
  158. {
  159. NativeObject.exclusiveOr(new geom.Area(rect.NativeObject));
  160. }
  161. public void Xor (Region region)
  162. {
  163. if (region == null)
  164. throw new ArgumentNullException("region");
  165. NativeObject.exclusiveOr(region.NativeObject);
  166. }
  167. #endregion
  168. #region GetBounds
  169. //
  170. public RectangleF GetBounds (Graphics graphics)
  171. {
  172. if (graphics == null)
  173. throw new ArgumentNullException("graphics");
  174. return new RectangleF(NativeObject.getBounds2D());
  175. }
  176. #endregion
  177. #region Translate
  178. //
  179. public void Translate (int dx, int dy)
  180. {
  181. Translate((float)dx, (float)dy);
  182. }
  183. public void Translate (float dx, float dy)
  184. {
  185. NativeObject.transform(geom.AffineTransform.getTranslateInstance(
  186. dx,
  187. dy));
  188. }
  189. #endregion
  190. #region IsVisible [TODO]
  191. //
  192. public bool IsVisible (int x, int y, Graphics g)
  193. {
  194. return IsVisible((float)x, (float)y, g);
  195. }
  196. public bool IsVisible (int x, int y, int width, int height)
  197. {
  198. return IsVisible((float)x, (float)y, (float)width, (float)height);
  199. }
  200. public bool IsVisible (int x, int y, int width, int height, Graphics g)
  201. {
  202. return IsVisible((float)x, (float)y, (float)width, (float)height, g);
  203. }
  204. public bool IsVisible (Point point)
  205. {
  206. return IsVisible(point.X, point.Y);
  207. }
  208. public bool IsVisible (PointF point)
  209. {
  210. return IsVisible(point.X, point.Y);
  211. }
  212. public bool IsVisible (Point point, Graphics g)
  213. {
  214. return IsVisible(point.X, point.Y, g);
  215. }
  216. public bool IsVisible (PointF point, Graphics g)
  217. {
  218. return IsVisible(point.X, point.Y, g);
  219. }
  220. public bool IsVisible (Rectangle rect)
  221. {
  222. return IsVisible(rect.X, rect.Y, rect.Width, rect.Height);
  223. }
  224. public bool IsVisible (RectangleF rect)
  225. {
  226. return IsVisible(rect.X, rect.Y, rect.Width, rect.Height);
  227. }
  228. public bool IsVisible (Rectangle rect, Graphics g)
  229. {
  230. return IsVisible(rect.X, rect.Y, rect.Width, rect.Height, g);
  231. }
  232. public bool IsVisible (RectangleF rect, Graphics g)
  233. {
  234. return IsVisible(rect.X, rect.Y, rect.Width, rect.Height, g);
  235. }
  236. public bool IsVisible (float x, float y)
  237. {
  238. return NativeObject.contains(x,y);
  239. }
  240. public bool IsVisible (float x, float y, Graphics g)
  241. {
  242. if (g == null)
  243. throw new ArgumentNullException("graphics");
  244. return NativeObject.contains(x,y);
  245. }
  246. public bool IsVisible (float x, float y, float width, float height)
  247. {
  248. return NativeObject.intersects(x,y,width,height);
  249. }
  250. public bool IsVisible (float x, float y, float width, float height, Graphics g)
  251. {
  252. if (g == null)
  253. throw new ArgumentNullException("graphics");
  254. return NativeObject.intersects(x,y,width,height);
  255. }
  256. #endregion
  257. #region IsEmpty
  258. public bool IsEmpty(Graphics g)
  259. {
  260. if (g == null)
  261. throw new ArgumentNullException("graphics");
  262. return NativeObject.isEmpty();
  263. }
  264. #endregion
  265. #region IsInfinite
  266. public bool IsInfinite(Graphics g)
  267. {
  268. if (g == null)
  269. throw new ArgumentNullException("graphics");
  270. //probably too naive.
  271. return NativeObject.equals(InfiniteRegion.NativeObject);
  272. }
  273. #endregion
  274. #region MakeEmpty
  275. public void MakeEmpty()
  276. {
  277. NativeObject.reset();
  278. }
  279. #endregion
  280. #region MakeInfinite
  281. public void MakeInfinite()
  282. {
  283. Shape = (geom.Area) InfiniteRegion.NativeObject.MemberwiseClone ();
  284. }
  285. #endregion
  286. #region Equals
  287. public bool Equals(Region region, Graphics g)
  288. {
  289. if (g == null)
  290. throw new ArgumentNullException("graphics");
  291. return NativeObject.equals(region.NativeObject);
  292. }
  293. #endregion
  294. [MonoTODO]
  295. public RegionData GetRegionData()
  296. {
  297. throw new NotImplementedException();
  298. }
  299. [MonoTODO]
  300. public IntPtr GetHrgn(Graphics g) {
  301. throw new NotImplementedException();
  302. }
  303. public RectangleF[] GetRegionScans(Matrix matrix)
  304. {
  305. throw new NotSupportedException();
  306. }
  307. #region Transform
  308. public void Transform(Matrix matrix)
  309. {
  310. if (matrix == null)
  311. throw new ArgumentNullException("matrix");
  312. NativeObject.transform(matrix.NativeObject);
  313. }
  314. #endregion
  315. #region Clone
  316. public Region Clone()
  317. {
  318. return new Region ((geom.Area) NativeObject.MemberwiseClone ());
  319. }
  320. #endregion
  321. }
  322. }