cd_clipping.e 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. deferred class CD_CLIPPING
  2. -- The clipping area is an area that limits the available drawing area inside
  3. -- the canvas. Any primitive is drawn only inside the clipping area. It affects
  4. -- all primitives.
  5. --
  6. -- You can set the clipping area by using the feature "set_clip_area", and
  7. -- retrieve it using "get_clip_area". The clipping area is a rectangle by
  8. -- default, but it can has other shapes. In some drivers a polygon area can be
  9. -- defined, and in display based drivers a complex region can be defined. The
  10. -- complex region can be a combination of boxes, polygons, sectors, chords and
  11. -- texts.
  12. --
  13. -- The Clip function activates and deactivaes the clipping.
  14. inherit
  15. CANVAS_DRAW
  16. feature {ANY}
  17. set_clipping_mode (mode: STRING)
  18. -- Activates or deactivates clipping. Values: CD_CLIPAREA,
  19. -- CD_CLIPPOLYGON, CD_CLIPREGION or CD_CLIPOFF. Default value: CD_CLIPOFF.
  20. --
  21. -- The value CD_CLIPAREA activates a rectangular area as the clipping
  22. -- region.
  23. --
  24. -- The value CD_CLIPPOLYGON activates a polygon as a clipping region, but
  25. -- works only in some drivers (please refer to the notes of each driver).
  26. -- The clipping polygon must be defined before activating the polygon
  27. -- clipping; if it is not defined, the current clipping state remains
  28. -- unchanged.
  29. --
  30. -- The value CD_CLIPREGION activates a complex clipping region. See the
  31. -- documentation of Regions.
  32. --
  33. -- The defined clipping area, polygon and complex regions are stored
  34. -- internally, so you may define them independently and switch between
  35. -- area, polygon and complex region without having to define them again.
  36. -- Also if the active clipping region is re-defined it immediately
  37. -- becomes the current clipping region.
  38. require
  39. is_valid_clipping_mode(mode)
  40. local
  41. i: INTEGER
  42. do
  43. if mode.is_equal("CD_CLIPOFF") then
  44. i := int_canvas_clip (cnvs, 0)
  45. elseif mode.is_equal("CD_CLIPAREA") then
  46. i := int_canvas_clip (cnvs, 1)
  47. elseif mode.is_equal("CD_CLIPPOLYGON") then
  48. i := int_canvas_clip (cnvs, 2)
  49. elseif mode.is_equal("CD_CLIPREGION") then
  50. i := int_canvas_clip (cnvs, 3)
  51. else
  52. i := int_canvas_clip (cnvs, 0)
  53. end
  54. end
  55. get_clipping_mode: STRING
  56. local
  57. i: INTEGER
  58. do
  59. i := int_canvas_clip (cnvs, -1)
  60. if i.is_equal(0) then
  61. Result := "CD_CLIPOFF"
  62. elseif i.is_equal(1) then
  63. Result := "CD_CLIPAREA"
  64. elseif i.is_equal(2) then
  65. Result := "CD_CLIPPOLYGON"
  66. elseif i.is_equal(3) then
  67. Result := "CD_CLIPREGION"
  68. else
  69. Result := "CD_CLIPOFF"
  70. end
  71. end
  72. set_clip_area (xmin, xmax, ymin, ymax: INTEGER)
  73. -- Defines the current rectangle for clipping. Only the points in the
  74. -- interval xmin<= x <= xmax and ymin <= y <= ymax will be printed.
  75. -- Default region: (0, w-1, 0, h-1).
  76. do
  77. int_canvas_clip_area (cnvs, xmin, xmax, ymin, ymax)
  78. end
  79. set_clip_area_real (xmin, xmax, ymin, ymax: REAL_64)
  80. -- Like "set_clip_area" but using REAL_64 values.
  81. do
  82. int_canvas_c_double_clip_area (cnvs, xmin, xmax, ymin, ymax)
  83. end
  84. set_wd_clip_area (xmin, xmax, ymin, ymax: REAL_64)
  85. -- Like "set_clip_area" but using World Coordinates.
  86. do
  87. int_wd_canvas_clip_area (cnvs, xmin, xmax, ymin, ymax)
  88. end
  89. get_clip_area: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  90. local
  91. xmin, xmax, ymin, ymax: INTEGER
  92. do
  93. int_canvas_get_clip_area (cnvs, $xmin, $xmax, $ymin, $ymax)
  94. Result := [xmin, xmax, ymin, ymax]
  95. end
  96. get_clip_area_real: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64]
  97. local
  98. xmin, xmax, ymin, ymax: REAL_64
  99. do
  100. int_canvas_c_double_get_clip_area (cnvs, $xmin, $xmax, $ymin, $ymax)
  101. Result := [xmin, xmax, ymin, ymax]
  102. end
  103. get_wd_clip_area: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64]
  104. local
  105. xmin, xmax, ymin, ymax: REAL_64
  106. do
  107. int_wd_canvas_get_clip_area (cnvs, $xmin, $xmax, $ymin, $ymax)
  108. Result := [xmin, xmax, ymin, ymax]
  109. end
  110. -- Validations
  111. is_valid_clipping_mode (mode: STRING): BOOLEAN
  112. do
  113. if mode.is_equal("CD_CLIPAREA") or
  114. mode.is_equal("CD_CLIPPOLYGON") or
  115. mode.is_equal("CD_CLIPREGION") or
  116. mode.is_equal("CD_CLIPOFF") then
  117. Result := True
  118. else
  119. Result := False
  120. end
  121. end
  122. feature {NONE}
  123. -- Internals
  124. int_canvas_clip (wgt: POINTER; m: INTEGER): INTEGER
  125. external
  126. "C inline use %"eiffel-iup.h%""
  127. alias
  128. "return cdCanvasClip ($wgt, $m);"
  129. end
  130. int_canvas_clip_area (wgt: POINTER; x1, x2, y1, y2: INTEGER)
  131. external
  132. "C inline use %"eiffel-iup.h%""
  133. alias
  134. "cdCanvasClipArea ($wgt, $x1, $x2, $y1, $y2);"
  135. end
  136. int_canvas_c_double_clip_area (wgt: POINTER; x1, x2, y1, y2: REAL_64)
  137. external
  138. "C inline use %"eiffel-iup.h%""
  139. alias
  140. "cdfCanvasClipArea ($wgt, $x1, $x2, $y1, $y2);"
  141. end
  142. int_wd_canvas_clip_area (wgt: POINTER; x1, x2, y1, y2: REAL_64)
  143. external
  144. "C inline use %"eiffel-iup.h%""
  145. alias
  146. "wdCanvasClipArea ($wgt, $x1, $x2, $y1, $y2);"
  147. end
  148. int_canvas_get_clip_area (wgt, x1, x2, y1, y2: POINTER)
  149. external
  150. "C inline use %"eiffel-iup.h%""
  151. alias
  152. "cdCanvasGetClipArea ($wgt, $x1, $x2, $y1, $y2);"
  153. end
  154. int_canvas_c_double_get_clip_area (wgt, x1, x2, y1, y2: POINTER)
  155. external
  156. "C inline use %"eiffel-iup.h%""
  157. alias
  158. "cdfCanvasGetClipArea ($wgt, $x1, $x2, $y1, $y2);"
  159. end
  160. int_wd_canvas_get_clip_area (wgt, x1, x2, y1, y2: POINTER)
  161. external
  162. "C inline use %"eiffel-iup.h%""
  163. alias
  164. "wdCanvasGetClipArea ($wgt, $x1, $x2, $y1, $y2);"
  165. end
  166. end
  167. -- The MIT License (MIT)
  168. -- Copyright (c) 2017, 2019 by German A. Arias
  169. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  170. -- of this software and associated documentation files (the "Software"), to deal
  171. -- in the Software without restriction, including without limitation the rights
  172. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  173. -- copies of the Software, and to permit persons to whom the Software is
  174. -- furnished to do so, subject to the following conditions:
  175. --
  176. -- The above copyright notice and this permission notice shall be included in
  177. -- all copies or substantial portions of the Software.
  178. --
  179. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  180. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  181. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  182. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  183. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  184. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  185. -- SOFTWARE.