iup_animated_label.e 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. class IUP_ANIMATED_LABEL
  2. -- Creates an animated label interface element, which displays an image that
  3. -- is changed periodically.
  4. --
  5. -- It uses an animation that is simply an IUP_USER with several IUP_IMAGE as
  6. -- children.
  7. --
  8. -- It inherits from IUP_LABEL all attributes. The IMAGE attribute is
  9. -- periodically changed by a timer.
  10. --
  11. -- After call "load_images" at IUP, there is available a simple animation to
  12. -- show an indefinite progress called "IUP_CircleProgressAnimation".
  13. --
  14. -- The IUP-IM functions has two functions that can create an animation from
  15. -- image files called load_animation and load_animation_frames.
  16. inherit
  17. IUP_LABEL
  18. rename
  19. label_empty as animated_label_empty,
  20. label as animated_label_with_title
  21. redefine
  22. animated_label_empty,
  23. animated_label_with_title
  24. end
  25. create {ANY}
  26. animated_label_empty,
  27. animated_label,
  28. animated_label_with_title
  29. feature {ANY}
  30. animated_label_empty
  31. -- An empty animated label.
  32. local
  33. a_animated_label, p: POINTER
  34. do
  35. a_animated_label := int_animated_label(p)
  36. set_widget(a_animated_label)
  37. end
  38. animated_label_with_title (title: STRING)
  39. -- An empty animated label with the provided title.
  40. do
  41. animated_label_empty
  42. set_title (title)
  43. end
  44. animated_label (animation: IUP_USER)
  45. -- An animated label.
  46. --
  47. -- animation: element that contains the list of images.
  48. local
  49. a_animated_label: POINTER
  50. do
  51. a_animated_label := int_animated_label(animation.widget)
  52. set_widget(a_animated_label)
  53. end
  54. -- Operations
  55. start
  56. -- Starts the animation.
  57. do
  58. iup_open.set_attribute(Current, "START", "Yes")
  59. end
  60. stop
  61. -- Stop the animation.
  62. do
  63. iup_open.set_attribute(Current, "STOP", "Yes")
  64. end
  65. -- Attributes
  66. set_stop_when_hidden (state: BOOLEAN)
  67. -- Automatically stops the animation when the label is hidden.
  68. -- Default: "True".
  69. do
  70. iup_open.set_attribute(Current, "STOPWHENHIDDEN", boolean_to_yesno(state))
  71. end
  72. is_running: BOOLEAN
  73. -- Return True if the animation is running.
  74. local
  75. str: STRING
  76. do
  77. str := iup_open.get_attribute(Current, "RUNNING")
  78. Result := yesno_to_boolean(str)
  79. end
  80. set_frame_time (time: REAL_32)
  81. -- The time between each frame. If the IUP_USER element has a FRAMETIME
  82. -- attribute it will be used to set the IUP_ANIMATED_LABEL FRAMETIME
  83. -- attribute, but it can be overwritten later on.
  84. do
  85. iup_open.set_attribute(Current, "FRAMETIME", time.out)
  86. end
  87. get_frame_count: INTEGER
  88. -- Number of frames in the animation.
  89. local
  90. str: STRING
  91. do
  92. str := iup_open.get_attribute(Current, "FRAMECOUNT")
  93. if str.is_integer then
  94. Result := str.to_integer
  95. end
  96. end
  97. set_animation (name: STRING)
  98. -- The name of the element that contains the list of images. The value
  99. -- passed must be the name of an IUP_USER element with several IUP_IMAGE
  100. -- as children.
  101. do
  102. iup_open.set_attribute(Current, "ANIMATION", name)
  103. end
  104. set_animation_widget (wgt: IUP_USER)
  105. -- Same as ANIMATION but directly using the widget of the element.
  106. do
  107. iup_open.set_attribute_widget(Current, "ANIMATION_HANDLE", wgt)
  108. end
  109. feature {NONE}
  110. -- Internals
  111. int_animated_label (animation: POINTER): POINTER
  112. external
  113. "C inline use %"eiffel-iup.h%""
  114. alias
  115. "return IupAnimatedLabel ($animation);"
  116. end
  117. end
  118. -- The MIT License (MIT)
  119. -- Copyright (c) 2016, 2017, 2019 by German A. Arias
  120. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  121. -- of this software and associated documentation files (the "Software"), to deal
  122. -- in the Software without restriction, including without limitation the rights
  123. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  124. -- copies of the Software, and to permit persons to whom the Software is
  125. -- furnished to do so, subject to the following conditions:
  126. --
  127. -- The above copyright notice and this permission notice shall be included in
  128. -- all copies or substantial portions of the Software.
  129. --
  130. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  131. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  132. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  133. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  134. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  135. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  136. -- SOFTWARE.