Currently the developers are putting their own money into JC2-MP to keep the servers online.

Please take a few seconds of your time and disable your AdBlock plugin for our website.

Ad revenue is not going to developers, it is used purely for covering our hosting costs.

 

You are also free to donate, which removes all ads from our website!

Patch 0.3 was just released! Full changelog here: https://t.co/4A50m6IKen

2 years ago

Advertisement
July 16, 2019, 01:01:00 am

Author Topic: Exact position of GUI element in BaseWindow  (Read 785 times)

Dev_34

  • Full Member
  • ***
  • Posts: 158
    • View Profile
Exact position of GUI element in BaseWindow
« on: October 22, 2015, 11:07:19 pm »
I've been working with jc-mp's GUI features for a while and have need of getting the exact position of a GUI element relative to the entire screen that is a child of a BaseWindow.
There might be a specific method for this but I haven't gotten anything I've tried to work.
I realize it's possible to just add the position of the BaseWindow and the position of the element together, but, this isn't entirely accurate and tends to be inconsistent among varying screen resolutions.
Any advice is appreciated  :)

dreadmullet

  • Developer
  • Hero Member
  • *****
  • Posts: 643
    • View Profile
Re: Exact position of GUI element in BaseWindow
« Reply #1 on: October 22, 2015, 11:52:22 pm »
For any control, you should be able to use http://wiki.jc-mp.com/Lua/Client/BaseWindow/Functions/RelativeToAbsolute

Code: [Select]
local posOnScreen = myControl:RelativeToAbsolute(Vector2.Zero)

Dev_34

  • Full Member
  • ***
  • Posts: 158
    • View Profile
Re: Exact position of GUI element in BaseWindow
« Reply #2 on: October 23, 2015, 12:09:56 am »
For any control, you should be able to use http://wiki.jc-mp.com/Lua/Client/BaseWindow/Functions/RelativeToAbsolute

Code: [Select]
local posOnScreen = myControl:RelativeToAbsolute(Vector2.Zero)

Thanks, that works!  :)

I tried this method but never would have guessed that it was used like this based on the Prototype:
Code: [Select]
BaseWindow:RelativeToAbsolute(Vector2)...
I kept trying to do:
Code: [Select]
MyBaseWindow:RelativeToAbsolute(Child:GetPosition())and
Code: [Select]
MyBaseWindow:RelativeToAbsolute(Child:GetPositionRel())