iup_color_dialog.e 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. class IUP_COLOR_DIALOG
  2. -- Creates the Color Dialog element. It is a predefined dialog for selecting a
  3. -- color.
  4. --
  5. -- There are 3 versions of the dialog. One for Windows only, one for GTK only
  6. -- and one for all systems, but it is based on the IUP_COLOR_BROWSER control
  7. -- that depends on the CD library.
  8. --
  9. -- The Windows and GTK dialogs can be shown only with the popup function. The
  10. -- IUP_COLOR_BROWSER based dialog is a IUP_DIALOG that can be shown as any
  11. -- regular IUP_DIALOG.
  12. --
  13. -- IMPORTANT: The IUP_COLOR_BROWSER based dialog is included in the Controls
  14. -- Library. When the Controls Library is initialized the Windows and GTK
  15. -- dialogs are not available anymore, i.e. before the Controls Library
  16. -- initialization only the Windows and GTK dialogs are available, after only
  17. -- the IUP_COLOR_BROWSER based dialog is available.
  18. inherit
  19. IUP_WIDGET
  20. redefine
  21. execute_colorupdate,
  22. execute_help
  23. end
  24. IUP_WIDGET_INTERNALS
  25. IUP_WIDGET_TITLE
  26. IUP_WIDGET_POPUP
  27. IUP_WIDGET_ICON
  28. IUP_WIDGET_PARENT_DIALOG
  29. create {ANY}
  30. color_dialog
  31. feature {ANY}
  32. color_dialog
  33. local
  34. a_color_dialog: POINTER
  35. do
  36. a_color_dialog := int_color_dialog
  37. set_widget(a_color_dialog)
  38. end
  39. -- Attributes
  40. set_alpha (value: INTEGER)
  41. -- [ColorBrowser and GTK only]: if defined it will enable an alpha
  42. -- selection additional controls with its initial value. If the user
  43. -- pressed the Ok button contains the returned value. Default: no
  44. -- defined, or 255 if SHOWALPHA=True.
  45. require
  46. value >= 0
  47. value <= 255
  48. do
  49. iup_open.set_attribute(Current, "ALPHA", value.out)
  50. end
  51. set_color_table (colors: STRING)
  52. -- List of colors separated by ";". In GTK and in the ColorBrowser based
  53. -- accepts 20 values and if not present the palette will not be visible.
  54. -- In Windows accepts 16 values and will be always visible, even if the
  55. -- colors are not defined (in this case are initialized with black). If a
  56. -- color is not specified then the default color is used. You can skip
  57. -- colors using ";;".
  58. do
  59. iup_open.set_attribute(Current, "COLORTABLE", colors)
  60. end
  61. get_color_table: STRING
  62. do
  63. Result := iup_open.get_attribute(Current, "COLORTABLE")
  64. end
  65. set_show_alpha (state: BOOLEAN)
  66. -- [ColorBrowser and GTK only]: if enabled will display the alpha
  67. -- selection controls, regardless if ALPHA is defined for the initial
  68. -- value or not.
  69. do
  70. iup_open.set_attribute(Current, "SHOWALPHA", boolean_to_yesno(state))
  71. end
  72. set_show_color_table (state: BOOLEAN)
  73. -- If enabled will display the color table, regardless if COLORTABLE is
  74. -- defined or not. The default colors in the color table are different in
  75. -- GTK and in the ColorBrowser based dialog. In Windows the default
  76. -- colors are all black.
  77. do
  78. iup_open.set_attribute(Current, "SHOWCOLORTABLE", boolean_to_yesno(state))
  79. end
  80. set_show_hexadecimal (state: BOOLEAN)
  81. -- [ColorBrowser only]: if enabled will display the Hexadecimal notation
  82. -- of the color.
  83. do
  84. iup_open.set_attribute(Current, "SHOWHEX", boolean_to_yesno(state))
  85. end
  86. set_show_help (state: BOOLEAN)
  87. -- [ColorBrowser only]: if enabled will display the Help button. In GTK
  88. -- and Windows, the Help button is shown only if the HELP_CB callback is
  89. -- defined.
  90. do
  91. iup_open.set_attribute(Current, "SHOWHELP", boolean_to_yesno(state))
  92. end
  93. get_status: INTEGER
  94. -- (read-only): Return "1" if the user pressed the Ok button, "0" if
  95. -- pressed the Cancel button or close the dialog.
  96. local
  97. str: STRING
  98. do
  99. str := iup_open.get_attribute(Current, "STATUS")
  100. if not str.is_empty then
  101. Result := 1
  102. else
  103. Result := 0
  104. end
  105. end
  106. set_value (red, green, blue, alpha: INTEGER)
  107. -- The color value in RGB coordinates and optionally alpha. It is used as
  108. -- the initial value and contains the selected value if the user pressed
  109. -- the Ok button. Format: "R G B A". Each component range from 0 to 255.
  110. do
  111. iup_open.set_attribute(Current, "VALUE", rgba_to_string(red,
  112. green,
  113. blue,
  114. alpha))
  115. end
  116. get_value: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  117. -- Return the selected value if the user pressed the Ok button.
  118. -- Format: "R G B A". Each component range from 0 to 255.
  119. do
  120. Result := iup_open.get_rgba(Current, "VALUE")
  121. end
  122. set_value_hsi (h, s, i: INTEGER)
  123. -- [ColorBrowser only]: The color value in HSI coordinates. It is used as
  124. -- the Format: "H S I". Each component range from 0-359, 0-100 and 0-100
  125. -- respectively.
  126. do
  127. iup_open.set_attribute(Current, "VALUEHSI", hsi_to_string(h, s, i))
  128. end
  129. get_value_hsi: TUPLE[INTEGER, INTEGER, INTEGER]
  130. -- Return the selected value if the user pressed the Ok button. Format:
  131. -- "H S I". Each component range from 0-359, 0-100 and 0-100 respectively.
  132. do
  133. Result := iup_open.get_hsi(Current, "VALUEHSI")
  134. end
  135. set_value_hexadecimal (color: STRING)
  136. -- [ColorBrowser only]: The color value in RGB Hexadecimal notation. It
  137. -- is used as the initial value. Format: "#RRGGBB". Each component range
  138. -- from 0-255, but in hexadecimal notation.
  139. do
  140. iup_open.set_attribute(Current, "VALUEHEX", color)
  141. end
  142. get_value_hexadecimal: STRING
  143. -- Return the selected value if the user pressed the Ok button. Format:
  144. -- "#RRGGBB". Each component range from 0-255, but in hexadecimal
  145. -- notation.
  146. do
  147. Result := iup_open.get_attribute(Current, "VALUEHEX")
  148. end
  149. -- Callbacks
  150. set_cb_help (act: detachable PROCEDURE[TUPLE[IUP_COLOR_DIALOG]])
  151. -- Action generated when the user press F1 at a control. In Motif
  152. -- is also activated by the Help button in some workstations
  153. -- keyboard.
  154. -- Returns: IUP_CLOSE will be processed.
  155. local
  156. operation: INTEGER
  157. do
  158. cb_help := act
  159. if cb_help /= Void then
  160. operation := 1
  161. else
  162. operation := 0
  163. end
  164. iup_open.set_callback (Current, "HELP_CB", "NONEEDED", operation)
  165. end
  166. set_cb_color_update (act: detachable FUNCTION[TUPLE[IUP_COLOR_DIALOG], STRING])
  167. -- [ColorBrowser only]: Action generated when the color is updated
  168. -- in the dialog. It is also called when the color is updated
  169. -- programmatically.
  170. local
  171. operation: INTEGER
  172. do
  173. cb_colorupdate := act
  174. if cb_colorupdate /= Void then
  175. operation := 1
  176. else
  177. operation := 0
  178. end
  179. iup_open.set_callback (Current, "COLORUPDATE_CB",
  180. "NONEEDED", operation)
  181. end
  182. feature {IUP}
  183. execute_help
  184. do
  185. if attached cb_help as int_cb then
  186. int_cb.call([Current])
  187. end
  188. end
  189. execute_colorupdate: STRING
  190. do
  191. if attached cb_colorupdate as int_cb then
  192. Result := int_cb.item([Current])
  193. else
  194. Result := "IUP_DEFAULT"
  195. end
  196. end
  197. feature {NONE}
  198. -- For callbacks
  199. cb_help: detachable PROCEDURE[TUPLE[IUP_COLOR_DIALOG]]
  200. cb_colorupdate: detachable FUNCTION[TUPLE[IUP_COLOR_DIALOG], STRING]
  201. -- Internal
  202. int_color_dialog: POINTER
  203. external
  204. "C inline use %"eiffel-iup.h%""
  205. alias
  206. "return IupColorDlg();"
  207. end
  208. end
  209. -- The MIT License (MIT)
  210. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  211. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  212. -- of this software and associated documentation files (the "Software"), to deal
  213. -- in the Software without restriction, including without limitation the rights
  214. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  215. -- copies of the Software, and to permit persons to whom the Software is
  216. -- furnished to do so, subject to the following conditions:
  217. --
  218. -- The above copyright notice and this permission notice shall be included in
  219. -- all copies or substantial portions of the Software.
  220. --
  221. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  222. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  223. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  224. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  225. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  226. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  227. -- SOFTWARE.