diff --git a/birb/modules/menusystem/menus/flowbox.lua b/birb/modules/menusystem/menus/flowbox.lua index 87a1f8a..7991af9 100644 --- a/birb/modules/menusystem/menus/flowbox.lua +++ b/birb/modules/menusystem/menus/flowbox.lua @@ -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 diff --git a/birb/modules/menusystem/menus/grid.lua b/birb/modules/menusystem/menus/grid.lua index 3c3db9b..6f985e4 100644 --- a/birb/modules/menusystem/menus/grid.lua +++ b/birb/modules/menusystem/menus/grid.lua @@ -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 diff --git a/birb/modules/menusystem/menus/hlistbox.lua b/birb/modules/menusystem/menus/hlistbox.lua index 6f9bbf6..c8f0394 100644 --- a/birb/modules/menusystem/menus/hlistbox.lua +++ b/birb/modules/menusystem/menus/hlistbox.lua @@ -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. diff --git a/birb/modules/menusystem/menus/listbox.lua b/birb/modules/menusystem/menus/listbox.lua index ce19de7..d1a3c6d 100644 --- a/birb/modules/menusystem/menus/listbox.lua +++ b/birb/modules/menusystem/menus/listbox.lua @@ -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. diff --git a/birb/modules/menusystem/menus/utils/menumodel.lua b/birb/modules/menusystem/menus/model/init.lua similarity index 100% rename from birb/modules/menusystem/menus/utils/menumodel.lua rename to birb/modules/menusystem/menus/model/init.lua diff --git a/birb/modules/menusystem/menus/parent.lua b/birb/modules/menusystem/menus/parent.lua index 8707896..ca0f890 100644 --- a/birb/modules/menusystem/menus/parent.lua +++ b/birb/modules/menusystem/menus/parent.lua @@ -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. diff --git a/birb/modules/menusystem/menus/utils/view1D.lua b/birb/modules/menusystem/menus/views/view1D.lua similarity index 100% rename from birb/modules/menusystem/menus/utils/view1D.lua rename to birb/modules/menusystem/menus/views/view1D.lua diff --git a/birb/modules/menusystem/menus/utils/view2D.lua b/birb/modules/menusystem/menus/views/view2D.lua similarity index 96% rename from birb/modules/menusystem/menus/utils/view2D.lua rename to birb/modules/menusystem/menus/views/view2D.lua index 0e510bf..77e8823 100644 --- a/birb/modules/menusystem/menus/utils/view2D.lua +++ b/birb/modules/menusystem/menus/views/view2D.lua @@ -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) diff --git a/birb/modules/menusystem/menus/widgets/utils.lua b/birb/modules/menusystem/utils.lua similarity index 93% rename from birb/modules/menusystem/menus/widgets/utils.lua rename to birb/modules/menusystem/utils.lua index e69c6d7..a8c73e6 100644 --- a/birb/modules/menusystem/menus/widgets/utils.lua +++ b/birb/modules/menusystem/utils.lua @@ -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