chore:move around menus sub-objects

This commit is contained in:
Kazhnuz 2020-12-04 13:16:32 +01:00
parent a72dfc0711
commit bb6cf14437
9 changed files with 56 additions and 63 deletions

View file

@ -26,7 +26,7 @@ local cwd = (...):gsub('%.flowbox$', '') .. "."
local Menu = require(cwd .. "parent")
local FlowBox = Menu:extend()
local View2D = require(cwd .. "utils.view2D")
local View2D = require(cwd .. "views.view2D")
-- INIT FUNCTIONS
-- Initialize and configure the flowbox

View file

@ -26,20 +26,16 @@ local cwd = (...):gsub('%.grid$', '') .. "."
local Menu = require(cwd .. "parent")
local GridBox = Menu:extend()
local menuutils = require(cwd .. "widgets.utils")
local View2D = require "birb.modules.menusystem.menus.views.view2D"
-- INIT FUNCTIONS
-- Initialize and configure the menu
function GridBox:new(menusystem, name, x, y, w, h, colNumber, lineNumber)
self.view = {}
self.view.slotNumber = colNumber * lineNumber
self.view.colNumber = colNumber
self.view.lineNumber = lineNumber
self.view.firstSlot = 1
self.view = View2D(colNumber, lineNumber)
GridBox.super.new(self, menusystem, name, x, y, w, h)
self.h = lineNumber * self.widget.h -- On fait en sorte que la hauteur
self.w = colNumber * self.widget.w -- et la largeur
self.h = lineNumber * self.widgetSize.h -- On fait en sorte que la hauteur
self.w = colNumber * self.widgetSize.w -- et la largeur
-- soit un multiple du nombre de slot et de leur dimensions
self.cursor = {}
self.cursor.x = 0
@ -56,14 +52,13 @@ function GridBox:addSlot(widgetID, x, y, w, h)
slot.y = y
slot.w = w
slot.h = h
slot.widgetID = widgetID
table.insert(self.slots, slot)
end
function GridBox:updateWidgetSize()
self.widget.h = math.floor( self.h / self.view.lineNumber )
self.widget.w = math.floor( self.w / self.view.colNumber )
self.widgetSize.h = math.floor( self.h / self.view.lineNumber )
self.widgetSize.w = math.floor( self.w / self.view.colNumber )
end
-- INFO FUNCTIONS
@ -71,19 +66,19 @@ end
function GridBox:getWidgetSize(id)
local slot = self:getWidgetSlot(id)
if slot == 0 then
if (slot == 0) then
return 1, 1
else
return self.widget.w * self.slots[slot].w, self.widget.h * self.slots[slot].h
return self.widgetSize.w * self.slots[slot].w, self.widgetSize.h * self.slots[slot].h
end
end
function GridBox:getSlotHitbox(slot)
local x, y, w, h
x = self.slots[slot].x * self.widget.w
y = self.slots[slot].y * self.widget.h
w = self.slots[slot].w * self.widget.w
h = self.slots[slot].h * self.widget.h
x = self.slots[slot].x * self.widgetSize.w
y = self.slots[slot].y * self.widgetSize.h
w = self.slots[slot].w * self.widgetSize.w
h = self.slots[slot].h * self.widgetSize.h
return x, y, w, h
end
@ -146,7 +141,7 @@ end
-- Handle the keyboard/manette functions
function GridBox:keyreleased(key, code)
local slotID = self:getWidgetSlot(self.widget.selected)
local slotID = self:getWidgetSlot(self.widget:getSelected())
local col, line = self.cursor.x, self.cursor.y
if key == 'left' then
self:moveCol(-1)
@ -164,13 +159,13 @@ function GridBox:keyreleased(key, code)
self:moveLine(1)
end
if key == "A" and self.widget.selected <= #self.widget.list then
self.widget.list[self.widget.selected]:action("key")
if key == "A" and self.widget:getSelected() <= self.widget:lenght() then
self.widget.list[self.widget:getSelected()]:action("key")
end
end
function GridBox:moveCol(direction)
local orig_x, orig_y = self:getSlotCenter(self.widget.selected)
local orig_x, orig_y = self:getSlotCenter(self.widget:getSelected())
local distance = self.w -- on met directement à la distance max possible le système
local nearestWidget = 0
for i,v in ipairs(self.slots) do
@ -185,13 +180,13 @@ function GridBox:moveCol(direction)
end
end
if nearestWidget ~= 0 then
self.widget.selected = nearestWidget
if (nearestWidget ~= 0) then
self.widget:setCursor(nearestWidget)
end
end
function GridBox:moveLine(direction)
local orig_x, orig_y = self:getSlotCenter(self.widget.selected)
local orig_x, orig_y = self:getSlotCenter(self.widget:getSelected())
local distance = self.h -- on met directement à la distance max possible le système
local nearestWidget = 0
for i,v in ipairs(self.slots) do
@ -206,8 +201,8 @@ function GridBox:moveLine(direction)
end
end
if nearestWidget ~= 0 then
self.widget.selected = nearestWidget
if (nearestWidget ~= 0) then
self.widget:setCursor(nearestWidget)
end
end
@ -217,31 +212,31 @@ end
function GridBox:mousemoved(x, y)
local widgetID = self:getWidgetAtPoint(x, y)
if widgetID ~= nil then
self.widget.selected = widgetID
self:getFocus()
end
-- if (widgetID ~= nil) then
-- self.widget:getSelected() = widgetID
-- self:getFocus()
-- end
if self.widget.selected < 1 then
self.widget.selected = 1
end
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end
-- if self.widget:getSelected() < 1 then
-- self.widget:getSelected() = 1
-- end
-- if self.widget:getSelected() > self.widget:lenght() then
-- self.widget:getSelected() = self.widget:lenght()
-- end
end
function GridBox:mousepressed(x, y, button, isTouch)
local widgetID = self:getWidgetAtPoint(x, y)
if widgetID ~= nil then
self.widget.selected = widgetID
self:getFocus()
-- if (widgetID ~= nil) then
-- self.widget:getSelected() = widgetID
-- self:getFocus()
if #self.widget.list > 0 and self.widget.selected > 1 and self.widget.selected <= #self.widget.list then
self.widget.list[self.widget.selected]:action("pointer")
end
end
-- if self.widget:lenght() > 0 and self.widget:getSelected() > 1 and self.widget:getSelected() <= self.widget:lenght() then
-- self.widget.list[self.widget:getSelected()]:action("pointer")
-- end
-- end
end
-- DRAW FUNCTIONS
@ -251,9 +246,9 @@ function GridBox:draw()
for i,v in ipairs(self.slots) do
if self:haveWidget(i) then
local widgetx = self.x + (v.x * self.widget.w)
local widgety = self.y + (v.y * self.widget.h)
if self.widget.selected == v.widgetID and self:haveFocus() == true then
local widgetx = self.x + (v.x * self.widgetSize.w)
local widgety = self.y + (v.y * self.widgetSize.h)
if self.widget:getSelected() == v.widgetID and self:haveFocus() == true then
self.widget.list[v.widgetID]:drawSelected(widgetx, widgety)
else
self.widget.list[v.widgetID]:draw(widgetx, widgety)
@ -264,12 +259,12 @@ end
function GridBox:drawCursor()
self:updateView()
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
local slot = self:getWidgetSlot(self.widget.selected)
if (self.widget:getSelected() >= 1 and self.widget:getSelected() <= self.widget:lenght()) then
local slot = self:getWidgetSlot(self.widget:getSelected())
local w, h = self:getWidgetSize(slot)
local x = self.slots[slot].x * self.widget.w
local y = self.slots[slot].y * self.widget.h
menuutils.drawCursor(self.x + x, self.y + y, w, h)
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)
end
end

View file

@ -26,8 +26,7 @@ local cwd = (...):gsub('%.hlistbox$', '') .. "."
local Menu = require(cwd .. "parent")
local HListBox = Menu:extend()
local menuutils = require(cwd .. "widgets.utils")
local View1D = require(cwd .. "utils.view1D")
local View1D = require(cwd .. "views.view1D")
-- INIT FUNCTIONS
-- Initialize and configure functions.

View file

@ -26,8 +26,7 @@ local Menu = require(cwd .. "parent")
local ListBox = Menu:extend()
local menuutils = require(cwd .. "widgets.utils")
local View1D = require(cwd .. "utils.view1D")
local View1D = require(cwd .. "views.view1D")
-- INIT FUNCTIONS
-- Initialize and configure functions.

View file

@ -24,9 +24,9 @@
local GuiElement = require "birb.modules.menusystem.parent"
local Menu = GuiElement:extend()
local MenuModel = require "birb.modules.menusystem.menus.utils.menumodel"
local MenuModel = require "birb.modules.menusystem.menus.model"
local menuUtils = require "birb.modules.menusystem.menus.widgets.utils"
local menuUtils = require "birb.modules.menusystem.utils"
-- INIT FUNCTIONS
-- Initialize and configure functions.

View file

@ -21,7 +21,7 @@
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local View1D = require "birb.modules.menusystem.menus.utils.menumodel"
local View1D = require "birb.modules.menusystem.menus.views.view1D"
local View2D = View1D:extend()
function View2D:new(colNumber, lineNumber)

View file

@ -1,4 +1,4 @@
-- widgets/utils :: basic utility functions for the widgets
-- menusystem/utils :: basic utility functions for the gui
--[[
Copyright © 2019 Kazhnuz
@ -21,9 +21,9 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local menuUtils = {}
local guiUtils = {}
function menuUtils.drawCursor(x, y, w, h)
function guiUtils.drawCursor(x, y, w, h)
love.graphics.setColor(0,0,0)
love.graphics.rectangle("fill", x, y, 4, 8)
@ -54,4 +54,4 @@ function menuUtils.drawCursor(x, y, w, h)
end
return menuUtils
return guiUtils