cd_complex_clipping_regions.e 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. deferred class CD_COMPLEX_CLIPPING_REGIONS
  2. -- A complex region can composed of boxes, sectors, chords, polygons and texts.
  3. -- It is implemented only in the Windows GDI, Windows GDI+, GDK, Cairo(*), and
  4. -- X-Windows base drivers.
  5. --
  6. -- Complex clipping regions can be created using
  7. -- "begin_region"/(filled primtives)/.../"end_polygon". For more about
  8. -- "begin_***" and "end_polygon" see Polygons.
  9. --
  10. -- Between a "begin_region" and a "end", all calls to "box", "sector", "chord",
  11. -- "begin_fill"/"vertex(x,y)"/.../"end_polygon" and Text will be composed in a
  12. -- region for clipping. This is the only exception when you can call a
  13. -- "begin_***" after another "begin_***".
  14. --
  15. -- When you call "begin_region" a new empty region will be created. So for the
  16. -- first operation you should use CD_UNION or CD_NOTINTERSECT combine modes.
  17. -- When you finished to compose the region call "end_polygon".
  18. --
  19. -- To make the region active you must call "clip_region". For other clipping
  20. -- regions see Clipping.
  21. --
  22. -- Although Cairo is capable of creating regions, you can not use them for
  23. -- clipping, just to use "is_point_in_region". And it can create only
  24. -- rectangle based regions, i.e. only "box" will actually combine rectangles
  25. -- into the region.
  26. --
  27. -- Complex clipping regions are not saved by "save_state".
  28. inherit
  29. CANVAS_DRAW
  30. feature {ANY}
  31. set_combine_mode (mode: STRING)
  32. -- Changes the way regions are combined when created. Values: CD_UNION,
  33. -- CD_INTERSECT, CD_DIFFERENCE or CD_NOTINTERSECT. Default
  34. -- value: CD_UNION.
  35. require
  36. is_valid_combine_mode (mode)
  37. local
  38. i: INTEGER
  39. do
  40. if mode.is_equal("CD_UNION") then
  41. i := int_canvas_region_combine_mode (cnvs, 0)
  42. elseif mode.is_equal("CD_INTERSECT") then
  43. i := int_canvas_region_combine_mode (cnvs, 1)
  44. elseif mode.is_equal("CD_DIFFERENCE") then
  45. i := int_canvas_region_combine_mode (cnvs, 2)
  46. elseif mode.is_equal("CD_NOTINTERSECT") then
  47. i := int_canvas_region_combine_mode (cnvs, 3)
  48. end
  49. end
  50. get_combine_mode: STRING
  51. local
  52. i: INTEGER
  53. do
  54. i := int_canvas_region_combine_mode (cnvs, -1)
  55. if i.is_equal(0) then
  56. Result := "CD_UNION"
  57. elseif i.is_equal(1) then
  58. Result := "CD_INTERSECT"
  59. elseif i.is_equal(2) then
  60. Result := "CD_DIFFERENCE"
  61. elseif i.is_equal(3) then
  62. Result := "CD_NOTINTERSECT"
  63. end
  64. end
  65. set_combine_mode_union
  66. local
  67. i: INTEGER
  68. do
  69. i := int_canvas_region_combine_mode (cnvs, 0)
  70. end
  71. set_combine_mode_intersect
  72. local
  73. i: INTEGER
  74. do
  75. i := int_canvas_region_combine_mode (cnvs, 1)
  76. end
  77. set_combine_mode_difference
  78. local
  79. i: INTEGER
  80. do
  81. i := int_canvas_region_combine_mode (cnvs, 2)
  82. end
  83. set_combine_mode_not_intersect
  84. local
  85. i: INTEGER
  86. do
  87. i := int_canvas_region_combine_mode (cnvs, 3)
  88. end
  89. is_point_in_region (x, y: INTEGER): BOOLEAN
  90. -- Returns a non zero value if the point is contained inside the current
  91. -- region.
  92. local
  93. i: INTEGER
  94. do
  95. i := int_canvas_is_point_in_region (cnvs, x, y)
  96. if i.is_equal(0) then
  97. Result := False
  98. else
  99. Result := True
  100. end
  101. end
  102. wd_is_point_in_region (x, y: REAL_64): BOOLEAN
  103. -- Like "is_point_in_region" but for World coordinates.
  104. local
  105. i: REAL_64
  106. do
  107. i := int_wd_canvas_is_point_in_region (cnvs, x, y)
  108. if i.is_equal(0) then
  109. Result := False
  110. else
  111. Result := True
  112. end
  113. end
  114. offset_region (dx, dy: INTEGER)
  115. -- Moves the current region by the given offset. In X-Windows, if the
  116. -- region moves to outside the canvas border, the part moved outside will
  117. -- be lost, the region will need to be reconstructed.
  118. do
  119. int_canvas_offset_region (cnvs, dx, dy)
  120. end
  121. wd_offset_region (dx, dy: REAL_64)
  122. -- Like "offset_region" but for World coordinates.
  123. do
  124. int_wd_canvas_offset_region (cnvs, dx, dy)
  125. end
  126. get_region_box: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  127. -- Returns the rectangle of the bounding box of the current region.
  128. -- In the form (xmin, xmax, ymin, ymax)
  129. local
  130. xmin, xmax, ymin, ymax: INTEGER
  131. do
  132. int_canvas_get_region_box (cnvs, $xmin, $xmax, $ymin, $ymax)
  133. Result := [xmin, xmax, ymin, ymax]
  134. end
  135. wd_get_region_box: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64]
  136. -- Like "get_region_box" but with World coordinates.
  137. local
  138. xmin, xmax, ymin, ymax: REAL_64
  139. do
  140. int_wd_canvas_get_region_box (cnvs, $xmin, $xmax, $ymin, $ymax)
  141. Result := [xmin, xmax, ymin, ymax]
  142. end
  143. feature {}
  144. -- Verifications
  145. is_valid_combine_mode (mode: STRING): BOOLEAN
  146. do
  147. if mode.is_equal("CD_UNION") or
  148. mode.is_equal("CD_INTERSECT") or
  149. mode.is_equal("CD_DIFFERENCE") or
  150. mode.is_equal("CD_NOTINTERSECT") then
  151. Result := True
  152. else
  153. Result := False
  154. end
  155. end
  156. -- Internals
  157. int_canvas_region_combine_mode (wgt: POINTER; m: INTEGER): INTEGER
  158. external "plug_in"
  159. alias "{
  160. location: "${sys}/plugins"
  161. module_name: "iup"
  162. feature_name: "cdCanvasRegionCombineMode"
  163. }"
  164. end
  165. int_canvas_is_point_in_region (wgt: POINTER; x, y: INTEGER): INTEGER
  166. external "plug_in"
  167. alias "{
  168. location: "${sys}/plugins"
  169. module_name: "iup"
  170. feature_name: "cdCanvasIsPointInRegion"
  171. }"
  172. end
  173. int_wd_canvas_is_point_in_region (wgt: POINTER; x, y: REAL_64): INTEGER
  174. external "plug_in"
  175. alias "{
  176. location: "${sys}/plugins"
  177. module_name: "iup"
  178. feature_name: "wdCanvasIsPointInRegion"
  179. }"
  180. end
  181. int_canvas_offset_region (wgt: POINTER; dx, dy: INTEGER)
  182. external "plug_in"
  183. alias "{
  184. location: "${sys}/plugins"
  185. module_name: "iup"
  186. feature_name: "cdCanvasOffsetRegion"
  187. }"
  188. end
  189. int_wd_canvas_offset_region (wgt: POINTER; dx, dy: REAL_64)
  190. external "plug_in"
  191. alias "{
  192. location: "${sys}/plugins"
  193. module_name: "iup"
  194. feature_name: "wdCanvasOffsetRegion"
  195. }"
  196. end
  197. int_canvas_get_region_box (wgt, c1, c2, c3, c4: POINTER)
  198. external "plug_in"
  199. alias "{
  200. location: "${sys}/plugins"
  201. module_name: "iup"
  202. feature_name: "cdCanvasGetRegionBox"
  203. }"
  204. end
  205. int_wd_canvas_get_region_box (wgt, c1, c2, c3, c4: POINTER)
  206. external "plug_in"
  207. alias "{
  208. location: "${sys}/plugins"
  209. module_name: "iup"
  210. feature_name: "wdCanvasGetRegionBox"
  211. }"
  212. end
  213. end
  214. -- The MIT License (MIT)
  215. -- Copyright (c) 2016 by German A. Arias
  216. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  217. -- of this software and associated documentation files (the "Software"), to deal
  218. -- in the Software without restriction, including without limitation the rights
  219. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  220. -- copies of the Software, and to permit persons to whom the Software is
  221. -- furnished to do so, subject to the following conditions:
  222. --
  223. -- The above copyright notice and this permission notice shall be included in
  224. -- all copies or substantial portions of the Software.
  225. --
  226. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  227. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  228. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  229. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  230. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  231. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  232. -- SOFTWARE.