Colour bars/Display: Difference between revisions

Content added Content deleted
m (Commodore BASIC: Converted program to lower case, which aids when copy-pasting into emulators.)
m (→‎{{header|Phix}}: simplified)
Line 1,338: Line 1,338:


Ihandle dlg, canvas
Ihandle dlg, canvas
cdCanvas cddbuffer, cdcanvas
cdCanvas cdcanvas


function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
function redraw_cb(Ihandle /*ih*/, integer /*posx*/, /*posy*/)
integer {width, height} = IupGetIntInt(canvas, "DRAWSIZE"),
cdCanvasActivate(cddbuffer)
x = 0, lc = length(colours)
integer {width, height} = IupGetIntInt(canvas, "DRAWSIZE")
cdCanvasActivate(cdcanvas)
integer x = 0, lc = length(colours)
for i=1 to lc do
for i=1 to lc do
integer w = floor((width-x)/(lc-i+1))
integer w = floor((width-x)/(lc-i+1))
cdCanvasSetForeground(cddbuffer, colours[i])
cdCanvasSetForeground(cdcanvas, colours[i])
cdCanvasBox(cddbuffer, x, x+w, 0, height)
cdCanvasBox(cdcanvas, x, x+w, 0, height)
x += w
x += w
end for
end for
cdCanvasFlush(cddbuffer)
cdCanvasFlush(cdcanvas)
return IUP_DEFAULT
return IUP_DEFAULT
end function
end function


IupOpen()
function map_cb(Ihandle ih)
canvas = IupCanvas(Icallback("redraw_cb"),"RASTERSIZE=600x400") -- initial size
cdcanvas = cdCreateCanvas(CD_IUP, ih)
dlg = IupDialog(canvas,`TITLE="Colour bars"`)
cddbuffer = cdCreateCanvas(CD_DBUFFER, cdcanvas)
IupMap(dlg)
return IUP_DEFAULT
cdcanvas = cdCreateCanvas(CD_IUP, canvas)
end function
IupShow(dlg)

IupSetAttribute(canvas, "RASTERSIZE", NULL) -- release the minimum limitation
function unmap_cb(Ihandle /*ih*/)
IupMainLoop()
cdKillCanvas(cddbuffer)
IupClose()</lang>
cdKillCanvas(cdcanvas)
return IUP_DEFAULT
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"))

IupMap(dlg)
IupSetAttribute(canvas, "RASTERSIZE", NULL) -- release the minimum limitation

IupShowXY(dlg,IUP_CENTER,IUP_CENTER)

IupMainLoop()

IupClose()
end procedure

main()</lang>


=={{header|PHP}}==
=={{header|PHP}}==