cd_canvas_general_attributes.e 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. deferred class CD_CANVAS_GENERAL_ATTRIBUTES
  2. -- Predefined values of colors:
  3. --
  4. -- cd_red = (255, 0, 0)
  5. -- cd_dark_red = (128, 0, 0)
  6. -- cd_green = (0 ,255, 0)
  7. -- cd_dark_green = ( 0,128, 0)
  8. -- cd_blue = ( 0, 0,255)
  9. -- cd_dark_blue = ( 0, 0,128)
  10. -- cd_yellow = (255,255, 0)
  11. -- cd_dark_yellow = (128,128, 0)
  12. -- cd_magenta = (255, 0,255)
  13. -- cd_dark_magenta = (128, 0,128)
  14. -- cd_cyan = ( 0,255,255)
  15. -- cd_dark_cyan = ( 0,128,128)
  16. -- cd_white = (255,255,255)
  17. -- cd_black = ( 0, 0 , 0)
  18. -- cd_dark_gray = (128,128,128)
  19. -- cd_gray = (192,192,192)
  20. inherit
  21. CANVAS_DRAW
  22. feature {ANY}
  23. -- Color features
  24. set_foreground_color (red, green, blue: INTEGER)
  25. -- Configures a new current foreground rgb color. This color is used in
  26. -- all primitives (lines, areas, marks and text). Default value: black.
  27. local
  28. i: INTEGER
  29. do
  30. i := int_canvas_foreground (cnvs, encode_color(red, green, blue))
  31. end
  32. set_foreground_color_alpha (red, green, blue, alpha: INTEGER)
  33. -- Configures a new current foreground color with alpha (rgba). This
  34. -- color is used in all primitives (lines, areas, marks and text).
  35. -- Default value: black.
  36. local
  37. i: INTEGER
  38. do
  39. i := int_canvas_foreground (cnvs, encode_color(red, green, blue))
  40. end
  41. set_predefined_foreground_color (color: INTEGER)
  42. -- Set a predefined foreground rgb color. The predefined values are:
  43. --
  44. -- cd_red, cd_dark_red, cd_green, cd_dark_green, cd_blue, cd_dark_blue,
  45. -- cd_yellow, cd_dark_yellow, cd_magenta, cd_dark_magenta, cd_cyan,
  46. -- cd_dark_cyan, cd_white, cd_black, cd_dark_gray, cd_gray.
  47. --
  48. -- Default value: cd_black
  49. local
  50. i: INTEGER
  51. do
  52. i := int_canvas_foreground (cnvs, color)
  53. end
  54. get_foreground_color: TUPLE[INTEGER, INTEGER, INTEGER]
  55. -- Return the rgb values of the current foreground color.
  56. local
  57. i: INTEGER
  58. do
  59. i := int_canvas_foreground (cnvs, -1)
  60. Result := decode_color (i)
  61. end
  62. get_foreground_color_alpha: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  63. -- Return the rgba values of the current foreground color.
  64. local
  65. i: INTEGER
  66. do
  67. i := int_canvas_foreground (cnvs, -1)
  68. Result := decode_color_alpha (i)
  69. end
  70. set_background_color (red, green, blue: INTEGER)
  71. -- Configures a new current background rgb color. However, it does not
  72. -- automatically change the background of a canvas. For such, it is
  73. -- necessary to call the "clear" function. The background color only
  74. -- makes sense for "clear" and for primitives affected by the background
  75. -- opacity attribute. Default value: white.
  76. local
  77. i: INTEGER
  78. do
  79. i := int_canvas_background (cnvs, encode_color(red, green, blue))
  80. end
  81. set_background_color_alpha (red, green, blue, alpha: INTEGER)
  82. -- Configures a new current background rgba color. However, it does not
  83. -- automatically change the background of a canvas. For such, it is
  84. -- necessary to call the "clear" function. The background color only
  85. -- makes sense for "clear" and for primitives affected by the background
  86. -- opacity attribute. Default value: white.
  87. local
  88. i: INTEGER
  89. do
  90. i := int_canvas_background (cnvs, encode_color(red, green, blue))
  91. end
  92. set_predefined_background_color (color: INTEGER)
  93. -- Set a predefined background rgb color. The predefined values are:
  94. --
  95. -- cd_red, cd_dark_red, cd_green, cd_dark_green, cd_blue, cd_dark_blue,
  96. -- cd_yellow, cd_dark_yellow, cd_magenta, cd_dark_magenta, cd_cyan,
  97. -- cd_dark_cyan, cd_white, cd_black, cd_dark_gray, cd_gray.
  98. --
  99. -- However, it does not automatically change the background of a canvas.
  100. -- For such, it is necessary to call the "clear" function. The background
  101. -- color only makes sense for "clear" and for primitives affected by the
  102. -- background opacity attribute.
  103. --
  104. -- Default value: cd_black
  105. local
  106. i: INTEGER
  107. do
  108. i := int_canvas_background (cnvs, color)
  109. end
  110. get_background_color: TUPLE[INTEGER, INTEGER, INTEGER]
  111. -- Return the rgb values of the current background color.
  112. local
  113. i: INTEGER
  114. do
  115. i := int_canvas_background (cnvs, -1)
  116. Result := decode_color (i)
  117. end
  118. get_background_color_alpha: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  119. -- Return the rgba values of the current background color.
  120. local
  121. i: INTEGER
  122. do
  123. i := int_canvas_background (cnvs, -1)
  124. Result := decode_color_alpha (i)
  125. end
  126. -- Write mode features
  127. set_write_mode_replace
  128. -- Set the replace writing type for all drawing primitives. This is the
  129. -- default value.
  130. local
  131. i: INTEGER
  132. do
  133. i := int_canvas_write_mode (cnvs, 0)
  134. end
  135. set_write_mode_xor
  136. -- Set the xor writing type for all drawing primitives.
  137. --
  138. -- Note: operation XOR is very useful, because, using white as the
  139. -- foreground color and drawing the same image twice, you can go back to
  140. -- the original color, before the drawing. This is commonly used for
  141. -- mouse selection feedback.
  142. local
  143. i: INTEGER
  144. do
  145. i := int_canvas_write_mode (cnvs, 1)
  146. end
  147. set_write_mode_not_xor
  148. -- Set the not xor writing type for all drawing primitives.
  149. local
  150. i: INTEGER
  151. do
  152. i := int_canvas_write_mode (cnvs, 2)
  153. end
  154. get_write_mode: STRING
  155. -- Return the current write type. Possible values: CD_REPLACE, CD_XOR or
  156. -- CD_NOT_XOR.
  157. local
  158. i: INTEGER
  159. do
  160. i := int_canvas_write_mode (cnvs, -1)
  161. if i.is_equal(2) then
  162. Result := "CD_NOT_XOR"
  163. elseif i.is_equal(1) then
  164. Result := "CD_XOR"
  165. else
  166. Result := "CD_REPLACE"
  167. end
  168. end
  169. feature {}
  170. -- Internals
  171. int_canvas_foreground (wgt: POINTER; cl: INTEGER): INTEGER
  172. external "plug_in"
  173. alias "{
  174. location: "${sys}/plugins"
  175. module_name: "iup"
  176. feature_name: "cdCanvasForeground"
  177. }"
  178. end
  179. int_canvas_background (wgt: POINTER; cl: INTEGER): INTEGER
  180. external "plug_in"
  181. alias "{
  182. location: "${sys}/plugins"
  183. module_name: "iup"
  184. feature_name: "cdCanvasBackground"
  185. }"
  186. end
  187. int_canvas_write_mode (wgt: POINTER; mode: INTEGER): INTEGER
  188. external "plug_in"
  189. alias "{
  190. location: "${sys}/plugins"
  191. module_name: "iup"
  192. feature_name: "cdCanvasWriteMode"
  193. }"
  194. end
  195. end
  196. -- The MIT License (MIT)
  197. -- Copyright (c) 2016 by German A. Arias
  198. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  199. -- of this software and associated documentation files (the "Software"), to deal
  200. -- in the Software without restriction, including without limitation the rights
  201. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  202. -- copies of the Software, and to permit persons to whom the Software is
  203. -- furnished to do so, subject to the following conditions:
  204. --
  205. -- The above copyright notice and this permission notice shall be included in
  206. -- all copies or substantial portions of the Software.
  207. --
  208. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  209. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  210. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  211. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  212. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  213. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  214. -- SOFTWARE.