CanvasGadget events

Just starting out? Need help? Post your questions and find answers here.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

CanvasGadget events

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: CanvasGadget events

Post 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. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: CanvasGadget events

Post 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.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: CanvasGadget events

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: CanvasGadget events

Post 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

Egypt my love
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: CanvasGadget events

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply