cd_canvas_world_coordinates.e 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 {}
  110. int_wd_canvas_window (wgt: POINTER; xmin, xmax, ymin, ymax: REAL_64)
  111. external "plug_in"
  112. alias "{
  113. location: "${sys}/plugins"
  114. module_name: "iup"
  115. feature_name: "wdCanvasWindow"
  116. }"
  117. end
  118. int_wd_canvas_get_window (wgt, xmin, xmax, ymin, ymax: POINTER)
  119. external "plug_in"
  120. alias "{
  121. location: "${sys}/plugins"
  122. module_name: "iup"
  123. feature_name: "wdCanvasGetWindow"
  124. }"
  125. end
  126. int_wd_canvas_viewport (wgt: POINTER; xmin, xmax, ymin, ymax: INTEGER)
  127. external "plug_in"
  128. alias "{
  129. location: "${sys}/plugins"
  130. module_name: "iup"
  131. feature_name: "wdCanvasViewport"
  132. }"
  133. end
  134. int_wd_canvas_get_viewport (wgt, xmin, xmax, ymin, ymax: POINTER)
  135. external "plug_in"
  136. alias "{
  137. location: "${sys}/plugins"
  138. module_name: "iup"
  139. feature_name: "wdCanvasGetViewport"
  140. }"
  141. end
  142. int_wd_canvas_world_to_canvas (wgt: POINTER; xw, yw: REAL_64; xv, yv: POINTER)
  143. external "plug_in"
  144. alias "{
  145. location: "${sys}/plugins"
  146. module_name: "iup"
  147. feature_name: "wdCanvasWorld2Canvas"
  148. }"
  149. end
  150. int_wd_canvas_canvas_to_world (wgt: POINTER; xv, yv: INTEGER; xw, yw: POINTER)
  151. external "plug_in"
  152. alias "{
  153. location: "${sys}/plugins"
  154. module_name: "iup"
  155. feature_name: "wdCanvasCanvas2World"
  156. }"
  157. end
  158. int_wd_canvas_set_transform (wgt: POINTER; sx, sy, tx, ty: REAL_64)
  159. external "plug_in"
  160. alias "{
  161. location: "${sys}/plugins"
  162. module_name: "iup"
  163. feature_name: "wdCanvasSetTransform"
  164. }"
  165. end
  166. int_wd_canvas_get_transform (wgt, sx, sy, tx, ty: POINTER)
  167. external "plug_in"
  168. alias "{
  169. location: "${sys}/plugins"
  170. module_name: "iup"
  171. feature_name: "wdCanvasGetTransform"
  172. }"
  173. end
  174. int_wd_canvas_translate (wgt: POINTER; dtx, dty: REAL_64)
  175. external "plug_in"
  176. alias "{
  177. location: "${sys}/plugins"
  178. module_name: "iup"
  179. feature_name: "wdCanvasTranslate"
  180. }"
  181. end
  182. int_wd_canvas_scale (wgt: POINTER; dsx, dsy: REAL_64)
  183. external "plug_in"
  184. alias "{
  185. location: "${sys}/plugins"
  186. module_name: "iup"
  187. feature_name: "wdCanvasScale"
  188. }"
  189. end
  190. end
  191. -- The MIT License (MIT)
  192. -- Copyright (c) 2017 by German A. Arias
  193. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  194. -- of this software and associated documentation files (the "Software"), to deal
  195. -- in the Software without restriction, including without limitation the rights
  196. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  197. -- copies of the Software, and to permit persons to whom the Software is
  198. -- furnished to do so, subject to the following conditions:
  199. --
  200. -- The above copyright notice and this permission notice shall be included in
  201. -- all copies or substantial portions of the Software.
  202. --
  203. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  204. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  205. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  206. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  207. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  208. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  209. -- SOFTWARE.