1. Win32Lib getPixel problem revised
- Posted by Andy Drummond <andy at kestreltele.com> Dec 16, 2005
- 543 views
I posted a query about getPixel() in Win32Lib recently. But when I tried the test here at work I couldn't replicate the problem. Now I have. The problem is this. I have two bitmaps. They overlay one another. I click on the top, visible, one with the mouse. I can then read the value of the top bitmap, which picked up the mouse events, fine. But using the same coordinates for the other bitmap I get -1 returned. I attach a sample program which shows the problem - left clicks use getPixel on one bitmap, right clicks on the other. So ...... now, does anyone have the answer to this? What have I missed? Why are you saying "What a dork!"? --------------------------------------------------------------- include Win32Lib.ew without warning with trace constant Test = createEx( Window, "Left-Click samples 'Page' and right-click samples 'Copy' - see program details", 0, Center, Center, 756, 526, 0, 0 ) constant Page = createEx( Bitmap, "", Test, 0, 0, 750, 500, 0, 0 ) constant Copy = createEx( Bitmap, "", Test, 0, 0, 750, 500, 0, 0 ) integer Status Status = 0 integer Request Request = 0 object res sequence Drawing Drawing = {} sequence Start, Stop -- Two "identical" bitmaps set to either Red or Green -- Page will have its mouse events monitored, Copy won't setPenColor(Copy, Red) drawRectangle(Copy, w32True, 0,0,750,500) setPenColor(Page, Green) drawRectangle(Page, w32True, 0,0,750,500) -- Collect mouse events on 'Page' only (topmost control) procedure Page_onMouse (integer self, integer event, sequence params) sequence pos event = params[1] -- Replace this with the mouse event pos = getPointerRelPos(Page) -- Get coordinate on 'Page' - same on 'Copy' if event = RightDown then event = getPixel(Copy, pos[1], pos[2]) -- Sample bitmap NOT clicked on elsif event = LeftDown then event = getPixel(Page, pos[1], pos[2]) -- Sample bitmap clicked on else return -- Any other event end if res = message_box("getPixel returned "&sprint(event), "getPixel()", MB_ICONEXCLAMATION) end procedure setHandler( Page, w32HMouse, routine_id("Page_onMouse")) WinMain( Test,Normal ) ---------------------------------------------------------------
2. Re: Win32Lib getPixel problem revised
- Posted by Brian Broker <brian_broker at yahoo.com> Dec 16, 2005
- 525 views
Andy Drummond wrote: > > I posted a query about getPixel() in Win32Lib recently. But when I tried > the test here at work I couldn't replicate the problem. Now I have. > > The problem is this. I have two bitmaps. They overlay one another. I > click on the top, visible, one with the mouse. I can then read the value > of the top bitmap, which picked up the mouse events, fine. But using the > same coordinates for the other bitmap I get -1 returned. <snipped sample> Hi Andy, From what I can see by your example, I think your issue is that you are confusing a Bitmap control and a Pixmap control. A Bitmap control is a static control. With a Bitmap control, you stick a bitmap image into it, maybe handle a click event, and that's about it. Windows will handle redrawing the bitmap in the control when it's needed. It doesn't appear to me that you can even draw on a Bitmap control like your example attempts. I believe the reason you are getting the -1 for 'Page' is because you declared 'Copy' after, and covering, 'Page' and, therefore, it's not accessible. You cannot get a pixel from something that can't get focus. However, a pixmap sits in memory so you don't have to worry about that issue. With a Pixmap, you basically have a bitmap in memory that you can draw to and blit to your window. I think you can stick a pixmap into a bitmap control but I usually just copyBlt the Pixmap to the window on repaint. If you can give me some more details about what you are trying to do, I can provide a better explanation with a demo but I really can't tell you how you should proceed based on your example. -- Brian
3. Re: Win32Lib getPixel problem revised
- Posted by Greg Haberek <ghaberek at gmail.com> Dec 16, 2005
- 521 views
> However, a pixmap sits in memory so you don't have to worry about that is= sue. With a Pixmap, you basically have a bitmap in memory that you can dra= w to and blit to your window. I think you can stick a pixmap into a bitmap= control but I usually just copyBlt the Pixmap to the window on repaint. Pixmaps can also parent other controls, like a Window.
4. Re: Win32Lib getPixel problem revised
- Posted by Brian Broker <brian_broker at yahoo.com> Dec 16, 2005
- 533 views
Greg Haberek wrote: > > > However, a pixmap sits in memory so you don't have to worry about that is= > sue. With a Pixmap, you basically have a bitmap in memory that you can dra= > w to and blit to your window. I think you can stick a pixmap into a bitmap= > control but I usually just copyBlt the Pixmap to the window on repaint. > > Pixmaps can also parent other controls, like a Window. > Really? That's an interesting fact that I wasn't aware of. Do you have a program that demonstrates this or can you provide a demo? I've never thought of a reason to do this so I'm looking for a good "what for?". The only thing that comes to mind is Judith's IDE... which I'm starting to look at again. Thanks, -- Brian