Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: KK20 on July 04, 2016, 04:40:27 am

Title: [XP] Mouse Wheel Scroll
Post by: KK20 on July 04, 2016, 04:40:27 am
Mouse Wheel Scroll
Authors: KK20
Version: 1.0
Type: Input Add-on
Key Term: Misc System



Introduction

This script allows the use of scrolling the mouse wheel. It was written as an extension to Blizzard's Mouse Controller:
http://forum.chaos-project.com/index.php/topic,4710.0.html

Note that this script is not necessarily complete. It is up to you, the developer, to make use of this script's features. I only added the ability to scroll through Window_Selectable contents.


Features




Screenshots

None.


Demo

None.


Script

Spoiler: ShowHide

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Mouse Wheel Scroll for Mouse Controller
# Version: 1.0
# Type: Custom Input System
# Date: July 4 2016
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# Compatibility:
#
#   Requires Blizzard's Mouse Controller
#        http://forum.chaos-project.com/index.php/topic,4710.0.html
#   Be sure the Mouse Controller is placed above this script.
#   
# Features:
#
#   - allows the ability to scroll the mouse wheel
#   - adds an option to keep the mouse cursor constantly displayed on screen
#
# Instructions:
#
#   Add the file MouseWheel.dll to your game project. Configure below.
#
# - Script Calls:
#   
#   The following commands are possible:
#    Input.scroll_up?       Returns TRUE if the wheel scrolled up
#    Input.scroll_down?     Returns TRUE if the wheel scrolled down
#    Input.scroll?          Returns TRUE if the wheel scrolled
#    Input.wheel_delta      Returns the number of times the wheel scrolled this
#                           frame (Positive for up, Negative for down)
#   
# Side Note:
#
#   Feel free to use this script in any way you want. If you would like the
#   mouse wheel scrolling for another mouse script, you may modify this script
#   accordingly.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# If you find any bugs, please report them here:
# http://forum.chaos-project.com
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#===============================================================================
# Mouse
#===============================================================================
class Mouse
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# START Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  # If true, the Windows cursor will always be displayed over the game window.
  # If HIDE_WINDOWS_CURSOR is true, this option will be ignored.
  ALWAYS_VISIBLE = true
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# END Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

  StartWheel = Win32API.new('MouseWheel', 'Initialize', 'i', 'i')
  StartWheel.call(HIDE_WINDOWS_CURSOR ? 0 : (ALWAYS_VISIBLE ? 1 : 0))
  WheelDelta = Win32API.new('MouseWheel', 'WheelDelta', '', 'i')

  attr_reader :delta

  alias init_mouse_scroll initialize
  def initialize
    @delta = 0
    init_mouse_scroll
  end

  alias update_for_mouse_scroll update
  def update
    @delta = WheelDelta.call
    update_for_mouse_scroll
  end

end
#===============================================================================
# Input
#===============================================================================
module Input

  def self.scroll_up?
    $mouse.delta > 0
  end

  def self.scroll_down?
    $mouse.delta < 0
  end

  def self.scroll?
    $mouse.delta != 0
  end

  def self.wheel_delta
    $mouse.delta
  end
 
end
#===============================================================================
# Window_Selectable
#===============================================================================

class Window_Selectable
 
  alias update_for_mouse_wheel update
  def update
    if self.active
      if Input.scroll_up?
        self.top_row -= 1
      elsif Input.scroll_down? &&
            self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
        self.top_row += 1
      end
    end
    update_for_mouse_wheel
  end

end



Instructions

Requires Blizzard's Mouse Controller script (link above). The Controller should be placed above this add-on in the script list.
Download the required DLL here (includes source code): Download (https://www.dropbox.com/s/iig0ckd9u5wbta5/MouseWheel.zip?dl=0)
All other instructions in script.


Compatibility

Requires Blizzard's Mouse Controller.



Credits and Thanks




Author's Notes

Performance might be slow on terrible computers. I would appreciate it if people can test this for me.
If you wish to adapt this script to other existing mouse controller scripts, you are free to do so.
Title: Re: [XP] Mouse Wheel Scroll
Post by: LiTTleDRAgo on August 29, 2016, 12:10:51 pm
(http://imgur.com/3Y8otkWs.png) (http://imgur.com/3Y8otkW.png)
http://imgur.com/3Y8otkW

it seems... not compatible with my Windows 7 Ultimate (Service Pack 1)

Script used :

RTP
Custom Control (Ripped from Tons)
Mouse Controller
Mouse Wheel Scroll

Title: Re: [XP] Mouse Wheel Scroll
Post by: Blizzard on August 29, 2016, 01:10:01 pm
KK20, you should probably check my linker settings in XPA_Window. Mine works on XP SP3 and higher.
Title: Re: [XP] Mouse Wheel Scroll
Post by: KK20 on August 29, 2016, 02:06:27 pm
But does this only apply to this script or all my DLLs? I wonder if it has anything to do with the window events or creating a thread.
Title: Re: [XP] Mouse Wheel Scroll
Post by: Blizzard on August 29, 2016, 02:12:55 pm
Likely all DLLs if you are using the same compilation settings. I set up mine to use the minimum of dependencies and to link to static libs so no extra stuff is needed. Handling window events and creating a thread shouldn't be a problem. Though, it might not be a bad idea to run Game.exe as admin to see if that is the problem.
Title: Re: [XP] Mouse Wheel Scroll
Post by: KK20 on August 29, 2016, 04:42:14 pm
I just installed a Win7Ultimatex64 VM to test it out. I think I uploaded the wrong version of the DLL, one that was using some optimization [-O2] (this is set by default :\ ). On my Windows10, it just gave me a critical error.

Anyways, the version I've been using for my tests is here: -removed-

Worked on my end.
I'll update the dropbox link when I get back home.
Edit: Done.
Title: Re: [XP] Mouse Wheel Scroll
Post by: LiTTleDRAgo on August 30, 2016, 03:28:35 am
Perfect! :D