It is currently Thu Jun 20, 2013 11:59 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: EventHoverGadget() - How to check if mouse is over a gadget!
PostPosted: Sun Oct 23, 2005 10:29 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 5:05 pm
Posts: 1693
Location: Norway
Code:
;There is one large drawback with this procedure,
;gadget enumeration MUST start with 1 and not at 0 as many tend to do,
;the reason is that 0 is returned on failure or if no mouseover/hover occurs.
;so enumerate your gadgets as 1, 2, 3, 4 etc.

Procedure.l EventHoverGadget()
Protected cursor.POINT,hndl.l
 If GetCursorPos_(cursor.POINT)
  hndl=WindowFromPoint_(cursor\x,cursor\y)
  If hndl
   hndl=GetDlgCtrlID_(hndl)
   If hndl
    ProcedureReturn hndl
   EndIf
  EndIf
 EndIf
ProcedureReturn 0
EndProcedure

OpenWindow(1,0,0,400,100,#PB_Window_ScreenCentered|#PB_Window_SystemMenu,"MouseOver example")
CreateGadgetList(WindowID())
ButtonGadget(1,10,10,380,20,"Button 1") ;Please note that the first gadgetid start with 1
ButtonGadget(2,10,30,380,20,"Button 2")

hover=0
oldhover=hover
Repeat
 event=WindowEvent()
 Select event
  Case #WM_MOUSEMOVE

   hover=EventHoverGadget()
   If hover<>oldhover
    Select hover
     Case 1 : SetGadgetText(1,"Hover")
     Case 2 : SetGadgetText(2,"Hover")
    EndSelect
    Select oldhover
     Case 1 : SetGadgetText(1,"Button 1")
     Case 2 : SetGadgetText(2,"Button 2")
    EndSelect
    oldhover=hover
   EndIf

 EndSelect
 Delay(1)
Until event = #PB_Event_CloseWindow


Now let's hope something similar appear in a future PB version :)

_________________
Image website, journal, projects, reviews and more.
Normality exist in the minds of others, not mine! - Rescator


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 8:49 am 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4008
Location: Spa, relaxing and thinking, and thinking...
That's not a new.
http://forums.purebasic.com/english/vie ... hp?t=11047
http://forums.purebasic.com/english/vie ... hp?t=14964
http://forums.purebasic.com/english/vie ... hp?t=17290 8)

_________________
http://www.nietzscheana.com.ar
http://www.zeitgeistmovie.com


for (humanlife=0 ; world==business ; humanlife++)
{
mafia+=world;
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 4:13 pm 
Offline
Always Here
Always Here
User avatar

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7304
Location: Norway
Why not make it return -1 on failure?

_________________
Woa, I set up a web server.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 3:11 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 5:05 pm
Posts: 1693
Location: Norway
I decided to use 0, because that is also what the windows API returns.
(so why the windows API itself allow gadget enumerations of 0 is beyond me, as you can't tell a gadget 0 and error apart in this case)

If anyone know how to allow 0 gadget id's and retrn -1 instead by all means post and I'll update the first post.
But, don't try to complicate the code any more, the goal of this one vs the other examples and snippets on the forum was simplicity,
clean implementation, no callbacks, and an example that shows how to avoid the "flicker" in the program loop itself.

_________________
Image website, journal, projects, reviews and more.
Normality exist in the minds of others, not mine! - Rescator


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2009 7:35 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 2:23 am
Posts: 139
Is there any way to get this to work with TextGadget? Currently GetDlgCtrlID_ does not seem to register anything when hovering over a textgadget, or any gadget that is disabled for that matter...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2009 8:18 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 6466
Quote:
Is there any way to get this to work with TextGadget?

Sure, just give your TextGadget the #SS_NOTIFY style flag and it will work.

_________________
Veni, vidi, vici.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2009 9:48 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 2:23 am
Posts: 139
Thanks Netmaestro! And as a follow-up, what would be the simplest/easiest/shortest way to detect a mouse click on a TextGadget, preferably *without* using a callback of any kind?

Just using the code above with the #WM_LBUTTONDOWN event instead of #WM_MOUSEMOVE reports clicks on ButtonGadgets correctly, but again, not TextGadget, even with #SS_Notify enabled.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 7:12 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 2:23 am
Posts: 139
Argh. PB 4.3 breaks this function, reporting incorrect number of parameters for:

hndl=WindowFromPoint_(cursor\x,cursor\y)

Apparently it only wants one parameter now instead of two?? Can anyone please tell me how to correct this so that it will still work under 4.3??


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 7:36 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 9859
Location: Beyond the pale...
Code:
hndl=WindowFromPoint_(cursor\y<<32|cursor\x)

_________________
I may look like a mule, but I'm not a complete ass.

eScript
Arctic Reports
nxSoftware


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 7:44 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 2:23 am
Posts: 139
srod wrote:
Code:
hndl=WindowFromPoint_(cursor\y<<32|cursor\x)


Okay, that works... but it brings the compile/run time for my program from about three seconds, to about ONE FULL MINUTE, from the time I hit the compile/run button. Wow.

hndl=WindowFromPoint_(PeekQ(@cursor))

This brings it back to about the three second mark... why does the first one slow down compile time sooooooooooo dramatically?

Thanks...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 7:47 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 9859
Location: Beyond the pale...
No problems here. Not sure how this could possibly affect the compile time?

_________________
I may look like a mule, but I'm not a complete ass.

eScript
Arctic Reports
nxSoftware


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 8:40 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 2:23 am
Posts: 139
srod wrote:
No problems here. Not sure how this could possibly affect the compile time?


Me neither..? But then I readily admit that I know nothing about these things. However I've switched it back and forth several times now to test, and I can verify that it changes the compile time in my program from 3 to 60 seconds every time. On its own with nothing else it compiles fast.. only in my program does it slow the compile time.. even though nothing else in the program slows it down.. weird!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 8:43 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 9859
Location: Beyond the pale...
Can you post the code? Does the above code slow down?

_________________
I may look like a mule, but I'm not a complete ass.

eScript
Arctic Reports
nxSoftware


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 8:56 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 2:23 am
Posts: 139
Okay it's not that line specifically, it turns out. I'm having weird issues with compile time chaging based on any number of seemingly arbitrary things.

I commented an old CreateGadget() line because it's not needed anymore in PB 4.3, and THAT caused compile time to slow to a minute again. I uncommented the line and it went back to 3 seconds.

But if I save the file, close it and then re-open it again, compile time is 3 seconds no matter which lines I leave in which state. If at that point I change the WindowFromPoint_ line to the other version (whichever I wasn't using and had commented), it will change compile time to one minite again. Regardless of which way the switch happens. If I open the file with the "PeekQ" version active, and then change it to the "<<32" version, it slows compile time. Same happens if I open it with the "<<32" version and change to the "PeekQ" version.

But no matter what, if I save, close and re-open the file (just saving isn't enough) it slows down until I either revert the change, or close and re-open again.

It doesn't happen with just that EventHoverGadget() procedure alone, so I will have to methodically remove other bits of the code until I get down to which parts are involved in this. It's very odd.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 9:17 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 9859
Location: Beyond the pale...
I occasionally find that the IDE appears to hang having just completed compiling my code and before running the resulting exe. Really quite rare (happened once today amongst the three million and one compilations I have undertaken!) It will compile the code, get to the last line and then there is a long delay before proceeding; as if the IDE awaits some final signal from the compiler.

It is weird and happens very infrequently; too infrequent for me to have made any kind of fuss about it. Perhaps though it is related to whatever it is that is happening with your installation?

_________________
I may look like a mule, but I'm not a complete ass.

eScript
Arctic Reports
nxSoftware


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: ostapas and 0 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