From 168f03125c0f4b1611ab34d280f215f206256705 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Thu, 19 Jan 2012 17:15:38 -0200 Subject: [PATCH] combobox with wheel event --- modules/client/client.otmod | 1 + modules/core_lib/const.lua | 6 +++++- modules/core_widgets/uicombobox.lua | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/modules/client/client.otmod b/modules/client/client.otmod index 002c5bc8..fa8555bb 100644 --- a/modules/client/client.otmod +++ b/modules/client/client.otmod @@ -2,6 +2,7 @@ Module name: client description: Load all other otclient dependecies author: OTClient team + website: https://github.com/edubart/otclient // NOTE: order does matter dependencies: diff --git a/modules/core_lib/const.lua b/modules/core_lib/const.lua index ee41e514..fb398199 100644 --- a/modules/core_lib/const.lua +++ b/modules/core_lib/const.lua @@ -28,6 +28,10 @@ MouseLeftButton = 1 MouseRightButton = 2 MouseMidButton = 3 +MouseNoWheel = 0 +MouseWheelUp = 1 +MouseWheelDown = 2 + AlignNone = 0 AlignLeft = 1 AlignRight = 2 @@ -293,4 +297,4 @@ KeyCodeDescs = { [KeyNumpad7] = 'Numpad7', [KeyNumpad8] = 'Numpad8', [KeyNumpad9] = 'Numpad9' -} \ No newline at end of file +} diff --git a/modules/core_widgets/uicombobox.lua b/modules/core_widgets/uicombobox.lua index b6de5e63..5522a823 100644 --- a/modules/core_widgets/uicombobox.lua +++ b/modules/core_widgets/uicombobox.lua @@ -19,6 +19,15 @@ function UIComboBox:setCurrentOption(text) end end +function UIComboBox:setCurrentIndex(index) + if index >= 1 and index <= #self.m_options then + local v = self.m_options[index] + self.m_currentIndex = index + self:setText(v.text) + self:onOptionChange(v.text, v.data) + end +end + function UIComboBox:addOption(text, data) table.insert(self.m_options, { text = text, data = data }) local index = #self.m_options @@ -38,6 +47,17 @@ function UIComboBox:onMousePress(mousePos, mouseButton) return true end +function UIComboBox:onMouseWheel(mousePos, direction) + if direction == MouseWheelUp and self.m_currentIndex > 1 then + self:setCurrentIndex(self.m_currentIndex - 1) + return true + elseif direction == MouseWheelDown and self.m_currentIndex < #self.m_options then + self:setCurrentIndex(self.m_currentIndex + 1) + return true + end + return false +end + function UIComboBox:onStyleApply(styleName, styleNode) if styleNode.options then for k,option in pairs(styleNode.options) do