example5.e 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. class EXAMPLE5
  2. -- This example show how use tabs and many other controls.
  3. insert
  4. IUP_INTERFACE
  5. create {ANY}
  6. make
  7. feature {ANY}
  8. ml: IUP_MULTILINE
  9. l4: IUP_LABEL
  10. pb: IUP_PROGRESS_BAR
  11. lm: LOOP_STACK
  12. counter: INTEGER
  13. time: MICROSECOND_TIME
  14. make
  15. local
  16. gui: IUP
  17. i: STRING
  18. w: IUP_DIALOG
  19. t: IUP_TABS
  20. v1, v2, v3: IUP_VBOX
  21. h1: IUP_HBOX
  22. b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12: IUP_BUTTON
  23. im: IUP_IMAGE
  24. l1, l2, l3: IUP_LABEL
  25. s1: IUP_VAL
  26. lt: IUP_LIST
  27. fl: IUP_FILL
  28. al: IUP_ANIMATED_LABEL
  29. d: IUP_DATE_PICK
  30. c: IUP_CALENDAR
  31. tx1: IUP_TEXT
  32. sb1: IUP_SPIN_BOX
  33. scll: IUP_SCROLL_BOX
  34. frm: IUP_FRAME
  35. ml1: IUP_MULTILINE
  36. sb: IUP_SPLIT
  37. do
  38. gui := iup_open
  39. gui.load_images
  40. gui.load_iup_controls
  41. -- Controls at first tab
  42. ---------------------------------
  43. create im.image({FAST_ARRAY2[INTEGER] 10, 10, << 15, 15, 15, 15, 15, 15, 15, 15, 15, 15;
  44. 15, 15, 15, 1, 1, 1, 1, 15, 15, 15;
  45. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15;
  46. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15;
  47. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15;
  48. 15, 15, 15, 1, 1, 1, 15, 15, 15, 15;
  49. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15;
  50. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15;
  51. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15;
  52. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 >>})
  53. im.set_widget_name("my_image")
  54. create b1.button("Launch an alarn")
  55. b1.set_cb_action(agent alarm(?))
  56. create b2.button("Select a file")
  57. b2.set_cb_action(agent file(?))
  58. create b3.button("Select a color")
  59. b3.set_cb_action(agent color(?))
  60. create b4.button("Write a message")
  61. b4.set_cb_action(agent get_message(?))
  62. create b5.button("Select an option")
  63. b5.set_cb_action(agent list(?))
  64. create b6.button("Preferences")
  65. b6.set_cb_action(agent param(?))
  66. create b7.button("Font")
  67. b7.set_image("my_image")
  68. b7.set_cb_action(agent font(?))
  69. create b8.button("A message")
  70. b8.set_cb_action(agent message(?))
  71. create b9.button("Color dialog")
  72. b9.set_cb_action(agent color_dialog(?))
  73. create b10.button("A message dialog")
  74. b10.set_cb_action(agent message_dlg(?))
  75. create fl.fill
  76. create al.animated_label_empty
  77. al.set_animation("IUP_CircleProgressAnimation")
  78. create ml.multiline
  79. ml.set_expand("YES")
  80. create v1.vbox({ARRAY[IUP_WIDGET] 1, << b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, fl, al >>})
  81. v1.set_alignment("ACENTER")
  82. v1.set_gap(10)
  83. v1.set_margin(10, 10)
  84. v1.set_normalize_size("HORIZONTAL")
  85. create h1.hbox({ARRAY[IUP_WIDGET] 1, << v1, ml >>})
  86. -- Controls at second tab
  87. -----------------------------------------
  88. create l1.label("Age")
  89. create l2.label("City")
  90. create l3.label("Date")
  91. create d.date_pick
  92. create s1.horizontal_val
  93. create lt.list
  94. lt.set_drop_down(True)
  95. lt.set_size(80, 12)
  96. create c.calendar
  97. create v2.vbox({ARRAY[IUP_WIDGET] 1, << d, l1, s1, l2, lt, l3,
  98. c >>})
  99. v2.set_gap(10)
  100. v2.set_margin(10, 10)
  101. -- Controls at third tab
  102. -----------------------------------------
  103. create tx1.text
  104. tx1.set_value("0")
  105. tx1.set_spin(True)
  106. create l4.label("0")
  107. l4.set_size(40, 12)
  108. l4.set_alignment("ACENTER", "ACENTER")
  109. create sb1.spin_box(l4)
  110. sb1.set_cb_spin(agent spin_click(?, ?))
  111. create frm.frame(sb1)
  112. frm.set_title("Spin-label")
  113. create ml1.multiline
  114. ml1.set_expand("YES")
  115. ml1.set_size(550, 350)
  116. create pb.progress_bar
  117. create b11.button("Starts")
  118. b11.set_cb_action(agent progress_bar(?))
  119. create b12.button("Progress dialog")
  120. b12.set_cb_action(agent progress_dialog(?))
  121. create scll.scroll_box(ml1)
  122. create v3.vbox({ARRAY[IUP_WIDGET] 1, << tx1, sb1, pb, b11, b12 >>})
  123. v3.set_gap(10)
  124. v3.set_margin(10, 10)
  125. create sb.split(v3, scll)
  126. --sb.set_show_grip("LINES")
  127. sb.set_min_and_max(250, 750)
  128. sb.set_value(500)
  129. -- Create the tabs
  130. -------------------------------
  131. create t.tabs({ARRAY[IUP_WIDGET] 1, << h1, v2, sb >>})
  132. t.set_tab_n_title("Buttons", 0)
  133. t.set_tab_n_title("List, Slider and Date", 1)
  134. t.set_tab_n_title("Split", 2)
  135. -- Create the window.
  136. -------------------------
  137. create w.dialog(t)
  138. w.set_title("Controls test")
  139. w.set_predefined_size("HALF", "250")
  140. w.set_widget_name("window")
  141. i := w.show
  142. -- Start the animation.
  143. al.start
  144. -- Add items at list.
  145. lt.append_item("London")
  146. lt.append_item("Madrid")
  147. lt.append_item("New York")
  148. lt.append_item("Paris")
  149. lt.append_item("Milan")
  150. lt.append_item("Tokyo")
  151. lt.append_item("Buenos Aires")
  152. lt.set_value_string("Milan")
  153. gui.main_loop
  154. gui.close
  155. end
  156. alarm (widget: IUP_WIDGET): STRING
  157. local
  158. r: INTEGER
  159. al: IUP_ALARM
  160. do
  161. create al.alarm_three_buttons("Alarm", "Select a button", "1",
  162. "2", "3")
  163. r := al.launch
  164. if r.is_equal(1) then
  165. ml.append("You selected the first button; %N")
  166. elseif r.is_equal(2) then
  167. ml.append("You selected the second button; %N")
  168. elseif r.is_equal(3) then
  169. ml.append("You selected the third button; %N")
  170. end
  171. Result := "IUP_DEFAULT"
  172. end
  173. file (widget: IUP_WIDGET): STRING
  174. local
  175. tup: TUPLE[INTEGER, STRING]
  176. fl: IUP_GET_FILE
  177. do
  178. create fl.get_file("~/", "*.txt")
  179. tup := fl.launch
  180. if tup.item_1.is_equal(0) then
  181. ml.append(tup.item_2)
  182. ml.append("%N")
  183. end
  184. Result := "IUP_DEFAULT"
  185. end
  186. color (widget: IUP_BUTTON): STRING
  187. local
  188. tup: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  189. gc: IUP_GET_COLOR
  190. do
  191. create gc.get_color_with_initial(0, 0, 0)
  192. tup := gc.launch_predefined_xy("IUP_CENTER", "IUP_CENTER")
  193. if tup.item_1.is_equal(1) then
  194. ml.set_rgb_foreground_color(tup.item_2, tup.item_3, tup.item_4)
  195. end
  196. Result := "IUP_DEFAULT"
  197. end
  198. get_message (widget: IUP_BUTTON): STRING
  199. local
  200. tup: TUPLE[INTEGER, STRING]
  201. gt: IUP_GET_TEXT
  202. do
  203. create gt.get_text_with_initial("Write a message", "...", 40)
  204. tup := gt.launch
  205. if not tup.item_1.is_equal(0) then
  206. ml.append(tup.item_2)
  207. ml.append("%N")
  208. end
  209. Result := "IUP_DEFAULT"
  210. end
  211. list (widget: IUP_BUTTON): STRING
  212. local
  213. ld: IUP_LIST_DIALOG
  214. a: ARRAY[STRING]
  215. tup: TUPLE[INTEGER, STRING]
  216. do
  217. a := {ARRAY[STRING] 1, << "Uno", "Dos", "Tres", "Cuatro", "Cinco",
  218. "Seis", "Siete", "Ocho", "Nueve", "Diez" >>}
  219. --create ld.list_dialog_simple("Select", a, 1, 1, 1)
  220. create ld.list_dialog_multiple("Select", a, 1, 5)
  221. tup := ld.launch
  222. ml.append(tup.item_2)
  223. ml.append("%N")
  224. Result := "IUP_DEFAULT"
  225. end
  226. param (widget: IUP_BUTTON): STRING
  227. local
  228. i: INTEGER
  229. gp: IUP_GET_PARAM
  230. p: POINTER
  231. d1, d2, d3, d4, d5: INTEGER
  232. dr1, dr2, dr3: REAL_32
  233. do
  234. d1 := 1.to_integer_32
  235. d2 := 3456.to_integer_32
  236. d3 := 192
  237. d4 := 1
  238. d5 := 2
  239. dr1 := 3.543.force_to_real_32
  240. dr2 := 0.5.force_to_real_32
  241. dr3 := 90.to_real_32
  242. create gp.get_param ("Preferences", agent preferences(?, ?, ?), p)
  243. gp.add_buttons_parameter (", MyCancel, Help!")
  244. gp.add_boolean_parameter ("Boolean:", "No,Yes", "", $d1)
  245. gp.add_integer_parameter ("Integer:", "", "", $d2)
  246. gp.add_real_parameter ("Real 1:", "", "", $dr1)
  247. gp.add_separator ("Sep1")
  248. gp.add_integer_parameter ("Integer:", "0,255", "", $d3)
  249. gp.add_real_parameter ("Real 2:", "-1.5,1.5,0.05", "", $dr2)
  250. gp.add_separator ("Sep2")
  251. gp.add_angle_real_parameter ("Angle:", "0,360", "", $dr3)
  252. gp.add_string_parameter ("String:", "", "", "string text".to_external)
  253. gp.add_radio_parameter ("Options:", "item0|item1|item2", "", $d4)
  254. gp.add_list_parameter ("List:", "item0|item1|item2|item3|item4|item5|item6", "", $d5)
  255. gp.add_file_parameter ("File:", "OPEN|*.bmp;*.jpg|CURRENT|NO|NO", "", "test.jpg".to_external)
  256. gp.add_color_parameter ("Color", "", "255 0 128".to_external)
  257. gp.add_font_parameter ("Font", "", "Courier, 24".to_external)
  258. gp.add_separator ("Sep3")
  259. gp.add_multiline_parameter ("Multiline:", "", "", "second text%Nsecond line".to_external)
  260. i := gp.launch
  261. Result := "IUP_DEFAULT"
  262. end
  263. preferences (dialog: IUP_GET_PARAM; index: INTEGER; data: POINTER): INTEGER
  264. local
  265. dat: STRING
  266. do
  267. --io.put_string("Hello %N")
  268. dat := dialog.get_parameter_value_at(index)
  269. io.put_string(dat)
  270. io.put_string("%N")
  271. Result := 1
  272. end
  273. font (widget: IUP_BUTTON): STRING
  274. local
  275. fd: IUP_FONT_DIALOG
  276. str: STRING
  277. status: INTEGER
  278. do
  279. create fd.font_dialog
  280. str := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  281. status := fd.get_status
  282. if status.is_equal(1) then
  283. ml.set_font(fd.get_value)
  284. end
  285. Result := "IUP_DEFAULT"
  286. end
  287. message (widget: IUP_BUTTON): STRING
  288. local
  289. ms: IUP_MESSAGE
  290. do
  291. create ms.message("A message", "Your message")
  292. Result := "IUP_DEFAULT"
  293. end
  294. color_dialog (widget: IUP_BUTTON): STRING
  295. local
  296. cd: IUP_COLOR_DIALOG
  297. rs: STRING
  298. status: INTEGER
  299. tup: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  300. do
  301. create cd.color_dialog
  302. rs := cd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  303. status := cd.get_status
  304. if status.is_equal(1) then
  305. tup := cd.get_value
  306. ml.set_rgb_foreground_color(tup.item_1, tup.item_2, tup.item_3)
  307. end
  308. cd.destroy
  309. Result := "IUP_DEFAULT"
  310. end
  311. message_dlg (widget: IUP_BUTTON): STRING
  312. local
  313. mdlg: IUP_MESSAGE_DIALOG
  314. i: STRING
  315. r: INTEGER
  316. do
  317. create mdlg.message_dialog
  318. mdlg.set_title("A message dialog")
  319. mdlg.set_value("Are you sure?")
  320. mdlg.set_buttons("YESNOCANCEL")
  321. mdlg.set_dialog_type("QUESTION")
  322. mdlg.set_parent_dialog("window")
  323. i := mdlg.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  324. r := mdlg.get_button_response
  325. ml.append(r.to_string)
  326. ml.append("%N")
  327. Result := "IUP_DEFAULT"
  328. end
  329. progress_bar (widget: IUP_BUTTON): STRING
  330. local
  331. cl: INTEGER
  332. pr: REAL_64
  333. ls: STRING
  334. do
  335. from
  336. cl := 0
  337. until
  338. cl > 1000
  339. loop
  340. pr := cl.to_real_64 / 1000.to_real_64
  341. pb.set_value(pr)
  342. ls := iup_open.loop_step
  343. cl := cl + 1
  344. end
  345. Result := "IUP_DEFAULT"
  346. end
  347. progress_dialog (widget: IUP_BUTTON): STRING
  348. local
  349. pdlg: IUP_PROGRESS_DIALOG
  350. cl: INTEGER
  351. ls, i: STRING
  352. do
  353. create pdlg.progress_dialog
  354. pdlg.set_total_count(500)
  355. i := pdlg.show
  356. from
  357. cl := 0
  358. until
  359. cl > 1000
  360. loop
  361. pdlg.increment_one
  362. ls := iup_open.loop_step
  363. cl := cl + 1
  364. end
  365. pdlg.hide
  366. pdlg.destroy
  367. Result := "IUP_DEFAULT"
  368. end
  369. spin_click (wgt: IUP_SPIN_BOX; inc: INTEGER): STRING
  370. local
  371. lint: INTEGER
  372. do
  373. if l4.get_title.is_integer then
  374. lint := l4.get_title.to_integer + inc
  375. l4.set_title(lint.to_string)
  376. end
  377. Result := "IUP_DEFAULT"
  378. end
  379. end -- class EXAMPLE5