Re: win32lib help: Error code 436: getrect:getObject for bitmap failed.
- Posted by ryanj Sep 08, 2008
- 1285 views
dasium said...
Also, I noticed that my code post is messed up, so here's snow.exw: http://www.aglitchinthematrix.net/snow.exw
You can put source inside <eucode></eucode> to format it correctly.
without warning with trace include Win32lib.ew include get.e constant NUM_FLAKES = 40 constant WIN = createEx(Window, "", 0, Default, Default, 500, 550, 0, 0) integer theTimer atom bmp_saved atom bmp_snowflake atom tpc_handle sequence temp_pixel_color sequence BMsize sequence flakes sequence snowflake_image sequence bmp_image sequence bmp_mask sequence bmp_width sequence bmp_height sequence bmp_mask_data tpc_handle = 0 snowflake_image = "snowflake.bmp" bmp_image = "cottage.bmp" bmp_mask = "cottage_mask.bmp" theTimer = 1 bmp_saved = create(Pixmap, "", WIN, 0, 0, 500, 500, 0) bmp_snowflake = create(Pixmap, "", WIN, 0, 0, 1, 1, 0) temp_pixel_color = repeat(-1, NUM_FLAKES) flakes = repeat({0,0}, NUM_FLAKES) for j = 1 to NUM_FLAKES do flakes[j] = {rand(500),1} end for function mod(atom a, atom b) return remainder(a, b) end function function load_bitmap(sequence bmp_fname) return read_bitmap(bmp_fname) --load the bitmap and display it end function function put_next_flake(sequence w) sequence next_flake_pos next_flake_pos = {mod(w[1]+((rand(3)-2)),500), w[2]+1} copyBlt(bmp_saved, next_flake_pos[1], next_flake_pos[2], bmp_snowflake) return next_flake_pos end function function create_pixmap_pixel(integer color) sequence xpm sequence rgb_seq printf(1, "%d\n", color) rgb_seq = split_rgb(color) xpm = {"1 1 1 1", sprintf("t c #%02x%02x%02x", {rgb_seq[1], rgb_seq[2], rgb_seq[3]}), "t"} return xpmToPixmap(xpm) end function procedure timer_stuff(integer self, integer event, sequence params) sequence next_flake atom x next_flake = {0,0} for i = 1 to NUM_FLAKES do next_flake = put_next_flake(flakes[i]) -- put snow if temp_pixel_color[i] != -1 then -- problem here? printf(1, "%d, ", flakes[i][2]) -- if flakes[i][2] = 252 then -- trace(1) -- end if if flakes[i][1] >= 0 and flakes[i][1] < 500 then tpc_handle = create_pixmap_pixel(temp_pixel_color[i]) bitBlt(bmp_saved, flakes[i][1], flakes[i][2], tpc_handle, 0, 0, 1, 1, SRCCOPY) -- replace pixel end if end if flakes[i] = next_flake -- set flakes[i] to next_flake temp_pixel_color[i] = getPixel(WIN, flakes[i][1], flakes[i][2]) -- get pixels to be replaced end for -- Render to screen -- Repaint window (some logic, some paint) repaintFG(WIN) end procedure procedure paint_bitmap(integer self, integer event, sequence params) copyBlt(WIN, 0, 0, bmp_saved) end procedure -- INIT bmp_saved = loadBitmapFromFile(bmp_image) bmp_snowflake = loadBitmapFromFile(snowflake_image) setBitmap(WIN, bmp_saved) for i = 1 to NUM_FLAKES do temp_pixel_color[i] = getPixel(WIN, flakes[i][1], flakes[i][2]) end for -- Handlers setHandler(WIN, w32HPaint, routine_id("paint_bitmap")) setHandler(theTimer, w32HTimer, routine_id("timer_stuff")) setTimer(WIN, theTimer, 50) -- Main loop WinMain(WIN, Normal) --*oOo