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

Untitled

By: a guest on Apr 14th, 2012  |  syntax: Lua  |  size: 50.59 KB  |  hits: 18  |  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. -- ===============================================
  2. --                      LOCALS
  3.  
  4. local tinsert = table.insert
  5. local tremove = table.remove
  6. local min = math.min
  7. local max = math.max
  8. local strlower = string.lower
  9. local strupper = string.upper
  10. local floor = math.floor
  11. love.graphics.newCanvas = love.graphics.newCanvas or love.graphics.newFrameBuffer
  12.  
  13. local valid = { top = true,
  14.                                 left = true,
  15.                                 right = true,
  16.                                 bottom = true,
  17.                                 topleft = true,
  18.                                 topright = true,
  19.                                 bottomleft = true,
  20.                                 bottomright = true,
  21.                                 center = true}
  22.  
  23.  
  24. --=============================================
  25.  
  26. --[[
  27.  
  28. ISSUES:
  29. button:
  30. anchoring: need to check it works for most cases.
  31. anchor to center doesnt work
  32.  
  33.  
  34. fonstring needs re writing to move the syntax highlighting to the multilineeditbox
  35.  
  36.  
  37. todo:
  38. MLEB:
  39. turn the MLEBLine into the single line edit box for use in other place
  40. MLEBLine is the newer version of editbox, but needs converting to be standalone
  41. add fonts per editbox
  42. move the box inwards when showing the scrollbars
  43.  
  44. ]]
  45.  
  46. blue = {80, 160, 255, 255}
  47. purple = {220, 50, 210, 255}
  48. red = {200, 50, 80, 255}
  49.  
  50. local StringTypes = {}
  51.        
  52. StringTypes["if"] = blue
  53. StringTypes["then"] = blue
  54. StringTypes["else"] = blue
  55. StringTypes["end"] = blue
  56. StringTypes["local"] = blue
  57. StringTypes["function"] = blue
  58. StringTypes["while"] = blue
  59. StringTypes["return"] = blue
  60.  
  61. StringTypes["1"] = purple
  62. StringTypes["2"] =purple
  63. StringTypes["3"] = purple
  64. StringTypes["4"] = purple
  65. StringTypes["5"] = purple
  66. StringTypes["6"] = purple
  67. StringTypes["7"] = purple
  68. StringTypes["8"] = purple
  69. StringTypes["9"] = purple
  70. StringTypes["0"] = purple
  71. StringTypes["+"] = red
  72. StringTypes["-"] = red
  73. StringTypes["="] = red
  74. StringTypes["*"] = red
  75. StringTypes["("] = red
  76. StringTypes[")"] = red
  77. StringTypes[","] = red
  78.  
  79. StringTypes["{"] = purple
  80. StringTypes["}"] = purple
  81.  
  82. local Strata = {BACKGROUND = 1,
  83.                                 LOW = 2,
  84.                                 MEDIUM = 3,
  85.                                 HIGH = 4,
  86.                                 DIALOG = 5,
  87.                                 FULLSCREEN = 6,
  88.                                 FULLSCREEN_DIALOG = 7,
  89.                                 TOOLTIP = 8}
  90.  
  91. local Layers = {BACKGROUND = 1,
  92.                                 BORDER  =2,
  93.                                 ARTWORK = 3,
  94.                                 OVERLAY = 4,
  95.                                 HIGHLIGHT = 5}
  96.  
  97. UIParent = {}
  98. UIParent.__VARS = {}
  99.  
  100. UIParent.Frames = {} --flat list of all frames
  101. UIParent.EditBoxs = {}
  102.  
  103. UIParent.Strings = {}
  104.  
  105. UIParent.Scripts = {}
  106. UIParent.Scripts.OnKeyDown = {}
  107. UIParent.Scripts.OnMouseDown = {}
  108. UIParent.Scripts.OnEnter = {}
  109. UIParent.Scripts.OnLeave = {}
  110. UIParent.Scripts.OnMouseUp = {}
  111. UIParent.Scripts.OnUpdate = {}
  112. UIParent.Scripts.OnClick = {}
  113. UIParent.Scripts.OnEnterPressed = {}
  114. UIParent.Scripts.OnDraw = {}
  115. UIParent.Scripts.OnShow = {}
  116. UIParent.Scripts.OnHide = {}
  117. UIParent.Scripts.OnEscapePressed = {}
  118. UIParent.Scripts.PreDraw = {}
  119. UIParent.Scripts.OnSizeChanged = {}
  120.  
  121. UIParent.children = {}
  122.  
  123. UIParent.__LAYERS = {}
  124. UIParent.__LAYERS[1] = {} -- BACKGROUND
  125. UIParent.__LAYERS[2] = {} -- LOW
  126. UIParent.__LAYERS[3] = {} -- MEDIUM
  127. UIParent.__LAYERS[4] = {} -- HIGH
  128. UIParent.__LAYERS[5] = {} -- DIALOG
  129. UIParent.__LAYERS[6] = {} -- FULLSCREEN
  130. UIParent.__LAYERS[7] = {} -- FULLSCREEN_DIALOG
  131. UIParent.__LAYERS[8] = {} -- TOOLTIP
  132.  
  133. UIParent.__VARS.children = {}
  134.  
  135. function IsMouseButtonDown(button)
  136.         return love.mouse.isDown(button)
  137. end
  138.  
  139. local mx, my
  140.  
  141. function UIParent:update(dt)
  142.         for f, func in pairs(self.Scripts.OnUpdate) do
  143.                 func(f, dt)
  144.         end
  145.  
  146.         mx, my = love.mouse.getPosition()
  147.        
  148.         local found
  149.         for i = #self.__LAYERS,1,-1 do
  150.                 for j = #self.__LAYERS[i],1,-1 do
  151.                         if self.__LAYERS[i][j]:CheckMouse(mx,my) then
  152.                                 found = true
  153.                                 break
  154.                         end
  155.                 end
  156.         end
  157.  
  158.         if not found then
  159.                 for i = 1, #self.Frames do
  160.                         if self.Frames[i].__VARS.mouseover then
  161.                                 self.Frames[i].__VARS.mouseover = nil
  162.                                 if self.Frames[i].__SCRIPTS.OnLeave then
  163.                                         self.Frames[i].__SCRIPTS.OnLeave(self.Frames[i])
  164.                                 end
  165.                         end
  166.                 end
  167.         end
  168.  
  169.  
  170.         for _,child in pairs(self.Frames) do
  171.                
  172.                 if child.__VARS.moving then
  173.                         child.__VARS.left = mx - child.__VARS.xoff
  174.                         child.__VARS.right = my - child.__VARS.yoff
  175.                         child:SetPoint("TOPLEFT", UIParent, "TOPLEFT", child.__VARS.left, child.__VARS.right)
  176.                         child:ReCalcPosition()
  177.                 end
  178.                 if child.__VARS.sizing then
  179.                         if child.__VARS.sizing == "TOP" then
  180.                                 child:SetHeight( child:GetBottom() -my + child.__VARS.yoff)
  181.                         elseif child.__VARS.sizing == "LEFT" then
  182.                                 child:SetWidth( child:GetRight() -mx + child.__VARS.xoff)
  183.                         elseif child.__VARS.sizing == "RIGHT" then
  184.                                 child:SetWidth(mx-child:GetLeft() -child.__VARS.xoff)
  185.                         elseif child.__VARS.sizing == "BOTTOM" then
  186.                                 child:SetHeight(my-child:GetTop() -child.__VARS.yoff)
  187.                         end
  188.                 end
  189.         end
  190. end
  191.  
  192. function UIParent:draw()
  193.         for i = 1, #self.__LAYERS do
  194.                 for j = 1, #self.__LAYERS[i] do
  195.                         if self.__LAYERS[i][j].__VARS.isshown then
  196.                                 self.__LAYERS[i][j]:Draw()
  197.                         end
  198.                 end
  199.         end
  200. end
  201.  
  202. function UIParent:mousepressed(x,y,button)
  203.         for i = #UIParent.__LAYERS, 1, -1 do
  204.                 for j = #UIParent.__LAYERS[i],1,-1 do
  205.                         if UIParent.__LAYERS[i][j]:MouseDown(x,y,button,j) then
  206.                                 return
  207.                         end
  208.                 end
  209.         end
  210. end
  211.  
  212. function UIParent:mousereleased(x,y,button)
  213.         for _,frame in pairs(UIParent.Frames) do
  214.                 if frame.__VARS.mousedown then
  215.                         frame.__VARS.mousedown = nil
  216.  
  217.                        
  218.                         if frame.__VARS.pushedtexture then
  219.                                 frame.__VARS.pushedtexture:Hide()
  220.                                 frame.__VARS.normaltexture:Show()
  221.                         end
  222.  
  223.                         if frame.__SCRIPTS.OnClick then
  224.                                 if x > frame:GetLeft() and x < frame:GetRight() and y > frame:GetTop() and y < frame:GetBottom() then
  225.                                         frame.__SCRIPTS.OnClick(frame, x, y, button)
  226.                                 end
  227.                         end
  228.  
  229.                 end
  230.  
  231.                 if frame.__SCRIPTS and frame.__SCRIPTS.OnMouseUp then
  232.                         frame.__SCRIPTS.OnMouseUp(frame,x,y,button)
  233.                 end
  234.         end
  235. end
  236.  
  237. function UIParent:keypressed(key,uni)
  238.         for _,f in pairs(self.Frames) do
  239.                 if f.__VARS.focus or f.__VARS.keyenabled then
  240.                         f:keypressed(key,uni)
  241.                 end
  242.         end
  243. end
  244.  
  245. function UIParent:keyreleased(key,uni)
  246.         for _,f in pairs(self.Frames) do
  247.                 if f.__VARS.focus or f.__VARS.keyenabled then
  248.                         --f:keyreleased(key,uni)
  249.                 end
  250.         end
  251. end
  252.  
  253. function UIParent:GetWidth()
  254.         return self.__VARS.width
  255. end
  256.  
  257. function UIParent:GetHeight()
  258.         return self.__VARS.height
  259. end
  260.  
  261. function UIParent:GetX()
  262.         return self.__VARS.x
  263. end
  264.  
  265. function UIParent:GetY()
  266.         return self.__VARS.y
  267. end
  268.  
  269. function UIParent:GetLeft()
  270.         return 0
  271. end
  272.  
  273. function UIParent:GetTop()
  274.         return 0
  275. end
  276.  
  277. function UIParent:GetRight()
  278.         return love.graphics.getWidth()
  279. end
  280.  
  281. function UIParent:GetBottom()
  282.         return love.graphics.getHeight()
  283. end
  284.  
  285. function UIParent:GetRot()
  286.         return self.__VARS.rot
  287. end
  288.  
  289. function UIParent:GetPoint()
  290.         return self.__VARS.x, self.__VARS.y
  291. end
  292.  
  293. function UIParent:SetPoint(x,y)
  294.        
  295. end
  296.  
  297. function UIParent:IsVisible()
  298.         return true
  299. end
  300.  
  301. function UIParent:SetScale(x,y)
  302.         self.__VARS.scalex = x
  303.         self.__VARS.scaley = y
  304. end
  305.  
  306. function UIParent:GetScale()
  307.         return self.__VARS.scalex, self.__VARS.scaley
  308. end
  309.  
  310. function UIParent:SetScaleX(x)
  311.         self.__VARS.scalex = x
  312. end
  313.  
  314. function UIParent:GetScaleX()
  315.         return self.__VARS.scalex
  316. end
  317.  
  318. function UIParent:SetScaleY(y)
  319.         self.__VARS.scaley = y
  320. end
  321.  
  322. function UIParent:GetScaleY()
  323.         return self.__VARS.scaley
  324. end
  325.  
  326. UIParent.__VARS.width = love.graphics.getWidth()
  327. UIParent.__VARS.height = love.graphics.getHeight()
  328. UIParent.__VARS.x = 0
  329. UIParent.__VARS.y = 0
  330. UIParent.__VARS.rot = 0
  331. UIParent.__VARS.scalex = 1
  332. UIParent.__VARS.scaley = 1
  333. UIParent.__VARS.childanch = {}
  334.  
  335.  
  336. --=====================================================================
  337. --=====================================================================
  338. --=====================================================================
  339. --=====================================================================
  340. --=====================================================================
  341. --=====================================================================
  342. --=====================================================================
  343. --=====================================================================
  344. --=====================================================================
  345. --=====================================================================
  346. --=====================================================================
  347.  
  348. local tinsert = table.insert
  349.  
  350. local UIObject = {} --basic methods common to all objects
  351.  
  352. UIObject.__index = UIObject
  353.  
  354.  
  355. function UIObject:Create(parent,name)
  356.         local temp = {}
  357.         temp.__index = UIObject
  358.         setmetatable(temp, temp)
  359.         temp.__VARS = {}
  360.         temp.__VARS.x = 0
  361.         temp.__VARS.y = 0
  362.         temp.__VARS.rot = 0
  363.         temp.__VARS.width = 0
  364.         temp.__VARS.height = 0
  365.         temp.__VARS.minheight = 0
  366.         temp.__VARS.minwidth = 0
  367.         temp.__VARS.children = {}
  368.         temp.__VARS.parent = parent
  369.         temp.__VARS.shown = true
  370.         temp.__VARS.isshown = true
  371.         temp.__VARS.scalex = 1
  372.         temp.__VARS.scaley = 1
  373.         temp.__VARS.anchors = {} -- this objects anchors
  374.         temp.__VARS.childanch = {} -- objects anchored to this object
  375.  
  376.  
  377.         temp.__LAYERS = {}
  378.         temp.__LAYERS[1] = {} -- BACKGROUND
  379.         temp.__LAYERS[2] = {} -- BORDER
  380.         temp.__LAYERS[3] = {} -- ARTWORK
  381.         temp.__LAYERS[4] = {} -- OVERLAY
  382.         temp.__LAYERS[5] = {} -- HIGHLIGHT
  383.         temp.__LAYERS[6] = {} -- FRAMES
  384.        
  385.         if tostring(name) then
  386.                 _G[tostring(name)] = temp
  387.         end
  388.  
  389.         tinsert(UIParent.Frames, temp)
  390.         tinsert(parent.__VARS.children, temp)
  391.        
  392.         return temp
  393. end
  394.  
  395. function UIObject:SetFrameStrata(strata)
  396.         strata = Strata[strata] or strata
  397.         for i = 1, #self.__VARS.parent.__LAYERS[self.__VARS.layer] do
  398.                 if self.__VARS.parent.__LAYERS[self.__VARS.layer][i] == self then
  399.                         tremove(self.__VARS.parent.__LAYERS[self.__VARS.layer], i)
  400.                         break
  401.                 end
  402.         end
  403.         self.__VARS.layer = strata
  404.         tinsert(self.__VARS.parent.__LAYERS[strata], self)
  405. end
  406.  
  407. function UIObject:ReDraw()
  408.         if self.__VARS.parent == UIParent then
  409.                 --[[
  410.                         make a new framebuffer
  411.                         draw all anchored objects
  412.                         and child anchored objects
  413.  
  414.                 ]]
  415.         else
  416.                 self.__VARS.parent:ReDraw()
  417.         end
  418. end
  419.  
  420.  
  421. local testcoords = {left = {"topleft", "bottomleft", "left"},
  422.                                         right = {"topright", "bottomright", "right" },
  423.                                         top = {"top", "topleft", "topright"},
  424.                                         bottom = {"bottomright", "bottom", "bottomleft"},
  425.                                         }
  426.  
  427. local function GetAnchor(anch,dir, rev)
  428.         for i = 1, #testcoords[dir] do
  429.                 local a = anch[testcoords[dir][i]]
  430.                 if a then
  431.                         if rev then
  432.                                 if a[2] == "top" or a[2] == "topleft" or a[2] == "topright" then
  433.                                         return a[1]:GetTop() + a[4]
  434.                                 elseif a[2] == "left" or a[2] == "right" or a[2] == "center" then
  435.                                         return a[1]:GetTop() + a[1]:GetHeight()/2 + a[4]
  436.                                 elseif a[2] == "bottomright" or a[2] == "bottom" or a[2] == "bottomleft" then
  437.                                         return a[1]:GetBottom() + a[4]
  438.                                 end
  439.                         else
  440.                                 if a[2] == "topleft" or a[2] == "left" or a[2] == "bottomleft" then
  441.                                         if a[1]:GetLeft() then
  442.                                                 return a[1]:GetLeft() + a[3]
  443.                                         end
  444.                                 elseif a[2] == "top" or a[2] == "bottom" or a[2] == "center" then
  445.                                                 return a[1]:GetLeft() + a[1]:GetWidth()/2 + a[3]
  446.                                 elseif a[2] == "topright" or a[2] == "right" or a[2] == "bottomright" then
  447.                                         if a[1]:GetRight() then
  448.                                                 return a[1]:GetRight() + a[3]
  449.                                         end
  450.                                 end
  451.                         end
  452.                 end
  453.         end
  454. end
  455.  
  456. function UIObject:ReCalcPosition()
  457.        
  458.         --this function needs a rewrite to better handler anchor/size precedence
  459.        
  460.  
  461.         self.__VARS.left = GetAnchor(self.__VARS.anchors, "left")
  462.         self.__VARS.right = GetAnchor(self.__VARS.anchors, "right")
  463.  
  464.         self.__VARS.top = GetAnchor(self.__VARS.anchors,"top", true)
  465.         self.__VARS.bottom = GetAnchor(self.__VARS.anchors,"bottom", true)
  466.        
  467.        
  468.         local width = self.__VARS.left and self.__VARS.right and (self.__VARS.right-self.__VARS.left) or self.__VARS.width or 0
  469.         local height = self.__VARS.top and self.__VARS.bottom and (self.__VARS.bottom-self.__VARS.top) or self.__VARS.height or 0
  470.        
  471.         if width ~= self.__VARS.width or height ~= self.__VARS.height then
  472.                 self.__VARS.height = height
  473.                 self.__VARS.width = width
  474.                 if self.__SCRIPTS and self.__SCRIPTS.OnSizeChanged then
  475.                         self.__SCRIPTS.OnSizeChanged(self)
  476.                 end
  477.         end
  478.        
  479.  
  480.  
  481.         --work out the new position of all things anchored to this object
  482.        
  483.         for obj in pairs(self.__VARS.childanch) do
  484.                         obj:ReCalcPosition()
  485.         end
  486.  
  487.  
  488. end
  489.  
  490. function UIObject:GetCanvasSize(coords)
  491.        
  492.         coords[1] = math.min(coords[1], self:GetLeft())
  493.         coords[2] = math.max(coords[1], self:GetRight())
  494.         coords[3] = math.min(coords[1], self:GetTop())
  495.         coords[4] = math.max(coords[1], self:GetBottom())
  496.  
  497.         for i = 1, self.__VARS.children do
  498.                 self.__VARS.children[i]:GetCanvasSize(coords)
  499.         end
  500. end
  501.  
  502.  
  503.  
  504. function UIObject:SetScale(x,y)
  505.         if not y then
  506.                 y = x
  507.         end
  508.        
  509.         self.__VARS.scalex = x
  510.         self.__VARS.scaley = y
  511.         self:ReCalcPosition()
  512.         self:ReDraw()
  513. end
  514.  
  515. function UIObject:GetScale()
  516.         return self.__VARS.scalex, self.__VARS.scaley
  517. end
  518.  
  519. function UIObject:SetMinWidth(w)
  520.         self.__VARS.minwidth = w
  521.         self:ReCalcPosition()
  522.         self:ReDraw()
  523. end
  524.  
  525. function UIObject:SetMinHeight(h)
  526.         self.__VARS.minheight = h
  527.         self:ReCalcPosition()
  528.         self:ReDraw()
  529. end
  530.  
  531. function UIObject:GetPoint()
  532.         return self.__VARS.x, self.__VARS.y
  533. end
  534.  
  535. function UIObject:SetScaleX(x)
  536.         self.__VARS.scalex = x
  537.  
  538.         self:ReCalcPosition()
  539.         self:ReDraw()
  540. end
  541.  
  542. function UIObject:IsVisible()
  543.         return self.__VARS.parent:IsVisible() and self.__VARS.isshown
  544. end
  545.  
  546. function UIObject:GetScaleX()
  547.         return self.__VARS.scalex * self.__VARS.parent:GetScaleX()
  548. end
  549.  
  550. function UIObject:SetScaleY(self,y)
  551.        
  552.         self.scaley = y
  553.         self:ReCalcPosition()
  554.         self:ReDraw()
  555. end
  556.  
  557. function UIObject:SetParent( parent)
  558.         for i = 1, #self.__VARS.parent.__VARS.children do
  559.                 if self.__VARS.parent.__VARS.children[i] == self then
  560.                         tremove(self.__VARS.parent.__VARS.children, i)
  561.                 end
  562.         end
  563.         for i = 1, #self.__VARS.parent.__LAYERS[self.__VARS.layer] do
  564.                 if self.__VARS.parent.__LAYERS[self.__VARS.layer][i] == self then
  565.                         tremove(self.__VARS.parent.__LAYERS[self.__VARS.layer],i)
  566.                 end
  567.         end
  568.  
  569.         tinsert(parent.__LAYERS[self.__VARS.layer], self)
  570.         tinsert(parent.__VARS.children, self)
  571.         self.__VARS.parent = parent
  572.         self:ReCalcPosition()
  573.         self:ReDraw()
  574. end
  575.  
  576. function UIObject:GetScaleY()
  577.         return self.__VARS.scaley * self.__VARS.parent:GetScaleY()
  578. end
  579.  
  580. function UIObject:SetWidth( width)
  581.         if width ~= self:GetWidth() then
  582.                 self.__VARS.width = math.max(width, self.__VARS.minwidth)
  583.                 self:ReCalcPosition()
  584.         end
  585. end
  586.  
  587. function UIObject:SetHeight(height)
  588.         if height ~= self:GetHeight() then
  589.                 self.__VARS.height = math.max(height, self.__VARS.minheight)
  590.                 self:ReCalcPosition()
  591.         end
  592. end
  593.  
  594.  
  595. function UIObject:SetSize(x,y)
  596.         if not y then y = x end
  597.         self.__VARS.width = x
  598.         self.__VARS.height = y
  599.         self:ReCalcPosition()
  600. end
  601.  
  602.  
  603. function UIObject:GetLeft()
  604.         return self.__VARS.left or self.__VARS.right and (self.__VARS.right - self:GetWidth()) or 0
  605. end
  606.  
  607.  
  608.  
  609. function UIObject:GetRight()
  610.         return self.__VARS.right or self.__VARS.left and (self.__VARS.left+ self:GetWidth()) or 0
  611. end
  612.  
  613.  
  614. function UIObject:GetTop()
  615.         return self.__VARS.top or self.__VARS.bottom and self.__VARS.bottom - self:GetHeight() or 0
  616. end
  617.  
  618.  
  619. function UIObject:GetBottom()
  620.         return self.__VARS.bottom or self.__VARS.top and self.__VARS.top + self:GetHeight() or 0
  621. end
  622.  
  623. function UIObject:GetCenter()
  624.         --dodgy? needs a think
  625.         return (self:GetLeft() + self:GetRight())/2, (self:GetTop() + self:GetBottom())/2
  626. end
  627.  
  628.  
  629. function UIObject:GetWidth()
  630.         return math.max((self.__VARS.width or self.__VARS.right - self.__VARS.left or 0),self.__VARS.minwidth)
  631. end
  632. function UIObject:GetHeight()
  633.         return math.max((self.__VARS.height  or self:GetBottom() - self:GetTop() or 0),self.__VARS.minheight)
  634. end
  635.  
  636. function UIObject:GetRot()
  637.         return self.__VARS.rot + self.__VARS.parent:GetRot()
  638. end
  639.  
  640. function UIObject:SetRot(rot)
  641.          self__VARS.rot = rot
  642. end
  643.  
  644. function UIObject:SetPoint(point, rframe, rpoint, ofx, ofy)
  645.        
  646.         if rframe == self then
  647.                 error("Attempt to anchor to self")
  648.         end
  649.  
  650.         ofx = ofx or 0
  651.         ofy = ofy or 0
  652.        
  653.         point = strlower(point)
  654.         rpoint = rpoint and strlower(rpoint) or point
  655.         rframe = (type(rframe) == "table")  and rframe or rframe or  _G[rframe] or self.__VARS.parent
  656.        
  657.        
  658.         if not valid[point] then
  659.                 error("Incorrect syntax: SetPoint(point, relativeFrame, relativePoint, offsetx, offsety")
  660.         end
  661.        
  662.         if self.__VARS.anchors[point] then
  663.                 self.__VARS.anchors[point][1].__VARS.childanch[self] = nil --remove its listing from the frame it was anchored to
  664.         end
  665.          
  666.         self.__VARS.anchors[point] = {rframe, rpoint, ofx or 0 , ofy or 0}
  667.         rframe.__VARS.childanch[self] = self
  668.  
  669.         self:ReCalcPosition()
  670.         self:ReDraw()
  671. end
  672.  
  673. function UIObject:SetAllPoints(f)
  674.         for point in pairs(valid) do
  675.                 if self.__VARS.anchors[point] then
  676.                         self.__VARS.anchors[point][1].__VARS.childanch[self] = nil
  677.                 end
  678.  
  679.                 self.__VARS.anchors[point] = {f, point, 0,0}
  680.                 f.__VARS.childanch[self] = self
  681.         end
  682.  
  683.         self:ReCalcPosition()
  684.         self:ReDraw()
  685. end
  686.  
  687. function UIObject:ClearAllPoints()
  688.         self.__VARS.anchors = {}
  689.         --self:ReCalcPosition()
  690.         --self:ReDraw()
  691. end
  692.  
  693. function UIObject:Show()
  694.         if not self.__VARS.isshown then
  695.                 if self.__SCRIPTS and self.__SCRIPTS.OnShow then
  696.                         self.__SCRIPTS.OnShow(self)
  697.                 end
  698.         end
  699.         self.__VARS.isshown = true
  700. end
  701.  
  702. function UIObject:Hide()
  703.         if self.__VARS.isshown then
  704.                 if self.__SCRIPTS and self.__SCRIPTS.OnHide then
  705.                         self.__SCRIPTS.OnHide(self)
  706.                 end
  707.         end
  708.         self.__VARS.isshown = nil
  709. end
  710.  
  711. --======================================================================================
  712. --======================================================================================
  713. --======================================================================================
  714. --======================================================================================
  715. --======================================================================================
  716. --======================================================================================
  717. --======================================================================================
  718. --======================================================================================
  719.  
  720. local Texture = {}
  721. Texture.__index = UIObject
  722. setmetatable(Texture, Texture)
  723.  
  724. function Texture:Create(parent, name, layer, inherits)
  725.  
  726.         local temp = UIObject:Create(parent,name)
  727.                 temp.__index = Texture
  728.                 setmetatable(temp, temp)
  729.                 temp.__VARS.layer = Layers[layer] or layer or 2
  730.                 temp.__VARS.isshown = false
  731.                 tinsert(parent.__LAYERS[temp.__VARS.layer], temp)
  732.                 return temp
  733. end
  734.  
  735. function Texture:SetTexture(path,g,b,a) -- textures stored as quads to handle settexcoords
  736.         if type(path) == "table" then
  737.                 self.__VARS.block = true
  738.                 self.__VARS.color = path
  739.         elseif type(path) == "number" then
  740.                 self.__VARS.block = true
  741.                 self.__VARS.color = {path,g,b,a}
  742.         else
  743.                
  744.                 self.__VARS.image = love.graphics.newImage(path)
  745.                 self.__VARS.basewidth = self.__VARS.image:getWidth()
  746.                 self.__VARS.baseheight = self.__VARS.image:getHeight()
  747.                 self.__VARS.quadheight = 1
  748.                 self.__VARS.quadwidth = 1
  749.                 self.__VARS.quad = love.graphics.newQuad(0,0,self.__VARS.basewidth,self.__VARS.baseheight,self.__VARS.basewidth,self.__VARS.baseheight)
  750.                 self.__VARS.color = nil
  751.                 self.__VARS.block = nil
  752.                 self:SetTexCoord(0,1,0,1)
  753.         end
  754.         self.__VARS.isshown = true
  755. end
  756.  
  757. function Texture:SetTexCoord(left, right, top, bottom)
  758.        
  759.                 self.__VARS.quadcoords = {left, right, top, bottom}
  760.                 left = self.__VARS.basewidth*left
  761.                 right = self.__VARS.basewidth*right
  762.                 top = self.__VARS.baseheight*top
  763.                 bottom = self.__VARS.baseheight*bottom
  764.                 local width = right - left
  765.                 local height = bottom-top
  766.                 self.__VARS.quadheight = height
  767.                 self.__VARS.quadwidth = width
  768.                 self.__VARS.quad = love.graphics.newQuad(left, top, width, height, self.__VARS.basewidth, self.__VARS.baseheight)
  769.        
  770.        
  771. end
  772.  
  773. function Texture:SetColor(color)
  774.         self.__VARS.color = color
  775. end
  776.  
  777. function Texture:Draw()
  778.         if self.__VARS.block then
  779.                 local oldcolor = {love.graphics.getColor()}
  780.                 love.graphics.setColor(self.__VARS.color)
  781.                 love.graphics.rectangle("fill", self:GetLeft(), self:GetTop(), self:GetWidth(), self:GetHeight())
  782.                 love.graphics.setColor(oldcolor)
  783.  
  784.         else
  785.                 if self.__VARS.color then
  786.                                 love.graphics.setColorMode("modulate")
  787.                                 love.graphics.setColor(unpack(self.__VARS.color))
  788.                 else
  789.                         love.graphics.setColorMode("replace")
  790.                         love.graphics.setColor(255,255,255,255)
  791.                 end
  792.        
  793.                 love.graphics.drawq(self.__VARS.image, self.__VARS.quad, self:GetLeft(), self:GetTop(), self:GetRot(), (self.__VARS.width/self.__VARS.quadwidth),(self.__VARS.height/self.__VARS.quadheight))
  794.                 love.graphics.setColorMode("modulate")
  795.                 love.graphics.setColor(255,255,255,255)
  796.         end
  797. end
  798.  
  799.  
  800.  
  801. --======================================================================================
  802. --======================================================================================
  803. --======================================================================================
  804. --======================================================================================
  805. --======================================================================================
  806.  
  807. local Frame = {} --frame objects can handle mouse and keyboard events
  808. Frame.__index = UIObject
  809. setmetatable(Frame, Frame)
  810.  
  811. function Frame:Create(parent,name)
  812.         local temp = UIObject:Create(parent,name)
  813.                 temp.__index = Frame
  814.                 setmetatable(temp, temp)
  815.        
  816.                 temp.__SCRIPTS = {}
  817.                 temp.__VARS.mouseEnabled = true -- REMOVE
  818.                 temp.__VARS.layer = 6
  819.                 tinsert(parent.__LAYERS[6], temp)
  820.                
  821.                 return temp
  822. end
  823.  
  824. function Frame:CreateTexture(...)
  825.         return Texture:Create(self,...)
  826. end
  827.  
  828. function Frame:StartSizing(dir)
  829.  
  830.         local mx, my = love.mouse.getPosition()
  831.        
  832.         self:SetPoint("TOPLEFT", UIParent, "TOPLEFT", self:GetLeft(), self:GetTop())
  833.         self:SetPoint("BOTTOMRIGHT", UIParent, "TOPLEFT", self:GetRight(), self:GetBottom())
  834.         if dir == "TOP" then
  835.                 self.__VARS.yoff = my - self:GetTop()
  836.                 self.__VARS.anchors.topleft = nil
  837.                 self.__VARS.anchors.top = nil
  838.                 self.__VARS.anchors.topright = nil
  839.         elseif dir == "LEFT" then
  840.                 self.__VARS.xoff = mx - self:GetLeft()
  841.                 self.__VARS.anchors.topleft = nil
  842.                 self.__VARS.anchors.left = nil
  843.                 self.__VARS.anchors.bottomleft = nil
  844.         elseif dir == "RIGHT" then
  845.                 self.__VARS.xoff = mx-self:GetRight()
  846.                 self.__VARS.anchors.topright = nil
  847.                 self.__VARS.anchors.right = nil
  848.                 self.__VARS.anchors.bottomright = nil
  849.         elseif dir == "BOTTOM" then
  850.                 self.__VARS.yoff = my-self:GetBottom()
  851.                 self.__VARS.anchors.bottomright = nil
  852.                 self.__VARS.anchors.bottom = nil
  853.                 self.__VARS.anchors.bottomleft = nil
  854.         end
  855.         self.__VARS.sizing = dir
  856. end
  857.  
  858. function Frame:StartMoving()
  859.         self.__VARS.width = self.__VARS.width or self:GetRight() - self:GetLeft()
  860.         self.__VARS.height = self.__VARS.height or self:GetBottom() - self:GetTop()
  861.  
  862.         local mx, my = love.mouse.getPosition()
  863.         self.__VARS.xoff = mx - self:GetLeft()
  864.         self.__VARS.yoff = my - self:GetTop()
  865.         self:ClearAllPoints()
  866.         self.__VARS.moving = true
  867. end
  868.  
  869. function Frame:StopMovingOrSizing()
  870.         self.__VARS.moving = false
  871.         self.__VARS.sizing = false
  872. end
  873.  
  874. function Frame:EnableMouse(var)
  875. self.__VARS.mouseEnabled = var
  876.  
  877. end
  878.  
  879. function Frame:EnableKeyboard(var)
  880.         self.__VARS.keyenabled = var
  881. end
  882.  
  883.  
  884. function Frame:MouseDown(x,y,button,index)
  885.         for i = 1, #self.__LAYERS do
  886.                 for j =  #self.__LAYERS[i],1,-1 do
  887.                         if self.__LAYERS[i][j].MouseDown then
  888.                                 if self.__LAYERS[i][j]:MouseDown(x,y,button,j) then
  889.                                         tremove(self.__VARS.parent.__LAYERS[self.__VARS.layer],index)
  890.                                         tinsert(self.__VARS.parent.__LAYERS[self.__VARS.layer], self)
  891.                                         return true
  892.                                 end
  893.                         end
  894.                 end
  895.         end
  896.        
  897.         if x > self:GetLeft() and x < self:GetRight() and y > self:GetTop() and y < self:GetBottom() then
  898.                 if self.__SCRIPTS.OnMouseDown then
  899.                         self.__VARS.mousedown = true
  900.                         self.__SCRIPTS.OnMouseDown(self, x, y, button)
  901.                         tremove(self.__VARS.parent.__LAYERS[self.__VARS.layer],index)
  902.                         tinsert(self.__VARS.parent.__LAYERS[self.__VARS.layer], self)
  903.                         return true
  904.                 end
  905.         end
  906. end
  907.  
  908. function Frame:keypressed(key,uni)
  909.         if key == "escape" then
  910.                 if self.__SCRIPTS.OnEscapePressed then
  911.                         self.__SCRIPTS.OnEscapePressed(self)
  912.                 end
  913.         end
  914.         if self.__SCRIPTS.OnKeyDown then
  915.                 self.__SCRIPTS.OnKeyDown(self, key,uni)
  916.         end
  917. end
  918.  
  919.  
  920. function Frame:CheckMouse(x,y)
  921.         for i = 1, #self.__LAYERS do
  922.                 for j =  #self.__LAYERS[i],1,-1 do
  923.                         if self.__LAYERS[i][j].CheckMouse then
  924.                                 if self.__LAYERS[i][j]:CheckMouse(x,y) then
  925.                                         return true
  926.                                 end
  927.                         end
  928.                 end
  929.         end
  930.        
  931.         if x > self:GetLeft() and x < self:GetRight() and y > self:GetTop() and y < self:GetBottom() then
  932.                 --if self.__SCRIPTS.OnEnter then
  933.                         if not self.__VARS.mouseover then
  934.                                 for i = 1, #UIParent.Frames do
  935.                                         if UIParent.Frames[i] == self then
  936.                                                 if self.__SCRIPTS.OnEnter then
  937.                                                         self.__SCRIPTS.OnEnter(self, x, y)
  938.                                                 end
  939.                                                 self.__VARS.mouseover = true
  940.                                         elseif UIParent.Frames[i].__VARS.mouseover then
  941.                                                 UIParent.Frames[i].__VARS.mouseover = nil
  942.                                                 if UIParent.Frames[i].__SCRIPTS.OnLeave then
  943.                                                         UIParent.Frames[i].__SCRIPTS.OnLeave(UIParent.Frames[i])
  944.                                                 end
  945.                                         end
  946.                                 end
  947.                         end
  948.                         return true
  949.                 --end
  950.         end
  951.  
  952. end
  953.  
  954.  
  955. function Frame:SetScript(script, func)
  956.         if not (type(script) == "string") then
  957.                 error("string expected, got "..type(script))
  958.         end
  959.        
  960.  
  961.         UIParent.Scripts[script][self] = func
  962.         self.__SCRIPTS[script] = func
  963. end
  964.  
  965. function Frame:Draw()
  966.         if self.__VARS.isshown then
  967.                 if self.__SCRIPTS.PreDraw then
  968.                         self.__SCRIPTS.PreDraw(self)
  969.                 end
  970.         end
  971.  
  972.         for i = 1, #self.__LAYERS do
  973.                 for j = 1,#self.__LAYERS[i] do
  974.                         if self.__LAYERS[i][j].__VARS.isshown then
  975.                                 self.__LAYERS[i][j]:Draw()
  976.                         end
  977.                 end
  978.         end
  979.         if self.__VARS.isshown then
  980.                 if self.__SCRIPTS.OnDraw then
  981.                         self.__SCRIPTS.OnDraw(self)
  982.                 end
  983.         end
  984. end
  985.  
  986. function Frame:SetBackdrop(t)
  987.         ---[[
  988.         self.__VARS.tl = self:CreateTexture(nil, 1)
  989.         self.__VARS.tl:SetTexture(t.edgeFile)
  990.         self.__VARS.tl:SetTexCoord(0.5, 0.625, 0,1)
  991.         self.__VARS.tl:SetPoint("TOPLEFT", self, "TOPLEFT")
  992.         self.__VARS.tl:SetSize(t.edgeSize)
  993.  
  994.         self.__VARS.tr = self:CreateTexture(nil, 1)
  995.         self.__VARS.tr:SetTexture(t.edgeFile)
  996.         self.__VARS.tr:SetTexCoord(0.625, 0.75, 0,1)
  997.         self.__VARS.tr:SetPoint("TOPRIGHT", self, "TOPRIGHT")
  998.         self.__VARS.tr:SetSize(t.edgeSize)
  999.  
  1000.         self.__VARS.bl = self:CreateTexture(nil,1)
  1001.         self.__VARS.bl:SetTexture(t.edgeFile)
  1002.         self.__VARS.bl:SetTexCoord(0.75, 0.875, 0,1)
  1003.         self.__VARS.bl:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT")
  1004.         self.__VARS.bl:SetSize(t.edgeSize)
  1005.        
  1006.         self.__VARS.br = self:CreateTexture(nil, 1)
  1007.         self.__VARS.br:SetTexture(t.edgeFile)
  1008.         self.__VARS.br:SetTexCoord(0.875, 1, 0,1)
  1009.         self.__VARS.br:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT")
  1010.         self.__VARS.br:SetSize(t.edgeSize)
  1011.  
  1012.         self.__VARS.l = self:CreateTexture(nil,1)
  1013.         self.__VARS.l:SetTexture(t.edgeFile)
  1014.         self.__VARS.l:SetTexCoord(0, 0.125, 0,1)
  1015.         self.__VARS.l:SetPoint("TOPLEFT", self, "TOPLEFT", 0, t.edgeSize)
  1016.         self.__VARS.l:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", 0, -t.edgeSize)
  1017.         self.__VARS.l:SetWidth(t.edgeSize)
  1018.  
  1019.         self.__VARS.r = self:CreateTexture(nil,1)
  1020.         self.__VARS.r:SetTexture(t.edgeFile)
  1021.         self.__VARS.r:SetTexCoord(0.125, 0.25, 0,1)
  1022.         self.__VARS.r:SetPoint("TOPRIGHT", self, "TOPRIGHT", 0, t.edgeSize)
  1023.         self.__VARS.r:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", 0, -t.edgeSize)
  1024.         self.__VARS.r:SetWidth(t.edgeSize)
  1025.  
  1026.  
  1027.         local img2 = love.image.newImageData(t.edgeFile)
  1028.        
  1029.         local w = img2:getHeight()
  1030.         local img = love.image.newImageData(w,w)
  1031.  
  1032.         for i = 0, w-1 do
  1033.                 for j = 0, w-1 do
  1034.                         img:setPixel(i, j, img2:getPixel(j+w*2, w-1-i))
  1035.                 end
  1036.         end
  1037.  
  1038.         self.__VARS.t = self:CreateTexture(nil, 1)
  1039.         self.__VARS.t:SetTexture(img)
  1040.         self.__VARS.t:SetPoint("TOPLEFT", self, "TOPLEFT", t.edgeSize, 0)
  1041.         self.__VARS.t:SetPoint("TOPRIGHT", self, "TOPRIGHT", -t.edgeSize, 0)
  1042.         self.__VARS.t:SetHeight(t.edgeSize)
  1043.        
  1044.  
  1045.         for i = 0, w-1 do
  1046.                 for j = 0, w-1 do
  1047.                         img:setPixel(i, j, img2:getPixel(j+w*3, i))
  1048.                 end
  1049.         end
  1050.  
  1051.         self.__VARS.b = self:CreateTexture(nil, 1)
  1052.         self.__VARS.b:SetTexture(img)
  1053.         self.__VARS.b:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", t.edgeSize, 0)
  1054.         self.__VARS.b:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -t.edgeSize,0)
  1055.         self.__VARS.b:SetHeight(t.edgeSize)
  1056.  
  1057. end
  1058.  
  1059.  
  1060. --======================================================================================
  1061. --======================================================================================
  1062. --======================================================================================
  1063. --======================================================================================
  1064. --======================================================================================
  1065. --======================================================================================
  1066. --======================================================================================
  1067.  
  1068.  
  1069.  
  1070. local FontString = {}
  1071. FontString.__index = UIObject
  1072. setmetatable(FontString, FontString)
  1073.  
  1074. function FontString:Create(parent, font, size)
  1075.  
  1076.         local temp = UIObject:Create(parent)
  1077.         temp.__index = FontString
  1078.         setmetatable(temp, temp)
  1079.        
  1080.         temp.__VARS.text = ""
  1081.         if size then
  1082.                 temp.__VARS.font = love.graphics.newFont(font,size)
  1083.         elseif font then
  1084.                 temp.__VARS.font = love.graphics.newFont(font)
  1085.         else
  1086.                 temp.__VARS.font = love.graphics.newFont(12)
  1087.         end
  1088.         tinsert(parent.__LAYERS[3], temp)
  1089.  
  1090.         temp.words = {}
  1091.         return temp
  1092. end
  1093.  
  1094. function FontString:GetStringWidth()
  1095.         return self.__VARS.font:getWidth(self.__VARS.text)
  1096. end
  1097.  
  1098. function FontString:GetStringHeight()
  1099.         return self.__VARS.font:getHeight(self.__VARS.text)
  1100. end
  1101.  
  1102. function words(s)
  1103.  local r = {};
  1104.  local last = ""
  1105.         for p = 1, s:len() do
  1106.                 local c = s:sub(p, p);
  1107.                 if c:find("%w") then
  1108.                         if last:find("%w") then
  1109.                                 r[#r].w = r[#r].w .. c
  1110.                         else
  1111.                                 r[#r+1] = {w = c}
  1112.                         end
  1113.                         --elseif  (c == " ") or (c == "\n") or (c == "\t") then
  1114.                         --table.insert(r, {w = c})
  1115.                 else
  1116.                         table.insert(r, {w = c})
  1117.                 end
  1118.                 last = c
  1119.         end
  1120.        
  1121.         return r
  1122. end
  1123.  
  1124.  
  1125.  
  1126. function FontString:SetColor(color)
  1127.         self.__VARS.color = color
  1128. end
  1129.  
  1130.  
  1131.  
  1132. function FontString:SetText(text)
  1133.         self.__VARS.text = text or ""
  1134. end
  1135.  
  1136. function FontString:GetText()
  1137.         return self.__VARS.text
  1138. end
  1139.  
  1140.  
  1141. function FontString:Draw()
  1142.         love.graphics.setFont(self.__VARS.font)
  1143.        
  1144.                 if self.__VARS.color then --override any color formatting if needed
  1145.                         love.graphics.setColor(unpack(self.__VARS.color))
  1146.                 end    
  1147.  
  1148.                 if self:GetWidth() + self:GetHeight() == 0 then
  1149.                         love.graphics.print(self.__VARS.text, self:GetLeft(), self:GetTop(), self:GetRot(), self:GetScaleX(),
  1150.                         self:GetScaleY())
  1151.                 elseif self:GetStringWidth() > self:GetWidth() then
  1152.                         --if height > self height
  1153.                         --else
  1154.                         love.graphics.printf(self.__VARS.text, self:GetLeft(), self:GetTop(), self:GetWidth(), "left")
  1155.                         --end
  1156.                 else
  1157.                         love.graphics.print(self.__VARS.text, self:GetLeft(), self:GetTop(), self:GetRot(), self:GetScaleX())
  1158.                 end
  1159. end
  1160.  
  1161. function Frame:CreateFontString( path, size)
  1162.         return FontString:Create(self, path, size)
  1163. end
  1164.  
  1165. --======================================================================================
  1166. --======================================================================================
  1167. --======================================================================================
  1168. --======================================================================================
  1169. --======================================================================================
  1170. --======================================================================================
  1171.  
  1172. local Button = {} --comes with a fontstring by default (also needs a texture)
  1173. Button.__index = Frame
  1174. setmetatable(Button, Button)
  1175.  
  1176. function Button:Create(parent, name)
  1177.  
  1178.         local temp = Frame:Create(parent, name)
  1179.         temp.__index = Button
  1180.         setmetatable(temp, temp)
  1181.         temp.__VARS.enabled = true
  1182.        
  1183.         temp.__VARS.normaltexture = temp:CreateTexture()
  1184.         temp.__VARS.normaltexture:SetAllPoints(temp)
  1185.         temp.__VARS.normaltexture:SetTexture(0,0,0,0)
  1186.        
  1187.         temp.__VARS.pushedfont = temp:CreateFontString()
  1188.         temp.__VARS.disabledfont = temp:CreateFontString()
  1189.         return temp
  1190. end
  1191.  
  1192. function Button:Click()
  1193.         if self.__Scripts.OnClick then
  1194.                 self.__Scripts.OnClick(self)
  1195.         end
  1196. end
  1197.  
  1198. function Button:Disable()
  1199.         --set texture to disabled if available
  1200.         --block the onclick
  1201.         self.__VARS.enabled = false
  1202.         function self:MouseDown() end
  1203.  
  1204. end
  1205.  
  1206. function Button:Enable()
  1207.         --restore the texture
  1208.         --delete the blocked onclick
  1209.         self.__VARS.enabled= true
  1210.         self.MouseDown = nil
  1211. end
  1212.  
  1213. function Button:GetButtonState()
  1214.         return self.__VARS.mousedown
  1215. end
  1216.  
  1217. function Button:IsEnabled()
  1218.         return self.__VARS.enabled
  1219. end
  1220.  
  1221. function Button:SetNormalTexture(path)
  1222.         self.__VARS.normaltexture:SetTexture(path)
  1223. end
  1224.  
  1225. function Button:SetPushedTexture(path)
  1226.         if not self.__VARS.pushedtexture then
  1227.                 self.__VARS.pushedtexture = self:CreateTexture()
  1228.                 self.__VARS.pushedtexture:SetAllPoints(self)
  1229.         end
  1230.         self.__VARS.pushedtexture:SetTexture(path)
  1231. end
  1232.  
  1233. function Button:SetDisabledTexture(path)
  1234.         if not self.__VARS.disabledtexture then
  1235.                 self.__VARS.disabledtexture = self:CreateTexture()
  1236.                 self.__VARS.disabledtexture:SetAllPoints(self)
  1237.         end
  1238.         self.__VARS.disabledtexture:SetTexture(path)
  1239. end
  1240.  
  1241. function Button:SetText(text)
  1242.         if not self.__VARS.normalfontstring then
  1243.                 self.__VARS.normalfontstring = self:CreateFontString()
  1244.                 self.__VARS.normalfontstring:SetPoint("TOPLEFT", self, "TOPLEFT", 10, 5)
  1245.                 self.__VARS.normalfontstring:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT",-10, -5)
  1246.         end
  1247.         self.__VARS.normalfontstring:SetText(text)
  1248. end
  1249.  
  1250. function Button:GetText()
  1251.         return self.__VARS.normalfontstring:GetText()
  1252. end
  1253.  
  1254. function Button:SetPushedTextOffset(x,y)
  1255.         self.__VARS.pushedoffsetx = x
  1256.         self.__VARS.pushedoffsety = y
  1257. end
  1258.  
  1259. function Button:MouseDown(x,y,button,index)
  1260.         for i = 1, #self.__LAYERS do
  1261.                 for j =  #self.__LAYERS[i],1,-1 do
  1262.                         if self.__LAYERS[i][j].MouseDown then
  1263.                                 if self.__LAYERS[i][j]:MouseDown(x,y,button,j) then
  1264.                                         return true
  1265.                                 end
  1266.                         end
  1267.                 end
  1268.         end
  1269.        
  1270.         if x > self:GetLeft() and x < self:GetRight() and y > self:GetTop() and y < self:GetBottom() then
  1271.                 if self.__VARS.enabled then
  1272.                         self.__VARS.mousedown = true
  1273.                         if self.__SCRIPTS.OnMouseDown then
  1274.  
  1275.                                 if self.__VARS.pushedtexture then
  1276.                                         self.__VARS.pushedtexture:Show()
  1277.                                         self.__VARS.normaltexture:Hide()
  1278.                                 end
  1279.  
  1280.                                 self.__SCRIPTS.OnMouseDown(self, x, y, button)
  1281.                                 tremove(self.__VARS.parent.__LAYERS[self.__VARS.layer],index)
  1282.                                 tinsert(self.__VARS.parent.__LAYERS[self.__VARS.layer], self)
  1283.                                 return true
  1284.                         end
  1285.                 end
  1286.         end
  1287. end
  1288.  
  1289.  
  1290. function Button:GetStringWidth()
  1291.         return self.__VARS.normalfontstring:GetWidth()
  1292. end
  1293.  
  1294.  
  1295. --======================================================================================
  1296. --======================================================================================
  1297. --======================================================================================
  1298. --======================================================================================
  1299. --======================================================================================
  1300. --======================================================================================
  1301. --======================================================================================
  1302. --======================================================================================
  1303.  
  1304. local EditBox = {}
  1305. EditBox.__index = Frame
  1306. setmetatable(EditBox, EditBox)
  1307.  
  1308.  
  1309. function EditBox:Create(parent, ...)
  1310.  
  1311.         local temp = Frame:Create(parent, ...)
  1312.         temp.__index = EditBox
  1313.         setmetatable(temp, temp)
  1314.  
  1315.         temp.__VARS.mouseEnabled = true
  1316.        
  1317.         tinsert(UIParent.EditBoxs, temp)
  1318.        
  1319.         return temp
  1320. end
  1321.  
  1322. function EditBox:MouseDown(x,y,button)
  1323.  
  1324.         for i = 1, #self.__LAYERS do
  1325.                 for j =  #self.__LAYERS[i],1,-1 do
  1326.                         if self.__LAYERS[i][j].MouseDown then
  1327.                                 if self.__LAYERS[i][j]:MouseDown(x,y,button,j) then
  1328.                                         return true
  1329.                                 end
  1330.                         end
  1331.                 end
  1332.         end
  1333.        
  1334.         if x > self:GetLeft() and x < self:GetRight() and y > self:GetTop() and y < self:GetBottom() then
  1335.                
  1336.                         for _,eb in pairs(UIParent.EditBoxs) do
  1337.                                 if eb == self then
  1338.                                         eb.__VARS.focus = true
  1339.                                 else
  1340.                                         eb.__VARS.focus = nil
  1341.                                 end
  1342.                         end
  1343.        
  1344.                         self.__VARS.mousedown = true
  1345.                 if self.__SCRIPTS.OnMouseDown then
  1346.                         self.__SCRIPTS.OnMouseDown(self, x, y, button)
  1347.                         tremove(self.__VARS.parent.__LAYERS[self.__VARS.layer],index)
  1348.                         tinsert(self.__VARS.parent.__LAYERS[self.__VARS.layer], self)
  1349.                         return true
  1350.                 end
  1351.         end
  1352. end
  1353.  
  1354. function EditBox:SetText(text)
  1355.         if not self.__VARS.body then
  1356.                 self.__VARS.body  = self:CreateFontString()
  1357.                 self.__VARS.body:SetPoint("TOPLEFT", self, "TOPLEFT", 5, 5)
  1358.                 self.__VARS.body:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -5, -5)
  1359.         end
  1360.         self.__VARS.body:SetText(text)
  1361.  
  1362. end
  1363.  
  1364. function EditBox:GetText()
  1365.         return self.__VARS.body:GetText()
  1366. end
  1367.  
  1368. function EditBox:GetStringHeight()
  1369.         return self.__VARS.body:GetStringHeight()
  1370. end
  1371.  
  1372. function EditBox:GetStringWidth()
  1373.         return self.__VARS.body:GetStringWidth()
  1374. end
  1375.  
  1376. function EditBox:keypressed(key,uni)
  1377.         if self.__SCRIPTS.OnKeyDown then
  1378.                 self.__SCRIPTS.OnKeyDown(self,key,uni)
  1379.         end
  1380.         if not self.__VARS.body then
  1381.                 self.__VARS.body  = self:CreateFontString()
  1382.                 self.__VARS.body:SetAllPoints(self)
  1383.         end
  1384.         if key == "tab" then
  1385.                
  1386.         elseif key == 'backspace' then
  1387.                 self:SetText(self:GetText():sub(1,-2))
  1388.         elseif key == 'return' then
  1389.                 if self.__SCRIPTS.OnEnterPressed then
  1390.                         self.__SCRIPTS.OnEnterPressed(self)
  1391.                 end
  1392.         elseif key == "escape" then
  1393.                 if self.__SCRIPTS.OnEscapePressed then 
  1394.                         self.__SCRIPTS.OnEscapePressed(self)
  1395.                 end
  1396.         else
  1397.                 if uni > 31 and uni < 127 then
  1398.                         self.__VARS.body.__VARS.text = self.__VARS.body.__VARS.text..string.char(uni)
  1399.                        
  1400.                 end
  1401.         end
  1402. end
  1403.  
  1404. function EditBox:ClearFocus()
  1405.         self.__VARS.focus = nil
  1406. end
  1407.  
  1408.  
  1409. --======================================================================================
  1410. --======================================================================================
  1411. --======================================================================================
  1412. --======================================================================================
  1413. --======================================================================================
  1414. --======================================================================================
  1415.  
  1416. --[[
  1417. edit frame combines a fonstring title with an editbox and blips to control itself
  1418. --]]
  1419.  
  1420.  
  1421.  
  1422.  
  1423. local MultiLineEditBox = {}
  1424. MultiLineEditBox.__index = Frame
  1425. setmetatable(MultiLineEditBox, MultiLineEditBox)
  1426.  
  1427.  
  1428. function MultiLineEditBox:Create(parent, ...)
  1429.  
  1430.         local temp = Frame:Create(parent, ...)
  1431.         temp.__index = MultiLineEditBox
  1432.         setmetatable(temp, temp)
  1433.  
  1434.         temp.__VARS.mouseEnabled = true
  1435.         temp.__VARS.fontsize = 12
  1436.         temp.__VARS.lines = {}
  1437.         temp.__VARS.blockwidth = 0
  1438.         temp.__VARS.blockheight = 0
  1439.        
  1440.         tinsert(UIParent.EditBoxs, temp)
  1441.        
  1442.         temp.vscroll = CreateFrame("Button")
  1443.         temp.vscroll:SetWidth(10)
  1444.         temp.vscroll:SetPoint("TOPRIGHT", temp, "TOPRIGHT", -2, 2)
  1445.         temp.vscroll.t = temp.vscroll:CreateTexture()
  1446.         temp.vscroll.t:SetTexture(80,80,80,120)
  1447.         temp.vscroll.t:SetAllPoints(temp.vscroll)
  1448.        
  1449.         temp.vscroll:SetScript("OnMouseDown", function(self)
  1450.                                                                                                                                                                                                                         self.yoff = self:GetTop()-love.mouse.getY()
  1451.                                                                                                                                                                                                                        
  1452.                                                                                                                                                                                                                                 self:SetScript("OnUpdate", function(self)
  1453.                                                                                                                                                                                                                                         local y = love.mouse.getY()-temp:GetTop()+self.yoff
  1454.                                                                                                                                                                                                                                         y = math.max(y,0)
  1455.                                                                                                                                                                                                                                         y = math.min(temp:GetHeight()-self:GetHeight(),y)
  1456.                                                                                                                                                                                                                                         self:SetPoint("TOPRIGHT", temp, "TOPRIGHT", -2, y)
  1457.                                                                                                                                                                                                                                         temp:SetOffset(nil, -(y/(temp:GetHeight() -self:GetHeight()))*temp.__VARS.blockheight)
  1458.                                                                                                                                                                                                                                        
  1459.                                                                                                                                                                                                                                 end)
  1460.                                                                                                                                                                                                                         end)
  1461.         temp.vscroll:SetScript("OnMouseUp", function(self) self:SetScript("OnUpdate", nil) end)
  1462.        
  1463.         temp.hscroll = CreateFrame("Button")
  1464.         temp.hscroll:SetHeight(10)
  1465.         temp.hscroll:SetPoint("BOTTOMLEFT", temp, "BOTTOMLEFT", 2, -2)
  1466.         temp.hscroll.t = temp.hscroll:CreateTexture()
  1467.         temp.hscroll.t:SetTexture(80,80,80,120)
  1468.         temp.hscroll.t:SetAllPoints(temp.hscroll)
  1469.  
  1470.         temp.hscroll:SetScript("OnMouseDown", function(self)
  1471.                                                                                                                                                                                                                         self.xoff = self:GetLeft()-love.mouse.getX()
  1472.                                                                                                                                                                                                                        
  1473.                                                                                                                                                                                                                                 self:SetScript("OnUpdate", function(self)
  1474.                                                                                                                                                                                                                                         local x = love.mouse.getX()-temp:GetLeft()+self.xoff
  1475.                                                                                                                                                                                                                                         x = math.max(x,2)
  1476.                                                                                                                                                                                                                                         x = math.min(temp:GetWidth()-self:GetWidth(),x)
  1477.                                                                                                                                                                                                                                         self:SetPoint("BOTTOMLEFT", temp, "BOTTOMLEFT", x, -2)
  1478.                                                                                                                                                                                                                                         temp:SetOffset(-(x/(temp:GetWidth() -self:GetWidth()))*temp.__VARS.blockwidth,nil)
  1479.                                                                                                                                                                                                                                        
  1480.                                                                                                                                                                                                                                 end)
  1481.                                                                                                                                                                                                                         end)
  1482.         temp.hscroll:SetScript("OnMouseUp", function(self) self:SetScript("OnUpdate", nil) end)
  1483.        
  1484.         temp:SetScript("OnSizeChanged", function(self) self:Resize() end)
  1485.         temp:AddLine()
  1486.         temp:SetOffset(0,0) --compensate for the extra line that the first new line adds
  1487.        
  1488.                
  1489.         return temp
  1490. end
  1491.  
  1492. function MultiLineEditBox:SetOffset(offsx, offsy)
  1493.         if not offsx then
  1494.                 offsx = self.__VARS.lines[1]:GetLeft() - self:GetLeft()
  1495.         end
  1496.         if not offsy then
  1497.                 offsy = self.__VARS.lines[1]:GetTop() - self:GetTop()
  1498.         end
  1499.         self.__VARS.lines[1]:SetPoint("TOPLEFT", self, "TOPLEFT", offsx, offsy)
  1500.        
  1501. end
  1502.  
  1503. function MultiLineEditBox:GetOffset()
  1504.  return self.__VARS.lines[1]:GetLeft() - self:GetLeft(), self.__VARS.lines[1]:GetTop() - self:GetTop()
  1505. end
  1506.  
  1507. function MultiLineEditBox:Resize() --resizes the scrollbars and shows/hides them
  1508.        
  1509.         if love.graphics.getFont() then
  1510.        
  1511.         self.__VARS.blockwidth = 0
  1512.        
  1513.                 for i = 1, #self.__VARS.lines do
  1514.                                 self.__VARS.blockwidth = math.max(self.__VARS.blockwidth,love.graphics.getFont():getWidth(self.__VARS.lines[i].text))
  1515.                 end
  1516.        
  1517.         self.__VARS.blockheight = #self.__VARS.lines*self.__VARS.fontsize
  1518.                
  1519.                 if self.__VARS.blockwidth > self:GetWidth() then
  1520.                         self.hscroll:SetWidth(math.max(10,(self:GetWidth()/self.__VARS.blockwidth)*self:GetWidth()-20))
  1521.                         self.hscroll:Show()
  1522.                 else
  1523.                         self.hscroll:Hide()
  1524.                         self:SetOffset(0, nil)
  1525.                 end
  1526.                
  1527.                 if self.__VARS.blockheight > self:GetHeight() then
  1528.                         self.vscroll:SetHeight(math.max(10,(self:GetHeight()/self.__VARS.blockheight)*self:GetHeight()-20))
  1529.                         self.vscroll:Show()
  1530.                 else
  1531.                         self.vscroll:Hide()
  1532.                         self:SetOffset(nil,0)
  1533.                 end
  1534.         end
  1535. end
  1536.  
  1537.  
  1538.  
  1539. function MultiLineEditBox:MouseDown(x,y,button)
  1540.  
  1541.         for i = 1, #self.__LAYERS do
  1542.                 for j =  #self.__LAYERS[i],1,-1 do
  1543.                         if self.__LAYERS[i][j].MouseDown then
  1544.                                 if self.__LAYERS[i][j]:MouseDown(x,y,button,j) then
  1545.                                         return true
  1546.                                 end
  1547.                         end
  1548.                 end
  1549.         end
  1550.        
  1551.         if x > self:GetLeft() and x < self:GetRight() and y > self:GetTop() and y < self:GetBottom() then
  1552.                
  1553.                         for _,eb in pairs(UIParent.EditBoxs) do
  1554.                                 if eb == self then
  1555.                                         eb.__VARS.focus = true
  1556.                                 else
  1557.                                         eb.__VARS.focus = nil
  1558.                                 end
  1559.                         end
  1560.        
  1561.                         self.__VARS.mousedown = true
  1562.                 if self.__SCRIPTS.OnMouseDown then
  1563.                         self.__SCRIPTS.OnMouseDown(self, x, y, button)
  1564.                         tremove(self.__VARS.parent.__LAYERS[self.__VARS.layer],index)
  1565.                         tinsert(self.__VARS.parent.__LAYERS[self.__VARS.layer], self)
  1566.                         return true
  1567.                 end
  1568.         end
  1569.        
  1570.        
  1571.        
  1572.                 self:SelectLine(floor((y - self:GetTop()+(self:GetTop()-self.__VARS.lines[1]:GetTop()))/self.__VARS.fontsize)+1) --set the line mouse is on as the selected
  1573.                 -- the below needs changing to use the editbox font and not just a random one!
  1574.                 if self.__VARS.selectedline.text:len() > 0  then
  1575.                         local cpos = floor(((x-self:GetLeft())/(love.graphics.getFont():getWidth(self.__VARS.selectedline.text)/self.__VARS.selectedline.text:len()))) --set the character position
  1576.                         self.__VARS.selectedline.cpos = math.min(cpos, self.__VARS.selectedline.text:len())
  1577.                 end
  1578.        
  1579. end
  1580.  
  1581.  
  1582.  
  1583. function MultiLineEditBox:SelectLine(index)
  1584.         if self.__VARS.lines[index] then
  1585.                 for i = 1, #self.__VARS.lines do
  1586.                         local l = self.__VARS.lines[i]
  1587.                         if i == index then
  1588.                                 l.selected = true
  1589.                         elseif l.selected then
  1590.                                 l:Split()
  1591.                                 l.buffer = love.graphics.newCanvas(self:GetWidth(), self.__VARS.fontsize)
  1592.                                 love.graphics.setCanvas(l.buffer)
  1593.                                 l:Draw(true) -- true means destined for buffer
  1594.                                 love.graphics.setCanvas()
  1595.                                 l.selected = false
  1596.                         else
  1597.                                 l.selected = false
  1598.                         end
  1599.         end
  1600.         self.__VARS.selectedline = self.__VARS.lines[index]
  1601.         self.__VARS.selectedline.selected = true
  1602.         end
  1603. end
  1604.  
  1605. function MultiLineEditBox:keypressed(key,uni)
  1606.  
  1607.         local sl = self.__VARS.selectedline
  1608.  
  1609.         if key == "escape" then
  1610.                 self:ClearFocus()
  1611.         elseif key == "left" then
  1612.                 if sl.cpos == 0 then
  1613.                         if sl.index > 1 then
  1614.                                 self:SelectLine(sl.index-1)
  1615.                                 self.__VARS.selectedline.cpos = self.__VARS.selectedline.text:len()
  1616.                         end
  1617.                 else
  1618.                         sl:keypressed(key, uni)
  1619.                 end
  1620.                
  1621.         elseif  key == "right" then
  1622.                 if sl.cpos == sl.text:len() then
  1623.                         if sl.index < #self.__VARS.lines then
  1624.                                 self:SelectLine(sl.index+1)
  1625.                                 self.__VARS.selectedline.cpos = 0
  1626.                         end
  1627.                 else
  1628.                         sl:keypressed(key, uni)
  1629.                 end
  1630.         elseif key == "up" then
  1631.                 if sl.index > 1 then
  1632.                         self:SelectLine(sl.index-1)
  1633.                         self.__VARS.selectedline.cpos = math.min(self.__VARS.selectedline.text:len(), sl.cpos)
  1634.                 end
  1635.         elseif key == "down" then
  1636.                 if sl.index < #self.__VARS.lines then
  1637.                         self:SelectLine(sl.index+1)
  1638.                         self.__VARS.selectedline.cpos = math.min(self.__VARS.selectedline.text:len(), sl.cpos)
  1639.                 end
  1640.         elseif key == "backspace" then
  1641.                 if sl.cpos == 0 then
  1642.                         if sl.index > 1 then
  1643.                                 self:SelectLine(sl.index-1)
  1644.                                 self.__VARS.selectedline.cpos = self.__VARS.selectedline.text:len()
  1645.                                 self.__VARS.selectedline.text = self.__VARS.selectedline.text..sl.text
  1646.                                
  1647.                                 table.remove(self.__VARS.lines, sl.index)
  1648.                                 for i = 2, #self.__VARS.lines do
  1649.                                         self.__VARS.lines[i]:SetPoint("TOPLEFT", self.__VARS.lines[i-1], "BOTTOMLEFT")
  1650.                                         self.__VARS.lines[i].index = i
  1651.                                 end
  1652.                                 self.__VARS.selectedline:Split() -- re highlight the new current line
  1653.                         end
  1654.                 else
  1655.                         sl:keypressed(key,uni)
  1656.                 end
  1657.         elseif key == "return" then
  1658.                 local temp = sl.text
  1659.                 sl.text = sl.text:sub(1, sl.cpos)
  1660.                 self:AddLine(sl.index+1, temp:sub(sl.cpos+1))
  1661.         else
  1662.                 sl:keypressed(key,uni)
  1663.         end
  1664.        
  1665.         self.timer = -0.5
  1666.         self.lastkey = key
  1667.         self:SetScript("OnUpdate", function(self,dt)
  1668.                 self.timer = self.timer + dt
  1669.                 if self.timer > 0.05 then
  1670.                         if love.keyboard.isDown(self.lastkey) then
  1671.                                 self:keypressed(key, uni)
  1672.                                 self.timer = 0
  1673.                         else
  1674.                                 self:SetScript("OnUpdate", nil)
  1675.                         end
  1676.                 end
  1677.         end)
  1678.         self:Resize()
  1679. end
  1680.  
  1681. function MultiLineEditBox:Draw()
  1682.         love.graphics.setScissor(self:GetLeft(), self:GetTop(), self:GetWidth(), self:GetHeight())
  1683.         for i = 1, #self.__VARS.lines do
  1684.                 local l = self.__VARS.lines[i]
  1685.                
  1686.                 if l.selected then
  1687.                         l:Draw()
  1688.                         local f = love.graphics.getFont()
  1689.                         local x
  1690.                         if self.__VARS.selectedline.text:len() > 0 then
  1691.                          x = l:GetLeft()+love.graphics.getFont():getWidth(l.text:sub(1, l.cpos))
  1692.                          else
  1693.                          x = l:GetLeft()
  1694.                         end
  1695.                         love.graphics.line(x, l:GetTop(),x, l:GetBottom())
  1696.                 else
  1697.                         love.graphics.setBlendMode("premultiplied")
  1698.                         love.graphics.draw(l.buffer, l:GetLeft(), l:GetTop())
  1699.                         love.graphics.setBlendMode("alpha")
  1700.                 end
  1701.         end
  1702.         love.graphics.setScissor()
  1703. end
  1704.  
  1705. function MultiLineEditBox:ClearFocus()
  1706.         self.__VARS.focus = nil
  1707. end
  1708.  
  1709.  
  1710.  
  1711. --============================ MLEBLINE ====================================================
  1712.  
  1713. local MLEBLine = {}
  1714. MLEBLine.__index = Frame
  1715. setmetatable(MLEBLine, MLEBLine)
  1716.  
  1717. function MLEBLine:Draw(buffer)
  1718. local dist = 0
  1719.         if self.set then
  1720.                 for i = 1, #self.set do
  1721.                         love.graphics.setColor(StringTypes[self.set[i].w] or {255,255,255,255})
  1722.                         if buffer then
  1723.                                 love.graphics.print(self.set[i].w, dist, 0)
  1724.                         else
  1725.                                         love.graphics.print(self.set[i].w, dist+self:GetLeft(), self:GetTop())
  1726.                         end
  1727.                         dist = dist + love.graphics.getFont():getWidth(self.set[i].w)
  1728.                 end
  1729.                 love.graphics.setColor(255,255,255,255)
  1730.         end
  1731. end
  1732.  
  1733. function MLEBLine:Create(parent,...)
  1734.  
  1735.         local temp = Frame:Create(parent, ...)
  1736.         temp.__index = MLEBLine
  1737.         setmetatable(temp, temp)
  1738.         temp.__VARS.mouseEnabled = true
  1739.        
  1740.         tinsert(UIParent.EditBoxs, temp)
  1741.        
  1742.         return temp
  1743. end
  1744.  
  1745. function MultiLineEditBox:AddLine(position, text)
  1746.         if type(position) == "string" then
  1747.                 text = position
  1748.                 position = #self.__VARS.lines+1
  1749.         elseif not position then
  1750.                 position = #self.__VARS.lines+1
  1751.                 text = ""
  1752.         end
  1753.        
  1754.         local l = MLEBLine:Create(self)
  1755.        
  1756.         l.text = text or ""
  1757.         l.cpos = 0
  1758.         l.index = position
  1759.        
  1760.         if #self.__VARS.lines <1 then
  1761.                 l:SetPoint("TOPLEFT", self, "TOPLEFT")
  1762.                 l:SetHeight(12)
  1763.                 l:SetPoint("RIGHT", self, "RIGHT")
  1764.         else
  1765.                 l:SetPoint("TOPLEFT", self.__VARS.lines[position-1], "BOTTOMLEFT")
  1766.                 l:SetHeight(12)
  1767.                 l:SetPoint("RIGHT", self, "RIGHT")
  1768.         end
  1769.        
  1770.         if position < #self.__VARS.lines then
  1771.                 table.insert(self.__VARS.lines, position,l)
  1772.                 self.__VARS.lines[1]:SetPoint("TOPLEFT", self, "TOPLEFT")
  1773.                 for i = 2, #self.__VARS.lines do
  1774.                         self.__VARS.lines[i]:SetPoint("TOPLEFT", self.__VARS.lines[i-1], "BOTTOMLEFT")
  1775.                         self.__VARS.lines[i].index = i
  1776.                 end
  1777.         else
  1778.                 table.insert(self.__VARS.lines,position,l)
  1779.         end
  1780.        
  1781.         self:SelectLine(position)
  1782.         l:Split()
  1783.         local x, y = self:GetOffset()
  1784.         self:SetOffset(nil, y-self.__VARS.fontsize)
  1785.                
  1786. end
  1787.  
  1788.  
  1789.  
  1790. function MLEBLine:keypressed(key, uni)
  1791.  
  1792.         if key == "left" then
  1793.                 self.cpos = math.max(0, self.cpos - 1)
  1794.         elseif key == "right" then
  1795.                 self.cpos = math.min(self.cpos+1, self.text:len())
  1796.         elseif key == 'backspace' then
  1797.                 if self.cpos > 0 then
  1798.                         self.text = self.text:sub(1, self.cpos-1)..self.text:sub(self.cpos+1)
  1799.                         self.cpos = self.cpos - 1
  1800.                 end
  1801.         elseif key == "return" then
  1802.                 if self.__SCRIPTS.OnEnterPressed then
  1803.                         self.__SCRIPTS.OnEnterPressed(self)
  1804.                 end
  1805.         elseif key == "escape" then
  1806.                 if self.__SCRIPTS.OnEscapePressed then 
  1807.                         self.__SCRIPTS.OnEscapePressed(self)
  1808.                 end
  1809.         elseif key == "tab" then
  1810.                 self.text = self.text:sub(1, self.cpos).."    "..self.text:sub(self.cpos+1)
  1811.                 self.cpos = self.cpos+4
  1812.         elseif uni > 31 and uni < 127 then
  1813.                
  1814.                 self.text = self.text:sub(1, self.cpos)..string.char(uni)..self.text:sub(self.cpos+1)
  1815.                 self.cpos = self.cpos+1
  1816.                
  1817.         end
  1818.         self:Split()
  1819.        
  1820. end
  1821.  
  1822.  
  1823. function MLEBLine:ClearFocus()
  1824.         self.__VARS.focus = nil
  1825. end
  1826.  
  1827. function MLEBLine:Split()
  1828.         self.set = words(self.text)
  1829. end
  1830.  
  1831.  
  1832. --======================================================================================
  1833. --======================================================================================
  1834. --======================================================================================
  1835. --======================================================================================
  1836. --======================================================================================
  1837.  
  1838.  
  1839. function CreateFrame(typ, name, parent)
  1840.         parent = parent or UIParent
  1841.         if typ == "Frame" then
  1842.                 return Frame:Create(parent,name)
  1843.         elseif typ == "Button" then
  1844.                 return Button:Create(parent,name)
  1845.         elseif typ == "EditFrame" then
  1846.                 return EditFrame:Create(parent,name)
  1847.         elseif typ == "EditBox" then
  1848.                 return EditBox:Create(parent,name)
  1849.         elseif typ == "MultiLineEditBox" then
  1850.                 return MultiLineEditBox:Create(parent, name)
  1851.         end
  1852. end
  1853.  
  1854. function RequireFrame()
  1855.         return Frame
  1856. end
  1857.  
  1858.  
  1859.  
  1860. return UIParent