example1.e 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. class EXAMPLE1
  2. -- This example is a test of basic primitives of eiffel-cd (marks,
  3. -- lines, polygons and filled areas).
  4. insert
  5. IUP_INTERFACE
  6. create {ANY}
  7. make
  8. feature {ANY}
  9. make
  10. local
  11. gui: IUP
  12. i: STRING
  13. a: ARRAY[IUP_WIDGET]
  14. l: IUP_LABEL
  15. v: IUP_VBOX
  16. canv: IUP_CANVAS
  17. w: IUP_DIALOG
  18. do
  19. gui := iup_open
  20. create l.label("First test of eiffel-cd!")
  21. create canv.canvas
  22. canv.set_size(300, 150)
  23. canv.set_cb_map(agent map_canvas(?))
  24. canv.set_cb_canvas_action(agent draw(?, ?, ?))
  25. canv.set_cb_button(agent button(?,?,?,?,?,?))
  26. a := {ARRAY[IUP_WIDGET] 1, << l, canv >>}
  27. create v.vbox(a)
  28. v.set_alignment("ACENTER")
  29. v.set_gap(10)
  30. v.set_margin(10, 10)
  31. create w.dialog(v)
  32. w.set_title("CD test")
  33. i := w.show
  34. gui.main_loop
  35. gui.close
  36. end
  37. map_canvas (widget: IUP_CANVAS): STRING
  38. -- Create the canvas (CD_IUP) when the widget is mapped (IUP_CANVAS)
  39. local
  40. canvas: CD_IUP
  41. do
  42. create canvas.create_double_buffer_with_canvas(widget)
  43. Result := "IUP_DEFAULT"
  44. end
  45. draw (widget: IUP_CANVAS; x, y: FLOAT): STRING
  46. local
  47. ok: BOOLEAN
  48. canvas: CD_IUP
  49. do
  50. canvas := widget.get_cd_canvas
  51. ok := canvas.activate
  52. if ok then
  53. -- Clear the canvas with a white background
  54. canvas.set_predefined_background_color(canvas.cd_white)
  55. canvas.clear
  56. canvas.set_interior_style_solid
  57. -- Draw two lines
  58. canvas.set_line_width(3)
  59. canvas.set_predefined_foreground_color(canvas.cd_blue)
  60. canvas.draws_line(40, 40, 450, 40)
  61. canvas.draws_line(45, 65, 455, 65)
  62. -- Draw a rect with dotted line
  63. canvas.set_line_style_dotted
  64. canvas.set_predefined_foreground_color(canvas.cd_red)
  65. canvas.draws_rect(60, 200, 80, 175)
  66. -- Draw an arc
  67. canvas.set_line_style_continuous
  68. canvas.draws_arc(150, 200, 100, 50, 0, 150)
  69. -- Draw a box (filled rect)
  70. canvas.set_predefined_foreground_color(canvas.cd_yellow)
  71. canvas.draws_box(240, 470, 80, 175)
  72. -- Draw a sector (filled arc)
  73. canvas.set_predefined_foreground_color(canvas.cd_magenta)
  74. canvas.draws_sector(260, 200, 100, 50, 0, 150)
  75. -- Test of polygons
  76. canvas.set_line_width(1)
  77. -- Draw an open polygon
  78. canvas.set_predefined_foreground_color(canvas.cd_dark_red)
  79. canvas.begin_open_lines
  80. canvas.vertex(50,250)
  81. canvas.vertex(80,340)
  82. canvas.vertex(150,300)
  83. canvas.vertex(110,265)
  84. canvas.vertex(90,290)
  85. canvas.end_polygon
  86. -- Draw a closed polygon
  87. canvas.set_predefined_foreground_color(canvas.cd_cyan)
  88. canvas.begin_closed_lines
  89. canvas.vertex(200,250)
  90. canvas.vertex(230,340)
  91. canvas.vertex(300,300)
  92. canvas.vertex(260,265)
  93. canvas.vertex(240,290)
  94. canvas.end_polygon
  95. -- Draw a filled polygon
  96. canvas.set_predefined_foreground_color(canvas.cd_black)
  97. canvas.set_line_style_continuous
  98. canvas.set_hatch_backward_diagonal
  99. canvas.begin_fill
  100. canvas.vertex(350,250)
  101. canvas.vertex(380,340)
  102. canvas.vertex(450,300)
  103. canvas.vertex(410,265)
  104. canvas.vertex(390,290)
  105. canvas.end_polygon
  106. -- Draw three marks
  107. canvas.set_predefined_foreground_color(canvas.cd_green)
  108. canvas.draws_mark(100, 350)
  109. canvas.draws_mark(260, 156)
  110. canvas.draws_mark(358, 289)
  111. canvas.flush
  112. end
  113. Result := "IUP_DEFAULT"
  114. end
  115. button (widget: IUP_CANVAS; btn, prs, x, y: INTEGER; status: STRING): STRING
  116. -- Draws a mark at click coordinates.
  117. local
  118. ok: BOOLEAN
  119. canvas: CD_IUP
  120. do
  121. canvas := widget.get_cd_canvas
  122. ok := canvas.activate
  123. if ok then
  124. canvas.set_predefined_foreground_color(canvas.cd_green)
  125. canvas.draws_mark(x, canvas.update_y_axis(y))
  126. canvas.flush
  127. end
  128. Result := "IUP_DEFAULT"
  129. end
  130. end -- class EXAMPLE1