iup_spin.e 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. class IUP_SPIN
  2. -- This functions will create a control set with a vertical box containing two
  3. -- buttons, one with an up arrow and the other with a down arrow, to be used to
  4. -- increment and decrement values.
  5. inherit
  6. IUP_WIDGET
  7. redefine
  8. execute_spin
  9. end
  10. IUP_WIDGET_CHILD
  11. IUP_WIDGET_NAME
  12. IUP_WIDGET_CUSTOM_ATTRIBUTES
  13. create {ANY}
  14. spin
  15. feature {ANY}
  16. spin
  17. -- New spin.
  18. local
  19. a_spin: POINTER
  20. do
  21. a_spin := int_spin
  22. set_widget(a_spin)
  23. end
  24. -- Callback
  25. set_cb_spin (act: FUNCTION[TUPLE[IUP_SPIN, INTEGER], STRING])
  26. -- Called each time the user clicks in the buttons. It will increment 1
  27. -- and decrement -1 by default. Holding the Shift key will set a factor
  28. -- of 2, holding Ctrl a factor of 10, and both a factor of 100.
  29. local
  30. operation: INTEGER
  31. do
  32. cb_spin := act
  33. if cb_spin /= Void then
  34. operation := 1
  35. else
  36. operation := 0
  37. end
  38. iup_open.set_callback (Current, "SPIN_CB", "NONEEDED", operation)
  39. end
  40. feature {IUP}
  41. execute_spin (inc: INTEGER): STRING
  42. do
  43. Result := cb_spin.item([Current, inc])
  44. end
  45. feature {}
  46. -- For callback
  47. cb_spin: FUNCTION[TUPLE[IUP_SPIN, INTEGER], STRING]
  48. -- Internal
  49. int_spin: POINTER
  50. external "plug_in"
  51. alias "{
  52. location: "${sys}/plugins"
  53. module_name: "iup"
  54. feature_name: "IupSpin()"
  55. }"
  56. end
  57. end
  58. -- The MIT License (MIT)
  59. -- Copyright (c) 2016, 2017 by German A. Arias
  60. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  61. -- of this software and associated documentation files (the "Software"), to deal
  62. -- in the Software without restriction, including without limitation the rights
  63. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  64. -- copies of the Software, and to permit persons to whom the Software is
  65. -- furnished to do so, subject to the following conditions:
  66. --
  67. -- The above copyright notice and this permission notice shall be included in
  68. -- all copies or substantial portions of the Software.
  69. --
  70. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  71. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  72. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  73. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  74. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  75. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  76. -- SOFTWARE.