MouseWheel Factor | Can control zoom factors for both 2D/3D!

Share your advanced PureBasic knowledge/code with the community.
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

MouseWheel Factor | Can control zoom factors for both 2D/3D!

Post by Mythros »

After learning Purebasic a bit better thanks to a couple of kind souls who have helped me out immensely on this forum, I would like to dedicate my first ever code entry to those few individuals! Kudos guys!

I also credit the original creator of another mouse wheel code which was similar to this one. (I forgot where I found it on the forum).

And now...

The code!

MouseWheel.pb:

Code: Select all

;-------------------------
;==================================================
; Author: Mythros
; Operating System(s): ALL OS' as far as I know (haven't tested on anything but
; windows 7 64 bit)
; Date Created: August 28th, 2013 | 3:45 PM
;==================================================
;-------------------------

#Window = #PB_Any
#WM_MOUSEWHEEL = $20A

Procedure.w MouseWheelDelta() 
  x.w = ((EventwParam()>>16)&$FFFF) 
  ProcedureReturn -(x / 120) 
EndProcedure 

#zoomspeed = 1
Wheel = 0

wnd = OpenWindow(#Window, 0, 0, 800, 600, "Mouse Wheel Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
InitSprite()
InitKeyboard()
InitMouse()
OpenWindowedScreen(WindowID(wnd), 0, 0, 800, 600, 1, 0, 0, 0)

sgadget = StringGadget(#PB_Any, 1, 0, WindowWidth(wnd)-2, 25, "", #PB_String_ReadOnly | #PB_String_BorderLess)

DisableGadget(sgadget, 1)

Repeat
  
  ClearScreen(RGB(240, 240, 240))
  
  ExamineKeyboard()
  
  Select WaitWindowEvent() 
      
    Case #PB_Event_CloseWindow: Quit=1
    Case #WM_MOUSEWHEEL
      If #zoomspeed >= 0
        Wheel - MouseWheelDelta() * #zoomspeed
      ElseIf #zoomspeed < 0
        Wheel + MouseWheelDelta() * #zoomspeed
      EndIf
  EndSelect
  SetGadgetText(sgadget, "Times Mousewheel has been scrolled with up or down: "+Str(Wheel))
Until KeyboardPushed(#PB_Key_Escape) Or Quit

; IDE Options = PureBasic v5.11 (Windows - x86)
; Folding = -
Enjoy, all! =)
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: MouseWheel Factor | Can control zoom factors for both 2D

Post by fsw »

As soon you use an OS specific command or constant (#WM_MOUSEWHEEL = $20A) you tie the app to that OS.
In yor case the WindowsOS.

Other OS have different values...

I am to provide the public with beneficial shocks.
Alfred Hitshock
Post Reply