From 935c91f0426852bdcc4a90facb9d4d2afb92d177 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Mon, 4 Nov 2013 21:51:23 +0100 Subject: Fix #9: Default input style and the scissor state. Better late than never - thanks Boolsheet! --- style-default.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/style-default.lua b/style-default.lua index b1e5d4d..e970d7a 100644 --- a/style-default.lua +++ b/style-default.lua @@ -127,7 +127,18 @@ local function Input(state, text, cursor, x,y,w,h) local cursorPos = x + 2 + f:getWidth(text:sub(1,cursor)) local offset = 2 - math.floor((cursorPos-x) / (w-4)) * (w-4) - love.graphics.setScissor(x+1,y,w-2,h) + local tsx,tsy,tsw,tsh = x+1, y, w-2, h + local sx,sy,sw,sh = love.graphics.getScissor() + if sx then -- intersect current scissors with our's + local l,r = math.max(sx, tsx), math.min(sx+sw, tsx+tsw) + local t,b = math.max(sy, tsy), math.min(sy+sh, tsy+tsh) + if l > r or t > b then -- there is no intersection + return + end + tsx, tsy, tsw, tsh = l, t, r-l, b-t + end + + love.graphics.setScissor(tsx, tsy, tsw, tsh) love.graphics.setLine(1, 'rough') love.graphics.setColor(color.normal.fg) love.graphics.print(text, x+offset,y+(h-th)/2) @@ -135,7 +146,11 @@ local function Input(state, text, cursor, x,y,w,h) love.graphics.setColor(color.active.fg) love.graphics.line(cursorPos+offset, y+4, cursorPos+offset, y+h-4) end - love.graphics.setScissor() + if sx then + love.graphics.setScissor(sx,sy,sw,sh) + else + love.graphics.setScissor() + end end local function Checkbox(state, checked, label, align, x,y,w,h) -- cgit v1.2.3-54-g00ecf