Page 1 of 1
Test if button has focus
Posted: Fri Jun 26, 2015 12:40 am
by IdeasVacuum
When the mouse cursor hovers over a button, a focus rectangle is displayed around the button border. If there is a tooltip associated with the button, it is displayed.
I would like to be able to test for focus on button gadgets so that I can display my own tooltip widget. PB does not support #PB_EventType_Focus or #PB_EventType_LostFocus for ButtonGadget() or ButtonImageGadget().
Does the API deliver focus/lost focus events for buttons?
Re: Test if button has focus
Posted: Fri Jun 26, 2015 12:09 pm
by Julian
Focus isn't strictly the same as mouse over, which is what I think you're after.
Focus changes when you click on a button or TAB through buttons that allow input focus on them. Focus is defined as the item that will receive input which is different to mouse over highlighting, but I know what you mean.
You would need to track #PB_EventType_MouseEnter and #PB_EventType_MouseLeave which is also not supported by ButtonGadget.
I could quickly add this feature to my
BetterButtons library if you wished?
Re: Test if button has focus
Posted: Fri Jun 26, 2015 1:23 pm
by IdeasVacuum
Your lib looks very very interesting Julian. I have made canvas-based buttons for tiny apps where only a few buttons are required, but your 'swap a ButtonImageGadget for a BetterButton' sounds great. I don't understand your notes about using tooltips though - perhaps you could explain how/why that works and does it mean that the button cannot have a tooltip to provide the User with, erm, a tip?
Edit: Just ran your Example, that really is nice, I'm going to see how painfull it is to replace all my ImageButtons (I don't have a .pbf)

Re: Test if button has focus
Posted: Fri Jun 26, 2015 3:22 pm
by Julian
I have updated to version 0.1.3 to add #B8_Event_MouseEnter and #B8_Event_MouseLeave for you.
I have made an example using button 2 in both "Example.pb" and "Example Form.pb" for you to see how the Tooltip system works a little more clearly.
Let me know if you're still running into problem and I'll bring forward the production of a tutorial video that I plan on doing for the library.
Re: Test if button has focus
Posted: Fri Jun 26, 2015 9:05 pm
by IdeasVacuum
Hi Julian
I have certainly learnt a few things from your code, but it currently does not sit well with my own code. When I find the time, I will re-write my button stuff. Keep up the good work

Re: Test if button has focus
Posted: Thu Jul 02, 2015 4:11 pm
by RASHAD
Try the next
Code: Select all
OpenWindow(0,300,350,400,200,"Track Mouse Test",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget| #PB_Window_MaximizeGadget|#PB_Window_SizeGadget| #PB_Window_ScreenCentered)
ButtonGadget(1,10,10,80,20,"Test #1")
ButtonImageGadget(2,10,40,80,20,0)
TextGadget(3,10,70,80,20,"TEST 3",#SS_NOTIFY)
EditorGadget(4,10,100,200,80,0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #WM_MOUSEMOVE
GetCursorPos_ (@p.POINT)
ScreenToClient_ (WindowID(0), @p)
hWnd = ChildWindowFromPoint_ (WindowID(0), p\y<< 32 + p\x)
TRACK.TRACKMOUSEEVENT
TRACK\cbSize = SizeOf(TRACK)
TRACK\dwFlags = #TME_HOVER|#TME_LEAVE
TRACK\hwndTrack = hWnd
TRACK\dwHoverTime = 10
TrackMouseEvent_(@TRACK)
Case #WM_MOUSEHOVER
Gad = GetDlgCtrlID_(hWnd)
If Gad > 0
Debug "MOUSEHOVER Gadet : " + Str(Gad)
EndIf
Case #WM_MOUSELEAVE
If Gad > 0
Debug "MOUSELEAVE Gadget : " + Str(Gad)
EndIf
EndSelect
Until Quit = 1
Re: Test if button has focus
Posted: Fri Jul 03, 2015 11:42 am
by IdeasVacuum
Hi Rashad
Now that is a very handy piece of code, thank you!