feat: make the cursor part of texture
This commit is contained in:
parent
af23416c4e
commit
5c5b551d8d
6 changed files with 32 additions and 6 deletions
|
@ -16,6 +16,8 @@ function CanvasElement:initCanvas()
|
||||||
self.canvas.texture = nil
|
self.canvas.texture = nil
|
||||||
self.canvas.isAnimated = false
|
self.canvas.isAnimated = false
|
||||||
self.canvas.padding = 8
|
self.canvas.padding = 8
|
||||||
|
self.canvas.final = nil
|
||||||
|
self.canvas.dual = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function CanvasElement:updateElement(dt)
|
function CanvasElement:updateElement(dt)
|
||||||
|
@ -30,6 +32,18 @@ function CanvasElement:redraw()
|
||||||
if (self.canvas.needRedraw or self.canvas.isAnimated) then
|
if (self.canvas.needRedraw or self.canvas.isAnimated) then
|
||||||
self:generateTexture()
|
self:generateTexture()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (self.canvas.dual) then
|
||||||
|
local w, h = self:getDimensions()
|
||||||
|
local canvas = love.graphics.newCanvas(w + (self.canvas.padding*2), h + (self.canvas.padding*2))
|
||||||
|
love.graphics.setCanvas(canvas)
|
||||||
|
|
||||||
|
love.graphics.draw(self.canvas.texture, 0, 0)
|
||||||
|
self:drawFinalTexture()
|
||||||
|
|
||||||
|
self.canvas.final = canvas
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function CanvasElement:generateTexture()
|
function CanvasElement:generateTexture()
|
||||||
|
@ -55,6 +69,10 @@ function CanvasElement:drawTexture()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CanvasElement:drawFinalTexture()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
function CanvasElement:parseOrigin(origin, size)
|
function CanvasElement:parseOrigin(origin, size)
|
||||||
if (origin == "center") then
|
if (origin == "center") then
|
||||||
return size/2
|
return size/2
|
||||||
|
@ -67,7 +85,11 @@ end
|
||||||
|
|
||||||
function CanvasElement:draw()
|
function CanvasElement:draw()
|
||||||
love.graphics.setColor(1, 1, 1, self.opacity)
|
love.graphics.setColor(1, 1, 1, self.opacity)
|
||||||
love.graphics.draw(self.canvas.texture, self.x - self.canvas.padding,self.y - self.canvas.padding,self.r,self.sx,self.sy,self.ox,self.oy)
|
local texture = self.canvas.texture
|
||||||
|
if (self.canvas.dual) then
|
||||||
|
texture = self.canvas.final
|
||||||
|
end
|
||||||
|
love.graphics.draw(texture, self.x - self.canvas.padding,self.y - self.canvas.padding,self.r,self.sx,self.sy,self.ox,self.oy)
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ function FlowBox:getGraphicalCursorPosition()
|
||||||
local col, line = self.view:getCoord(self.widget:getSelected())
|
local col, line = self.view:getCoord(self.widget:getSelected())
|
||||||
local x = (col) * h
|
local x = (col) * h
|
||||||
local y = (line - beginline) * h
|
local y = (line - beginline) * h
|
||||||
return self.x + x, self.y + y, w, h
|
return x, y, w, h
|
||||||
end
|
end
|
||||||
|
|
||||||
return FlowBox
|
return FlowBox
|
||||||
|
|
|
@ -273,7 +273,7 @@ function GridBox:drawCursor()
|
||||||
local w, h = self:getWidgetSize(slot)
|
local w, h = self:getWidgetSize(slot)
|
||||||
local x = self.slots[slot].x * self.widgetSize.w
|
local x = self.slots[slot].x * self.widgetSize.w
|
||||||
local y = self.slots[slot].y * self.widgetSize.h
|
local y = self.slots[slot].y * self.widgetSize.h
|
||||||
self:drawGraphicalCursor(self.x + x, self.y + y, w, h)
|
self:drawGraphicalCursor(x, y, w, h)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ function HListBox:getGraphicalCursorPosition()
|
||||||
local w, h = self:getWidgetSize()
|
local w, h = self:getWidgetSize()
|
||||||
local x = (self.widget:getSelected() - self.view.firstSlot) * w
|
local x = (self.widget:getSelected() - self.view.firstSlot) * w
|
||||||
|
|
||||||
return self.x + x,self.y, w, h
|
return x, 0, w, h
|
||||||
end
|
end
|
||||||
|
|
||||||
return HListBox
|
return HListBox
|
||||||
|
|
|
@ -108,7 +108,7 @@ end
|
||||||
function ListBox:getGraphicalCursorPosition()
|
function ListBox:getGraphicalCursorPosition()
|
||||||
local x, y, w, h = self:getListPart(self.widget:getSelected() - self.view.firstSlot)
|
local x, y, w, h = self:getListPart(self.widget:getSelected() - self.view.firstSlot)
|
||||||
|
|
||||||
return self.x - self.ox + x,self.y + y - self.oy, w, h
|
return self:getListPart(self.widget:getSelected() - self.view.firstSlot)
|
||||||
end
|
end
|
||||||
|
|
||||||
return ListBox
|
return ListBox
|
||||||
|
|
|
@ -43,6 +43,7 @@ function Menu:new(name, x, y, w, h)
|
||||||
|
|
||||||
self:initCanvas()
|
self:initCanvas()
|
||||||
self.cancelFunc = nil
|
self.cancelFunc = nil
|
||||||
|
self.canvas.dual = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- FUNCTIONS FUNCTIONS
|
-- FUNCTIONS FUNCTIONS
|
||||||
|
@ -180,9 +181,12 @@ end
|
||||||
|
|
||||||
function Menu:drawElement()
|
function Menu:drawElement()
|
||||||
self:draw()
|
self:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Menu:drawFinalTexture()
|
||||||
if (self:haveFocus()) then
|
if (self:haveFocus()) then
|
||||||
local x, y, w, h = self:getGraphicalCursorPosition()
|
local x, y, w, h = self:getGraphicalCursorPosition()
|
||||||
self:drawGraphicalCursor(x, y, w, h)
|
self:drawGraphicalCursor(self.canvas.padding + x, self.canvas.padding + y, w, h)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue