It is currently Mon Nov 20, 2017 1:06 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: CustomCursor
PostPosted: Sun Oct 08, 2017 10:48 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 604
Code:
; 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.

Top
 Profile  
Reply with quote  
 Post subject: Re: CustomCursor
PostPosted: Mon Oct 09, 2017 8:19 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 377
Location: Berlin and Ibiza
+1

_________________
ImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: CustomCursor
PostPosted: Fri Oct 13, 2017 6:50 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1035
Location: Germany
+1

_________________
My Projects OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer /
PB v3.30 / v5.60 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: CustomCursor
PostPosted: Sat Oct 14, 2017 6:20 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1461
Location: Germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: CustomCursor
PostPosted: Sat Oct 14, 2017 6:53 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 604
I agree, but I could not install macos in a virtual box :oops:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye