Don't like ads? PRO users don't see any ads ;-)
Guest

lib.dragalize

By: a guest on Aug 1st, 2012  |  syntax: Lua  |  size: 1.23 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. lib.dragalize = function (frame)
  2.         local fn = frame:GetName()
  3.         frame:SetScript("OnDragStart", function(s) s:StartMoving() end)
  4.     frame:SetScript("OnDragStop", function(s) s:StopMovingOrSizing() end)
  5.         frame:SetMovable(true)
  6.         frame:SetUserPlaced(true)
  7.        
  8.         local d = CreateFrame("Frame", fn, UIParent)
  9.         d:SetBackdrop(backdrop)
  10.         d:SetBackdropColor(0,1,0,.5)
  11.         d:SetAllPoints(frame)
  12.         d:SetFrameLevel(frame:GetFrameLevel()+5)
  13.         d:SetFrameStrata"HIGH"
  14.         d:SetAlpha(0)  -- should be always 0, put 1 if you need to display frame names for edit
  15.         frame.draggable = d
  16.        
  17.         local name = lib.SetFontString(d, cfg.font, 10, "OUTLINE, MONOCHROME")
  18.         name:SetText(fn)
  19.         name:SetPoint("CENTER", d, "CENTER")
  20.         name:SetJustifyH"CENTER"
  21.        
  22.         local btn = CreateFrame("Frame", fn.."btn", d)
  23.         btn:SetBackdrop(backdrop)
  24.         btn:SetBackdropColor(1,0,0)
  25.         btn:SetBackdropBorderColor(0,0,0)
  26.         btn:SetSize(10,10)
  27.         btn:SetPoint("BOTTOMRIGHT", d, "BOTTOMRIGHT", -2, 2)
  28.         btn:Hide()
  29.         frame.btn = btn
  30.        
  31.         btn:SetScript("OnMouseUp", function(self, b)
  32.          if frame:IsShown() then
  33.                 lib.setfield(fn, false)
  34.             frame:Hide()
  35.           else
  36.                 lib.setfield(fn, true)
  37.         frame:Show()      
  38.           end
  39.           local v
  40.           if lib.getfield(fn) then v = 1
  41.           else v = 0
  42.           end
  43.         end)
  44. end