cd_canvas_world_coordinates.e 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. deferred class CD_CANVAS_WORLD_COORDINATES
  2. -- Allows the use of a World Coordinate System. In this system you can
  3. -- attribute coordinates to any unit you want. After you define a window
  4. -- (rectangular region) in your world, each given coordinate is then mapped to
  5. -- canvas coordinates to draw the primitives. You can define a viewport in your
  6. -- canvas to change the coordinate mapping from world to canvas.
  7. --
  8. -- If you want to map coordinates from one system to another, use the
  9. -- "wd_world_to_canvas" e "wd_canvas_to_world" functions.
  10. --
  11. -- The quality of the picture depends on the conversion from World to Canvas,
  12. -- so if the canvas has a small size the picture quality will be poor. To
  13. -- increase picture quality create a canvas with a larger size, if possible.
  14. --
  15. -- All World Coordinate drawing in all drivers are simulated using other CD
  16. -- primitives and do NOT depend or use the "set_transform" transformation
  17. -- matrix.
  18. inherit
  19. CANVAS_DRAW
  20. feature {ANY}
  21. set_window (xmin, xmax, ymin, ymax: REAL_64)
  22. -- Configures a window in the world coordinate system to be used to
  23. -- convert world coordinates (with values in real numbers) into canvas
  24. -- coordinates (with values in integers). The default window is the size
  25. -- in millimeters of the whole canvas.
  26. do
  27. int_wd_canvas_window(cnvs, xmin, xmax, ymin, ymax)
  28. end
  29. get_window: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64]
  30. -- Queries the current window in the world coordinate system being
  31. -- used to convert world coordinates into canvas coordinates (and the
  32. -- other way round).
  33. local
  34. xmin, xmax, ymin, ymax: REAL_64
  35. do
  36. int_wd_canvas_get_window(cnvs, $xmin, $xmax, $ymin, $ymax)
  37. Result := [xmin, xmax, ymin, ymax]
  38. end
  39. set_viewport (xmin, xmax, ymin, ymax: INTEGER)
  40. -- Configures a viewport in the canvas coordinate system to be used to
  41. -- convert world coordinates (with values in real numbers) into canvas
  42. -- coordinates (with values in integers). The default viewport is the
  43. -- whole canvas (0,w-1,0,h-1). If the canvas size is changed, the
  44. -- viewport will not be automatically updated.
  45. do
  46. int_wd_canvas_viewport(cnvs, xmin, xmax, ymin, ymax)
  47. end
  48. get_viewport: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  49. -- Queries the current viewport in the world coordinate system being used
  50. -- to convert world coordinates into canvas coordinates (and the other
  51. -- way round).
  52. local
  53. xmin, xmax, ymin, ymax: INTEGER
  54. do
  55. int_wd_canvas_get_viewport(cnvs, $xmin, $xmax, $ymin, $ymax)
  56. Result := [xmin, xmax, ymin, ymax]
  57. end
  58. world_to_canvas (xw, yw: REAL_64): TUPLE[INTEGER, INTEGER]
  59. -- Converts world coordinates into canvas coordinates.
  60. local
  61. xv, yv: INTEGER
  62. do
  63. int_wd_canvas_world_to_canvas(cnvs, xw, yw, $xv, $yv)
  64. Result := [xv, yv]
  65. end
  66. canvas_to_world (xv, yv: INTEGER): TUPLE[REAL_64, REAL_64]
  67. -- Converts canvas coordinates into world coordinates.
  68. local
  69. xw, yw: REAL_64
  70. do
  71. int_wd_canvas_canvas_to_world(cnvs, xv, yv, $xw, $yw)
  72. Result := [xw, yw]
  73. end
  74. set_wd_transform (sx, sy, tx, ty: REAL_64)
  75. -- Configures the world coordinate system transformation to be used to
  76. -- convert world coordinates (with values in real numbers) into canvas
  77. -- coordinates (with values in integers). The transformation is
  78. -- automatically set by "set_window" and "set_viewport". This has NO
  79. -- relation with "set_transform".
  80. do
  81. int_wd_canvas_set_transform(cnvs, sx, sy, tx, ty)
  82. end
  83. get_wd_transform: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64]
  84. -- Queries the current transformation being used to convert world
  85. -- coordinates into canvas coordinates (and the other way round).
  86. local
  87. sx, sy, tx, ty: REAL_64
  88. do
  89. int_wd_canvas_get_transform(cnvs, $sx, $sy, $tx, $ty)
  90. Result := [sx, sy, tx, ty]
  91. end
  92. set_wd_translate (dtx, dty: REAL_64)
  93. -- Translates the transformation by a delta, by adding the given values
  94. -- to the current tx and ty values.
  95. do
  96. int_wd_canvas_translate(cnvs, dtx, dty)
  97. end
  98. set_wd_scale (dsx, dsy: REAL_64)
  99. -- Scales the transformation by a delta, by multiplying the given values
  100. -- by the current sx and sy values.
  101. do
  102. int_wd_canvas_scale(cnvs, dsx, dsy)
  103. end
  104. -- Extra
  105. wd_hard_copy
  106. do
  107. -- Not sure how add this feature.
  108. end
  109. feature {NONE}
  110. int_wd_canvas_window (wgt: POINTER; xmin, xmax, ymin, ymax: REAL_64)
  111. external
  112. "C inline use %"eiffel-iup.h%""
  113. alias
  114. "wdCanvasWindow ($wgt, $xmin, $xmax, $ymin, $ymax);"
  115. end
  116. int_wd_canvas_get_window (wgt, xmin, xmax, ymin, ymax: POINTER)
  117. external
  118. "C inline use %"eiffel-iup.h%""
  119. alias
  120. "wdCanvasGetWindow ($wgt, $xmin, $xmax, $ymin, $ymax);"
  121. end
  122. int_wd_canvas_viewport (wgt: POINTER; xmin, xmax, ymin, ymax: INTEGER)
  123. external
  124. "C inline use %"eiffel-iup.h%""
  125. alias
  126. "wdCanvasViewport ($wgt, $xmin, $xmax, $ymin, $ymax);"
  127. end
  128. int_wd_canvas_get_viewport (wgt, xmin, xmax, ymin, ymax: POINTER)
  129. external
  130. "C inline use %"eiffel-iup.h%""
  131. alias
  132. "wdCanvasGetViewport ($wgt, $xmin, $xmax, $ymin, $ymax);"
  133. end
  134. int_wd_canvas_world_to_canvas (wgt: POINTER; xw, yw: REAL_64; xv, yv: POINTER)
  135. external
  136. "C inline use %"eiffel-iup.h%""
  137. alias
  138. "wdCanvasWorld2Canvas ($wgt, $xw, $yw, $xv, $yv);"
  139. end
  140. int_wd_canvas_canvas_to_world (wgt: POINTER; xv, yv: INTEGER; xw, yw: POINTER)
  141. external
  142. "C inline use %"eiffel-iup.h%""
  143. alias
  144. "wdCanvasCanvas2World ($wgt, $xv, $yv, $xw, $yw);"
  145. end
  146. int_wd_canvas_set_transform (wgt: POINTER; sx, sy, tx, ty: REAL_64)
  147. external
  148. "C inline use %"eiffel-iup.h%""
  149. alias
  150. "wdCanvasSetTransform ($wgt, $sx, $sy, $tx, $ty);"
  151. end
  152. int_wd_canvas_get_transform (wgt, sx, sy, tx, ty: POINTER)
  153. external
  154. "C inline use %"eiffel-iup.h%""
  155. alias
  156. "wdCanvasGetTransform ($wgt, $sx, $sy, $tx, $ty);"
  157. end
  158. int_wd_canvas_translate (wgt: POINTER; dtx, dty: REAL_64)
  159. external
  160. "C inline use %"eiffel-iup.h%""
  161. alias
  162. "wdCanvasTranslate ($wgt, $dtx, $dty);"
  163. end
  164. int_wd_canvas_scale (wgt: POINTER; dsx, dsy: REAL_64)
  165. external
  166. "C inline use %"eiffel-iup.h%""
  167. alias
  168. "wdCanvasScale ($wgt, $dsx, $dsy);"
  169. end
  170. end
  171. -- The MIT License (MIT)
  172. -- Copyright (c) 2017, 2019 by German A. Arias
  173. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  174. -- of this software and associated documentation files (the "Software"), to deal
  175. -- in the Software without restriction, including without limitation the rights
  176. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  177. -- copies of the Software, and to permit persons to whom the Software is
  178. -- furnished to do so, subject to the following conditions:
  179. --
  180. -- The above copyright notice and this permission notice shall be included in
  181. -- all copies or substantial portions of the Software.
  182. --
  183. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  184. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  185. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  186. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  187. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  188. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  189. -- SOFTWARE.