accept keyboard input after focusing using the mouse

This commit is contained in:
Kartik K. Agaram 2023-11-16 01:06:58 -08:00
parent aba35638a5
commit 3d16454dcd
7 changed files with 34 additions and 2 deletions

View File

@ -1,8 +1,8 @@
draw_sum_grid = function(g)
-- lines
love.graphics.setLineWidth(3)
local x1,y1 = 250,200
local x2,y2 = 450,400
local x1,y1 = X,Y
local x2,y2 = X+Square_side*2, Y+Square_side*2
love.graphics.line(x1,y1, x2,y1)
love.graphics.line(x1,y2, x2,y2)
love.graphics.line(x1,y1, x1,y2)

View File

@ -9,5 +9,20 @@ on.keychord_press = function(chord, key)
elseif Draw == 'solution' then
Draw = 'problem'
end
elseif chord:match('%d') then
-- cursor visible
local x,y = Cursor[1], Cursor[2]
if x > 0 and y > 0 then
-- it's not in the provided square
if x ~= Problem.x or y ~= Problem.y then
local c = Problem.data[y][x]
local d = (string.byte(chord) - 48)
if c == '' then
Problem.data[y][x] = d
elseif c < 2 then -- not overfull
Problem.data[y][x] = Problem.data[y][x]*10 + d
end
end
end
end
end

View File

@ -11,4 +11,5 @@ create_problem = function()
local x = math.random(1, 2)
local y = math.random(1, 2)
Problem.data[y][x] = s.data[y][x]
Problem.x, Problem.y = x, y
end

1
0029-Cursor Normal file
View File

@ -0,0 +1 @@
Cursor = {0, 0} -- x, y coordinate

1
0030-X Normal file
View File

@ -0,0 +1 @@
X = 250

1
0031-Y Normal file
View File

@ -0,0 +1 @@
Y = 200

13
0032-on.mouse_press Normal file
View File

@ -0,0 +1,13 @@
on.mouse_press = function(x,y, mouse_button)
if x >= X and x < X+Square_side and y >= Y and y < Y+Square_side then
Cursor = {1, 1}
elseif x >= X+Square_side and x < X+Square_side*2 and y >= Y and y < Y+Square_side then
Cursor = {2, 1}
elseif x >= X and x < X+Square_side and y >= Y+Square_side and y < Y+Square_side*2 then
Cursor = {1, 2}
elseif x >= X+Square_side and x < X+Square_side*2 and y >= Y+Square_side and y < Y+Square_side*2 then
Cursor = {2, 2}
else
Cursor = {0, 0} -- invalid
end
end