Page 1 of 1

Change mouse pointer icon simplified: SetMouseIcon

Posted: Tue Dec 30, 2008 4:59 am
by USCode
I know lots of folks have requested the ability to set the mouse pointer icon when hovering over specific gadgets but I'd settle for just a simple command to change the mouse pointer icon, not necessarily when it is over a specific gadget.

In particular it would be nice to change it to a "busy" icon (hourglass on windows) during long processing, then back to the default arrow when done.

You then can easily change the mouse pointer icon when over specific gadgets by trapping the mouse enter/leave events for the specific gadgets and change the icon to whatever you see fit then using the new mouse pointer icon command.

Maybe something like SetMouseIcon(#Image) and GetMouseIcon() please? :D

Posted: Tue Dec 30, 2008 6:15 am
by Erlend
Til we get a native solution, maby you could use this?

Code: Select all

Enumeration
  #CURSOR_CROSSHAIR
  #CURSOR_NORMAL
  #CURSOR_WAIT
  #CURSOR_IBEAM
  #CURSOR_HAND
  #CURSOR_HELP
  #CURSOR_MOVE
  #CURSOR_UPARROW
EndEnumeration

Procedure LoadCursor(Type) 
    CompilerIf #PB_Compiler_OS=#PB_OS_Linux
    Select Type
      Case #CURSOR_HELP:Cursor=#GDK_QUESTION_ARROW
      Case #CURSOR_HAND:Cursor=#GDK_HAND2
      Case #CURSOR_IBEAM:Cursor=#GDK_XTERM
      Case #CURSOR_NORMAL:Cursor=#GDK_ARROW
      Case #CURSOR_CROSSHAIR:Cursor=#GDK_CROSSHAIR
      Case #CURSOR_WAIT:Cursor=#GDK_WATCH
      Case #CURSOR_MOVE:Cursor=#GDK_FLEUR   
      Case #CURSOR_UPARROW:Cursor=#GDK_CENTER_PTR
    EndSelect
    ProcedureReturn gdk_cursor_new_(Cursor)
    CompilerElse
    Select Type
      Case #CURSOR_HELP:Cursor=#IDC_HELP
      Case #CURSOR_HAND:Cursor=#IDC_HAND
      Case #CURSOR_IBEAM:Cursor=#IDC_IBEAM
      Case #CURSOR_NORMAL:Cursor=#IDC_ARROW
      Case #CURSOR_CROSSHAIR:Cursor=#IDC_CROSS
      Case #CURSOR_WAIT:Cursor=#IDC_WAIT    
      Case #CURSOR_MOVE:Cursor=#IDC_SIZEALL
      Case #CURSOR_UPARROW:Cursor=#IDC_UPARROW      
    EndSelect
    ProcedureReturn LoadCursor_(0,Cursor)
    CompilerEndIf
EndProcedure

ProcedureDLL SetCursor(Handle,Cursor)
  CompilerIf #PB_Compiler_OS=#PB_OS_Linux
    *widget.gtkwidget=Handle
    gdk_window_set_cursor_(*widget\window, Cursor)
  CompilerElse
    SetWindowLong_(Handle,#GCL_HCURSOR,Cursor)
    ;Should set a property instead and handle the #WM_SETCURSOR event in window procedure
  CompilerEndIf
EndProcedure

Almost there!

Posted: Tue Dec 30, 2008 6:17 pm
by USCode
Thanks, looks pretty good!
You've already done some of the work for Fred there! 8)

Also, I really want to commend you for making the effort to make it partially cross-platform! To me, that is one of the KEY strengths/advantages of applications developed in PB!

We just need some OSX code in there and it'd be good to go! Though in my original post I proposed we have the ability to create an image object from any file we choose ... but using the OS's common pre-defined icons is a good idea as well and would probably work for the vast majority of uses.

Posted: Wed Dec 31, 2008 4:27 am
by Erlend
The code snippit I posted is actually only part of a larger project to create a canvas gadget witch is more or less finished allready, and OSX support for this function as well as the canvas gadget is on my todo list:-)

Posted: Mon Jan 12, 2009 11:49 pm
by mike.harris
Erland

I am just starting out with Windows programming with Purebasic and found your code. Unfortunately it never changes the mouse cursor.
From the look of it it should work on Windows.
Code run as below

LoadCursor(#CURSOR_WAIT)
.... 10 second job
LoadCursor(#CURSOR_NORMAL)

Thanks

Mike

Posted: Mon Jan 12, 2009 11:57 pm
by Kaeru Gaman
I'm not sure, but maybe LoadCursor produces an event.
if so, the event must be processed before the change takes place,
that means you have to run past a (Wait)WindowEvent() to see the change.

Posted: Tue Jan 13, 2009 9:24 am
by eesau
mike.harris wrote:Erland

I am just starting out with Windows programming with Purebasic and found your code. Unfortunately it never changes the mouse cursor.
From the look of it it should work on Windows.
Code run as below

LoadCursor(#CURSOR_WAIT)
.... 10 second job
LoadCursor(#CURSOR_NORMAL)
You should also use SetCursor()...

Posted: Tue Jan 13, 2009 10:11 am
by mike.harris
eesau

Thanks for this tip, I will check it out.

Mike