From 60ad73f8b7e7bb6197ad4f470b136ff878698ca6 Mon Sep 17 00:00:00 2001 From: Kenny Shields Date: Thu, 3 Apr 2014 18:55:46 -0400 Subject: [PATCH] Remove support for LOVE 0.8.0 --- changelog.txt | 4 +- init.lua | 158 +++--- libraries/util.lua | 9 +- objects/base.lua | 4 +- .../internal/columnlist/columnlistarea.lua | 8 +- objects/internal/linenumberspanel.lua | 8 +- .../internal/multichoice/multichoicelist.lua | 8 +- .../internal/multichoice/multichoicerow.lua | 4 +- objects/list.lua | 8 +- objects/numberbox.lua | 14 +- objects/tabs.lua | 8 +- objects/text.lua | 1 - objects/textinput.lua | 533 ++++++++---------- 13 files changed, 334 insertions(+), 433 deletions(-) diff --git a/changelog.txt b/changelog.txt index 5f9b459..034a476 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,5 @@ ================================================ -Version 0.9.8 - Alpha (Release date TBD) +Version 0.9.8 - Alpha (April 3 - 2014) ================================================ [ADDED] support for method chaining [ADDED] a new tooltip method: GetPadding() @@ -11,6 +11,8 @@ Version 0.9.8 - Alpha (Release date TBD) [CHANGED] the text object will now detect newlines that are not separated by spaces +[REMOVED] support for LOVE 0.8.0 + ================================================ Version 0.9.7.2 - Alpha (January 29 - 2014) ================================================ diff --git a/init.lua b/init.lua index d2ff55e..3dadb57 100644 --- a/init.lua +++ b/init.lua @@ -45,12 +45,6 @@ loveframes.collisions = {} --]]--------------------------------------------------------- function loveframes.load() - local loveversion = love._version - - if loveversion ~= "0.8.0" and loveversion ~= "0.9.0" then - error("Love Frames is not compatible with your version of LOVE.") - end - -- install directory of the library local dir = loveframes.config["DIRECTORY"] or path @@ -95,6 +89,9 @@ function loveframes.load() local base = loveframes.objects["base"] loveframes.base = base:new() + -- enable key repeat + love.keyboard.setKeyRepeat(true) + end --[[--------------------------------------------------------- @@ -105,7 +102,6 @@ function loveframes.update(dt) local base = loveframes.base local input_cursor_set = loveframes.input_cursor_set - local version = love._version loveframes.collisioncount = 0 loveframes.objectcount = 0 @@ -124,86 +120,84 @@ function loveframes.update(dt) end end - if version == "0.9.0" then - local hoverobject = loveframes.hoverobject - local arrow = love.mouse.getSystemCursor("arrow") - local curcursor = love.mouse.getCursor() - if hoverobject then - local ibeam = love.mouse.getSystemCursor("ibeam") - local mx, my = love.mouse.getPosition() - if hoverobject.type == "textinput" and not loveframes.resizeobject then - if curcursor ~= ibeam then - love.mouse.setCursor(ibeam) - end - elseif hoverobject.type == "frame" then - if not hoverobject.dragging and hoverobject.canresize then - if loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y, my, 5, 1, 5, 1) then - local sizenwse = love.mouse.getSystemCursor("sizenwse") - if curcursor ~= sizenwse then - love.mouse.setCursor(sizenwse) - end - elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then - local sizenwse = love.mouse.getSystemCursor("sizenwse") - if curcursor ~= sizenwse then - love.mouse.setCursor(sizenwse) - end - elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y, my, 5, 1, 5, 1) then - local sizenesw = love.mouse.getSystemCursor("sizenesw") - if curcursor ~= sizenesw then - love.mouse.setCursor(sizenesw) - end - elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then - local sizenesw = love.mouse.getSystemCursor("sizenesw") - if curcursor ~= sizenesw then - love.mouse.setCursor(sizenesw) - end - elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y, my, hoverobject.width - 10, 1, 2, 1) then - local sizens = love.mouse.getSystemCursor("sizens") - if curcursor ~= sizens then - love.mouse.setCursor(sizens) - end - elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y + hoverobject.height - 2, my, hoverobject.width - 10, 1, 2, 1) then - local sizens = love.mouse.getSystemCursor("sizens") - if curcursor ~= sizens then - love.mouse.setCursor(sizens) - end - elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then - local sizewe = love.mouse.getSystemCursor("sizewe") - if curcursor ~= sizewe then - love.mouse.setCursor(sizewe) - end - elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 2, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then - local sizewe = love.mouse.getSystemCursor("sizewe") - if curcursor ~= sizewe then - love.mouse.setCursor(sizewe) - end - else - if not loveframes.resizeobject then - local arrow = love.mouse.getSystemCursor("arrow") - if curcursor ~= arrow then - love.mouse.setCursor(arrow) - end + local hoverobject = loveframes.hoverobject + local arrow = love.mouse.getSystemCursor("arrow") + local curcursor = love.mouse.getCursor() + if hoverobject then + local ibeam = love.mouse.getSystemCursor("ibeam") + local mx, my = love.mouse.getPosition() + if hoverobject.type == "textinput" and not loveframes.resizeobject then + if curcursor ~= ibeam then + love.mouse.setCursor(ibeam) + end + elseif hoverobject.type == "frame" then + if not hoverobject.dragging and hoverobject.canresize then + if loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y, my, 5, 1, 5, 1) then + local sizenwse = love.mouse.getSystemCursor("sizenwse") + if curcursor ~= sizenwse then + love.mouse.setCursor(sizenwse) + end + elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then + local sizenwse = love.mouse.getSystemCursor("sizenwse") + if curcursor ~= sizenwse then + love.mouse.setCursor(sizenwse) + end + elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y, my, 5, 1, 5, 1) then + local sizenesw = love.mouse.getSystemCursor("sizenesw") + if curcursor ~= sizenesw then + love.mouse.setCursor(sizenesw) + end + elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then + local sizenesw = love.mouse.getSystemCursor("sizenesw") + if curcursor ~= sizenesw then + love.mouse.setCursor(sizenesw) + end + elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y, my, hoverobject.width - 10, 1, 2, 1) then + local sizens = love.mouse.getSystemCursor("sizens") + if curcursor ~= sizens then + love.mouse.setCursor(sizens) + end + elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y + hoverobject.height - 2, my, hoverobject.width - 10, 1, 2, 1) then + local sizens = love.mouse.getSystemCursor("sizens") + if curcursor ~= sizens then + love.mouse.setCursor(sizens) + end + elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then + local sizewe = love.mouse.getSystemCursor("sizewe") + if curcursor ~= sizewe then + love.mouse.setCursor(sizewe) + end + elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 2, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then + local sizewe = love.mouse.getSystemCursor("sizewe") + if curcursor ~= sizewe then + love.mouse.setCursor(sizewe) + end + else + if not loveframes.resizeobject then + local arrow = love.mouse.getSystemCursor("arrow") + if curcursor ~= arrow then + love.mouse.setCursor(arrow) end end end - elseif hoverobject.type == "text" and hoverobject.linkcol and not loveframes.resizeobject then - local hand = love.mouse.getSystemCursor("hand") - if curcursor ~= hand then - love.mouse.setCursor(hand) - end end - if curcursor ~= arrow then - if hoverobject.type ~= "textinput" and hoverobject.type ~= "frame" and not hoverobject.linkcol and not loveframes.resizeobject then - love.mouse.setCursor(arrow) - elseif hoverobject.type ~= "textinput" and curcursor == ibeam then - love.mouse.setCursor(arrow) - end + elseif hoverobject.type == "text" and hoverobject.linkcol and not loveframes.resizeobject then + local hand = love.mouse.getSystemCursor("hand") + if curcursor ~= hand then + love.mouse.setCursor(hand) end - else - if curcursor ~= arrow and not loveframes.resizeobject then + end + if curcursor ~= arrow then + if hoverobject.type ~= "textinput" and hoverobject.type ~= "frame" and not hoverobject.linkcol and not loveframes.resizeobject then + love.mouse.setCursor(arrow) + elseif hoverobject.type ~= "textinput" and curcursor == ibeam then love.mouse.setCursor(arrow) end end + else + if curcursor ~= arrow and not loveframes.resizeobject then + love.mouse.setCursor(arrow) + end end loveframes.collisions = {} @@ -281,13 +275,13 @@ function loveframes.mousereleased(x, y, button) end --[[--------------------------------------------------------- - - func: keypressed(key) + - func: keypressed(key, isrepeat) - desc: called when the player presses a key --]]--------------------------------------------------------- -function loveframes.keypressed(key, unicode) +function loveframes.keypressed(key, isrepeat) local base = loveframes.base - base:keypressed(key, unicode) + base:keypressed(key, isrepeat) end diff --git a/libraries/util.lua b/libraries/util.lua index 46cc5f0..b4a494d 100644 --- a/libraries/util.lua +++ b/libraries/util.lua @@ -136,17 +136,10 @@ end --]]--------------------------------------------------------- function loveframes.util.GetDirectoryContents(dir, t) - local version = love._version local dir = dir local t = t or {} local dirs = {} - local files - - if version == "0.9.0" then - files = love.filesystem.getDirectoryItems(dir) - else - files = love.filesystem.enumerate(dir) - end + local files = love.filesystem.getDirectoryItems(dir) for k, v in ipairs(files) do local isdir = love.filesystem.isDirectory(dir.. "/" ..v) diff --git a/objects/base.lua b/objects/base.lua index f078609..73a5ac4 100644 --- a/objects/base.lua +++ b/objects/base.lua @@ -151,10 +151,10 @@ function newobject:mousereleased(x, y, button) end --[[--------------------------------------------------------- - - func: keypressed(key) + - func: keypressed(key, isrepeat) - desc: called when the player presses a key --]]--------------------------------------------------------- -function newobject:keypressed(key, unicode) +function newobject:keypressed(key, isrepeat) local state = loveframes.state local selfstate = self.state diff --git a/objects/internal/columnlist/columnlistarea.lua b/objects/internal/columnlist/columnlistarea.lua index 49cfc61..755bf63 100644 --- a/objects/internal/columnlist/columnlistarea.lua +++ b/objects/internal/columnlist/columnlistarea.lua @@ -105,7 +105,6 @@ function newobject:draw() local width = self.width local height = self.height local stencilfunc = function() love.graphics.rectangle("fill", x, y, width, height) end - local loveversion = love._version local skins = loveframes.skins.available local skinindex = loveframes.config["ACTIVESKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"] @@ -127,12 +126,7 @@ function newobject:draw() drawfunc(self) end - if loveversion == "0.8.0" then - local stencil = love.graphics.newStencil(stencilfunc) - love.graphics.setStencil(stencil) - else - love.graphics.setStencil(stencilfunc) - end + love.graphics.setStencil(stencilfunc) for k, v in ipairs(children) do local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height) diff --git a/objects/internal/linenumberspanel.lua b/objects/internal/linenumberspanel.lua index 37b8bdb..348d364 100644 --- a/objects/internal/linenumberspanel.lua +++ b/objects/internal/linenumberspanel.lua @@ -87,7 +87,6 @@ function newobject:draw() local width = self.width local height = self.height local stencilfunc = function() love.graphics.rectangle("fill", x, y, width, height) end - local loveversion = love._version local skins = loveframes.skins.available local skinindex = loveframes.config["ACTIVESKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"] @@ -105,12 +104,7 @@ function newobject:draw() -- set the object's draw order self:SetDrawOrder() - if loveversion == "0.8.0" then - local stencil = love.graphics.newStencil(stencilfunc) - love.graphics.setStencil(stencil) - else - love.graphics.setStencil(stencilfunc) - end + love.graphics.setStencil(stencilfunc) if draw then draw(self) diff --git a/objects/internal/multichoice/multichoicelist.lua b/objects/internal/multichoice/multichoicelist.lua index 35eb097..79edc63 100644 --- a/objects/internal/multichoice/multichoicelist.lua +++ b/objects/internal/multichoice/multichoicelist.lua @@ -144,7 +144,6 @@ function newobject:draw() local width = self.width local height = self.height local stencilfunc = function() love.graphics.rectangle("fill", x, y, width, height) end - local loveversion = love._version local skins = loveframes.skins.available local skinindex = loveframes.config["ACTIVESKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"] @@ -170,12 +169,7 @@ function newobject:draw() v:draw() end - if loveversion == "0.8.0" then - local stencil = love.graphics.newStencil(stencilfunc) - love.graphics.setStencil(stencil) - else - love.graphics.setStencil(stencilfunc) - end + love.graphics.setStencil(stencilfunc) for k, v in ipairs(children) do local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height) diff --git a/objects/internal/multichoice/multichoicerow.lua b/objects/internal/multichoice/multichoicerow.lua index 3e03145..09c095c 100644 --- a/objects/internal/multichoice/multichoicerow.lua +++ b/objects/internal/multichoice/multichoicerow.lua @@ -147,10 +147,10 @@ function newobject:mousereleased(x, y, button) end --[[--------------------------------------------------------- - - func: keypressed(key) + - func: keypressed(key, isrepeat) - desc: called when the player presses a key --]]--------------------------------------------------------- -function newobject:keypressed(key, unicode) +function newobject:keypressed(key, isrepeat) local text = self.text local selectedobject = loveframes.selectedobject diff --git a/objects/list.lua b/objects/list.lua index 2ce2076..01725ea 100644 --- a/objects/list.lua +++ b/objects/list.lua @@ -133,7 +133,6 @@ function newobject:draw() local width = self.width local height = self.height local stencilfunc = function() love.graphics.rectangle("fill", x, y, width, height) end - local loveversion = love._version local internals = self.internals local children = self.children local skins = loveframes.skins.available @@ -155,12 +154,7 @@ function newobject:draw() drawfunc(self) end - if loveversion == "0.8.0" then - local stencil = love.graphics.newStencil(stencilfunc) - love.graphics.setStencil(stencil) - else - love.graphics.setStencil(stencilfunc) - end + love.graphics.setStencil(stencilfunc) for k, v in ipairs(children) do local col = loveframes.util.BoundingBox(x, v.x, y, v.y, width, v.width, height, v.height) diff --git a/objects/numberbox.lua b/objects/numberbox.lua index 2df28b0..119a66e 100644 --- a/objects/numberbox.lua +++ b/objects/numberbox.lua @@ -74,13 +74,8 @@ function newobject:initialize() end end increasebutton.Update = function(object) - local loveversion = love._version local time = 0 - if loveversion == "0.8.0" then - time = love.timer.getMicroTime() - else - time = love.timer.getTime() - end + time = love.timer.getTime() local delay = self.delay local down = object.down local canmodify = self.canmodify @@ -114,13 +109,8 @@ function newobject:initialize() end end decreasesbutton.Update = function(object) - local loveversion = love._version local time = 0 - if loveversion == "0.8.0" then - time = love.timer.getMicroTime() - else - time = love.timer.getTime() - end + time = love.timer.getTime() local delay = self.delay local down = object.down local canmodify = self.canmodify diff --git a/objects/tabs.lua b/objects/tabs.lua index f333890..f128c7e 100644 --- a/objects/tabs.lua +++ b/objects/tabs.lua @@ -140,7 +140,6 @@ function newobject:draw() local internals = self.internals local tabheight = self:GetHeightOfButtons() local stencilfunc = function() love.graphics.rectangle("fill", x + self.buttonareax, y, self.buttonareawidth, height) end - local loveversion = love._version local internals = self.internals local skins = loveframes.skins.available local skinindex = loveframes.config["ACTIVESKIN"] @@ -161,12 +160,7 @@ function newobject:draw() drawfunc(self) end - if loveversion == "0.8.0" then - local stencil = love.graphics.newStencil(stencilfunc) - love.graphics.setStencil(stencil) - else - love.graphics.setStencil(stencilfunc) - end + love.graphics.setStencil(stencilfunc) for k, v in ipairs(internals) do local col = loveframes.util.BoundingBox(x + self.buttonareax, v.x, self.y, v.y, self.buttonareawidth, v.width, tabheight, v.height) diff --git a/objects/text.lua b/objects/text.lua index ac6030c..bd1b652 100644 --- a/objects/text.lua +++ b/objects/text.lua @@ -92,7 +92,6 @@ function newobject:update(dt) local hover = self.hover local linksenabled = self.linksenabled - local version = love._version local linkcol = false if hover and linksenabled and not loveframes.resizeobject then diff --git a/objects/textinput.lua b/objects/textinput.lua index 7eb952a..243f641 100644 --- a/objects/textinput.lua +++ b/objects/textinput.lua @@ -98,7 +98,6 @@ function newobject:update(dt) local time = love.timer.getTime() local keydown = self.keydown - local unicode = self.unicode local parent = self.parent local base = loveframes.base local update = self.Update @@ -116,7 +115,6 @@ function newobject:update(dt) local internals = self.internals local repeatrate = self.repeatrate local hover = self.hover - local version = love._version -- move to parent if there is a parent if parent ~= base then @@ -133,18 +131,6 @@ function newobject:update(dt) self.alltextselected = false end - -- keydown check - if keydown ~= "none" then - if time > delay then - if (loveframes.util.IsCtrlDown()) and keydown == "v" then - self:Paste() - else - self:RunKey(keydown, unicode, true) - end - self.delay = time + repeatrate - end - end - self:PositionText() self:UpdateIndicator() @@ -294,7 +280,6 @@ function newobject:draw() local skinindex = loveframes.config["ACTIVESKIN"] local defaultskin = loveframes.config["DEFAULTSKIN"] local stencilfunc = function() love.graphics.rectangle("fill", x, y, width, height) end - local loveversion = love._version local selfskin = self.skin local skin = skins[selfskin] or skins[skinindex] local drawfunc = skin.DrawTextInput or skins[defaultskin].DrawTextInput @@ -312,12 +297,7 @@ function newobject:draw() stencilfunc = function() love.graphics.rectangle("fill", x, y, width - 16, height - 16) end end - if loveversion == "0.8.0" then - local stencil = love.graphics.newStencil(stencilfunc) - love.graphics.setStencil(stencil) - else - love.graphics.setStencil(stencilfunc) - end + love.graphics.setStencil(stencilfunc) if draw then draw(self) @@ -454,10 +434,10 @@ function newobject:mousereleased(x, y, button) end --[[--------------------------------------------------------- - - func: keypressed(key) + - func: keypressed(key, isrepeat) - desc: called when the player presses a key --]]--------------------------------------------------------- -function newobject:keypressed(key, unicode) +function newobject:keypressed(key, isrepeat) local state = loveframes.state local selfstate = self.state @@ -477,7 +457,6 @@ function newobject:keypressed(key, unicode) local repeatdelay = self.repeatdelay local alltextselected = self.alltextselected local editable = self.editable - local version = love._version self.delay = time + repeatdelay self.keydown = key @@ -485,14 +464,14 @@ function newobject:keypressed(key, unicode) if (loveframes.util.IsCtrlDown()) and focus then if key == "a" then self.alltextselected = true - elseif key == "c" and alltextselected and version == "0.9.0" then + elseif key == "c" and alltextselected then local text = self:GetText() local oncopy = self.OnCopy love.system.setClipboardText(text) if oncopy then oncopy(self, text) end - elseif key == "x" and alltextselected and version == "0.9.0" and editable then + elseif key == "x" and alltextselected and editable then local text = self:GetText() local oncut = self.OnCut love.system.setClipboardText(text) @@ -501,16 +480,13 @@ function newobject:keypressed(key, unicode) else self:SetText("") end - elseif key == "v" and version == "0.9.0" and editable then + elseif key == "v" and editable then self:Paste() + else + self:RunKey(key, false) end else - local version = love._version - if version == "0.8.0" then - self:RunKey(key, unicode, true) - else - self:RunKey(key, unicode, false) - end + self:RunKey(key, false) end end @@ -543,25 +519,19 @@ end --]]--------------------------------------------------------- function newobject:textinput(text) - local unicode = unicode if text:find("kp.") then text = text:gsub("kp", "") end - if text:len() == 1 then - unicode = string.byte(text) - else - unicode = 0 - end - self:RunKey(text, unicode, true) + self:RunKey(text, true) end --[[--------------------------------------------------------- - - func: RunKey(key, unicode) + - func: RunKey(key, istext) - desc: runs a key event on the object --]]--------------------------------------------------------- -function newobject:RunKey(key, unicode, is_text) +function newobject:RunKey(key, istext) local visible = self.visible local focus = self.focus @@ -593,277 +563,264 @@ function newobject:RunKey(key, unicode, is_text) local ontextchanged = self.OnTextChanged local onenter = self.OnEnter - if key == "left" then - indicatornum = self.indicatornum - if not multiline then - self:MoveIndicator(-1) - local indicatorx = self.indicatorx - if indicatorx <= x and indicatornum ~= 0 then - local width = font:getWidth(text:sub(indicatornum, indicatornum + 1)) - self.offsetx = offsetx - width - elseif indicatornum == 0 and offsetx ~= 0 then - self.offsetx = 0 + if not istext then + if key == "left" then + indicatornum = self.indicatornum + if not multiline then + self:MoveIndicator(-1) + local indicatorx = self.indicatorx + if indicatorx <= x and indicatornum ~= 0 then + local width = font:getWidth(text:sub(indicatornum, indicatornum + 1)) + self.offsetx = offsetx - width + elseif indicatornum == 0 and offsetx ~= 0 then + self.offsetx = 0 + end + else + if indicatornum == 0 then + if line > 1 then + self.line = line - 1 + local numchars = #lines[self.line] + self:MoveIndicator(numchars) + end + else + self:MoveIndicator(-1) + end end - else - if indicatornum == 0 then + if alltextselected then + self.line = 1 + self.indicatornum = 0 + self.alltextselected = false + end + return + elseif key == "right" then + indicatornum = self.indicatornum + if not multiline then + self:MoveIndicator(1) + local indicatorx = self.indicatorx + if indicatorx >= (x + swidth) and indicatornum ~= #text then + local width = font:getWidth(text:sub(indicatornum, indicatornum)) + self.offsetx = offsetx + width + elseif indicatornum == #text and offsetx ~= ((font:getWidth(text)) - swidth + 10) and font:getWidth(text) + textoffsetx > swidth then + self.offsetx = ((font:getWidth(text)) - swidth + 10) + end + else + if indicatornum == #text then + if line < numlines then + self.line = line + 1 + self:MoveIndicator(0, true) + end + else + self:MoveIndicator(1) + end + end + if alltextselected then + self.line = #lines + self.indicatornum = lines[#lines]:len() + self.alltextselected = false + end + return + elseif key == "up" then + if multiline then if line > 1 then self.line = line - 1 - local numchars = #lines[self.line] - self:MoveIndicator(numchars) - end - else - self:MoveIndicator(-1) - end - end - if alltextselected then - self.line = 1 - self.indicatornum = 0 - self.alltextselected = false - end - return - elseif key == "right" then - indicatornum = self.indicatornum - if not multiline then - self:MoveIndicator(1) - local indicatorx = self.indicatorx - if indicatorx >= (x + swidth) and indicatornum ~= #text then - local width = font:getWidth(text:sub(indicatornum, indicatornum)) - self.offsetx = offsetx + width - elseif indicatornum == #text and offsetx ~= ((font:getWidth(text)) - swidth + 10) and font:getWidth(text) + textoffsetx > swidth then - self.offsetx = ((font:getWidth(text)) - swidth + 10) - end - else - if indicatornum == #text then - if line < numlines then - self.line = line + 1 - self:MoveIndicator(0, true) - end - else - self:MoveIndicator(1) - end - end - if alltextselected then - self.line = #lines - self.indicatornum = lines[#lines]:len() - self.alltextselected = false - end - return - elseif key == "up" then - if multiline then - if line > 1 then - self.line = line - 1 - if indicatornum > #lines[self.line] then - self.indicatornum = #lines[self.line] - end - end - end - return - elseif key == "down" then - if multiline then - if line < #lines then - self.line = line + 1 - if indicatornum > #lines[self.line] then - self.indicatornum = #lines[self.line] - end - end - end - return - end - - if not editable then - return - end - - -- key input checking system - if key == "backspace" then - ckey = key - if alltextselected then - self:Clear() - self.alltextselected = false - indicatornum = self.indicatornum - else - if text ~= "" and indicatornum ~= 0 then - text = self:RemoveFromText(indicatornum) - self:MoveIndicator(-1) - lines[line] = text - end - if multiline then - if line > 1 and indicatornum == 0 then - local newindicatornum = 0 - local oldtext = lines[line] - table.remove(lines, line) - self.line = line - 1 - if #oldtext > 0 then - newindicatornum = #lines[self.line] - lines[self.line] = lines[self.line] .. oldtext - self:MoveIndicator(newindicatornum) - else - self:MoveIndicator(#lines[self.line]) + if indicatornum > #lines[self.line] then + self.indicatornum = #lines[self.line] end end end - local masked = self.masked - local cwidth = 0 - if masked then - local maskchar = self.maskchar - cwidth = font:getWidth(text:sub(#text):gsub(".", maskchar)) - else - cwidth = font:getWidth(text:sub(#text)) - end - if self.offsetx > 0 then - self.offsetx = self.offsetx - cwidth - elseif self.offsetx < 0 then - self.offsetx = 0 + return + elseif key == "down" then + if multiline then + if line < #lines then + self.line = line + 1 + if indicatornum > #lines[self.line] then + self.indicatornum = #lines[self.line] + end + end end + return end - elseif key == "delete" then + if not editable then return end - ckey = key - if alltextselected then - self:Clear() - self.alltextselected = false - indicatornum = self.indicatornum - else - if text ~= "" and indicatornum < #text then - text = self:RemoveFromText(indicatornum + 1) - lines[line] = text - elseif indicatornum == #text and line < #lines then - local oldtext = lines[line + 1] - if #oldtext > 0 then - newindicatornum = #lines[self.line] - lines[self.line] = lines[self.line] .. oldtext - end - table.remove(lines, line + 1) - end - end - elseif key == "return" or key == "kpenter" then - ckey = key - -- call onenter if it exists - if onenter then - onenter(self, text) - end - -- newline calculations for multiline mode - if multiline then + + -- key input checking system + if key == "backspace" then + ckey = key if alltextselected then - self.alltextselected = false self:Clear() + self.alltextselected = false indicatornum = self.indicatornum - line = self.line - end - local newtext = "" - if indicatornum == 0 then - newtext = self.lines[line] - self.lines[line] = "" - elseif indicatornum > 0 and indicatornum < #self.lines[line] then - newtext = self.lines[line]:sub(indicatornum + 1, #self.lines[line]) - self.lines[line] = self.lines[line]:sub(1, indicatornum) - end - if line ~= #lines then - table.insert(self.lines, line + 1, newtext) - self.line = line + 1 else - table.insert(self.lines, newtext) - self.line = line + 1 - end - self.indicatornum = 0 - end - elseif key == "tab" then - ckey = key - for i=1, #self.tabreplacement do - local number = string.byte(self.tabreplacement:sub(i, i)) - self.lines[self.line] = self:AddIntoText(number, self.indicatornum) - self:MoveIndicator(1) - end - else - if not is_text then - return - end - self.unicode = unicode - if unicode > 31 and unicode < 127 then - -- do not continue if the text limit has been reached or exceeded - if #text >= self.limit and self.limit ~= 0 and not alltextselected then - return - end - -- set the current key - ckey = string.char(unicode) - -- check for unusable characters - if #self.usable > 0 then - local found = false - for k, v in ipairs(self.usable) do - if v == ckey then - found = true + if text ~= "" and indicatornum ~= 0 then + text = self:RemoveFromText(indicatornum) + self:MoveIndicator(-1) + lines[line] = text + end + if multiline then + if line > 1 and indicatornum == 0 then + local newindicatornum = 0 + local oldtext = lines[line] + table.remove(lines, line) + self.line = line - 1 + if #oldtext > 0 then + newindicatornum = #lines[self.line] + lines[self.line] = lines[self.line] .. oldtext + self:MoveIndicator(newindicatornum) + else + self:MoveIndicator(#lines[self.line]) + end end end - if not found then - return - end - end - -- check for usable characters - if #self.unusable > 0 then - local found = false - for k, v in ipairs(self.unusable) do - if v == ckey then - found = true - end - end - if found then - return - end - end - if alltextselected then - self.alltextselected = false - self:Clear() - indicatornum = self.indicatornum - text = "" - lines = self.lines - line = self.line - end - if indicatornum ~= 0 and indicatornum ~= #text then - text = self:AddIntoText(unicode, indicatornum) - lines[line] = text - self:MoveIndicator(1) - elseif indicatornum == #text then - text = text .. ckey - lines[line] = text - self:MoveIndicator(1) - elseif indicatornum == 0 then - text = self:AddIntoText(unicode, indicatornum) - lines[line] = text - self:MoveIndicator(1) - end - lines = self.lines - line = self.line - curline = lines[line] - text = curline - if not multiline then local masked = self.masked - local twidth = 0 local cwidth = 0 if masked then local maskchar = self.maskchar - twidth = font:getWidth(text:gsub(".", maskchar)) - cwidth = font:getWidth(ckey:gsub(".", maskchar)) + cwidth = font:getWidth(text:sub(#text):gsub(".", maskchar)) else - twidth = font:getWidth(text) - cwidth = font:getWidth(ckey) + cwidth = font:getWidth(text:sub(#text)) end - -- swidth - 1 is for the "-" character - if (twidth + textoffsetx) >= (swidth - 1) then - self.offsetx = self.offsetx + cwidth + if self.offsetx > 0 then + self.offsetx = self.offsetx - cwidth + elseif self.offsetx < 0 then + self.offsetx = 0 end end + elseif key == "delete" then + if not editable then + return + end + ckey = key + if alltextselected then + self:Clear() + self.alltextselected = false + indicatornum = self.indicatornum + else + if text ~= "" and indicatornum < #text then + text = self:RemoveFromText(indicatornum + 1) + lines[line] = text + elseif indicatornum == #text and line < #lines then + local oldtext = lines[line + 1] + if #oldtext > 0 then + newindicatornum = #lines[self.line] + lines[self.line] = lines[self.line] .. oldtext + end + table.remove(lines, line + 1) + end + end + elseif key == "return" or key == "kpenter" then + ckey = key + -- call onenter if it exists + if onenter then + onenter(self, text) + end + -- newline calculations for multiline mode + if multiline then + if alltextselected then + self.alltextselected = false + self:Clear() + indicatornum = self.indicatornum + line = self.line + end + local newtext = "" + if indicatornum == 0 then + newtext = self.lines[line] + self.lines[line] = "" + elseif indicatornum > 0 and indicatornum < #self.lines[line] then + newtext = self.lines[line]:sub(indicatornum + 1, #self.lines[line]) + self.lines[line] = self.lines[line]:sub(1, indicatornum) + end + if line ~= #lines then + table.insert(self.lines, line + 1, newtext) + self.line = line + 1 + else + table.insert(self.lines, newtext) + self.line = line + 1 + end + self.indicatornum = 0 + end + elseif key == "tab" then + ckey = key + self.lines[self.line] = self:AddIntoText(self.tabreplacement, self.indicatornum) + self:MoveIndicator(#self.tabreplacement) + end + else + -- do not continue if the text limit has been reached or exceeded + if #text >= self.limit and self.limit ~= 0 and not alltextselected then + return + end + -- check for unusable characters + if #self.usable > 0 then + local found = false + for k, v in ipairs(self.usable) do + if v == key then + found = true + end + end + if not found then + return + end + end + -- check for usable characters + if #self.unusable > 0 then + local found = false + for k, v in ipairs(self.unusable) do + if v == key then + found = true + end + end + if found then + return + end + end + if alltextselected then + self.alltextselected = false + self:Clear() + indicatornum = self.indicatornum + text = "" + lines = self.lines + line = self.line + end + if indicatornum ~= 0 and indicatornum ~= #text then + text = self:AddIntoText(key, indicatornum) + lines[line] = text + self:MoveIndicator(1) + elseif indicatornum == #text then + text = text .. key + lines[line] = text + self:MoveIndicator(1) + elseif indicatornum == 0 then + text = self:AddIntoText(key, indicatornum) + lines[line] = text + self:MoveIndicator(1) + end + lines = self.lines + line = self.line + curline = lines[line] + text = curline + if not multiline then + local masked = self.masked + local twidth = 0 + local cwidth = 0 + if masked then + local maskchar = self.maskchar + twidth = font:getWidth(text:gsub(".", maskchar)) + cwidth = font:getWidth(key:gsub(".", maskchar)) + else + twidth = font:getWidth(text) + cwidth = font:getWidth(key) + end + -- swidth - 1 is for the "-" character + if (twidth + textoffsetx) >= (swidth - 1) then + self.offsetx = self.offsetx + cwidth + end end - end - - if love._version == "0.9.0" then - self.unicode = 0 end local curtext = self:GetText() if ontextchanged and initialtext ~= curtext then - ontextchanged(self, ckey) + ontextchanged(self, key) end return self @@ -975,7 +932,7 @@ function newobject:AddIntoText(t, p) local text = curline local part1 = text:sub(1, p) local part2 = text:sub(p + 1) - local new = part1 .. string.char(t) .. part2 + local new = part1 .. t .. part2 return new @@ -1833,12 +1790,8 @@ end --]]--------------------------------------------------------- function newobject:Copy() - local version = love._version - - if version == "0.9.0" then - local text = self:GetText() - love.system.setClipboardText(text) - end + local text = self:GetText() + love.system.setClipboardText(text) return self