iup_progress_bar.e 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. class IUP_PROGRESS_BAR
  2. -- Creates a progress bar control. Shows a percent value that can be updated to
  3. -- simulate a progression.
  4. inherit
  5. IUP_WIDGET
  6. redefine
  7. execute_map,
  8. execute_unmap,
  9. execute_destroy
  10. end
  11. IUP_WIDGET_BGCOLOR
  12. IUP_WIDGET_FGCOLOR
  13. IUP_WIDGET_RASTERSIZE
  14. IUP_WIDGET_USERSIZE
  15. IUP_WIDGET_ACTIVE
  16. IUP_WIDGET_EXPAND
  17. IUP_WIDGET_FONT
  18. IUP_WIDGET_SCREENPOSITION
  19. IUP_WIDGET_POSITION
  20. IUP_WIDGET_MAXMIN_SIZE
  21. IUP_WIDGET_TIP
  22. IUP_WIDGET_SIZE
  23. IUP_WIDGET_ZORDER
  24. IUP_WIDGET_VISIBLE
  25. IUP_WIDGET_CHILD
  26. IUP_WIDGET_NAME
  27. IUP_WIDGET_CUSTOM_ATTRIBUTES
  28. create {ANY}
  29. progress_bar
  30. feature {ANY}
  31. progress_bar
  32. -- Create a new progress bar.
  33. local
  34. a_progress_bar: POINTER
  35. do
  36. min := 0
  37. max := 1
  38. a_progress_bar := int_progress_bar
  39. set_widget(a_progress_bar)
  40. end
  41. -- Attributes
  42. set_dashed (state: BOOLEAN)
  43. -- (creation only in Windows) [Windows and GTK only]: Changes the style
  44. -- of the progress bar for a dashed pattern. Default is "False".
  45. do
  46. iup_open.set_attribute(Current, "DASHED", boolean_to_yesno(state))
  47. end
  48. set_marquee (state: BOOLEAN)
  49. -- (creation): displays an undefined state. Default: False. You can set
  50. -- the attribute after map but only to start or stop the animation. In
  51. -- Windows it will work only if using Visual Styles.
  52. do
  53. iup_open.set_attribute(Current, "MARQUEE", boolean_to_yesno(state))
  54. end
  55. set_max (value: REAL_64)
  56. -- (non inheritable): Contains the maximum value. Default is "1". The
  57. -- control display is not updated, must set VALUE attribute to
  58. -- update.
  59. require
  60. value > min
  61. do
  62. iup_open.set_attribute(Current, "MAX", value.out)
  63. -- Update value
  64. max := value
  65. ensure
  66. updated: max = value
  67. end
  68. set_min (value: REAL_64)
  69. -- (non inheritable): Contains the minimum value. Default is "0". The
  70. -- control display is not updated, must set VALUE attribute to
  71. -- update.
  72. require
  73. value < max
  74. do
  75. iup_open.set_attribute(Current, "MIN", value.out)
  76. -- Update value
  77. min := value
  78. ensure
  79. updated: min = value
  80. end
  81. set_horizontal_orientation
  82. -- (creation only): Set an horizontal orientation (from left to
  83. -- right). This is the default value.
  84. do
  85. iup_open.set_attribute(Current, "ORIENTATION", "HORIZONTAL")
  86. end
  87. set_vertical_orientation
  88. -- (creation only): Set a vertical orientation (from bottom to
  89. -- top). By default the progress bar has an horizontal
  90. -- orientation (from left to right).
  91. do
  92. iup_open.set_attribute(Current, "ORIENTATION", "VERTICAL")
  93. end
  94. set_value (value: REAL_64)
  95. -- (non inheritable): Contains a number between "MIN" and "MAX",
  96. -- controlling the current position.
  97. do
  98. iup_open.set_attribute(Current, "VALUE", value.out)
  99. end
  100. get_value: REAL_64
  101. -- (non inheritable): Contains a number between "MIN" and "MAX",
  102. -- controlling the current position.
  103. local
  104. str: STRING
  105. do
  106. str := iup_open.get_attribute(Current, "VALUE")
  107. if str.is_real then
  108. Result := str.to_real
  109. end
  110. end
  111. -- Callbacks
  112. set_cb_map (act: detachable FUNCTION[TUPLE[IUP_PROGRESS_BAR], STRING])
  113. -- Called right after an element is mapped and its attributes updated.
  114. local
  115. operation: INTEGER
  116. do
  117. cb_map := act
  118. if cb_map /= Void then
  119. operation := 1
  120. else
  121. operation := 0
  122. end
  123. iup_open.set_callback (Current, "MAP_CB", "NONEEDED", operation)
  124. end
  125. set_cb_unmap (act: detachable FUNCTION[TUPLE[IUP_PROGRESS_BAR], STRING])
  126. -- Called right before an element is unmapped.
  127. local
  128. operation: INTEGER
  129. do
  130. cb_unmap := act
  131. if cb_unmap /= Void then
  132. operation := 1
  133. else
  134. operation := 0
  135. end
  136. iup_open.set_callback (Current, "UNMAP_CB", "NONEEDED", operation)
  137. end
  138. set_cb_destroy (act: detachable FUNCTION[TUPLE[IUP_PROGRESS_BAR], STRING])
  139. -- Called right before an element is destroyed.
  140. local
  141. operation: INTEGER
  142. do
  143. cb_destroy := act
  144. if cb_destroy /= Void then
  145. operation := 1
  146. else
  147. operation := 0
  148. end
  149. iup_open.set_callback (Current, "DESTROY_CB", "NONEEDED", operation)
  150. end
  151. -- For limits
  152. min: REAL_64
  153. max: REAL_64
  154. feature {IUP} -- Internal handle of callbacks
  155. execute_map: STRING
  156. do
  157. if attached cb_map as int_cb then
  158. Result := int_cb.item([Current])
  159. else
  160. Result := "IUP_DEFAULT"
  161. end
  162. end
  163. execute_unmap: STRING
  164. do
  165. if attached cb_unmap as int_cb then
  166. Result := int_cb.item([Current])
  167. else
  168. Result := "IUP_DEFAULT"
  169. end
  170. end
  171. execute_destroy: STRING
  172. do
  173. if attached cb_destroy as int_cb then
  174. Result := int_cb.item([Current])
  175. else
  176. Result := "IUP_DEFAULT"
  177. end
  178. end
  179. feature {NONE}
  180. -- For callbacks
  181. cb_map: detachable FUNCTION[TUPLE[IUP_PROGRESS_BAR], STRING]
  182. cb_unmap: detachable FUNCTION[TUPLE[IUP_PROGRESS_BAR], STRING]
  183. cb_destroy: detachable FUNCTION[TUPLE[IUP_PROGRESS_BAR], STRING]
  184. -- Internals
  185. int_progress_bar: POINTER
  186. external
  187. "C inline use %"eiffel-iup.h%""
  188. alias
  189. "return IupProgressBar();"
  190. end
  191. invariant
  192. max > min
  193. end
  194. -- The MIT License (MIT)
  195. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  196. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  197. -- of this software and associated documentation files (the "Software"), to deal
  198. -- in the Software without restriction, including without limitation the rights
  199. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  200. -- copies of the Software, and to permit persons to whom the Software is
  201. -- furnished to do so, subject to the following conditions:
  202. --
  203. -- The above copyright notice and this permission notice shall be included in
  204. -- all copies or substantial portions of the Software.
  205. --
  206. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  207. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  208. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  209. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  210. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  211. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  212. -- SOFTWARE.