From c4ce0f5c5dfbd643556a1bf0eadc862cac084d26 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 12 Feb 2019 18:15:17 +0100 Subject: [PATCH] core/menusystem: don't update cursor position when hovering no widget --- .../core/modules/menusystem/flowbox.lua | 26 +++++++----------- .../core/modules/menusystem/listbox.lua | 27 +++++++++---------- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/sonic-boost.love/core/modules/menusystem/flowbox.lua b/sonic-boost.love/core/modules/menusystem/flowbox.lua index c5a7d6d..ffef17f 100644 --- a/sonic-boost.love/core/modules/menusystem/flowbox.lua +++ b/sonic-boost.love/core/modules/menusystem/flowbox.lua @@ -112,39 +112,31 @@ end function FlowBox:mousemoved(x, y) local col, line = self:getCoord(self.widget.selected) local begincol, beginline = self:getCoord(self.begin) - local newcol, newline + local newcol, newline, widget_selected newline = beginline + math.floor(y / self.widget.h) newcol = math.floor(x / self.widget.w) - self.widget.selected = (newline * self.slots_hor) + newcol + 1 + widget_selected = (newline * self.slots_hor) + newcol + 1 - 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 + if widget_selected >= 1 and widget_selected <= #self.widget.list then + self.widget.selected = widget_selected end end function FlowBox:mousepressed(x, y, button, isTouch) local col, line = self:getCoord(self.widget.selected) local begincol, beginline = self:getCoord(self.begin) - local newline, newcol + local newline, newcol, widget_selected newline = beginline + math.floor(y / self.widget.h) newcol = math.floor(x / self.widget.w) - self.widget.selected = (newline * self.slots_hor) + newcol + 1 + widget_selected = (newline * self.slots_hor) + newcol + 1 - 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.list > 0 then + if widget_selected >= 1 and widget_selected <= #self.widget.list then + self.widget.selected = widget_selected self.widget.list[self.widget.selected]:action() end + end function FlowBox:draw() diff --git a/sonic-boost.love/core/modules/menusystem/listbox.lua b/sonic-boost.love/core/modules/menusystem/listbox.lua index eeb59d5..b818218 100644 --- a/sonic-boost.love/core/modules/menusystem/listbox.lua +++ b/sonic-boost.love/core/modules/menusystem/listbox.lua @@ -46,26 +46,23 @@ function ListBox:keyreleased(key, code) end function ListBox:mousemoved(x, y) - self.widget.selected = self.begin + math.floor(y / self.widget.h) - 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 + local widget_selected = self.begin + math.floor(y / self.widget.h) + + if widget_selected >= 1 and widget_selected <= #self.widget.list then + self.widget.selected = widget_selected end end function ListBox:mousepressed(x, y, button, isTouch) - self.widget.selected = self.begin + math.floor(y / self.widget.h) - 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.list > 0 then - self.widget.list[self.widget.selected]:action() + local widget_selected = self.begin + math.floor(y / self.widget.h) + + if widget_selected >= 1 and widget_selected <= #self.widget.list then + self.widget.selected = widget_selected + if #self.widget.list > 0 then + self.widget.list[self.widget.selected]:action() + end end + end function ListBox:draw()