example9.e 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. class EXAMPLE9
  2. insert
  3. IUP_INTERFACE
  4. create {ANY}
  5. make
  6. feature {ANY}
  7. colors: ARRAY[TUPLE[INTEGER, INTEGER, INTEGER]]
  8. cb: IUP_COLOR_BAR
  9. selected_cell: INTEGER
  10. make
  11. local
  12. gui: IUP
  13. i: STRING
  14. lab: IUP_LABEL
  15. a: ARRAY[IUP_CANVAS]
  16. b: ARRAY[IUP_WIDGET]
  17. a_cells: IUP_CELLS
  18. h: IUP_HBOX
  19. v: IUP_VBOX
  20. w: IUP_DIALOG
  21. do
  22. gui := iup_open
  23. gui.load_iup_controls
  24. create lab.label("Select a color and click a cell")
  25. create a_cells.cells
  26. a_cells.set_scrollbar(False)
  27. a_cells.set_cb_number_of_lines(agent lines(?))
  28. a_cells.set_cb_number_of_columns(agent columns(?))
  29. a_cells.set_cb_height(agent height(?,?))
  30. a_cells.set_cb_width(agent width(?,?))
  31. a_cells.set_cb_draw(agent draw(?,?,?,?,?,?,?,?))
  32. a_cells.set_cb_scroll(agent scroll(?,?,?,?))
  33. a_cells.set_cb_mouse_click(agent mouse_click(?,?,?,?,?,?,?,?))
  34. create cb.color_bar
  35. cb.set_raster_size(70, 0)
  36. cb.set_number_of_parts(2)
  37. cb.set_expand_vertical
  38. cb.set_cb_select(agent select_color(?,?,?))
  39. a := {ARRAY[IUP_CANVAS] 1, << a_cells, cb >>}
  40. create h.hbox(a)
  41. b := {ARRAY[IUP_WIDGET] 1, << lab, h >>}
  42. create v.vbox(b)
  43. create w.dialog(v)
  44. w.set_title("An example of IUP_CELLS")
  45. w.set_raster_size(400, 350)
  46. w.set_resize(False)
  47. i := w.show
  48. gui.main_loop
  49. gui.close
  50. end
  51. select_color (widget: IUP_COLOR_BAR; cell, type: INTEGER): STRING
  52. do
  53. Result := "IUP_DEFAULT"
  54. end
  55. lines (widget: IUP_CELLS): INTEGER
  56. do
  57. Result := 10
  58. end
  59. columns (widget: IUP_CELLS): INTEGER
  60. do
  61. Result := 10
  62. end
  63. height (widget: IUP_CELLS; l: INTEGER): INTEGER
  64. do
  65. Result := 30
  66. end
  67. width (widget: IUP_CELLS; c: INTEGER): INTEGER
  68. do
  69. Result := 30
  70. end
  71. draw (widget: IUP_CELLS; l, c, xmin, xmax, ymin, ymax: INTEGER; cd: CD_IUP): STRING
  72. local
  73. mx, my: INTEGER
  74. do
  75. cd.set_predefined_background_color(cd.cd_black)
  76. mx := xmin + 15
  77. my := ymin + 15
  78. cd.draws_mark(mx, my)
  79. Result := "IUP_DEFAULT"
  80. end
  81. scroll (widget: IUP_CANVAS; op: INTEGER; posx, posy: REAL_32): STRING
  82. do
  83. Result := "IUP_IGNORE"
  84. end
  85. mouse_click (widget: IUP_CELLS; b, p, l, c, x, y: INTEGER; s: STRING): STRING
  86. local
  87. i: INTEGER
  88. tup: TUPLE[INTEGER, INTEGER, INTEGER]
  89. do
  90. -- If user press the left mouse button, draw a mark with
  91. -- the selected color.
  92. if b.is_equal(1) and p.is_equal(1) then
  93. i := cb.get_primary_cell
  94. tup := cb.get_cell_n_color(i)
  95. widget.get_cd_canvas.set_foreground_color(tup.item_1, tup.item_2, tup.item_3)
  96. widget.get_cd_canvas.draws_mark(30*(c - 1) + 15, (10 - l)*30 + 21)
  97. widget.get_cd_canvas.flush
  98. end
  99. Result := "IUP_CONTINUE"
  100. end
  101. end -- class EXAMPLE9