Mac canvas mouse x/y inaccurate to cursor?
BlitzMax Forums/BlitzMax Programming/Mac canvas mouse x/y inaccurate to cursor?
| ||
| I have found a bug in mac canvas. It seems the mouse x/y do not fall directly under the tip of the mouse cursor. I am using the latest snow leopard with maxgui 1.38. In the code below, try and draw a rect starting at the very top-left of the black area. It looks like the coordinates are offset x:+1 y:+2 from where the cursor actually lies...
Import maxgui.drivers
Local window:TGadget = CreateWindow("test me ",300,60,400,400)
Local panel:TGadget = CreatePanel(50,50,ClientWidth(window)-50,ClientHeight(window)-50,window)
Global canvas1:TGadget = CreateCanvas(0,0,ClientWidth(panel),ClientHeight(panel),panel)
Global rectx:Int,recty:Int,rectwidth:Int,rectheight:Int,rect:Int = False
SetGraphicsDriver GLMax2DDriver()
AddHook(EmitEventHook,hook,Null)
Repeat
WaitEvent()
Forever
Function hook:Object(id:Int,data:Object,context:Object)
Local event:TEvent = TEvent(data)
' + make sure there is event data +
If event
Local gadget:TGadget = TGadget(Event.source)
Select event.id
Case EVENT_GADGETPAINT
SetGraphics gadget.CanvasGraphics()
Cls
SetColor(255,0,0)
DrawRect(rectx,recty,rectwidth,rectheight)
Flip
Case EVENT_MOUSEMOVE
If rect
rectwidth = event.x-rectx
rectheight = event.y-recty
RedrawGadget(canvas1)
End If
Case EVENT_MOUSEUP
rect = False
rectx = event.x
recty = event.y
RedrawGadget(canvas1)
Case EVENT_MOUSEDOWN
rect = True
rectx = event.x
recty = event.y
RedrawGadget(canvas1)
Case EVENT_WINDOWCLOSE
End
End Select
End If
End Function
|
| ||
| It seems the offset for the click is based on the black inner part of the pointer instead of the white border part... |
| ||
| http://blitzmax.com/Community/posts.php?topic=88728 Related? |
| ||
| Possibly, will have a look when get on my mac tomorrow. I temporarily got round the prolem by just offsetting all mouse positions by x and y offset constants. |
| ||
| Hi skn3[ac], I've had a quick look into this for you and this appears to be the correct behaviour. All mouse cursor images have a hotspot associated with them (the x,y coordinate within the icon that defined which pixel this multi-pixel cursor is pointing to). For the Mac OS X arrow, Apple seems to have decided that this is the top right black part of the arrow. And this is how other Mac apps, such as Digital Color Meter work when dealing with precise pixel selection. In other words, Mac users may expect this behaviour to be consistent for their platform, so subtracting your offset might annoy some hardcore Mac users. :-) I guess it's a matter of taste. Of course, different cursors have different hotspots, and if you are looking for a cursor to use for pixel precision, try calling SetPointer( POINTER_CROSS ) - the hotspot for this cursor appears to be dead-on in the middle of the cross-hairs. Hope this clears things up. :-) |