1. Clearing a bitmap?
- Posted by lockiedownunder Jun 23, 2009
- 848 views
Probably a dumb question but how do I clear a WIN32LIB BitmapImage.
If I show one image then show a smaller image, I can still see to old image below.
2. Re: Clearing a bitmap?
- Posted by ghaberek (admin) Jun 23, 2009
- 797 views
Are you blit-ing the image during a paint event? Or are you manually blit-ing it elsewhere?
-Greg
3. Re: Clearing a bitmap?
- Posted by DerekParnell (admin) Jun 23, 2009
- 807 views
Probably a dumb question but how do I clear a WIN32LIB BitmapImage.
If I show one image then show a smaller image, I can still see to old image below.
Don't use a bitmap because they are really only useful for static bitmaps, ones that don't change. If you want to scroll, zoom, clear, change etc ... use a Pixmap control instead. These are basically the same as bitmaps, except they do not show on screen. It is up to you to render it (via bitBlt etc) onto some viewport, such as a child window.
A Pixmap also makes it easy to mess around with it. Clearing it is a simple as ...
clearWindow(myPixMap)
Here is an example of Pixmaps and scrolling...
include win32lib.ew constant MainWindow = create(Window, "Sample", 0, 0, 0, 600, 600, 0) integer IMGWIDTH, IMGHEIGHT IMGWIDTH = 1960 IMGHEIGHT = 1280 constant myPixMap = create(Pixmap, "", 0, 0, 0, IMGWIDTH, IMGHEIGHT, 0) integer VIEWWIDTH, VIEWHEIGHT VIEWWIDTH = 320 VIEWHEIGHT = 320 constant ViewPort = create(Window, "", MainWindow, 20, 20, VIEWWIDTH, VIEWHEIGHT, {WS_CHILD, WS_VISIBLE, WS_BORDER}) integer DestX, DestY integer IsMoving integer DownX, DownY IsMoving = 0 DownX = 0 DownY = 0 DestX = 0 DestY = 0 procedure onPaint_ViewPort(integer self, integer event, sequence parms) -- Copy the image in 'myPixMap' to the viewport destination 0,0 copyBlt(self, DestX, DestY, myPixMap) end procedure setHandler(ViewPort, w32HPaint, routine_id("onPaint_ViewPort")) procedure onMouse_ViewPort(integer self, integer event, sequence parms) if parms[1] = LeftDown then DownX = parms[2] DownY = parms[3] IsMoving = 1 elsif parms[1] = LeftUp then IsMoving = 0 repaintFG(ViewPort) elsif parms[1] = LeftDoubleClick then IsMoving = 0 DestX = 0 DestY = 0 repaintFG(ViewPort) elsif parms[1] = MouseMove then if IsMoving then DestX = parms[2] - DownX DestY = parms[3] - DownY if DestX > 0 or DestY > 0 then clearWindow(ViewPort) end if repaintFG(ViewPort) end if end if end procedure setHandler(ViewPort, w32HMouse, routine_id("onMouse_ViewPort")) -- Draw some stuff into the Pixmap. setBackColor(myPixMap, BrightWhite) setPenWidth(myPixMap, 3) drawLines(myPixMap, {Green,{40,0,0,80},{80,80},{40,0}, Blue, {80,0,140,185},{80,85},{80,5}, Red, {1, 140,40,365,90} } ) setTextColor(myPixMap, Gray) wPuts({myPixMap, 350, 45}, "Hello there") WinMain(MainWindow, Normal)
4. Re: Clearing a bitmap?
- Posted by lockiedownunder Jun 27, 2009
- 763 views
Hello Derek or anyone who can help
Your example above works well, thank you BUT (yep always a but) If I drag and image all is good until I let go of the mouse to reposition the pointer and try to drag further. It resets to position 0,0 on mouse down.
Is it possible to correct this, I tried and failed. It would be helpful for laptop touch pad use.
Thanks Heaps
5. Re: Clearing a bitmap?
- Posted by DerekParnell (admin) Jun 27, 2009
- 781 views
If I drag and image all is good until I let go of the mouse to reposition the pointer and try to drag further. It resets to position 0,0 on mouse down.
Is it possible to correct this?
include win32lib.ew constant MainWindow = create(Window, "Sample", 0, 0, 0, 600, 600, 0) integer IMGWIDTH, IMGHEIGHT IMGWIDTH = 1960 IMGHEIGHT = 1280 constant myPixMap = create(Pixmap, "", 0, 0, 0, IMGWIDTH, IMGHEIGHT, 0) integer VIEWWIDTH, VIEWHEIGHT VIEWWIDTH = 320 VIEWHEIGHT = 320 constant ViewPort = create(Window, "", MainWindow, 20, 20, VIEWWIDTH, VIEWHEIGHT, {WS_CHILD, WS_VISIBLE, WS_BORDER}) integer DestX, DestY integer IsMoving integer DownX, DownY integer OrigX, OrigY IsMoving = 0 DownX = -9 DownY = -9 OrigX = 0 OrigY = 0 DestX = 0 DestY = 0 procedure onPaint_ViewPort(integer self, integer event, sequence parms) -- Copy the image in 'myPixMap' to the viewport destination 0,0 copyBlt(self, DestX, DestY, myPixMap) end procedure setHandler(ViewPort, w32HPaint, routine_id("onPaint_ViewPort")) with trace procedure onMouse_ViewPort(integer self, integer event, sequence parms) if parms[1] = LeftDown then DownX = parms[2] DownY = parms[3] OrigX = DestX OrigY = DestY IsMoving = 1 elsif parms[1] = LeftUp then IsMoving = 0 repaintFG(ViewPort) elsif parms[1] = LeftDoubleClick then IsMoving = 0 DestX = 0 DestY = 0 repaintFG(ViewPort) elsif parms[1] = MouseMove then if IsMoving then DestX = OrigX + parms[2] - DownX DestY = OrigY + parms[3] - DownY ?{DestX, parms[2], DownX, DestY, parms[3], DownY} if DestX > 0 or DestY > 0 then clearWindow(ViewPort) end if repaintFG(ViewPort) end if end if end procedure setHandler(ViewPort, w32HMouse, routine_id("onMouse_ViewPort")) -- Draw some stuff into the Pixmap. setBackColor(myPixMap, BrightWhite) setPenWidth(myPixMap, 3) drawLines(myPixMap, {Green,{40,0,0,80},{80,80},{40,0}, Blue, {80,0,140,185},{80,85},{80,5}, Red, {1, 140,40,365,90} } ) setTextColor(myPixMap, Gray) wPuts({myPixMap, 350, 45}, "Hello there") WinMain(MainWindow, Normal)
6. Re: Clearing a bitmap?
- Posted by DerekParnell (admin) Jun 27, 2009
- 769 views
Except that I left this debug code in, sorry.
Remove this line ...
?{DestX, parms[2], DownX, DestY, parms[3], DownY}
7. Re: Clearing a bitmap?
- Posted by lockiedownunder Jun 27, 2009
- 750 views
Awesome thanks.
Not an AFL fan (north of the boarder) myself but hope you enjoyed the footy last night.
8. Re: Clearing a bitmap?
- Posted by DerekParnell (admin) Jun 27, 2009
- 776 views
Awesome thanks.
You're welcome. That flickering when clearing the viewport (moving the image down or right) can be fixed too. I was just lazy so I clear the entire viewport. All you need to do is just clear the one or two rectangles that were exposed when the image moved. The two rectangles are the boxes whose top-left and bottom-right corners are ...
- (Old_DestX, Old_DestY)
- (Old_DestX, Old_DestY)
Just do a drawRectangle() call (filled of course) with the viewport's background color for both of these boxes. Note that you can avoid drawing both if Old_DestY = New_DestY or Old_DestX = New_DestX.
I'll leave this as an exercise
9. Re: Clearing a bitmap?
- Posted by DerekParnell (admin) Jun 27, 2009
- 859 views
I'm obviously tired or drunk ... I meant ...
- (Old_DestX, Old_DestY) --- (Viewport_RightEdge, New_DestY)
- (Old_DestX, Old_DestY) --- (New_DestX, Viewport_BottomEdge)