1. #1
    Deleted

    [lua] dynamic border template

    hey out there,

    i've written this dynamic border template and want to know if i can optimise in term of memory usage and so on

    Code:
    --------------------------------------------------- 
    --- || DYNAMIC BORDER TEMPLATE || -----------------
    ---------------------------------------------------
    local function DynamicBorderTemplate(name, parent, strata, flevel, ...)
    --- || TOPLEFT || ---
    local f = CreateFrame("FRAME", name, parent)
        f:SetPoint("TOPLEFT", parent, -9, 9)
        f:SetWidth(64)
        f:SetHeight(64)
        
        if (...) then
            f:SetScale(...)
        else
        end
        
        f:SetFrameStrata(strata)
        f:SetFrameLevel(flevel)
        local f_Tex = f:CreateTexture(nil, strata)
              f_Tex:SetParent(f)
              f_Tex:SetAllPoints(f)
              f_Tex:SetTexture(cfg.Dynamic_Border_Top_Left) 
    --- || TOPRIGHT || --- 
    local f1 = CreateFrame("FRAME", name, parent)
        f1:SetPoint("TOPRIGHT", parent, 9, 9)
        f1:SetWidth(64)
        f1:SetHeight(64)
        
        if (...) then
            f1:SetScale(...)
        else
        end
        
        f1:SetFrameStrata(strata)
        f1:SetFrameLevel(flevel)
        local f1_Tex = f1:CreateTexture(nil, strata)
              f1_Tex:SetParent(f1)
              f1_Tex:SetAllPoints(f1)
              f1_Tex:SetTexture(cfg.Dynamic_Border_Top_Right) 
    --- || BOTTOMRIGHT || ---
    local f2 = CreateFrame("FRAME", nil, parent)
          f2:SetPoint("BOTTOMRIGHT", parent, 9, -9)
          f2:SetHeight(64)
          f2:SetWidth(64)
          
        if (...) then
            f2:SetScale(...)
        else
        end
        
          f2:SetFrameStrata(strata)
          f2:SetFrameLevel(flevel)
          local f2_Tex = f2:CreateTexture(nil, strata)
                f2_Tex:SetParent(f2)
                f2_Tex:SetAllPoints(f2)
                f2_Tex:SetTexture(cfg.Dynamic_Border_Bottom_Right)
    --- || BOTTOMLEFT || ---
    local f3 = CreateFrame("FRAME", nil, parent)
          f3:SetPoint("BOTTOMLEFT", parent, -9, -9)
          f3:SetHeight(64)
          f3:SetWidth(64)
          
        if (...) then
            f3:SetScale(...)
        else
        end
          f3:SetFrameStrata(strata)
          f3:SetFrameLevel(flevel)
          local f3_Tex = f3:CreateTexture(nil, strata)
                f3_Tex:SetParent(f3)
                f3_Tex:SetAllPoints(f3)
                f3_Tex:SetTexture(cfg.Dynamic_Border_Bottom_Left)
    --- || TOP || ---
    local f4 = CreateFrame("FRAME", nil, parent)
          f4:SetPoint("RIGHT", f1, "LEFT", 0 ,0)
          f4:SetPoint("LEFT",  f, "RIGHT", 0 ,0)
          f4:SetFrameStrata(strata)
          f4:SetFrameLevel(flevel)
          f4:SetHeight(64)
          
        if (...) then
            f4:SetScale(...)
        else
        end
        
          local f4_Tex = f4:CreateTexture(nil, strata)
                f4_Tex:SetParent(f4)
                f4_Tex:SetAllPoints(f4)
                f4_Tex:SetTexture(cfg.Dynamic_Border_Top)
    --- || BOTTOM || ---
    local f5 = CreateFrame("FRAME", nil, parent)
          f5:SetPoint("RIGHT", f2, "LEFT", 0 ,0)
          f5:SetPoint("LEFT",  f3, "RIGHT", 0 ,0)
          f5:SetFrameStrata(strata)
          f5:SetFrameLevel(flevel)
          f5:SetHeight(64)
          
        if (...) then
            f5:SetScale(...)
        else
        end
        
          local f5_Tex = f5:CreateTexture(nil, strata)
                f5_Tex:SetParent(f5)
                f5_Tex:SetAllPoints(f5)
                f5_Tex:SetTexture(cfg.Dynamic_Border_Bottom) 
    --- || LEFT || ---
    local f6 = CreateFrame("FRAME", nil, parent)
          f6:SetWidth(64)
          
        if (...) then
            f6:SetScale(...)
        else
        end
        
          f6:SetPoint("TOP", f, "BOTTOM", 0 ,0)
          f6:SetPoint("BOTTOM", f3, "TOP", 0 ,0)
          f6:SetFrameStrata(strata)
          f6:SetFrameLevel(flevel)
          local f6_Tex = f6:CreateTexture(nil, strata)
                f6_Tex:SetParent(f6)
                f6_Tex:SetAllPoints(f6)
                f6_Tex:SetTexture(cfg.Dynamic_Border_Left)
    --- || RIGHT || --- 
    local f7 = CreateFrame("FRAME", nil, parent)
          f7:SetWidth(64)
          
        if (...) then
            f7:SetScale(...)
        else
        end
        
          f7:SetPoint("TOP", f1, "BOTTOM", 0 ,0)
          f7:SetPoint("BOTTOM", f2, "TOP", 0 ,0)
          f7:SetFrameStrata(strata)
          f7:SetFrameLevel(flevel)
          local f7_Tex = f7:CreateTexture(nil,strata)
                f7_Tex:SetParent(f7)
                f7_Tex:SetAllPoints(f7)
                f7_Tex:SetTexture(cfg.Dynamic_Border_Right)
              
        return f
    end
    hope that it's not to bad
    Last edited by mmocfa0c4bf235; 2013-07-06 at 07:44 PM.

  2. #2
    So you're using this to basically take a parent frame and add a border to it, correct?

    If this is the case it'd probably be a lot more efficient to use a looping element in your code to create the elements in reference to a base frame that's parented to the original parented frame rather than create a bunch of frames with a single texture element.

    You can make it much simpler with a table with all the texture region names and their "setpoint" references and texture names corresponding.

    Im replying from my phone right now but Ill write something out for you later.

    Check out the way I create buttons in this addon here with a looping element and tabled references: http://www.wowinterface.com/download...erButtons.html
    Last edited by Syronius; 2013-07-07 at 07:11 PM. Reason: I accidentally a word.

  3. #3
    I'll let syronius write the loop, but there are a couple things I'll point out.

    Frame strata and region layer aren't the same. They do have the "background" keyword in common though.
    (frames) http://wowprogramming.com/docs/api_types#frameStrata
    (textures/fontstrings) http://wowprogramming.com/docs/api_types#layer


    If scale is the only extra parameter, then forgo the ellipsis and just declare it in the parameters:
    local function DynamicBorderTemplate(name, parent, strata, flevel, scale)

    If it could possibly be nil, instead of having an if statement, use "or" to set it to default value:
    f:SetScale(scale or 1)

  4. #4
    Quote Originally Posted by Woogs View Post
    I'll let syronius write the loop, but there are a couple things I'll point out.

    Frame strata and region layer aren't the same. They do have the "background" keyword in common though.
    (frames) http://wowprogramming.com/docs/api_types#frameStrata
    (textures/fontstrings) http://wowprogramming.com/docs/api_types#layer


    If scale is the only extra parameter, then forgo the ellipsis and just declare it in the parameters:
    local function DynamicBorderTemplate(name, parent, strata, flevel, scale)

    If it could possibly be nil, instead of having an if statement, use "or" to set it to default value:
    f:SetScale(scale or 1)
    Should frame strata be important I took the liberty of factoring that into my code:
    http://pastebin.com/1ygnBcm1

    I'm not really able to test the code but things should be able to line up if you update your texture name references as I noted.
    Last edited by Syronius; 2013-07-07 at 07:43 AM.

  5. #5
    Deleted
    first of all, awesome in my eyes
    tried it an gettin' an lua error in line 66

    'do' expected near 'v'

    @Syronius
    P.S. oh wow i've just seen that you are the author of TUSUI. So basically it's your fault that I started programming my own UI. so thank you
    Last edited by mmocfa0c4bf235; 2013-07-07 at 11:34 AM.

  6. #6
    Quote Originally Posted by Vyntrox View Post
    first of all, awesome in my eyes
    tried it an gettin' an lua error in line 66

    'do' expected near 'v'

    @Syronius
    P.S. oh wow i've just seen that you are the author of TUSUI. So basically it's your fault that I started programming my own UI. so thank you
    Sorry forgot ()'s around 'v.a'.

    Should be fixed now on that link above. Glad you've gotten into programming :3

  7. #7
    Deleted

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •