core/menusystem: new size variable for widget handling
This commit is contained in:
parent
05c8691c56
commit
bf77a06741
5 changed files with 50 additions and 43 deletions
|
@ -9,10 +9,10 @@ function FlowBox:new(x,y,w,h,slots_hor,slots_vert)
|
|||
self.slots_hor = slots_hor
|
||||
self.slots_vert = slots_vert
|
||||
self.begin = 1
|
||||
self.widgetsH = math.floor( self.h / slots_vert )
|
||||
self.widgetsW = math.floor( self.w / slots_hor )
|
||||
self.h = slots_vert * self.widgetsH -- On fait en sorte que la hauteur
|
||||
self.w = slots_hor * self.widgetsW -- et la largeur
|
||||
self.widget.h = math.floor( self.h / slots_vert )
|
||||
self.widget.w = math.floor( self.w / slots_hor )
|
||||
self.h = slots_vert * self.widget.h -- On fait en sorte que la hauteur
|
||||
self.w = slots_hor * self.widget.w -- et la largeur
|
||||
-- soit un multiple du nombre de slot et de leur dimensions
|
||||
end
|
||||
|
||||
|
@ -109,8 +109,8 @@ function FlowBox:mousemoved(x, y)
|
|||
local begincol, beginline = self:getCoord(self.begin)
|
||||
local newcol, newline
|
||||
|
||||
newline = beginline + math.floor(y / self.widgetsH)
|
||||
newcol = math.floor(x / self.widgetsW)
|
||||
newline = beginline + math.floor(y / self.widget.h)
|
||||
newcol = math.floor(x / self.widget.w)
|
||||
self.widget.selected = (newline * self.slots_hor) + newcol + 1
|
||||
|
||||
if self.widget.selected < 1 then
|
||||
|
@ -126,8 +126,8 @@ function FlowBox:mousepressed(x, y, button, isTouch)
|
|||
local begincol, beginline = self:getCoord(self.begin)
|
||||
local newline, newcol
|
||||
|
||||
newline = beginline + math.floor(y / self.widgetsH)
|
||||
newcol = math.floor(x / self.widgetsW)
|
||||
newline = beginline + math.floor(y / self.widget.h)
|
||||
newcol = math.floor(x / self.widget.w)
|
||||
self.widget.selected = (newline * self.slots_hor) + newcol + 1
|
||||
|
||||
if self.widget.selected < 1 then
|
||||
|
@ -147,16 +147,16 @@ function FlowBox:draw()
|
|||
local widgetx = self.x
|
||||
for i,v in ipairs(self.widget.list) do
|
||||
if (i >= self.begin) and (i < self.begin + self.slots) then
|
||||
v:draw(widgetx, widgety, self.widgetsW, self.widgetsH)
|
||||
v:draw(widgetx, widgety, self.widget.w, self.widget.h)
|
||||
if self.widget.selected == i and self.focus == true then
|
||||
v:drawSelected(widgetx, widgety, self.widgetsW, self.widgetsH)
|
||||
v:drawSelected(widgetx, widgety, self.widget.w, self.widget.h)
|
||||
else
|
||||
v:draw(widgetx, widgety, self.widgetsW, self.widgetsH)
|
||||
v:draw(widgetx, widgety, self.widget.w, self.widget.h)
|
||||
end
|
||||
widgetx = widgetx + self.widgetsW
|
||||
widgetx = widgetx + self.widget.w
|
||||
if widgetx == (self.x + self.w) then
|
||||
widgetx = self.x
|
||||
widgety = widgety + self.widgetsH
|
||||
widgety = widgety + self.widget.h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,10 +10,10 @@ function GridBox:new(x,y,w,h,slots_hor,slots_vert)
|
|||
self.slots_hor = slots_hor
|
||||
self.slots_vert = slots_vert
|
||||
self.begin = 1
|
||||
self.widgetsH = math.floor( self.h / slots_vert )
|
||||
self.widgetsW = math.floor( self.w / slots_hor )
|
||||
self.h = slots_vert * self.widgetsH -- On fait en sorte que la hauteur
|
||||
self.w = slots_hor * self.widgetsW -- et la largeur
|
||||
self.widget.h = math.floor( self.h / slots_vert )
|
||||
self.widget.w = math.floor( self.w / slots_hor )
|
||||
self.h = slots_vert * self.widget.h -- On fait en sorte que la hauteur
|
||||
self.w = slots_hor * self.widget.w -- et la largeur
|
||||
-- soit un multiple du nombre de slot et de leur dimensions
|
||||
self.cursor = {}
|
||||
self.cursor.x = 0
|
||||
|
@ -158,8 +158,8 @@ function GridBox:mousemoved(x, y)
|
|||
local newcol, newline
|
||||
local newselect, slotID
|
||||
|
||||
newline = beginline + math.floor(y / self.widgetsH)
|
||||
newcol = math.floor(x / self.widgetsW)
|
||||
newline = beginline + math.floor(y / self.widget.h)
|
||||
newcol = math.floor(x / self.widget.w)
|
||||
self.cursor.x = newcol
|
||||
self.cursor.y = newline
|
||||
|
||||
|
@ -178,8 +178,8 @@ function GridBox:mousepressed(x, y, button, isTouch)
|
|||
local newcol, newline
|
||||
local newselect, slotID
|
||||
|
||||
newline = beginline + math.floor(y / self.widgetsH)
|
||||
newcol = math.floor(x / self.widgetsW)
|
||||
newline = beginline + math.floor(y / self.widget.h)
|
||||
newcol = math.floor(x / self.widget.w)
|
||||
newselect = (newline * self.slots_hor) + newcol + 1
|
||||
|
||||
if self.listSlot[newselect].isSlave > 0 then
|
||||
|
@ -202,30 +202,30 @@ function GridBox:draw()
|
|||
self:regenSlots() -- On reget les slots au cas où :p
|
||||
for i,v in ipairs(self.listSlot) do
|
||||
if (v.isSlave == 0) and (v.widgetID <= #self.widget.list) then
|
||||
--self.widget.list[v.widgetID]:draw(widgetx, widgety, self.widgetsW * v.sizeW, self.widgetsH * v.sizeH)
|
||||
--self.widget.list[v.widgetID]:draw(widgetx, widgety, self.widget.w * v.sizeW, self.widget.h * v.sizeH)
|
||||
if self.widget.selected == v.widgetID and self.focus == true then
|
||||
self.widget.list[v.widgetID]:drawSelected(widgetx, widgety, self.widgetsW * v.sizeW, self.widgetsH * v.sizeH)
|
||||
self.widget.list[v.widgetID]:drawSelected(widgetx, widgety, self.widget.w * v.sizeW, self.widget.h * v.sizeH)
|
||||
else
|
||||
self.widget.list[v.widgetID]:draw(widgetx, widgety, self.widgetsW * v.sizeW, self.widgetsH * v.sizeH)
|
||||
self.widget.list[v.widgetID]:draw(widgetx, widgety, self.widget.w * v.sizeW, self.widget.h * v.sizeH)
|
||||
end
|
||||
end
|
||||
if (v.isSlave > 0) and false then
|
||||
love.graphics.setColor(255,255,255,128)
|
||||
love.graphics.rectangle("fill", widgetx, widgety, self.widgetsW, self.widgetsH)
|
||||
love.graphics.rectangle("fill", widgetx, widgety, self.widget.w, self.widget.h)
|
||||
end
|
||||
local col, line = self:getCoord(i)
|
||||
|
||||
if (col == self.cursor.x) and (line == self.cursor.y) and false then
|
||||
love.graphics.setColor(255,255,0,128)
|
||||
love.graphics.rectangle("fill", widgetx, widgety, self.widgetsW, self.widgetsH)
|
||||
love.graphics.rectangle("fill", widgetx, widgety, self.widget.w, self.widget.h)
|
||||
end
|
||||
|
||||
--love.graphics.setColor(0,0,0,10)
|
||||
--love.graphics.rectangle("line", widgetx, widgety, self.widgetsW, self.widgetsH)
|
||||
widgetx = widgetx + self.widgetsW
|
||||
--love.graphics.rectangle("line", widgetx, widgety, self.widget.w, self.widget.h)
|
||||
widgetx = widgetx + self.widget.w
|
||||
if widgetx == (self.x + self.w) then
|
||||
widgetx = self.x
|
||||
widgety = widgety + self.widgetsH
|
||||
widgety = widgety + self.widget.h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,8 +7,9 @@ function ListBox:new(x,y,w,h,slots)
|
|||
ListBox.super.new(self, x, y, w, h)
|
||||
self.slots = slots
|
||||
self.begin = 1
|
||||
self.widgetsH = math.floor( self.h / slots )
|
||||
self.h = slots * self.widgetsH -- On fait en sorte que la hauteur
|
||||
self.widget.w = self.w
|
||||
self.widget.h = math.floor( self.h / slots )
|
||||
self.h = slots * self.widget.h -- On fait en sorte que la hauteur
|
||||
-- soit un multiple du nombre de slot et de leur hauteur
|
||||
end
|
||||
|
||||
|
@ -42,7 +43,7 @@ function ListBox:keyreleased(key, code)
|
|||
end
|
||||
|
||||
function ListBox:mousemoved(x, y)
|
||||
self.widget.selected = self.begin + math.floor(y / self.widgetsH)
|
||||
self.widget.selected = self.begin + math.floor(y / self.widget.h)
|
||||
if self.widget.selected < 1 then
|
||||
self.widget.selected = 1
|
||||
end
|
||||
|
@ -52,7 +53,7 @@ function ListBox:mousemoved(x, y)
|
|||
end
|
||||
|
||||
function ListBox:mousepressed(x, y, button, isTouch)
|
||||
self.widget.selected = self.begin + math.floor(y / self.widgetsH)
|
||||
self.widget.selected = self.begin + math.floor(y / self.widget.h)
|
||||
if self.widget.selected < 1 then
|
||||
self.widget.selected = 1
|
||||
end
|
||||
|
@ -68,13 +69,13 @@ function ListBox:draw()
|
|||
local widgety = self.y
|
||||
for i,v in ipairs(self.widget.list) do
|
||||
if (i >= self.begin) and (i < self.begin + self.slots) then
|
||||
v:draw(self.x, widgety, self.w, self.widgetsH)
|
||||
v:draw(self.x, widgety, self.w, self.widget.h)
|
||||
if self.widget.selected == i and self.focus == true then
|
||||
v:drawSelected(self.x, widgety, self.w, self.widgetsH)
|
||||
v:drawSelected(self.x, widgety, self.w, self.widget.h)
|
||||
else
|
||||
v:draw(self.x, widgety, self.w, self.widgetsH)
|
||||
v:draw(self.x, widgety, self.w, self.widget.h)
|
||||
end
|
||||
widgety = widgety + self.widgetsH
|
||||
widgety = widgety + self.widget.h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,6 +11,8 @@ function Menu:new(x,y,w,h)
|
|||
self.widget.selected = 0
|
||||
self.widget.selectedPrevious = 0
|
||||
self.widget.cancel = 0
|
||||
self.widget.h = 0
|
||||
self.widget.w = 0
|
||||
|
||||
self.isdestroyed = false
|
||||
self.focus = false
|
||||
|
@ -28,6 +30,10 @@ function Menu:setCancelWidget(id)
|
|||
self.widget.cancel = #self.widget.list
|
||||
end
|
||||
|
||||
function Menu:getWidgetSize(id)
|
||||
return self.widget.h, self.widget.w
|
||||
end
|
||||
|
||||
function Menu:cancelAction()
|
||||
if (self.widget.cancel ~= 0) then
|
||||
self.widget.list[self.widget.cancel]:action()
|
||||
|
|
|
@ -18,8 +18,8 @@ end
|
|||
|
||||
function TextMenu:getBoundingBox()
|
||||
self:setWidthAuto()
|
||||
self.widgetsH = self.font:getHeight()
|
||||
self.h = self.widgetsH * self.slots
|
||||
self.widget.h = self.font:getHeight()
|
||||
self.h = self.widget.h * self.slots
|
||||
|
||||
if self.align == "right" then
|
||||
self.x = self.ox - self.w
|
||||
|
@ -103,7 +103,7 @@ end
|
|||
|
||||
function TextMenu:mousemoved(x, y)
|
||||
local selectedPrevous = self.widget.selected
|
||||
self.widget.selected = self.begin + math.floor(y / self.widgetsH)
|
||||
self.widget.selected = self.begin + math.floor(y / self.widget.h)
|
||||
if self.widget.selected < 1 then
|
||||
self.widget.selected = 1
|
||||
end
|
||||
|
@ -117,7 +117,7 @@ function TextMenu:mousemoved(x, y)
|
|||
end
|
||||
|
||||
function TextMenu:mousepressed(x, y, button, isTouch)
|
||||
self.widget.selected = self.begin + math.floor(y / self.widgetsH)
|
||||
self.widget.selected = self.begin + math.floor(y / self.widget.h)
|
||||
if self.widget.selected < 1 then
|
||||
self.widget.selected = 1
|
||||
end
|
||||
|
@ -150,7 +150,7 @@ function TextMenu:drawCanvas()
|
|||
if (i >= self.begin) and (i < self.begin + self.slots) then
|
||||
self:drawWidget(i, widgety)
|
||||
|
||||
widgety = widgety + self.widgetsH
|
||||
widgety = widgety + self.widget.h
|
||||
end
|
||||
end
|
||||
utils.draw.resetColor()
|
||||
|
@ -176,7 +176,7 @@ function TextMenu:drawWidget(widgetID, y)
|
|||
end
|
||||
|
||||
function TextMenu:drawWidgetCanvas(widget)
|
||||
widget.canvas.texture = love.graphics.newCanvas(self.w, self.widgetsH)
|
||||
widget.canvas.texture = love.graphics.newCanvas(self.w, self.widget.h)
|
||||
|
||||
love.graphics.setCanvas( widget.canvas.texture )
|
||||
|
||||
|
|
Loading…
Reference in a new issue