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
|