Commits

Marek Kubica committed b5507e7

Fixed keyboard input

Still missing proper repeation detection but it runs kinda alright now.

Comments (0)

Files changed (2)

+# HG changeset patch
+# Parent 76d1ae890cefd8b531cf894675daa89c55fc4a8a
+
+diff --git a/zoetrope/input/keys.lua b/zoetrope/input/keys.lua
+--- a/zoetrope/input/keys.lua
++++ b/zoetrope/input/keys.lua
+@@ -44,6 +44,7 @@
+ 		the.keys = obj
+ 		love.keypressed = function (key, unicode) obj:keyPressed(key, unicode) end
+ 		love.keyreleased = function (key, unicode) obj:keyReleased(key, unicode) end
++		love.textinput = function (text) obj:textInput(text) end
+ 		if obj.onNew then obj:onNew() end
+ 		return obj
+ 	end,
+@@ -217,11 +218,11 @@
+ 
+ 	-- Connects to the love.keypressed callback
+ 
+-	keyPressed = function (self, key, unicode)
++	keyPressed = function (self, key, isrepeat)
+ 		self._thisFrame[key] = true
+-		if unicode and unicode >= 0x20 and unicode ~= 127 and unicode < 0x3000 then
+-			self.typed = self.typed .. self:unicodeChar(unicode)
+-		end
++		--if unicode and unicode >= 0x20 and unicode ~= 127 and unicode < 0x3000 then
++		--	self.typed = self.typed .. self:unicodeChar(unicode)
++		--end
+ 
+ 		-- aliases for modifiers
+ 
+@@ -234,6 +235,12 @@
+ 		end
+ 	end,
+ 
++	-- Connects to the love.textinput callback
++
++	textInput = function (self, text)
++		self.typed = self.typed .. text
++	end,
++
+ 	-- Connects to the love.keyreleased callback
+ 
+ 	keyReleased = function (self, key, unicode)
+diff --git a/zoetrope/sprites/tile.lua b/zoetrope/sprites/tile.lua
+--- a/zoetrope/sprites/tile.lua
++++ b/zoetrope/sprites/tile.lua
+@@ -94,7 +94,7 @@
+ 		if self.flipX then scaleX = scaleX * -1 end
+ 		if self.flipY then scaleY = scaleY * -1 end
+ 
+-		love.graphics.drawq(self._imageObj, self._quad, x + origX, y + origY, self.rotation,
++		love.graphics.draw(self._imageObj, self._quad, x + origX, y + origY, self.rotation,
+ 							scaleX, scaleY, origX, origY)
+ 		
+ 		-- reset color
+diff --git a/zoetrope/ui/textinput.lua b/zoetrope/ui/textinput.lua
+--- a/zoetrope/ui/textinput.lua
++++ b/zoetrope/ui/textinput.lua
+@@ -67,35 +67,16 @@
+ 			-- handle movement keys that repeat
+ 			-- we have to simulate repeat rates manually :(
+ 
+-			local delay, rate = love.keyboard.getKeyRepeat()
++			-- TODO: fix repeating keys
+ 			local frameAction
+ 
+ 			for _, key in pairs{'backspace', 'delete', 'left', 'right'} do
+ 				if the.keys:pressed(key) then
+-					if self._repeatKey == key then
+-						self._repeatTimer = self._repeatTimer + elapsed
+-						
+-						-- if we've made it past the maximum delay, then
+-						-- we reset the timer and take action
+-
+-						if self._repeatTimer > delay + rate then
+-							self._repeatTimer = delay
+-							frameAction = key
+-						end
+-					else
+-						-- we've just started holding down the key
+-
+-						self._repeatKey = key
+-						self._repeatTimer = 0
+-						frameAction = key
+-					end
+-				else
+-					if self._repeatKey == key then
+-						self._repeatKey = nil
+-					end
++					frameAction = key
+ 				end
+ 			end
+ 
++
+ 			if frameAction == 'backspace' and self.caret > 0 then
+ 				self.text = string.sub(self.text, 1, self.caret - 1) .. string.sub(self.text, self.caret + 1)
+ 				self.caret = self.caret - 1
 love-0.9-init
+love-0.9-keys
 # Placed by Bitbucket