mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-09 15:58:22 +00:00
Text widget: intersect scissor.
Fixes a visual bug where text would display outside widget boundary. Mved intersectScissor to Backend.
This commit is contained in:
@@ -1,8 +1,27 @@
|
|||||||
local ROOT = (...):gsub('[^.]*$', '')
|
local ROOT = (...):gsub('[^.]*$', '')
|
||||||
|
local Backend
|
||||||
|
|
||||||
if _G.love and _G.love._version_minor > 8 then
|
if _G.love and _G.love._version_minor > 8 then
|
||||||
return require(ROOT .. 'backend.love')
|
Backend = require(ROOT .. 'backend.love')
|
||||||
else
|
else
|
||||||
return require(ROOT .. 'backend.ffisdl')
|
Backend = require(ROOT .. 'backend.ffisdl')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Backend.intersectScissor = Backend.intersectScissor or function (x, y, w, h)
|
||||||
|
local sx, sy, sw, sh = Backend.getScissor()
|
||||||
|
if not sx then
|
||||||
|
return Backend.setScissor(x, y, w, h)
|
||||||
|
end
|
||||||
|
local x1 = math.max(sx, x)
|
||||||
|
local y1 = math.max(sy, y)
|
||||||
|
local x2 = math.min(sx + sw, x + w)
|
||||||
|
local y2 = math.min(sy + sh, y + h)
|
||||||
|
if x2 > x1 and y2 > y1 then
|
||||||
|
Backend.setScissor(x1, y1, x2 - x1, y2 - y1)
|
||||||
|
else
|
||||||
|
-- HACK
|
||||||
|
Backend.setScissor(-100, -100, 1, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return Backend
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ Backend.setClipboardText = love.system.setClipboardText
|
|||||||
|
|
||||||
Backend.getMousePosition = love.mouse.getPosition
|
Backend.getMousePosition = love.mouse.getPosition
|
||||||
|
|
||||||
Backend.getMousePosition = love.mouse.getPosition
|
Backend.setMousePosition = love.mouse.setPosition
|
||||||
|
|
||||||
Backend.getSystemCursor = love.mouse.getSystemCursor
|
Backend.getSystemCursor = love.mouse.getSystemCursor
|
||||||
|
|
||||||
@@ -79,6 +79,8 @@ Backend.setScissor = love.graphics.setScissor
|
|||||||
|
|
||||||
Backend.getScissor = love.graphics.getScissor
|
Backend.getScissor = love.graphics.getScissor
|
||||||
|
|
||||||
|
Backend.intersectScissor = love.graphics.intersectScissor
|
||||||
|
|
||||||
function Backend.hide (layout)
|
function Backend.hide (layout)
|
||||||
for _, item in ipairs(layout.hooks) do
|
for _, item in ipairs(layout.hooks) do
|
||||||
Hooker.unhook(item)
|
Hooker.unhook(item)
|
||||||
|
|||||||
@@ -11,23 +11,6 @@ local Painter = Base:extend()
|
|||||||
local imageCache = {}
|
local imageCache = {}
|
||||||
-- local sliceCache = {}
|
-- local sliceCache = {}
|
||||||
|
|
||||||
local function intersectScissor (x, y, w, h)
|
|
||||||
local sx, sy, sw, sh = Backend.getScissor()
|
|
||||||
if not sx then
|
|
||||||
return Backend.setScissor(x, y, w, h)
|
|
||||||
end
|
|
||||||
local x1 = math.max(sx, x)
|
|
||||||
local y1 = math.max(sy, y)
|
|
||||||
local x2 = math.min(sx + sw, x + w)
|
|
||||||
local y2 = math.min(sy + sh, y + h)
|
|
||||||
if x2 > x1 and y2 > y1 then
|
|
||||||
Backend.setScissor(x1, y1, x2 - x1, y2 - y1)
|
|
||||||
else
|
|
||||||
-- HACK
|
|
||||||
Backend.setScissor(-100, -100, 1, 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Painter:constructor (widget)
|
function Painter:constructor (widget)
|
||||||
self.widget = widget
|
self.widget = widget
|
||||||
end
|
end
|
||||||
@@ -198,7 +181,7 @@ function Painter:paintIconAndText ()
|
|||||||
|
|
||||||
Backend.push()
|
Backend.push()
|
||||||
|
|
||||||
intersectScissor(x, y, w, h)
|
Backend.intersectScissor(x, y, w, h)
|
||||||
|
|
||||||
-- draw the icon
|
-- draw the icon
|
||||||
if icon then
|
if icon then
|
||||||
@@ -237,7 +220,7 @@ function Painter:paint ()
|
|||||||
Backend.push()
|
Backend.push()
|
||||||
|
|
||||||
if widget.parent then
|
if widget.parent then
|
||||||
intersectScissor(x, y, w, h)
|
Backend.intersectScissor(x, y, w, h)
|
||||||
else
|
else
|
||||||
Backend.setScissor()
|
Backend.setScissor()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ This color is used to indicate the selected range of text.
|
|||||||
local textTop = math.floor(y + (h - font:getLineHeight()) / 2)
|
local textTop = math.floor(y + (h - font:getLineHeight()) / 2)
|
||||||
|
|
||||||
Backend.push()
|
Backend.push()
|
||||||
Backend.setScissor(x, y, w, h)
|
Backend.intersectScissor(x, y, w, h)
|
||||||
Backend.setFont(font)
|
Backend.setFont(font)
|
||||||
|
|
||||||
if self.focused then
|
if self.focused then
|
||||||
|
|||||||
Reference in New Issue
Block a user