cd_complex_clipping_regions.e 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. else
  64. Result := "CD_UNION"
  65. end
  66. end
  67. set_combine_mode_union
  68. local
  69. i: INTEGER
  70. do
  71. i := int_canvas_region_combine_mode (cnvs, 0)
  72. end
  73. set_combine_mode_intersect
  74. local
  75. i: INTEGER
  76. do
  77. i := int_canvas_region_combine_mode (cnvs, 1)
  78. end
  79. set_combine_mode_difference
  80. local
  81. i: INTEGER
  82. do
  83. i := int_canvas_region_combine_mode (cnvs, 2)
  84. end
  85. set_combine_mode_not_intersect
  86. local
  87. i: INTEGER
  88. do
  89. i := int_canvas_region_combine_mode (cnvs, 3)
  90. end
  91. is_point_in_region (x, y: INTEGER): BOOLEAN
  92. -- Returns a non zero value if the point is contained inside the current
  93. -- region.
  94. local
  95. i: INTEGER
  96. do
  97. i := int_canvas_is_point_in_region (cnvs, x, y)
  98. if i.is_equal(0) then
  99. Result := False
  100. else
  101. Result := True
  102. end
  103. end
  104. wd_is_point_in_region (x, y: REAL_64): BOOLEAN
  105. -- Like "is_point_in_region" but for World coordinates.
  106. local
  107. i: REAL_64
  108. do
  109. i := int_wd_canvas_is_point_in_region (cnvs, x, y)
  110. if i.is_equal(0) then
  111. Result := False
  112. else
  113. Result := True
  114. end
  115. end
  116. offset_region (dx, dy: INTEGER)
  117. -- Moves the current region by the given offset. In X-Windows, if the
  118. -- region moves to outside the canvas border, the part moved outside will
  119. -- be lost, the region will need to be reconstructed.
  120. do
  121. int_canvas_offset_region (cnvs, dx, dy)
  122. end
  123. wd_offset_region (dx, dy: REAL_64)
  124. -- Like "offset_region" but for World coordinates.
  125. do
  126. int_wd_canvas_offset_region (cnvs, dx, dy)
  127. end
  128. get_region_box: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  129. -- Returns the rectangle of the bounding box of the current region.
  130. -- In the form (xmin, xmax, ymin, ymax)
  131. local
  132. xmin, xmax, ymin, ymax: INTEGER
  133. do
  134. int_canvas_get_region_box (cnvs, $xmin, $xmax, $ymin, $ymax)
  135. Result := [xmin, xmax, ymin, ymax]
  136. end
  137. wd_get_region_box: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64]
  138. -- Like "get_region_box" but with World coordinates.
  139. local
  140. xmin, xmax, ymin, ymax: REAL_64
  141. do
  142. int_wd_canvas_get_region_box (cnvs, $xmin, $xmax, $ymin, $ymax)
  143. Result := [xmin, xmax, ymin, ymax]
  144. end
  145. -- Verifications
  146. is_valid_combine_mode (mode: STRING): BOOLEAN
  147. do
  148. if mode.is_equal("CD_UNION") or
  149. mode.is_equal("CD_INTERSECT") or
  150. mode.is_equal("CD_DIFFERENCE") or
  151. mode.is_equal("CD_NOTINTERSECT") then
  152. Result := True
  153. else
  154. Result := False
  155. end
  156. end
  157. feature {NONE}
  158. -- Internals
  159. int_canvas_region_combine_mode (wgt: POINTER; m: INTEGER): INTEGER
  160. external
  161. "C inline use %"eiffel-iup.h%""
  162. alias
  163. "return cdCanvasRegionCombineMode ($wgt, $m);"
  164. end
  165. int_canvas_is_point_in_region (wgt: POINTER; x, y: INTEGER): INTEGER
  166. external
  167. "C inline use %"eiffel-iup.h%""
  168. alias
  169. "return cdCanvasIsPointInRegion ($wgt, $x, $y);"
  170. end
  171. int_wd_canvas_is_point_in_region (wgt: POINTER; x, y: REAL_64): INTEGER
  172. external
  173. "C inline use %"eiffel-iup.h%""
  174. alias
  175. "return wdCanvasIsPointInRegion ($wgt, $x, $y);"
  176. end
  177. int_canvas_offset_region (wgt: POINTER; dx, dy: INTEGER)
  178. external
  179. "C inline use %"eiffel-iup.h%""
  180. alias
  181. "cdCanvasOffsetRegion ($wgt, $dx, $dy);"
  182. end
  183. int_wd_canvas_offset_region (wgt: POINTER; dx, dy: REAL_64)
  184. external
  185. "C inline use %"eiffel-iup.h%""
  186. alias
  187. "wdCanvasOffsetRegion ($wgt, $dx, $dy);"
  188. end
  189. int_canvas_get_region_box (wgt, c1, c2, c3, c4: POINTER)
  190. external
  191. "C inline use %"eiffel-iup.h%""
  192. alias
  193. "cdCanvasGetRegionBox ($wgt, $c1, $c2, $c3, $c4);"
  194. end
  195. int_wd_canvas_get_region_box (wgt, c1, c2, c3, c4: POINTER)
  196. external
  197. "C inline use %"eiffel-iup.h%""
  198. alias
  199. "wdCanvasGetRegionBox ($wgt, $c1, $c2, $c3, $c4);"
  200. end
  201. end
  202. -- The MIT License (MIT)
  203. -- Copyright (c) 2016, 2019 by German A. Arias
  204. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  205. -- of this software and associated documentation files (the "Software"), to deal
  206. -- in the Software without restriction, including without limitation the rights
  207. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  208. -- copies of the Software, and to permit persons to whom the Software is
  209. -- furnished to do so, subject to the following conditions:
  210. --
  211. -- The above copyright notice and this permission notice shall be included in
  212. -- all copies or substantial portions of the Software.
  213. --
  214. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  215. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  216. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  217. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  218. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  219. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  220. -- SOFTWARE.