#PB_Canvas_MouseDeltaX and #PB_Canvas_MouseDeltaY

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Olli
Addict
Addict
Posts: 1200
Joined: Wed May 27, 2020 12:26 pm

#PB_Canvas_MouseDeltaX and #PB_Canvas_MouseDeltaY

Post by Olli »

I talk about the real Deltas which are not limited by the screen borders.
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: #PB_Canvas_MouseDeltaX and #PB_Canvas_MouseDeltaY

Post by kernadec »

hello
very simple

Code: Select all

Enumeration
  #windows
  #canvas
  #TextGadget1
  #TextGadget2
EndEnumeration
Global scale.d

Procedure drawing(zoom.d)
  
  StartDrawing(CanvasOutput(#canvas))
  Box(0,0,600,580,#White)
  Box(200 - zoom, 200 - zoom, 200 + zoom * 2, 180 + zoom * 2, RGB(0,200,200))
  StopDrawing()
  
EndProcedure 

If OpenWindow(#Windows, 0, 0, 620, 620, " Zoom Box X Y ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(#Canvas, 10, 30, 600, 580, #PB_Canvas_Keyboard)
  TextGadget(#TextGadget1, 10,  5, 120, 20, "")
  TextGadget(#TextGadget2, 140,  5, 120, 20, "")
  
  SetActiveGadget(#Canvas)
  
  StartDrawing(CanvasOutput(#canvas))
  Box(200,200,200,180, RGB(0,200,200))
  StopDrawing()
 
  Repeat
    
    Event = WaitWindowEvent(20)
    
    SetGadgetText(#TextGadget1, "X_DeltaScreen : " + Str(- 1000 + DesktopMouseX()*2))  ;x - 1000 to resolutionX * 2
    SetGadgetText(#TextGadget2, "Y_DeltaScreen : " + Str(- 1000 + DesktopMouseY()*2))  ;y - 1000 to resolutionY * 2
    
    If Event = #PB_Event_Gadget
      If EventType() = #PB_EventType_MouseLeave | #PB_EventType_MouseMove
        SetActiveGadget(#Canvas)
      EndIf
      
      Select EventType()
        Case #PB_EventType_MouseWheel
          wheel = GetGadgetAttribute(#Canvas, #PB_Canvas_WheelDelta)
          If wheel > 0
            scale = scale + 5
            drawing(scale)
          ElseIf wheel = < 0
            scale = scale - 5
            drawing(scale)
          EndIf
      EndSelect
      
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
have a good day
Last edited by kernadec on Sat Jun 13, 2020 9:30 am, edited 2 times in total.
Olli
Addict
Addict
Posts: 1200
Joined: Wed May 27, 2020 12:26 pm

Re: #PB_Canvas_MouseDeltaX and #PB_Canvas_MouseDeltaY

Post by Olli »

Absolutely false :D

But you can move your code is the trick n' tips as the title MouseWheelDelta().

Here, I search the mouse position delta being cross-plateform too.
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: #PB_Canvas_MouseDeltaX and #PB_Canvas_MouseDeltaY

Post by kernadec »

Hello
Sorry :? Now in this code, I have added the delta coordinates of the mouse
which go beyond screen resolution with a little arithmetic
updated code,
you will notice that the coordinates may exceed the screen resolution.
If you don't like this code, I will delete it
of your topic

cordially
Olli
Addict
Addict
Posts: 1200
Joined: Wed May 27, 2020 12:26 pm

Re: #PB_Canvas_MouseDeltaX and #PB_Canvas_MouseDeltaY

Post by Olli »

There are two ways to get the mouse position deltas (the real-time mouse speed indeed).

1st Find all the cross-platform functions strongly specific.

2nd Find all the cross-platform functions allowing us to move the mouse. This to pass over the borders and calculate manually the mouse position deltas.

So your source code contains any native functions to calculate the deltas. Even if it is not the whole right way, I cannot not to like your code !!

Really, it just miss the API functions to move the mouse on Windows and on Linux. Certainly, there exist in the forum...
Post Reply