-- code generated by Win32Lib IDE v0.20.1 include Win32Lib.ew without warning include graphex.ew -------------------------------------------------------------------------------- -- Window Window1 constant Window1 = createEx( Window, "Manual management of gfx - lines and text", 0, Default, Default, 400, 300, 0, 0 ) constant StatusB = createEx( StatusBar, "Status", Window1, 0, 0, 0, 0, 0, 0 ) constant btnNewGfx = createEx( PushButton, "1. newGfx", Window1, 0, 0, 56, 28, 0, 0 ) constant PushButton11 = createEx( PushButton, "2. toggle update", Window1, 56, 0, 88, 28, 0, 0 ) constant btnAutoPaint = createEx( PushButton, "3. Toggle AutoPaint", Window1, 144, 0, 108, 28, 0, 0 ) constant bmpPlaceHolder = createEx( Bitmap, "BitmapPlaceHolderCanReceiveMessages", Window1, 0, 32, 392, 220, 0, 0 ) --------------------------------------------------------- -------------------------------------------------------------------------------- -- simple example managing dib drawing handler manually -- fixed sized dib with trace constant RECT_SX = 1, RECT_SY = 2, RECT_DX = 3, RECT_DY = 4 sequence status status = {} constant T_CLEARSTATUS = 1000, T_UPDATE = 1010, T_UPDATE_FREQ = 250 -- 250ms update integer updating, the_colour updating = 0 the_colour = 1 -- whether to decide when to paint or have it happen automatically integer autopaint autopaint = 0 object thegfx thegfx= -1 integer counter counter = 0 constant fontscale = 5 procedure sstatus(sequence text) setText(StatusB, text) setTimer(Window1, T_CLEARSTATUS, 10000) end procedure -- 1. Create the dib procedure create_the_dib() sequence bmprect bmprect = getRect(bmpPlaceHolder) thegfx = newGfx(Window1, bmprect[RECT_SX], bmprect[RECT_SY], bmprect[RECT_DX] - bmprect[RECT_SX], -- width = right (dest) - left (start) bmprect[RECT_DY] - bmprect[RECT_SY] -- height = bottom - top ) if integer(thegfx) then sstatus("Couldn't create gfx!") end if sstatus("Gfx Created") end procedure --3a. Update code -- This is where all the drawing is done procedure update_dib() atom oldscale integer circ_x, circ_y, circ_d, circ_clr gfxClear(thegfx, Black) if atom(thegfx) then return end if circ_x = rand(gfxWidth(thegfx)) circ_y = rand(gfxHeight(thegfx)) circ_d = rand(20) + 5 circ_clr = rand(15) if the_colour >= 15 then the_colour = 0 end if for j = 0 to floor(gfxHeight(thegfx)/2) by floor(gfxHeight(thegfx)/10) do for i = 0 to gfxWidth(thegfx) by floor(gfxWidth(thegfx)/20) do gfx_draw(thegfx, "line", gfxColour(the_colour), {i, 0, i, gfxHeight(thegfx)}) gfx_draw(thegfx, "line", gfxColour(the_colour), {0, j, gfxWidth(thegfx), j}) -- or dib_colours[the_colour] or {a, different, colour}, or Eu color constant end for end for gfxTextOutAt(thegfx, 21, floor(gfxHeight(thegfx)/2)-2, "Euphoria", gfxColour(15-the_colour)) gfx_draw(thegfx, "ellipse-solid", gfxColour(circ_clr), {circ_x, circ_y, circ_x + circ_d, circ_y + circ_d}) oldscale = setGfxFontScale(floor(rand(6)) + 1) gfxTextOutAt(thegfx, 21, gfxHeight(thegfx) - 32, sprintf("%5d", {counter}), Yellow) counter += floor(rand(33)) VOID = setGfxFontScale(oldscale) the_colour += 1 if not autopaint then doGfxPaint(Window1) end if end procedure --3. toggle updating on off with timer procedure toggle_update() if updating = 1 then updating = 0 killTimer(Window1, T_UPDATE) else updating = 1 setTimer(Window1, T_UPDATE, T_UPDATE_FREQ) end if end procedure -- init stuff VOID = setGfxFontScale(fontscale) -- not interested in old font size setGfxAutoPaint(0) -- we'll decide when to paint -------------------------------------------------------------------------------- procedure Window1_onTimer (integer self, integer event, sequence params)--params is ( int timerId) if params[1] = T_CLEARSTATUS then setText(StatusB, "") killTimer(Window1, T_CLEARSTATUS) elsif params[1] = T_UPDATE then update_dib() end if end procedure setHandler( Window1, w32HTimer, routine_id("Window1_onTimer")) -------------------------------------------------------------------------------- procedure btnNewGfx_onClick (integer self, integer event, sequence params)--params is () create_the_dib() end procedure setHandler( btnNewGfx, w32HClick, routine_id("btnNewGfx_onClick")) -------------------------------------------------------------------------------- procedure PushButton11_onClick (integer self, integer event, sequence params)--params is () toggle_update() end procedure setHandler( PushButton11, w32HClick, routine_id("PushButton11_onClick")) -------------------------------------------------------------------------------- procedure btnAutoPaint_onClick (integer self, integer event, sequence params)--params is () if autopaint then autopaint = 0 setGfxAutoPaint(0) sstatus("AutoPaint is off") else autopaint = 1 setGfxAutoPaint(1) sstatus("AutoPaint is on") end if end procedure setHandler( btnAutoPaint, w32HClick, routine_id("btnAutoPaint_onClick")) WinMain( Window1,Normal )