Skip to content

Commit c0fab23

Browse files
committed
Small update to 1.6.4
- added bimg support - reworked graphic object - added blit for drawsystem (makes drawing bit faster - added bimg lib - reworked image object - fixed thread bug
1 parent 7609708 commit c0fab23

21 files changed

+1481
-306
lines changed

Basalt/Frame.lua

+104-28
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ return function(name, parent, pTerm, basalt)
4949

5050
local activeEvents = {}
5151

52+
local colorTheme = {}
53+
5254
base:setZIndex(10)
5355

5456
local basaltDraw = BasaltDraw(termObject)
@@ -81,6 +83,7 @@ return function(name, parent, pTerm, basalt)
8183
end
8284

8385
local function getObject(name)
86+
if(type(name)~="string")then name = name.name end
8487
for _, value in pairs(objects) do
8588
for _, b in pairs(value) do
8689
if (b:getName() == name) then
@@ -240,11 +243,11 @@ return function(name, parent, pTerm, basalt)
240243
end
241244
return false
242245
end
243-
246+
local math = math
244247
local function stringToNumber(str)
245-
local ok, err = pcall(load("return " .. str))
248+
local ok, result = pcall(load("return " .. str, "", nil, {math=math}))
246249
if not(ok)then error(str.." is not a valid dynamic code") end
247-
return load("return " .. str)()
250+
return result
248251
end
249252

250253
local function newDynamicValue(_, obj, str)
@@ -327,8 +330,13 @@ return function(name, parent, pTerm, basalt)
327330
for _, index in pairs(objZIndex) do
328331
if (objects[index] ~= nil) then
329332
for _, value in pairs(objects[index]) do
330-
if (value.eventHandler ~= nil) then
331-
value:eventHandler("dynamicValueEvent", self)
333+
if(basalt.getDynamicValueEventSetting())then
334+
if (value.eventHandler ~= nil) then
335+
value:eventHandler("basalt_dynamicvalue", self)
336+
end
337+
end
338+
if (value.customEventHandler ~= nil) then
339+
value:customEventHandler("basalt_resize", self)
332340
end
333341
end
334342
end
@@ -340,17 +348,49 @@ return function(name, parent, pTerm, basalt)
340348
return dynamicValues[id][1]
341349
end
342350

343-
local function calculateMaxScroll(self)
351+
local function getVerticalScrollAmount(self)
352+
local amount = 0
344353
for _, value in pairs(objects) do
345354
for _, b in pairs(value) do
346355
if(b.getHeight~=nil)and(b.getY~=nil)then
347-
local h, y = b:getHeight(), b:getY()
348-
if (h + y - self:getHeight() > scrollAmount) then
349-
scrollAmount = max(h + y - self:getHeight(), 0)
356+
if(b:getType()=="Dropdown")then
357+
local h, y = b:getHeight(), b:getY()
358+
local wD, hD = b:getDropdownSize()
359+
h = h + hD - 1
360+
if (h + y - self:getHeight() >= amount) then
361+
amount = max(h + y - self:getHeight(), 0)
362+
end
363+
else
364+
local h, y = b:getHeight(), b:getY()
365+
if (h + y - self:getHeight() >= amount) then
366+
amount = max(h + y - self:getHeight(), 0)
367+
end
350368
end
351369
end
352370
end
353371
end
372+
return amount
373+
end
374+
375+
local function getHorizontalScrollAmount(self)
376+
local amount = 0
377+
for _, value in pairs(objects) do
378+
for _, b in pairs(value) do
379+
if(b.getWidth~=nil)and(b.getX~=nil)then
380+
local h, y = b:getWidth(), b:getX()
381+
if (h + y - self:getWidth() >= amount) then
382+
amount = max(h + y - self:getWidth(), 0)
383+
end
384+
end
385+
end
386+
end
387+
return amount
388+
end
389+
390+
local function calculateMaxScroll(self)
391+
if(autoScroll)then
392+
scrollAmount = getVerticalScrollAmount(self)
393+
end
354394
end
355395

356396
object = {
@@ -371,8 +411,8 @@ return function(name, parent, pTerm, basalt)
371411

372412
getType = function(self)
373413
return objectType
374-
end,
375-
414+
end;
415+
376416
setZIndex = function(self, newIndex)
377417
base.setZIndex(self, newIndex)
378418
for k,v in pairs(activeEvents)do
@@ -386,10 +426,14 @@ return function(name, parent, pTerm, basalt)
386426
setFocusedObject = function(self, obj)
387427
if(focusedObject~=obj)then
388428
if(focusedObject~=nil)then
389-
focusedObject:loseFocusHandler()
429+
if(getObject(focusedObject)~=nil)then
430+
focusedObject:loseFocusHandler()
431+
end
390432
end
391433
if(obj~=nil)then
392-
obj:getFocusHandler()
434+
if(getObject(obj)~=nil)then
435+
obj:getFocusHandler()
436+
end
393437
end
394438
focusedObject = obj
395439
end
@@ -408,8 +452,8 @@ return function(name, parent, pTerm, basalt)
408452
for _, index in pairs(objZIndex) do
409453
if (objects[index] ~= nil) then
410454
for _, value in pairs(objects[index]) do
411-
if (value.eventHandler ~= nil) then
412-
value:eventHandler("basalt_resize", value, self)
455+
if (value.customEventHandler ~= nil) then
456+
value:customEventHandler("basalt_resize", self)
413457
end
414458
end
415459
end
@@ -433,17 +477,34 @@ return function(name, parent, pTerm, basalt)
433477
return theme[name] or (self.parent~=nil and self.parent:getTheme(name) or basalt.getTheme(name))
434478
end,
435479

436-
setPosition = function(self, x, y, rel)
437-
base.setPosition(self, x, y, rel)
438-
for _, index in pairs(objZIndex) do
439-
if (objects[index] ~= nil) then
440-
for _, value in pairs(objects[index]) do
441-
if (value.eventHandler ~= nil) then
442-
value:eventHandler("basalt_reposition", value, self)
480+
getThemeColor = function(self, col)
481+
return col~=nil and colorTheme[col] or colorTheme
482+
end,
483+
484+
setThemeColor = function(self, col, ...)
485+
if(self.parent==nil)then
486+
if(self==basalt.getActiveFrame())then
487+
if(type(col)=="string")then
488+
colorTheme[col] = ...
489+
termObject.setPaletteColor(type(col)=="number" and col or colors[col], ...)
490+
elseif(type(col)=="table")then
491+
for k,v in pairs(col)do
492+
colorTheme[k] = v
493+
if(type(v)=="number")then
494+
termObject.setPaletteColor(type(k)=="number" and k or colors[k], v)
495+
else
496+
local r,g,b = table.unpack(v)
497+
termObject.setPaletteColor(type(k)=="number" and k or colors[k], r,g,b)
498+
end
443499
end
444500
end
445501
end
446502
end
503+
return self
504+
end,
505+
506+
setPosition = function(self, x, y, rel)
507+
base.setPosition(self, x, y, rel)
447508
self:recalculateDynamicValues()
448509
return self
449510
end;
@@ -469,7 +530,9 @@ return function(name, parent, pTerm, basalt)
469530

470531
removeFocusedObject = function(self)
471532
if(focusedObject~=nil)then
472-
focusedObject:loseFocusHandler()
533+
if(getObject(focusedObject)~=nil)then
534+
focusedObject:loseFocusHandler()
535+
end
473536
end
474537
focusedObject = nil
475538
return self
@@ -537,10 +600,26 @@ return function(name, parent, pTerm, basalt)
537600
return autoScroll and calculateMaxScroll(self) or scrollAmount
538601
end,
539602

603+
getCalculatedVerticalScroll = getVerticalScrollAmount,
604+
getCalculatedHorizontalScroll = getHorizontalScrollAmount,
605+
540606
show = function(self)
541607
base.show(self)
542608
if(self.parent==nil)then
543609
basalt.setActiveFrame(self)
610+
for k,v in pairs(colors)do
611+
if(type(v)=="number")then
612+
termObject.setPaletteColor(v, colors.packRGB(term.nativePaletteColor((v))))
613+
end
614+
end
615+
for k,v in pairs(colorTheme)do
616+
if(type(v)=="number")then
617+
termObject.setPaletteColor(type(k)=="number" and k or colors[k], v)
618+
else
619+
local r,g,b = table.unpack(v)
620+
termObject.setPaletteColor(type(k)=="number" and k or colors[k], r,g,b)
621+
end
622+
end
544623
if(isMonitor)and not(isGroupedMonitor)then
545624
basalt.setMonitorFrame(monSide, self)
546625
elseif(isGroupedMonitor)then
@@ -555,7 +634,7 @@ return function(name, parent, pTerm, basalt)
555634
hide = function (self)
556635
base.hide(self)
557636
if(self.parent==nil)then
558-
if(activeFrame == self)then activeFrame = nil end -- bug activeFrame always nil
637+
if(activeFrame == self)then activeFrame = nil end
559638
if(isMonitor)and not(isGroupedMonitor)then
560639
if(basalt.getMonitorFrame(monSide) == self)then
561640
basalt.setActiveFrame(nil)
@@ -804,9 +883,6 @@ return function(name, parent, pTerm, basalt)
804883
self:mouseHandler(1, p2, p3, true)
805884
end
806885
end
807-
if (event == "terminate")and(self.parent==nil)then
808-
basalt.stop()
809-
end
810886
end,
811887

812888
mouseHandler = function(self, button, x, y, _, side)
@@ -891,8 +967,8 @@ return function(name, parent, pTerm, basalt)
891967
self:updateDraw()
892968
end
893969
end
894-
self:removeFocusedObject()
895970
if(yOffset==cache)then return false end
971+
self:removeFocusedObject()
896972
return true
897973
end
898974
return false

0 commit comments

Comments
 (0)