Old 07-01-2018, 04:22 AM   #1
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default WDL/SWELL and C++ extensions: How to change mouse cursor?

Does anyone know how to do the following?

* Load REAPER's custom cursors. (I know how to load Windows' standard cursors, but not REAPER's.)

* Prevent REAPER from changing the cursor while the script is running. (When I change the cursor, REAPER immediately changes it back.)

* Do all this via WDL/SWELL. (The swell-functions.h file states: LoadCursor(). ** Notes: hinstance parameter ignored, currently only supports loading some of the predefined values.)
juliansader is offline   Reply With Quote
Old 07-01-2018, 12:25 PM   #2
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Not sure if it helps, but some stuff in SWS use their own cursors e.g. Zoom tool, Breeder's Grid warp, maybe have a look how it's done there.

https://github.com/reaper-oss/sws/bl...nsion.rc#L2008

edit:
I don't know how to load / use Reaper's custom cursors though.

Last edited by nofish; 07-01-2018 at 12:32 PM.
nofish is offline   Reply With Quote
Old 07-01-2018, 12:52 PM   #3
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

On Windows, possibly with LoadCursor and the MAKEINTRESOURCE macro. The Reaper custom cursors look like they start at number 236. No idea about OS-X/SWELL. (Maybe the same technique works.)
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 07-01-2018, 09:35 PM   #4
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

For example, to use the snap offset cursor on all platforms (I don't know if this supports theme-specific cursors):

Code:
// C++11
// Note: The SWELL implementation must be provided by the host application to use its cursors

enum struct REAPERCursor {
  SNAPOFFS = 183,
};

HCURSOR LoadREAPERCursor(const REAPERCursor id)
{
#ifdef _WIN32
  HINSTANCE reaper = GetModuleHandle(nullptr);
  return LoadCursor(reaper, MAKEINTRESOURCE(id));
#else
  return SWELL_LoadCursor(MAKEINTRESOURCE(id));
#endif
}

// Usage
HCURSOR cursor = LoadREAPERCursor(REAPERCursor::SNAPOFFS);
SetCursor(cursor);
You can use something like Resource Hacker on Windows to find the ID of the cursors embedded in the binary (under the Cursor Group group – not a typo).

Last edited by cfillion; 07-02-2018 at 01:19 AM.
cfillion is offline   Reply With Quote
Old 07-03-2018, 06:26 AM   #5
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Thanks everyone!

It seems the trick with question 1 was to get the correct cursor IDs. The numbers given in the Cockos website are not the actual IDs (and the list is outdated, since it doesn't include the new notation cursors, for example).

The trick with question 2 is to keep the script running in a while loop -- NOT a defer loop. When scripts use defer loops, REAPER restores the cursor in each cycle.

SWS functions such as Zoom and WarpGrid that run in the arrange view can use while loops, since the arrange view can be updated using UpdateArrange while the loop is running. The MIDI editor does not have such a function, and only updates during defer cycles.
juliansader is offline   Reply With Quote
Old 07-04-2018, 01:32 PM   #6
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Xenakios View Post
The Reaper custom cursors look like they start at number 236.
Quote:
Originally Posted by cfillion View Post
For example, to use the snap offset cursor on all platforms
SNAPOFFS = 183,
According to Resource Hacker, the cursor numbers start at 236, as Xenakios wrote.

However, to load these cursor, I have to use completely different IDs, as cfillion did: 105 for cursor 236 (adjustfade) and then 182-191 for a few others, etc,

What is going on here?
juliansader is offline   Reply With Quote
Old 07-04-2018, 01:51 PM   #7
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

The good news is that LoadCursorFromFile seems to work well.

So, we can simply include all of REAPER's native cursors as .cur files in SWS (as long as Justin doesn't object) - and even lots of other cute and weird cursors!
juliansader is offline   Reply With Quote
Old 07-04-2018, 07:18 PM   #8
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by juliansader View Post
What is going on here?
Look in the "Cursor Group" group, not the "Cursor" group. No need to include REAPER's cursors into SWS.


Last edited by cfillion; 07-04-2018 at 07:27 PM.
cfillion is offline   Reply With Quote
Old 07-05-2018, 02:38 AM   #9
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by cfillion View Post
Look in the "Cursor Group" group, not the "Cursor" group.
Oops, got it!


Quote:
Originally Posted by cfillion View Post
No need to include REAPER's cursors into SWS.
Will these same IDs also work on MacOS and Linux? (I.e. can SWELL_LoadCursor load Win32-type predefined cursors (with IDs >32000) as well as REAPER's embedded cursors (with IDs < 2000), even though it doesn't utilize a hInstance as first parameter?)

EDIT: Looking at the WDL/SWELL code, it seems that SWELL_LoadCursor can indeed do either standard system cursors, or "registered cursors".

The standard cursors are that SWELL_LoadCursor can load are:
IDC_NO, IDC_SIZENWSE, IDC_SIZENESW, IDC_SIZEALL, IDC_SIZEWE, IDC_SIZENS, IDC_ARROW, IDC_HAND, IDC_UPARROW and IDC_IBEAM.

Last edited by juliansader; 07-05-2018 at 03:53 AM.
juliansader 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 06:56 PM.


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