matrix.e 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. class MATRIX
  2. -- This example show how use a matrix.
  3. inherit
  4. IUP_INTERFACE
  5. IUP_GET_POINTER
  6. create {ANY}
  7. make
  8. feature {ANY}
  9. mt: IUP_MATRIX
  10. data: ARRAY2[STRING]
  11. bgcolors: ARRAY2[TUPLE[INTEGER, INTEGER, INTEGER]]
  12. make
  13. local
  14. gui: IUP
  15. i: STRING
  16. bg_button: IUP_BUTTON
  17. v1: IUP_VBOX
  18. w: IUP_DIALOG
  19. do
  20. gui := iup_open
  21. gui.load_images
  22. gui.load_iup_controls
  23. create bgcolors.make_filled([255, 255, 255], 25, 15)
  24. create data.make_filled("Hola", 25, 15)
  25. create mt.matrix
  26. mt.set_number_of_columns(15)
  27. mt.set_number_of_lines(25)
  28. mt.set_cb_background_color(agent background_color)
  29. mt.set_cb_value(agent matrix_value)
  30. mt.set_cb_value_edit(agent matrix_edited)
  31. mt.set_cb_drop(agent show_drop)
  32. mt.set_cb_menu_drop(agent show_menu_drop)
  33. mt.set_cb_drop_check(agent check_drop)
  34. mt.set_cb_drop_select(agent drop_select)
  35. mt.set_width_at_column(10, 0)
  36. mt.set_height_at_line(10, 0)
  37. create bg_button.button("Background color")
  38. bg_button.set_cb_action(agent click_button)
  39. create v1.vbox({ARRAY[IUP_WIDGET]} << bg_button, mt >>)
  40. create w.dialog(v1)
  41. w.set_title("Matrix test")
  42. w.set_predefined_size("HALF", "250")
  43. i := w.show
  44. gui.main_loop
  45. gui.close
  46. end
  47. click_button (b: IUP_BUTTON): STRING
  48. local
  49. tup: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  50. cell: TUPLE[INTEGER, INTEGER]
  51. gc: IUP_GET_COLOR
  52. do
  53. create gc.get_color_with_initial(0, 0, 0)
  54. tup := gc.launch_predefined_xy("IUP_CENTER", "IUP_CENTER")
  55. cell := mt.get_focus_cell
  56. if tup.integer_32_item(1).is_equal(1) then
  57. bgcolors.put([tup.integer_32_item(2), tup.integer_32_item(3), tup.integer_32_item(4)], cell.integer_32_item(1), cell.integer_32_item(2))
  58. mt.redraw
  59. end
  60. Result := "IUP_DEFAULT"
  61. end
  62. background_color (m: IUP_MATRIX; lin, col: INTEGER; r, g, b: POINTER): STRING
  63. do
  64. if attached bgcolors.item(lin, col) as t and
  65. lin >= 1 and
  66. col >= 1 then
  67. r.memory_copy(get_pointer(t.integer_32_item(1)), 8)
  68. g.memory_copy(get_pointer(t.integer_32_item(2)), 8)
  69. b.memory_copy(get_pointer(t.integer_32_item(3)), 8)
  70. Result := "IUP_DEFAULT"
  71. else
  72. Result := "IUP_IGNORE"
  73. end
  74. end
  75. matrix_value (m: IUP_MATRIX; lin, col: INTEGER): STRING
  76. do
  77. if col = 0 then
  78. Result := lin.out
  79. elseif lin = 0 then
  80. Result := col.out
  81. else
  82. Result := data.item(lin, col)
  83. end
  84. end
  85. matrix_edited (m: IUP_MATRIX; lin, col: INTEGER; new_value: STRING): STRING
  86. do
  87. data.put(new_value, lin, col)
  88. Result := "IUP_DEFAULT"
  89. end
  90. show_drop (m: IUP_MATRIX; d: IUP_DROP; lin, col: INTEGER): STRING
  91. do
  92. if lin.is_equal(5) and
  93. col.is_equal(3) then
  94. d.append_items({ARRAY[STRING]} << "January", "February", "March", "Aphril" >>)
  95. d.set_value(3)
  96. Result := "IUP_DEFAULT"
  97. else
  98. Result := "IUP_IGNORE"
  99. end
  100. end
  101. show_menu_drop (m: IUP_MATRIX; d: IUP_DROP; lin, col: INTEGER): STRING
  102. do
  103. if lin.is_equal(5) and
  104. col.is_equal(2) then
  105. d.append_items({ARRAY[STRING]} << "Cut", "Copy", "Paste" >>)
  106. d.set_image_at("IUP_EditCut", 1)
  107. d.set_image_at("IUP_EditCopy", 2)
  108. d.set_image_at("IUP_EditPaste", 3)
  109. d.set_value(2)
  110. Result := "IUP_DEFAULT"
  111. else
  112. Result := "IUP_IGNORE"
  113. end
  114. end
  115. check_drop (m: IUP_MATRIX; lin, col: INTEGER): STRING
  116. do
  117. if lin.is_equal(7) and
  118. col.is_equal(3) then
  119. Result := "IUP_CONTINUE"
  120. else
  121. Result := "IUP_IGNORE"
  122. end
  123. end
  124. drop_select (m: IUP_MATRIX; lin, col: INTEGER; d: IUP_DROP; t: STRING; i, v: INTEGER): STRING
  125. do
  126. io.put_string(t)
  127. io.put_new_line
  128. io.put_integer(i)
  129. io.put_new_line
  130. io.put_integer(v)
  131. io.put_new_line
  132. Result := "IUP_DEFAULT"
  133. end
  134. end