Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 04-01-2023, 09:09 AM   #1
glaiwo
Human being with feelings
 
Join Date: Dec 2021
Posts: 7
Default Way to check if mouse is hovering over media item bottom half?

I'm working on this script that will automatically set the play cursor to the start of an item whenever I drag it:
Code:
local function move_playhead_to_start_of_selected_item()
    reaper.Main_OnCommandEx(41173, 0, 0) -- go to start of selected item
end

local function media_item_left_drag()
    -- wait until the left mouse button is released
    while reaper.JS_Mouse_GetState(1) == true do
        reaper.sleep(0.05)
    end
    
    -- check if left drag was performed on a media item
    local _, _, _ = reaper.BR_ItemAtMouseCursor()
    if _ ~= -1 then
        -- move playhead to start of selected item
        move_playhead_to_start_of_selected_item()
    end
end

local function defer()
    media_item_left_drag()
    reaper.defer(defer)
end

-- run the script in the background
reaper.atexit(function() end) -- disable atexit function
defer() -- start main function
I'd like to replace reaper.BR_ItemAtMouseCursor() with something that will check for media item bottom half specifically so that I can still edit the item normally in the top half. What would be the best way to set this up?
glaiwo is offline   Reply With Quote
Old 04-01-2023, 10:03 AM   #2
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Maybe this give you some ideas,

Code:
-- Show tooltip when mouse over bottom of item
-- Tested: Win10, REAPER v6.75+dev0216, js_ReaScriptAPI v1.31
-- * Supports items in Fixed Lanes (REAPER v6.75+dev0216)

local arrange_hwnd = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 1000)

function Loop()
  local x,y = reaper.GetMousePosition()
  local item = reaper.GetItemFromPoint(x, y, true)
  if item then
    local track = reaper.GetTrackFromPoint(x, y)
    local tr_y = reaper.GetMediaTrackInfo_Value(track, "I_TCPY")
    local item_y = reaper.GetMediaItemInfo_Value(item, "I_LASTY")
    local item_h = reaper.GetMediaItemInfo_Value(item, "I_LASTH")
    local item_center = tr_y + item_y + (item_h / 2)
    local cx, cy = reaper.JS_Window_ScreenToClient(arrange_hwnd, x, y)

    if cy >= item_center then
      reaper.TrackCtl_SetToolTip("Item Bottom", x-32, y-32, true)
    else
      reaper.TrackCtl_SetToolTip("", 0, 0, false)
    end

  end
   reaper.defer(Loop)
end
Edgemeal is offline   Reply With Quote
Old 04-01-2023, 10:27 AM   #3
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

You'll find some scripts here, including mine and Edgemeal's
https://forum.cockos.com/showthread.php?t=260441
vitalker is online now   Reply With Quote
Old 04-01-2023, 10:38 AM   #4
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by vitalker View Post
You'll find some scripts here, including mine and Edgemeal's
https://forum.cockos.com/showthread.php?t=260441
Those don't work correctly if item(s) are in a Fixed Lane (+dev builds).
Edgemeal is offline   Reply With Quote
Old 04-01-2023, 10:59 AM   #5
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by Edgemeal View Post
Those don't work correctly if item(s) are in a Fixed Lane (+dev builds).
There is a cursor for bottom half in dev builds or they've deleted it?
vitalker is online now   Reply With Quote
Old 04-01-2023, 11:13 AM   #6
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by vitalker View Post
There is a cursor for bottom half in dev builds or they've deleted it?
No, they removed that some time ago.
Edgemeal is offline   Reply With Quote
Old 04-01-2023, 01:41 PM   #7
glaiwo
Human being with feelings
 
Join Date: Dec 2021
Posts: 7
Default

Alright here's where I landed with it. I set it up to trigger on both drag and also left click so it could replace a custom action I had made for that. Appreciate the help y'all!

Last edited by glaiwo; 04-01-2023 at 01:47 PM.
glaiwo 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 04:47 PM.


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