ID:1458685
 
(See the best response by DarkCampainger.)
Code:
Basically I can use this to retrieve another window's position.
var/Position = winget(src, "Inventory", "pos")
winset(src,"Equipment","pos='[Position]'")


What I'd like to do is retrieve an object's position on the screen.
var/obj/Whatever/O = locate() in src.client.screen
var/Position = O.screen_loc
winset(src,"Equipment","pos='[Position]'") //Now THIS, doesn't work.


The reason it doesn't work is because pos gives out something like this: pos=0%2c0, right? While screen_loc looks like this: "Window:2,4".

What should I do to convert screen_loc to pos.

Thanks.
Best response
If you think about how your object is positioned, it's relative to several other objects:

- The interface window it's inside
---- The window title bar/menu/border
------- The map control it's inside
---------- The object on the screen

So to get its absolute position, you'll have to factor those in as well.

Basically what you want is:

absolute_pos = map_window_pos + window_border + map_control_pos + screen_loc_tiles*world.icon_size + screen_loc_pixels

You can get map_window_pos and map_control_pos with winget(). You'll have to parse them into their x and y components so you can add them. The window_border value you'll just have to hard-code, I don't think there's a way to determine that currently. Then you'll have to parse the object's screen_loc into its tiles (screen_loc_tiles) and pixel offsets (screen_loc_pixels). Multiply the screen_loc_tiles by the world.icon_size to convert it to pixels, and then add that and the pixel offsets to the other positions. That should give you the value you're looking for.