Page 1 of 1
CanvasGadget events
Posted: Thu Jan 05, 2017 3:19 pm
by collectordave
Hopefully just a quick question on windows.
trying to use the mousewheel with the canvas gadget. Is it possible to set the keyboard focus on the gadget programmatically to allow mousewheel data to be read without having to click on the gadget on a windows system?
regards
cd
Re: CanvasGadget events
Posted: Thu Jan 05, 2017 3:33 pm
by TI-994A
collectordave wrote:Is it possible to set the keyboard focus on the gadget programmatically to allow mousewheel data to be read without having to click on the gadget on a windows system?
Yes; just call the
SetActiveGadget() function on the canvas in question.

Re: CanvasGadget events
Posted: Thu Jan 05, 2017 3:33 pm
by kenmo
Sure, create it with #PB_Canvas_Keyboard and later call SetActiveGadget().
You can even steal keyboard focus on the MouseEnter event, and "give it back" to the previous activegadget on the MouseLeave event.
Re: CanvasGadget events
Posted: Thu Jan 05, 2017 3:53 pm
by collectordave
Thanks TI-994A and kenmo
Works like a charm.
Handing back the focus using -1 as the gadget is that correct?
Cheers
cd
Re: CanvasGadget events
Posted: Thu Jan 05, 2017 4:31 pm
by RASHAD
Do I miss something ?
#PB_EventType_MouseWheel does not need SetActiveGadget()
Code: Select all
Procedure SizeWindowHandler()
ResizeGadget(1,10,10,WindowWidth(0)-20,WindowHeight(0)-20)
EndProcedure
LoadImage(0, #PB_Compiler_Home + "examples/Sources/Data/PureBasicLogo.bmp")
If OpenWindow(0, 0, 0, 400, 300, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered |#PB_Window_SizeGadget)
CanvasGadget(1, 10, 10, 200, 200)
StringGadget(2,220,10,100,20,"TEST")
;BindEvent( #PB_Event_SizeWindow,@SizeWindowHandler())
y = 100
SetActiveGadget(2)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Select EventType()
; Case #PB_EventType_MouseMove
; x = GetGadgetAttribute(1,#PB_Canvas_MouseX)
; y = GetGadgetAttribute(1,#PB_Canvas_MouseY)
;
Case #PB_EventType_MouseWheel
delta = GetGadgetAttribute(1, #PB_Canvas_WheelDelta )
StartVectorDrawing(CanvasVectorOutput(1))
VectorSourceColor($FFFFFFFF)
FillVectorOutput()
y = y+delta
MovePathCursor(10,y)
DrawVectorImage(ImageID(0),255,180,30)
StopVectorDrawing()
EndSelect
EndSelect
EndSelect
Until Quit = 1
EndIf
Re: CanvasGadget events
Posted: Thu Jan 05, 2017 5:04 pm
by collectordave
Hi RASHAD
I was working on this quote from the help file
On Windows, the #PB_EventType_MouseWheel event is also only reported if the gadget has keyboard focus. On the other OS, this event is reported to the gadget under the cursor, regardless of keyboard focus.
Tried your code and nothing happens when i use the mouse wheel on windows 7.
Added a debug line afte the Case #PB_EventType_MouseWheel eventtype and still nothing.
Creating the canvas with #PB_Canvas_Keyboard it works after clicking in the gadget.
You can then add the setactive gadget after eventgadget to set the focus on the gadget and it works immediatly.
Cheers
cd