# File gtk/sample/gtk-demo/drawingarea.rb, line 115 def checkerboard_expose(da) # At the start of an expose handler, a clip region of event.area # is set on the window, and event.area has been cleared to the # widget's background color. The docs for # gdk_window_begin_paint_region give more details on how this # works. # It would be a bit more efficient to keep these # GC's around instead of recreating on each expose, but # this is the lazy/slow way. gc1 = Gdk::GC.new(da.window) gc1.rgb_fg_color = Gdk::Color.new(30000, 0, 30000) gc2 = Gdk::GC.new(da.window) gc2.rgb_fg_color = Gdk::Color.new(65535, 65535, 65535) xcount = 0 SPACING.step(da.allocation.width, CHECK_SIZE + SPACING) do |i| ycount = xcount % 2; # start with even/odd depending on row SPACING.step(da.allocation.height, CHECK_SIZE + SPACING) do |j| gc = if ycount % 2 == 1 gc1 else gc2 end # If we're outside event.area, this will do nothing. # It might be mildly more efficient if we handled # the clipping ourselves, but again we're feeling lazy. da.window.draw_rectangle(gc, true, i, j, CHECK_SIZE, CHECK_SIZE) ycount += 1 end xcount += 1 end # return true because we've handled this event, so no # further processing is required. # return true end