1. IUP double buffering - SOLVED
- Posted by petelomax Mar 30, 2016
- 1275 views
- Last edited Mar 31, 2016
SOLVED - the trick was EXPAND=NO (which I'd guessed) and remove the RASTERSIZE=NULL. Code below replaced.
I cannot get this to work. What I was expecting in the following is that commenting out the cdCanvasClear and resizing the window would leave all the old red X that had been drawn still being shown as well as any new. Can someone try getting this to work on OpenEuphoria/IUP (instead of Phix/pGUI) or otherwise spot what I'm missing?
include pGUI.e function esc_close(Ihandle /*ih*/, atom c) -- (I like all my demos to close when escape is keyed) if c=K_ESC then return IUP_CLOSE end if return IUP_CONTINUE end function Ihandle dlg, canvas cdCanvas cddbuffer, cdcanvas procedure appUpdateRender() integer width, height cdCanvasActivate(cddbuffer) -- cdCanvasClear(cddbuffer) -- now does what I expect {width, height} = IupGetIntInt(dlg, "RASTERSIZE") cdCanvasLine(cddbuffer, 0, 0, width-1, height-1) cdCanvasLine(cddbuffer, 0, height-1, width-1, 0) cdCanvasFlush(cddbuffer) end procedure function resize_cb(Ihandle /*ih*/) appUpdateRender() 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 unmap_cb(Ihandle /*ih*/) cdKillCanvas(cddbuffer) cdKillCanvas(cdcanvas) return IUP_DEFAULT end function procedure CanvasCDDBufferTest() canvas = IupCanvas(NULL) IupSetAttribute(canvas, "RASTERSIZE", "300x200") -- initial size IupSetAttribute(canvas, "EXPAND", "NO") IupSetCallback(canvas, "MAP_CB", Icallback("map_cb")) IupSetCallback(canvas, "UNMAP_CB", Icallback("unmap_cb")) dlg = IupDialog(canvas) IupSetAttribute(dlg, "TITLE", "CD Double Buffer Test") IupSetCallback(dlg, "K_ANY", Icallback("esc_close")) IupSetCallback(dlg, "RESIZE_CB", Icallback("resize_cb")) IupMap(dlg) -- IupSetAttribute(canvas, "RASTERSIZE", NULL) -- release the minimum limitation IupShowXY(dlg,IUP_CENTER,IUP_CENTER) end procedure procedure main() IupOpen() CanvasCDDBufferTest() IupMainLoop() IupClose() end procedure main()