I have here a MWE for what is a Gtk window (Gkt.jl) that uses Cairo to draw on the canvas some png image files. There is a ‘button’ that changes a counter for the selection of which image is drawn, but the images are overlapping each other rather than starting on a ‘blank canvas’ or resetting it in some way.
using Gtk using Cairo global drawInt = 1 function drawSys(widget) ctx = Gtk.getgc(widget) global drawInt c = CairoRGBSurface(400,20); cr = CairoContext(c); set_source_rgb(cr,0.8,0.8,0.8); # light gray rectangle(cr,0.0,0.0,800.0,650.0); # background fill(cr); #save(cr); if(drawInt%2 == 0) image = read_from_png("dog.png") else image = read_from_png("pets.png") end set_source_surface(ctx, image, 0, 0) paint(ctx) #fill(ctx) end function drawUpdater1() global drawInt drawInt += 1 end function on_button_clicked(w) drawUpdater1() println("The button has been clicked and replot") ctx = Gtk.getgc(canvas) draw(canvas) end win = Gtk.Window("Gtk") |> (bx = Gtk.Box(:v)) canvas = Gtk.Canvas(800, 650) push!(bx, canvas) canvas.draw = drawSys#what is registered in every window event bt = Gtk.Button("ok") push!(bx, bt) signal_connect(on_button_clicked, bt, "clicked") Gtk.showall(win)
How can this be modified so that, the images start on a fresh canvas so that the previous image is not seen/visible? How can the images be resized so that they fit into a preset dimension size, or fill up the designated ‘canvas’ widet?