Maintenance for the week of March 3:
• PC/Mac: No maintenance – March 3
• NA megaservers for maintenance – March 5, 4:00AM EST (9:00 UTC) - 11:00AM EST (16:00 UTC)
• EU megaservers for maintenance – March 5, 9:00 UTC (4:00AM EST) - 16:00 UTC (11:00AM EST)
• ESO Store and Account System for maintenance – March 6, 6:00AM EST (11:00 UTC) - 4:00PM EST (21:00 UTC)

[HELP] Getting window's position?

claudekennilol
claudekennilol
✭✭✭
I've got a movable window that I'm trying to save off the position of. The window is defined in its own GuiXml. In its TopLevelControl I've given it a name. I was assuming that with its name I could access it from the .lua file via that name. Maybe that's the part I'm missing. I've got my method plugged in the OnMoveStop element and I know the method is firing off. I just can't get through this thread-bare API with its broken search and find anything useful.
So if someone could tell me how to get the position of my named window that would be awesome.
  • Wykkyd
    Wykkyd
    ✭✭✭✭✭
    if _G["name"] ~= nil then d( _G["name"]:GetAnchor() ) end

    Or :GetCenter() returns X, Y
    Or :GetTop()
    Or :GetRight()
    Or :GetBottom()
    Or :GetLeft()

    To get your offset from GuiRoot center I'd recommend something like this (off the top of my head from work):

    local myX, myY = _G["name"]:GetCenter()
    local grX, grY = GuiRoot:GetCenter()

    Then I recommend calculating your % distance between guiroot's center and top/left edges. That way if GuiRoot re-scales your addon stays relatively in the same position.

    EDIT-EDIT: I just found out about the scaling issue so I'm working on recalcuating all of that this weekend for all of my addons. Otherwise I'd suggest you use one of mine as a guide on how I'm reading/using positions of frames. This should hopefully help you get started though.
    Edited by Wykkyd on April 11, 2014 2:33PM
  • claudekennilol
    claudekennilol
    ✭✭✭
    Thanks, googling for _G shows me that is definitely what I was missing.

    But what is d? Is that a method I've defined with the anchor as the parameter being passed in or something else for lua that I'm not yet familiar with?
  • Wykkyd
    Wykkyd
    ✭✭✭✭✭
    D dumps data to chat window 1st tab
  • claudekennilol
    claudekennilol
    ✭✭✭
    d for debug, simple enough.
  • Seerah
    Seerah
    ✭✭✭
    This
    if _G["name"] ~= nil then d( _G["name"]:GetAnchor() )
    
    Can simply be this
    if name then d( name:GetAnchor() )
    
    Author & Moderator at ESOUI
    My Addons
  • claudekennilol
    claudekennilol
    ✭✭✭
    Seerah wrote: »
    This
    if _G["name"] ~= nil then d( _G["name"]:GetAnchor() )
    
    Can simply be this
    if name then d( name:GetAnchor() )
    

    So in my .xml in my TopLevelControl's name attribute I can still access it in my .lua file without having to get a reference to it via _G ?

    And you're right, I was reading a lua book last night and thought it was odd/interesting how any not null (er nil) object was true.
  • Aiiane
    Aiiane
    ✭✭✭
    Anything in _G is also automatically a top-level name. In fact, that's what _G is - the dictionary of things in the top-level Lua namespace.

    For instance, if you define a variable without "local", it'll wind up in _G as well. The following two lines are equivalent:
    foo = 1
    _G["foo"] = 1
    
    Aiiane, Aldmeri Dominion, Auriel's Bow, NA ☆ Twitter
  • claudekennilol
    claudekennilol
    ✭✭✭
    Aiiane wrote: »
    Anything in _G is also automatically a top-level name. In fact, that's what _G is - the dictionary of things in the top-level Lua namespace.

    For instance, if you define a variable without "local", it'll wind up in _G as well. The following two lines are equivalent:
    foo = 1
    _G["foo"] = 1
    

    Right, but that's what I'm confused about. In my xml I named an element. Does that make it a global variable?
  • Aiiane
    Aiiane
    ✭✭✭
    The way ESO handles its UI XML, yes, it does.
    Aiiane, Aldmeri Dominion, Auriel's Bow, NA ☆ Twitter
Sign In or Register to comment.