CustomCursor

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
mestnyi
Addict
Addict
Posts: 1001
Joined: Mon Nov 25, 2013 6:41 am

CustomCursor

Post 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
Last edited by mestnyi on Mon Oct 09, 2017 10:47 am, edited 1 time in total.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: CustomCursor

Post by RSBasic »

+1
Image
Image
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: CustomCursor

Post by mk-soft »

+1
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Shardik
Addict
Addict
Posts: 1991
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: CustomCursor

Post 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.
mestnyi
Addict
Addict
Posts: 1001
Joined: Mon Nov 25, 2013 6:41 am

Re: CustomCursor

Post by mestnyi »

I agree, but I could not install macos in a virtual box :oops:
Post Reply