cd_primitives_marks.e 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. deferred class CD_PRIMITIVES_MARKS
  2. -- A mark is a punctual representation. It can have different sizes and types.
  3. -- All types are affected only by mark attributes and by the foreground color.
  4. --
  5. -- All marks in all drivers are simulated using other CD primitives, except
  6. -- CanvasPixel.
  7. inherit
  8. CANVAS_DRAW
  9. feature {ANY}
  10. -- Pixel
  11. draws_pixel (x, y, red, green, blue: INTEGER)
  12. -- Configures the pixel (x,y) with the color defined. It is the smallest
  13. -- element of the canvas. It depends only on global attributes of the
  14. -- canvas. It can be very slow on some drivers. Sometimes it is
  15. -- implemented as a rectangle with size 1x1.
  16. local
  17. cl: INTEGER
  18. do
  19. cl := encode_color (red, green, blue)
  20. int_canvas_pixel (cnvs, x, y, cl)
  21. end
  22. draws_pixel_real (x, y: REAL_64; red, green, blue: INTEGER)
  23. -- As "canvas_pixel" but with REAL_64 for coordinates.
  24. local
  25. cl: INTEGER
  26. do
  27. cl := encode_color (red, green, blue)
  28. int_canvas_c_double_pixel (cnvs, x, y, cl)
  29. end
  30. wd_draws_pixel (x, y: REAL_64; red, green, blue: INTEGER)
  31. -- As "canvas_pixel_real" but use World coordinates.
  32. local
  33. cl: INTEGER
  34. do
  35. cl := encode_color (red, green, blue)
  36. int_wd_canvas_pixel (cnvs, x, y, cl)
  37. end
  38. -- Mark operations
  39. draws_mark (x, y: INTEGER)
  40. -- Draws a mark in (x,y) using the current foreground color. It is not
  41. -- possible to use this function between a call to functions "begin" and
  42. -- "end" if the type of mark is set to diamond. If the active driver does
  43. -- not include this primitive, it will be simulated using other
  44. -- primitives from the library.
  45. --
  46. -- If you will call this function several times in a sequence, then it is
  47. -- recommended that the application changes the filling and line
  48. -- attributes to those used by this function:
  49. --
  50. -- set_interior_style_solid
  51. -- set_line_style_continuous
  52. -- set_line_width(1)
  53. --
  54. -- This will greatly increase this function's performance. Also in this
  55. -- case, if the mark is very small, we suggest using the "canvas_pixel"
  56. -- function so that the application itself draws the mark. In many cases,
  57. -- this also increases this function's performance.
  58. do
  59. int_canvas_mark (cnvs, x, y)
  60. end
  61. draws_mark_real (x, y: REAL_64)
  62. -- As "canvas_mark" but with REAL_64 for coordinates.
  63. do
  64. int_canvas_c_double_mark (cnvs, x, y)
  65. end
  66. wd_draws_mark (x, y: REAL_64)
  67. -- As "canvas_mark_real" but use World coordinates.
  68. do
  69. int_wd_canvas_mark (cnvs, x, y)
  70. end
  71. -- Mark size
  72. set_mark_size (size: INTEGER)
  73. -- Configures the mark size in pixels.
  74. -- Default value: 10.
  75. require
  76. size >= 1
  77. local
  78. i: INTEGER
  79. do
  80. i := int_canvas_mark_size (cnvs, size)
  81. end
  82. set_wd_mark_size (size: REAL_64)
  83. -- Set the current size in millimeters.
  84. require
  85. size >= 1
  86. local
  87. i: REAL_64
  88. do
  89. i := int_wd_canvas_mark_size (cnvs, size)
  90. end
  91. get_mark_size: INTEGER
  92. -- Return the size in pixels.
  93. do
  94. Result := int_canvas_mark_size (cnvs, -1)
  95. end
  96. get_wd_mark_size: REAL_64
  97. -- Return the size in millimeters.
  98. do
  99. Result := int_wd_canvas_mark_size (cnvs, -1)
  100. end
  101. -- Mark attributes
  102. mark_type_plus: STRING
  103. local
  104. i: INTEGER
  105. do
  106. i := int_canvas_mark_type (cnvs, 0)
  107. Result := int_mark_type_integer_to_string(i)
  108. end
  109. mark_type_star: STRING
  110. local
  111. i: INTEGER
  112. do
  113. i := int_canvas_mark_type (cnvs, 1)
  114. Result := int_mark_type_integer_to_string(i)
  115. end
  116. mark_type_circle: STRING
  117. local
  118. i: INTEGER
  119. do
  120. i := int_canvas_mark_type (cnvs, 2)
  121. Result := int_mark_type_integer_to_string(i)
  122. end
  123. mark_type_x: STRING
  124. local
  125. i: INTEGER
  126. do
  127. i := int_canvas_mark_type (cnvs, 3)
  128. Result := int_mark_type_integer_to_string(i)
  129. end
  130. mark_type_box: STRING
  131. local
  132. i: INTEGER
  133. do
  134. i := int_canvas_mark_type (cnvs, 4)
  135. Result := int_mark_type_integer_to_string(i)
  136. end
  137. mark_type_diamond: STRING
  138. local
  139. i: INTEGER
  140. do
  141. i := int_canvas_mark_type (cnvs, 5)
  142. Result := int_mark_type_integer_to_string(i)
  143. end
  144. mark_type_hollow_circle: STRING
  145. local
  146. i: INTEGER
  147. do
  148. i := int_canvas_mark_type (cnvs, 6)
  149. Result := int_mark_type_integer_to_string(i)
  150. end
  151. mark_type_hollow_box: STRING
  152. local
  153. i: INTEGER
  154. do
  155. i := int_canvas_mark_type (cnvs, 7)
  156. Result := int_mark_type_integer_to_string(i)
  157. end
  158. mark_type_hollow_diamond: STRING
  159. local
  160. i: INTEGER
  161. do
  162. i := int_canvas_mark_type (cnvs, 8)
  163. Result := int_mark_type_integer_to_string(i)
  164. end
  165. mark_type: STRING
  166. -- Return the type of the mark. One of the follwing string:
  167. --
  168. -- "CD_PLUS"
  169. -- "CD_STAR"
  170. -- "CD_CIRCLE"
  171. -- "CD_X"
  172. -- "CD_BOX"
  173. -- "CD_DIAMOND"
  174. -- "CD_HOLLOW_CIRCLE"
  175. -- "CD_HOLLOW_BOX"
  176. -- "CD_HOLLOW_DIAMOND"
  177. local
  178. i: INTEGER
  179. do
  180. i := int_canvas_mark_type (cnvs, -1)
  181. Result := int_mark_type_integer_to_string(i)
  182. end
  183. feature {}
  184. -- Internals
  185. int_canvas_pixel (wgt: POINTER; x, y, cl: INTEGER)
  186. external "plug_in"
  187. alias "{
  188. location: "${sys}/plugins"
  189. module_name: "iup"
  190. feature_name: "cdCanvasPixel"
  191. }"
  192. end
  193. int_canvas_c_double_pixel (wgt: POINTER; x, y: REAL_64; cl: INTEGER)
  194. external "plug_in"
  195. alias "{
  196. location: "${sys}/plugins"
  197. module_name: "iup"
  198. feature_name: "cdfCanvasPixel"
  199. }"
  200. end
  201. int_wd_canvas_pixel (wgt: POINTER; x, y: REAL_64; cl: INTEGER)
  202. external "plug_in"
  203. alias "{
  204. location: "${sys}/plugins"
  205. module_name: "iup"
  206. feature_name: "wdCanvasPixel"
  207. }"
  208. end
  209. int_canvas_mark (wgt: POINTER; x, y: INTEGER)
  210. external "plug_in"
  211. alias "{
  212. location: "${sys}/plugins"
  213. module_name: "iup"
  214. feature_name: "cdCanvasMark"
  215. }"
  216. end
  217. int_canvas_c_double_mark (wgt: POINTER; x, y: REAL_64)
  218. external "plug_in"
  219. alias "{
  220. location: "${sys}/plugins"
  221. module_name: "iup"
  222. feature_name: "cdfCanvasMark"
  223. }"
  224. end
  225. int_wd_canvas_mark (wgt: POINTER; x, y: REAL_64)
  226. external "plug_in"
  227. alias "{
  228. location: "${sys}/plugins"
  229. module_name: "iup"
  230. feature_name: "wdCanvasMark"
  231. }"
  232. end
  233. int_canvas_mark_size (wgt: POINTER; s: INTEGER): INTEGER
  234. external "plug_in"
  235. alias "{
  236. location: "${sys}/plugins"
  237. module_name: "iup"
  238. feature_name: "cdCanvasMarkSize"
  239. }"
  240. end
  241. int_wd_canvas_mark_size (wgt: POINTER; s: REAL_64): REAL_64
  242. external "plug_in"
  243. alias "{
  244. location: "${sys}/plugins"
  245. module_name: "iup"
  246. feature_name: "wdCanvasMarkSize"
  247. }"
  248. end
  249. int_canvas_mark_type (wgt: POINTER; type: INTEGER): INTEGER
  250. external "plug_in"
  251. alias "{
  252. location: "${sys}/plugins"
  253. module_name: "iup"
  254. feature_name: "cdCanvasMarkType"
  255. }"
  256. end
  257. int_mark_type_integer_to_string (t: INTEGER): STRING
  258. do
  259. if t.is_equal(0) then
  260. Result := "CD_PLUS"
  261. elseif t.is_equal(1) then
  262. Result := "CD_STAR"
  263. elseif t.is_equal(2) then
  264. Result := "CD_CIRCLE"
  265. elseif t.is_equal(3) then
  266. Result := "CD_X"
  267. elseif t.is_equal(4) then
  268. Result := "CD_BOX"
  269. elseif t.is_equal(5) then
  270. Result := "CD_DIAMOND"
  271. elseif t.is_equal(6) then
  272. Result := "CD_HOLLOW_CIRCLE"
  273. elseif t.is_equal(7) then
  274. Result := "CD_HOLLOW_BOX"
  275. elseif t.is_equal(8) then
  276. Result := "CD_HOLLOW_DIAMOND"
  277. end
  278. end
  279. end
  280. -- The MIT License (MIT)
  281. -- Copyright (c) 2016 by German A. Arias
  282. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  283. -- of this software and associated documentation files (the "Software"), to deal
  284. -- in the Software without restriction, including without limitation the rights
  285. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  286. -- copies of the Software, and to permit persons to whom the Software is
  287. -- furnished to do so, subject to the following conditions:
  288. --
  289. -- The above copyright notice and this permission notice shall be included in
  290. -- all copies or substantial portions of the Software.
  291. --
  292. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  293. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  294. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  295. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  296. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  297. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  298. -- SOFTWARE.