canvas_draw.e 4.7 KB

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