Canvas and custom curser

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

Canvas and custom curser

Post by Wolfram »

Hi,

I want to use a custom cursor on a canvas, but every time the mouse leaves the canvas it change back to the default cursor.
Is there an easy way to fix that?

Code: Select all

Global Window_0, Canvas, NewCursor

Procedure ChangeCurser()

    Cursor = CreateImage(#PB_Any, 30, 30)

    Hotspot.NSPoint
    Hotspot\x = 15 
    Hotspot\y = 10
    
    NewCursor = CocoaMessage(0, 0, "NSCursor alloc")
    CocoaMessage(0, NewCursor, "initWithImage:", ImageID(Cursor), "hotSpot:@", @Hotspot)
    CocoaMessage(0, NewCursor, "set")

EndProcedure


Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
	Case #PB_Menu_Quit
          ProcedureReturn #False
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
        Case Canvas
          If EventType() = #PB_EventType_LeftButtonDown
;             SetGadgetAttribute(Canvas, #PB_Canvas_CustomCursor, NewCursor)
            ChangeCurser()
          EndIf
          
          
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure


  Window_0 = OpenWindow(#PB_Any, x, y, 200, 120, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  Canvas = CanvasGadget(#PB_Any, 10, 10, 180, 100)
  
  Repeat
    
  Until WaitWindowEvent() = 4
  
ChangeCurser()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False
macOS Catalina 10.15.7