Go Back   Cockos Incorporated Forums > REAPER Forums > Dstruct's Casa De Nitpicks

Reply
 
Thread Tools Display Modes
Old 01-16-2017, 09:02 PM   #1
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default API: reaper.GetMousePosition is off a little

Reusing code from the other nitpick thread I just posted, but whatever.

reaper.GetMousePosition is returning a point slightly to the right and a full cursor down from where my mouse cursor's point actually is. The code below should open with the window centered on the cursor (center being where the two lines meet), but as you can see:



Whoops? I think it's just not taking the window frame into account, but from what I can tell the only way to get proper coordinates in that sense is to query gfx.dock, which isn't available until after the window opens, which would necessitate quitting and reopening the window. Seems a bit much.

Code:
local name, w, h = "", 258, 258

local x, y = reaper.GetMousePosition()
x, y = x - (w / 2), y - (h / 2)

local ox, oy = w / 2, h / 2

local angle_a = -0.25 * math.pi
local angle_b = 0.25 * math.pi
local r = 96

function Main()
	
	local quit = gfx.getchar()
	if quit == -1 or quit == 27 then return 0 end


	gfx.set(0.2, 1, 0.2, 1)
	
	local ax = ox + r * math.cos(angle_a)
	local ay = oy + r * math.sin(angle_a)
	gfx.line(ox, oy, ax, ay)
	
	local bx = ox + r * math.cos(angle_b)
	local by = oy + r * math.sin(angle_b)
	gfx.line(ox, oy, bx, by)
	
	
	gfx.set(1, 0.2, 0.2, 1)

	gfx.arc(ox, oy, r, angle_a, angle_b, 1)

		
	reaper.defer(Main)
	gfx.update()
	
end

gfx.init(name, w, h, 0, x, y)
Main()
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate

Last edited by Lokasenna; 01-16-2017 at 09:09 PM.
Lokasenna is offline   Reply With Quote
Old 01-17-2017, 05:57 AM   #2
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,749
Default

It is opening the window exactly where you ask it to. As you say, it's positioning the upper left corner of the window there, not the upper left corner of the client area. It's not a typical use to need to calculate where the client area of a window would be before the window is opened; this is somewhat awkward to do even if you have access to the full Windows or macOS API.
schwa is offline   Reply With Quote
Old 01-17-2017, 06:03 AM   #3
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Fair enough, I'll stick with my "fudge the numbers a bit" approach. Cheerio.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna 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 08:19 AM.


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