66 lines
1.7 KiB
Text
66 lines
1.7 KiB
Text
--
|
|
-- demo\rosetta\Colour_bars.exw
|
|
--
|
|
include pGUI.e
|
|
|
|
constant colours = {CD_BLACK, CD_RED, CD_GREEN, CD_MAGENTA, CD_CYAN, CD_YELLOW, CD_WHITE}
|
|
|
|
Ihandle dlg, canvas
|
|
cdCanvas cddbuffer, cdcanvas
|
|
|
|
function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
|
|
cdCanvasActivate(cddbuffer)
|
|
integer {width, height} = IupGetIntInt(canvas, "DRAWSIZE")
|
|
integer x = 0, lc = length(colours)
|
|
for i=1 to lc do
|
|
integer w = floor((width-x)/(lc-i+1))
|
|
cdCanvasSetForeground(cddbuffer, colours[i])
|
|
cdCanvasBox(cddbuffer, x, x+w, 0, height)
|
|
x += w
|
|
end for
|
|
cdCanvasFlush(cddbuffer)
|
|
return IUP_DEFAULT
|
|
end function
|
|
|
|
function map_cb(Ihandle ih)
|
|
cdcanvas = cdCreateCanvas(CD_IUP, ih)
|
|
cddbuffer = cdCreateCanvas(CD_DBUFFER, cdcanvas)
|
|
return IUP_DEFAULT
|
|
end function
|
|
|
|
function unmap_cb(Ihandle /*ih*/)
|
|
cdKillCanvas(cddbuffer)
|
|
cdKillCanvas(cdcanvas)
|
|
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", "600x400") -- initial size
|
|
|
|
IupSetCallback(canvas, "MAP_CB", Icallback("map_cb"))
|
|
IupSetCallback(canvas, "UNMAP_CB", Icallback("unmap_cb"))
|
|
|
|
dlg = IupDialog(canvas)
|
|
IupSetAttribute(dlg, "TITLE", "Colour bars")
|
|
IupSetCallback(canvas, "ACTION", Icallback("redraw_cb"))
|
|
IupSetCallback(dlg, "K_ANY", Icallback("esc_close"))
|
|
|
|
IupMap(dlg)
|
|
IupSetAttribute(canvas, "RASTERSIZE", NULL) -- release the minimum limitation
|
|
|
|
IupShowXY(dlg,IUP_CENTER,IUP_CENTER)
|
|
|
|
IupMainLoop()
|
|
|
|
IupClose()
|
|
end procedure
|
|
|
|
main()
|