Page 1 of 1

CustomCursor

Posted: Sun Oct 08, 2017 10:48 am
by mestnyi

Code: Select all

; http://www.purebasic.fr/english/viewtopic.php?f=12&t=65293

ProcedureDLL CustomCursor3(ImageID, X=0, Y=0) ;- Return the custom cursor from the image handle
  If ImageID
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
        Protected *Cursor, Cursor.ICONINFO
        Cursor\fIcon = 0
        Cursor\xHotspot =- X 
        Cursor\yHotspot =- Y 
        Cursor\hbmMask = ImageID
        Cursor\hbmColor = ImageID
        *Cursor = CreateIconIndirect_(Cursor)
        If Not *Cursor : *Cursor = ImageID : EndIf
            
      CompilerCase #PB_OS_Linux
        Protected *Cursor.GdkCursor = gdk_cursor_new_from_pixbuf_(gdk_display_get_default_(), ImageID, X, Y)
        
      CompilerCase #PB_OS_MacOS
        Protected *Cursor, Hotspot.NSPoint
        Hotspot\x = X
        Hotspot\y = Y
        *Cursor = CocoaMessage(0, 0, "NSCursor alloc")
        CocoaMessage(0, *Cursor, "initWithImage:", ImageID, "hotSpot:@", @Hotspot)
        
    CompilerEndSelect
  EndIf
  
  ProcedureReturn *Cursor
EndProcedure  

ProcedureDLL CustomCursor2(ImageID, X)
  ProcedureReturn CustomCursor3(ImageID, X)
EndProcedure  

ProcedureDLL CustomCursor(ImageID) 
  ProcedureReturn CustomCursor3(ImageID)
EndProcedure  


CompilerIf #PB_Compiler_IsMainFile
  UsePNGImageDecoder()
  LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png")
  ;LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico")
    
  If OpenWindow(0, 0, 0, 270, 180, "demo set canvas custom image cursor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 10, 10, 250, 51)
    SetGadgetAttribute(0, #PB_Canvas_CustomCursor, CustomCursor(ImageID(0)))
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
CompilerEndIf

Re: CustomCursor

Posted: Mon Oct 09, 2017 8:19 am
by RSBasic
+1

Re: CustomCursor

Posted: Fri Oct 13, 2017 6:50 pm
by mk-soft
+1

Re: CustomCursor

Posted: Sat Oct 14, 2017 6:20 pm
by Shardik
mestnyi,

you should always test your code on all platforms when posting multi-platform code... :wink:
Your code example is working fine on my Windows 7 SP1 x64 and Linux Mint 18.1 x64 with Cinnamon with PB 5.61. But unfortunately it doesn't work on MacOS. This seems to be a bug in PureBasic for MacOS and I have therefore posted this bug report.

Re: CustomCursor

Posted: Sat Oct 14, 2017 6:53 pm
by mestnyi
I agree, but I could not install macos in a virtual box :oops: