canvas_draw.e 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. deferred class CANVAS_DRAW
  2. inherit
  3. ANY
  4. feature {ANY}
  5. cd_red, cd_dark_red, cd_green, cd_dark_green, cd_blue, cd_dark_blue: INTEGER
  6. cd_yellow, cd_dark_yellow, cd_magenta, cd_dark_magenta, cd_cyan: INTEGER
  7. cd_dark_cyan, cd_white, cd_black, cd_dark_gray, cd_gray: INTEGER
  8. feature {}
  9. cnvs: POINTER
  10. -- Colors
  11. initialize_colors
  12. do
  13. cd_red := encode_color(255, 0, 0)
  14. cd_dark_red := encode_color(128, 0, 0)
  15. cd_green := encode_color(0, 255, 0)
  16. cd_dark_green := encode_color(0, 128, 0)
  17. cd_blue := encode_color(0, 0, 255)
  18. cd_dark_blue := encode_color(0, 0, 128)
  19. cd_yellow := encode_color(255, 255, 0)
  20. cd_dark_yellow := encode_color(128, 128, 0)
  21. cd_magenta := encode_color(255, 0, 255)
  22. cd_dark_magenta := encode_color(128, 0, 128)
  23. cd_cyan := encode_color(0, 255, 255)
  24. cd_dark_cyan := encode_color(0, 128, 128)
  25. cd_white := encode_color(255, 255, 255)
  26. cd_black := encode_color(0, 0, 0)
  27. cd_dark_gray := encode_color(128, 128, 128)
  28. cd_gray := encode_color(192, 192, 192)
  29. end
  30. encode_color (red, green, blue: INTEGER): INTEGER
  31. require
  32. red >= 0
  33. red <= 255
  34. green >= 0
  35. green <= 255
  36. blue >= 0
  37. blue <= 255
  38. do
  39. Result := int_encode_color (red,
  40. green,
  41. blue)
  42. end
  43. encode_color_alpha (red, green, blue, alpha: INTEGER): INTEGER
  44. require
  45. red >= 0
  46. red <= 255
  47. green >= 0
  48. green <= 255
  49. blue >= 0
  50. blue <= 255
  51. alpha >= 0
  52. alpha <= 255
  53. do
  54. Result := int_encode_color_alpha (red,
  55. green,
  56. blue,
  57. alpha)
  58. end
  59. decode_color (color: INTEGER): TUPLE[INTEGER, INTEGER, INTEGER]
  60. local
  61. otr, otg, otb: STRING
  62. pr, pg, pb: POINTER
  63. tup: TUPLE[INTEGER, INTEGER, INTEGER]
  64. do
  65. int_decode_color (color, pr, pg, pb)
  66. create otr.from_external_copy(pr)
  67. create otg.from_external_copy(pg)
  68. create otb.from_external_copy(pb)
  69. if otr.is_empty then
  70. otr.append_string("0")
  71. end
  72. if otg.is_empty then
  73. otg.append_string("0")
  74. end
  75. if otb.is_empty then
  76. otb.append_string("0")
  77. end
  78. tup := [otr.first.code.to_integer_32,
  79. otg.first.code.to_integer_32,
  80. otb.first.code.to_integer_32]
  81. Result := tup
  82. end
  83. decode_color_alpha (color: INTEGER): TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  84. local
  85. otr, otg, otb, ota: STRING
  86. pr, pg, pb, pa: POINTER
  87. tup: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  88. do
  89. int_decode_color_alpha (color, pr, pg, pb, pa)
  90. create otr.from_external_copy(pr)
  91. create otg.from_external_copy(pg)
  92. create otb.from_external_copy(pb)
  93. create ota.from_external_copy(pa)
  94. if otr.is_empty then
  95. otr.append_string("0")
  96. end
  97. if otg.is_empty then
  98. otg.append_string("0")
  99. end
  100. if otb.is_empty then
  101. otb.append_string("0")
  102. end
  103. if ota.is_empty then
  104. ota.append_string("0")
  105. end
  106. tup := [otr.first.code.to_integer_32,
  107. otg.first.code.to_integer_32,
  108. otb.first.code.to_integer_32,
  109. ota.first.code.to_integer_32]
  110. Result := tup
  111. end
  112. -- Internals
  113. int_encode_color (r, g, b: INTEGER): INTEGER
  114. external "plug_in"
  115. alias "{
  116. location: "${sys}/plugins"
  117. module_name: "iup"
  118. feature_name: "cdEncodeColor"
  119. }"
  120. end
  121. int_encode_color_alpha (r, g, b, a: INTEGER): INTEGER
  122. external "plug_in"
  123. alias "{
  124. location: "${sys}/plugins"
  125. module_name: "iup"
  126. feature_name: "cdEncodeColorAlpha"
  127. }"
  128. end
  129. int_decode_color (cl: INTEGER; r, g, b: POINTER)
  130. external "plug_in"
  131. alias "{
  132. location: "${sys}/plugins"
  133. module_name: "iup"
  134. feature_name: "cdDecodeColor"
  135. }"
  136. end
  137. int_decode_color_alpha (cl: INTEGER; r, g, b, a: POINTER)
  138. external "plug_in"
  139. alias "{
  140. location: "${sys}/plugins"
  141. module_name: "iup"
  142. feature_name: "cdDecodeColorAlpha"
  143. }"
  144. end
  145. end -- Class CANVAS_DRAW
  146. -- The MIT License (MIT)
  147. -- Copyright (c) 2016 by German A. Arias
  148. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  149. -- of this software and associated documentation files (the "Software"), to deal
  150. -- in the Software without restriction, including without limitation the rights
  151. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  152. -- copies of the Software, and to permit persons to whom the Software is
  153. -- furnished to do so, subject to the following conditions:
  154. --
  155. -- The above copyright notice and this permission notice shall be included in
  156. -- all copies or substantial portions of the Software.
  157. --
  158. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  159. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  160. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  161. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  162. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  163. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  164. -- SOFTWARE.