Refonte pour utiliser le systeme de GUI #112
6 changed files with 32 additions and 6 deletions
|
@ -16,6 +16,8 @@ function CanvasElement:initCanvas()
|
|||
self.canvas.texture = nil
|
||||
self.canvas.isAnimated = false
|
||||
self.canvas.padding = 8
|
||||
self.canvas.final = nil
|
||||
self.canvas.dual = false
|
||||
end
|
||||
|
||||
function CanvasElement:updateElement(dt)
|
||||
|
@ -30,6 +32,18 @@ function CanvasElement:redraw()
|
|||
if (self.canvas.needRedraw or self.canvas.isAnimated) then
|
||||
self:generateTexture()
|
||||
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
|
||||
|
||||
function CanvasElement:generateTexture()
|
||||
|
@ -55,6 +69,10 @@ function CanvasElement:drawTexture()
|
|||
|
||||
end
|
||||
|
||||
function CanvasElement:drawFinalTexture()
|
||||
|
||||
end
|
||||
|
||||
function CanvasElement:parseOrigin(origin, size)
|
||||
if (origin == "center") then
|
||||
return size/2
|
||||
|
@ -67,7 +85,11 @@ end
|
|||
|
||||
function CanvasElement:draw()
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ function FlowBox:getGraphicalCursorPosition()
|
|||
local col, line = self.view:getCoord(self.widget:getSelected())
|
||||
local x = (col) * h
|
||||
local y = (line - beginline) * h
|
||||
return self.x + x, self.y + y, w, h
|
||||
return x, y, w, h
|
||||
end
|
||||
|
||||
return FlowBox
|
||||
|
|
|
@ -273,7 +273,7 @@ function GridBox:drawCursor()
|
|||
local w, h = self:getWidgetSize(slot)
|
||||
local x = self.slots[slot].x * self.widgetSize.w
|
||||
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
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ function HListBox:getGraphicalCursorPosition()
|
|||
local w, h = self:getWidgetSize()
|
||||
local x = (self.widget:getSelected() - self.view.firstSlot) * w
|
||||
|
||||
return self.x + x,self.y, w, h
|
||||
return x, 0, w, h
|
||||
end
|
||||
|
||||
return HListBox
|
||||
|
|
|
@ -108,7 +108,7 @@ end
|
|||
function ListBox:getGraphicalCursorPosition()
|
||||
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
|
||||
|
||||
return ListBox
|
||||
|
|
|
@ -43,6 +43,7 @@ function Menu:new(name, x, y, w, h)
|
|||
|
||||
self:initCanvas()
|
||||
self.cancelFunc = nil
|
||||
self.canvas.dual = true
|
||||
end
|
||||
|
||||
-- FUNCTIONS FUNCTIONS
|
||||
|
@ -180,9 +181,12 @@ end
|
|||
|
||||
function Menu:drawElement()
|
||||
self:draw()
|
||||
end
|
||||
|
||||
function Menu:drawFinalTexture()
|
||||
if (self:haveFocus()) then
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue