51 lines
1.3 KiB
Text
51 lines
1.3 KiB
Text
-- demo\rosetta\Munching_squares.exw
|
|
include pGUI.e
|
|
|
|
Ihandle dlg, canvas
|
|
cdCanvas cddbuffer, cdcanvas
|
|
|
|
function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
|
|
integer {width, height} = IupGetIntInt(canvas, "DRAWSIZE")
|
|
cdCanvasActivate(cddbuffer)
|
|
for y=0 to height-1 do
|
|
for x=0 to width-1 do
|
|
cdCanvasPixel(cddbuffer, x, y, xor_bits(x,y))
|
|
end for
|
|
end for
|
|
cdCanvasFlush(cddbuffer)
|
|
return IUP_DEFAULT
|
|
end function
|
|
|
|
function map_cb(Ihandle ih)
|
|
cdcanvas = cdCreateCanvas(CD_IUP, ih)
|
|
cddbuffer = cdCreateCanvas(CD_DBUFFER, cdcanvas)
|
|
cdCanvasSetBackground(cddbuffer, CD_WHITE)
|
|
cdCanvasSetForeground(cddbuffer, CD_RED)
|
|
return IUP_DEFAULT
|
|
end function
|
|
|
|
function esc_close(Ihandle /*ih*/, atom c)
|
|
if c=K_ESC then return IUP_CLOSE end if
|
|
return IUP_CONTINUE
|
|
end function
|
|
|
|
procedure main()
|
|
IupOpen()
|
|
|
|
canvas = IupCanvas(NULL)
|
|
IupSetAttribute(canvas, "RASTERSIZE", "250x250")
|
|
IupSetCallback(canvas, "MAP_CB", Icallback("map_cb"))
|
|
|
|
dlg = IupDialog(canvas)
|
|
IupSetAttribute(dlg, "TITLE", "Munching squares")
|
|
IupSetAttribute(dlg, "RESIZE", "NO")
|
|
IupSetCallback(dlg, "K_ANY", Icallback("esc_close"))
|
|
IupSetCallback(canvas, "ACTION", Icallback("redraw_cb"))
|
|
|
|
IupMap(dlg)
|
|
IupShowXY(dlg,IUP_CENTER,IUP_CENTER)
|
|
IupMainLoop()
|
|
IupClose()
|
|
end procedure
|
|
|
|
main()
|