123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- class CANVAS_EXAMPLE
- -- This example show how draw basic primitives at IUP_CANVAS (marks,
- -- lines, polygons, filled areas and text).
-
- insert
- IUP_INTERFACE
- create {ANY}
- make
- feature {ANY}
- angle: REAL_64
- canv: IUP_CANVAS
- make
- local
- gui: IUP
- i: STRING
- a: ARRAY[IUP_WIDGET]
- l: IUP_LABEL
- b: IUP_BUTTON
- v: IUP_VBOX
- w: IUP_DIALOG
- do
- gui := iup_open
-
- create l.label("First test of eiffel-cd!")
- create b.button("Rotate 30 degrees")
- b.set_cb_action(agent rotate_canvas(?))
-
- create canv.canvas
- canv.set_size(300, 150)
- canv.set_cb_map(agent map_canvas(?))
- canv.set_cb_canvas_action(agent draw(?, ?, ?))
- canv.set_cb_button(agent button(?,?,?,?,?,?))
- a := {ARRAY[IUP_WIDGET] 1, << l, b, canv >>}
- create v.vbox(a)
- v.set_alignment("ACENTER")
- v.set_gap(10)
- v.set_margin(10, 10)
-
- create w.dialog(v)
- w.set_title("CD test")
- i := w.show
- gui.main_loop
- gui.close
- end
- map_canvas (widget: IUP_CANVAS): STRING
- -- Create the internal canvas (CD_IUP) when the widget
- -- is mapped (IUP_CANVAS)
- local
- canvas: CD_IUP
- do
- create canvas.create_double_buffer_with_canvas(widget)
-
- Result := "IUP_DEFAULT"
- end
- draw (widget: IUP_CANVAS; x, y: REAL_32): STRING
- local
- ok: BOOLEAN
- canvas: CD_IUP
- do
- canvas := widget.get_cd_canvas
- ok := canvas.activate
- if ok then
- -- Rotate
- canvas.apply_transform_rotate(angle)
- -- Clear the canvas with a white background
- canvas.set_predefined_background_color(canvas.cd_white)
- canvas.clear
- canvas.set_interior_style_solid
- -- Draw two lines
- canvas.set_line_width(3)
- canvas.set_predefined_foreground_color(canvas.cd_blue)
- canvas.draws_line(40, 40, 450, 40)
- canvas.draws_line(45, 65, 455, 65)
- -- Draw a rect with dotted line
- canvas.set_line_style_dotted
- canvas.set_predefined_foreground_color(canvas.cd_red)
- canvas.draws_rect(60, 200, 80, 175)
- -- Draw an arc
- canvas.set_line_style_continuous
- canvas.draws_arc(150, 200, 100, 50, 0, 150)
- -- Draw a box (filled rect)
- canvas.set_predefined_foreground_color(canvas.cd_yellow)
- canvas.draws_box(240, 470, 80, 175)
- -- Draw a sector (filled arc)
- canvas.set_predefined_foreground_color(canvas.cd_magenta)
- canvas.draws_sector(260, 200, 100, 50, 0, 150)
- -- Draw a text
- --canvas.set_text_orientation(20)
- canvas.draws_text(370, 200, "Liberty Eiffel")
- -- Test of polygons
- canvas.set_line_width(1)
- -- Draw an open polygon
- canvas.set_predefined_foreground_color(canvas.cd_dark_red)
- canvas.begin_open_lines
- canvas.vertex(50,250)
- canvas.vertex(80,340)
- canvas.vertex(150,300)
- canvas.vertex(110,265)
- canvas.vertex(90,290)
- canvas.end_polygon
- -- Draw a closed polygon
- canvas.set_predefined_foreground_color(canvas.cd_cyan)
- canvas.begin_closed_lines
- canvas.vertex(200,250)
- canvas.vertex(230,340)
- canvas.vertex(300,300)
- canvas.vertex(260,265)
- canvas.vertex(240,290)
- canvas.end_polygon
- -- Draw a filled polygon
- canvas.set_predefined_foreground_color(canvas.cd_black)
- canvas.set_line_style_continuous
- canvas.set_hatch_backward_diagonal
- canvas.begin_fill
- canvas.vertex(350,250)
- canvas.vertex(380,340)
- canvas.vertex(450,300)
- canvas.vertex(410,265)
- canvas.vertex(390,290)
- canvas.end_polygon
- -- Draw three marks
- canvas.set_predefined_foreground_color(canvas.cd_green)
- canvas.draws_mark(100, 350)
- canvas.draws_mark(260, 156)
- canvas.draws_mark(358, 289)
-
- canvas.flush
- end
-
- Result := "IUP_DEFAULT"
- end
- button (widget: IUP_CANVAS; btn, prs, x, y: INTEGER; status: STRING): STRING
- -- Draws a mark at click coordinates.
- local
- --i: INTEGER
- --tup: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER]
- ok: BOOLEAN
- canvas: CD_IUP
- do
- canvas := widget.get_cd_canvas
- ok := canvas.activate
- --i := canvas.get_font_size
- --tup := canvas.get_text_bounds(100, 100, "Hello")
- if ok then
- canvas.set_predefined_foreground_color(canvas.cd_green)
- canvas.draws_mark(x, canvas.update_y_axis(y))
- canvas.flush
- end
- --io.put_integer(i)
- --io.put_new_line
- --io.put_string(tup.item_1.to_string + " " + tup.item_2.to_string + " " + tup.item_3.to_string + " " + tup.item_4.to_string + " " + tup.item_5.to_string + " " + tup.item_6.to_string + " " + tup.item_7.to_string + " " + tup.item_8.to_string)
- --io.put_new_line
-
- Result := "IUP_DEFAULT"
- end
- rotate_canvas (widget: IUP_WIDGET): STRING
- do
- angle := 5.to_real_64
- canv.redraw
-
- Result := "IUP_DEFAULT"
- end
- end -- class CAVAS_EXAMPLE
|