-monitor support & getAll() for list-objects

added multiple monitor support
added getAll() for lists, dropdowns, radios and menubars
This commit is contained in:
Robert Jelic
2022-05-30 22:45:37 +02:00
parent 628e02d600
commit 1675b71c40
18 changed files with 265 additions and 155 deletions

View File

@@ -19,7 +19,7 @@ local function Checkbox(name)
mouseClickHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then
if (event == "mouse_click") and (button == 1) then
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then
if (self:getValue() ~= true) and (self:getValue() ~= false) then
self:setValue(false)
else

View File

@@ -39,6 +39,10 @@ local function Dropdown(name)
return self
end;
getAll = function(self)
return list
end;
removeItem = function(self, index)
table.remove(list, index)
return self
@@ -93,16 +97,14 @@ local function Dropdown(name)
mouseClickHandler = function(self, event, button, x, y)
if (state == 2) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (event == "mouse_click") then
-- remove mouse_drag if i want to make objects moveable uwuwuwuw
if (button == 1) then
if (#list > 0) then
for n = 1, dropdownH do
if (list[n + yOffset] ~= nil) then
if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then
self:setValue(list[n + yOffset])
return true
end
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then
if (#list > 0) then
for n = 1, dropdownH do
if (list[n + yOffset] ~= nil) then
if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then
self:setValue(list[n + yOffset])
return true
end
end
end

View File

@@ -7,7 +7,7 @@ local function Label(name)
base.fgColor = colors.white
base.bgcolor = colors.black
local autoWidth = true
local autoSize = true
base:setValue("")
local textHorizontalAlign = "left"
@@ -21,7 +21,7 @@ local function Label(name)
setText = function(self, text)
text = tostring(text)
base:setValue(text)
if (autoWidth) then
if (autoSize) then
self.width = text:len()
end
return self
@@ -47,7 +47,7 @@ local function Label(name)
setSize = function(self, width, height)
base.setSize(self, width, height)
autoWidth = false
autoSize = false
self:setVisualChanged()
return self
end;
@@ -68,6 +68,10 @@ local function Label(name)
end
else
local tData = makeText(fontsize, self:getValue(), self.fgColor, self.bgColor)
if(autoSize)then
self.height = #tData[1]-1
self.width = #tData[1][1]
end
for n = 1, self.height do
if (n == verticalAlign) then
local oX, oY = self.parent:getSize()

View File

@@ -46,6 +46,10 @@ local function List(name)
return list[index]
end;
getAll = function(self)
return list
end;
getItemIndex = function(self)
local selected = self:getValue()
for key, value in pairs(list) do
@@ -91,16 +95,13 @@ local function List(name)
mouseClickHandler = function(self, event, button, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (obx <= x) and (obx + self.width > x) and (oby <= y) and (oby + self.height > y) and (self:isVisible()) then
if (event == "mouse_click") or (event == "mouse_drag") then
-- remove mouse_drag if i want to make objects moveable uwuwuwuw
if (button == 1) then
if (#list > 0) then
for n = 1, self.height do
if (list[n + yOffset] ~= nil) then
if (obx <= x) and (obx + self.width > x) and (oby + n - 1 == y) then
self:setValue(list[n + yOffset])
self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", 0, x, y, list[n + yOffset])
end
if (((event == "mouse_click") or (event == "mouse_drag"))and(button==1))or(event=="monitor_touch") then
if (#list > 0) then
for n = 1, self.height do
if (list[n + yOffset] ~= nil) then
if (obx <= x) and (obx + self.width > x) and (oby + n - 1 == y) then
self:setValue(list[n + yOffset])
self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", 0, x, y, list[n + yOffset])
end
end
end

View File

@@ -44,6 +44,10 @@ local function Menubar(name)
return self
end;
getAll = function(self)
return list
end;
getItemIndex = function(self)
local selected = self:getValue()
for key, value in pairs(list) do
@@ -119,7 +123,7 @@ local function Menubar(name)
if (self.parent ~= nil) then
self.parent:setFocusedObject(self)
end
if (event == "mouse_click") then
if (event == "mouse_click") or (event == "monitor_touch") then
local xPos = 1
for n = 1 + itemOffset, #list do
if (list[n] ~= nil) then

View File

@@ -601,7 +601,7 @@ local function Program(name)
end
if not (curProcess:isDead()) then
if not (paused) then
if (event ~= "mouse_click") and (event ~= "mouse_up") and (event ~= "mouse_scroll") and (event ~= "mouse_drag") and (event ~= "key_up") and (event ~= "key") and (event ~= "char") and (event ~= "terminate") then
if (event ~= "mouse_click") and (event ~= "monitor_touch") and (event ~= "mouse_up") and (event ~= "mouse_scroll") and (event ~= "mouse_drag") and (event ~= "key_up") and (event ~= "key") and (event ~= "char") and (event ~= "terminate") then
curProcess:resume(event, p1, p2, p3, p4)
end
if (self:isFocused()) then
@@ -618,7 +618,7 @@ local function Program(name)
end
end
else
if (event ~= "mouse_click") and (event ~= "mouse_up") and (event ~= "mouse_scroll") and (event ~= "mouse_drag") and (event ~= "key_up") and (event ~= "key") and (event ~= "char") and (event ~= "terminate") then
if (event ~= "mouse_click") and (event ~= "monitor_touch") and (event ~= "mouse_up") and (event ~= "mouse_scroll") and (event ~= "mouse_drag") and (event ~= "key_up") and (event ~= "key") and (event ~= "char") and (event ~= "terminate") then
table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } })
end
end

View File

@@ -28,6 +28,10 @@ local function Radio(name)
return self
end;
getAll = function(self)
return list
end;
removeItem = function(self, index)
table.remove(list, index)
return self
@@ -78,20 +82,17 @@ local function Radio(name)
mouseClickHandler = function(self, event, button, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (event == "mouse_click") then
-- remove mouse_drag if i want to make objects moveable uwuwuwuw
if (button == 1) then
if (#list > 0) then
for _, value in pairs(list) do
if (obx + value.x - 1 <= x) and (obx + value.x - 1 + value.text:len() + 2 >= x) and (oby + value.y - 1 == y) then
self:setValue(value)
if (self.parent ~= nil) then
self.parent:setFocusedObject(self)
end
--eventSystem:sendEvent(event, self, event, button, x, y)
self:setVisualChanged()
return true
if ((event == "mouse_click")and(button==1))or(event=="monitor_touch") then
if (#list > 0) then
for _, value in pairs(list) do
if (obx + value.x - 1 <= x) and (obx + value.x - 1 + value.text:len() + 2 >= x) and (oby + value.y - 1 == y) then
self:setValue(value)
if (self.parent ~= nil) then
self.parent:setFocusedObject(self)
end
--eventSystem:sendEvent(event, self, event, button, x, y)
self:setVisualChanged()
return true
end
end
end

View File

@@ -64,7 +64,7 @@ local function Scrollbar(name)
mouseClickHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if ((event == "mouse_click") or (event == "mouse_drag")) and (button == 1) then
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
if (barType == "horizontal") then
for _index = 0, self.width do
if (obx + _index == x) and (oby <= y) and (oby + self.height > y) then

View File

@@ -18,7 +18,7 @@ local function Switch(name)
mouseClickHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if ((event == "mouse_click") or (event == "mouse_drag")) and (button == 1) then
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
end

View File

@@ -248,7 +248,7 @@ local function Textfield(name)
if (base.mouseClickHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition()
if (event == "mouse_click") then
if (event == "mouse_click")or(event=="monitor_touch") then
if (lines[y - oby + hIndex] ~= nil) then
textX = x - obx + wIndex
textY = y - oby + hIndex