Old 12-07-2021, 06:07 PM   #1
BPBaker
Human being with feelings
 
BPBaker's Avatar
 
Join Date: Oct 2013
Location: Brooklyn, NY
Posts: 209
Default Help w/ script to change mouse cursor icons

I’d like to write a script that temporarily changes the mouse cursor icon to various other embedded cursors under certain contexts or locations. (Ultimately I'd like to use these scripts in custom actions to create "tool" modes--e.g. using the handscroll icon as the cursor for a "move" tool, or other icons for trim and selector tools.)

I’m still learning the very basics of scripting and hoping someone farther along the path can help and/or direct me to

I've attempted to use code from this page: https://forum.cockos.com/showthread.php?t=183251

Code:
reaper.Mouse_SetCursor(reaper.Mouse_LoadCursor(191)) -- Loads REAPER's native "key signature" cursor
This changes the mouse momentarily after the script is run but immediately reverts as soon as the mouse moves...

I've read this page, too:

https://www.reaper.fm/sdk/cursors/cursors.php

But the icon numbers listed here don't seem to work at all with the above code.

Ideally I'd like to just make a small script that would work as one step along with other actions to make various custom tools which also change cursor icons. Any guidance is appreciated!
BPBaker is online now   Reply With Quote
Old 12-13-2021, 06:17 AM   #2
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,146
Default

You might try a deferred script with reaper.BR_GetMouseCursorContext() function storing current context as a global variable and conditioning the cursor icon on it

Julian gives an example of a similar defer loop function in the same post where the icon is conditioned on moving in and out of a window

The function names in your quoted example are obsolete and these are not native API functions but those of Julian Sader's js_ReaScriptAPI extension where they are currently named

reaper.JS_Mouse_SetCursor()
reaper.JS_Mouse_LoadCursor()

(see Rodilab's post below)

So you will need the extension and then to look up their detailed descriptions export API Help document from REAPER because they're not listed in the native API help at https://www.reaper.fm/sdk/reascript/reascripthelp.html

This applies to reaper.BR_GetMouseCursorContext() function as well since it's an SWS extension function

Last edited by Buy One; 12-13-2021 at 09:50 AM.
Buy One is offline   Reply With Quote
Old 12-13-2021, 06:57 AM   #3
Rodilab
Human being with feelings
 
Rodilab's Avatar
 
Join Date: Jan 2021
Location: Paris
Posts: 255
Default

You need :
  • A defer() script
  • Get the window under mouse
  • Each time the window change :
    • Set your cursor
    • Intercept cursor messages to prevent changes
  • At exit : Release all windows messages

Something like this :
Code:
reaper.atexit(function()
  reaper.JS_WindowMessage_ReleaseAll()
end)

function loop()
  local x, y = reaper.GetMousePosition()
  local windowUnderMouse = reaper.JS_Window_FromPoint(x, y)
  if windowUnderMouse and (not lastWindow or lastWindow ~= windowUnderMouse)then
    reaper.JS_Mouse_SetCursor(reaper.JS_Mouse_LoadCursor(191))
    reaper.JS_WindowMessage_Intercept(windowUnderMouse, "WM_SETCURSOR", false)
  end
  lastWindow = windowUnderMouse
  reaper.defer(loop)
end

reaper.defer(loop)
Rodilab is offline   Reply With Quote
Old 12-13-2021, 07:16 AM   #4
Rodilab
Human being with feelings
 
Rodilab's Avatar
 
Join Date: Jan 2021
Location: Paris
Posts: 255
Default

You can also choose one single window. For example arrange view, like this :

Code:
reaper.atexit(function()
  reaper.JS_WindowMessage_Release(arrange, "WM_SETCURSOR")
end)

function loop()
  local arrange = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 1000)
  local x, y = reaper.GetMousePosition()
  local windowUnderMouse = reaper.JS_Window_FromPoint(x, y)
  if windowUnderMouse then
    if windowUnderMouse == arrange and wasOutsideWindow then
      wasOutsideWindow = false
      reaper.JS_Mouse_SetCursor(reaper.JS_Mouse_LoadCursor(191))
      reaper.JS_WindowMessage_Intercept(arrange, "WM_SETCURSOR", false)
    elseif windowUnderMouse ~= arrange and not wasOutsideWindow then
      wasOutsideWindow = true
      reaper.JS_WindowMessage_Release(arrange, "WM_SETCURSOR")
    end
  end
  reaper.defer(loop)
end

wasOutsideWindow = true
reaper.defer(loop)
Rodilab is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:19 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.