96 Commits

Author SHA1 Message Date
Robert Jelic
681d54b406 moving module 2022-10-09 12:16:38 +02:00
Robert Jelic
eab8794d38 ..forgot to add (1.6.3)
- Fixed focus system bug
- Fixed :getScrollAmount (frames)
- added :onHover
- added :onLeave
- Made drawing a bit faster
- Added a dragging throttle system
- Mouse events should send now relative coordinates
2022-10-09 12:14:20 +02:00
Robert Jelic
1d3e2018ef docs update
Updated some docs stuff
2022-10-09 12:05:30 +02:00
Robert Jelic
44402b1d26 Basalt 1.6.3 - some improvements
- added new animations (:setMode("animname")
- added :addMode("animname", f) to create custom easings
- Fixed a bug in input when using - or . nothing happens (inputmode number)
- Added a event for labels when using multiple line text and the window/frame gets resized)
- Changed some backend stuff for programs
- added a setEnviroment method for programs
- Added a program_done event and a program_error event for programs (:onError() and :onDone())
- Fixed a bug in textfields (when using editLine it doesn't update colors)
- seperated the char event from the key event (before both events executed :onKey events, now there is a :onChar() and :onKey() event
2022-10-09 10:50:02 +02:00
Robert Jelic
56d89ad6f0 added install/package script
Added install script
Added packager/minify script
2022-09-18 22:21:29 +02:00
Robert Jelic
4af3df72ab Merge pull request #28 from Erb3/master
Docs update, mostly Basalt, Sidebar and Footer.
2022-09-17 15:04:41 +02:00
Erb3
f404e0ad8f Small onEvent change 2022-09-17 14:59:46 +02:00
Erb3
45bb23476b Docs: Fix sidebar issue on all Basalt methods 2022-09-17 14:41:54 +02:00
Erb3
bd61da9593 Docs: basalt.update() 2022-09-17 14:33:10 +02:00
Erb3
9acf7d5345 Docs: Basalt.stopUpdate 2022-09-17 14:33:04 +02:00
Erb3
1efca45639 Docs: Basalt.setVariable.md 2022-09-17 14:28:53 +02:00
Erb3
2dfe69fe43 Docs: Basalt.setTheme 2022-09-17 14:28:44 +02:00
Erb3
40b24ccf46 Docs: Add basalt.setActiveFrame.md 2022-09-17 14:25:01 +02:00
Erb3
1ebeda0375 Docs: Clean up basalt.scheduel.md 2022-09-17 14:21:55 +02:00
Erb3
9a514e6f7c Docs: Add base onEvent.md 2022-09-17 14:21:43 +02:00
Erb3
4f1baee771 Docs: Update basalt.removeFrame.md 2022-09-15 15:34:59 +02:00
Erb3
6ed31dd44c Docs: Update log.md 2022-09-15 15:19:16 +02:00
Erb3
19bc07e350 Docs: Fix typo in basalt.getVariable.md 2022-09-15 15:06:26 +02:00
Erb3
27321380ae Docs: Finish Basalt.getTheme.md 2022-09-15 15:05:42 +02:00
Erb3
bf9f01aae7 Docs: basalt.isKeyDown 2022-09-12 21:07:31 +02:00
Erb3
651690d8ab Docs: basalt.getVariable & basalt.getVersion 2022-09-12 21:04:01 +02:00
Erb3
7bcbafe30b Docs: basalt.getTheme 2022-09-12 20:57:06 +02:00
Erb3
72f2c527b9 Docs: basalt.get(Active)Frame 2022-09-12 20:51:58 +02:00
Erb3
77eeb1ce81 Docs: basalt.debug 2022-09-12 20:47:37 +02:00
Erb3
04d5919a82 Docs: basalt.createFrame 2022-09-12 20:44:18 +02:00
Erb3
6fa519be86 Docs: basalt.autoUpdate() 2022-09-12 20:35:01 +02:00
Erb3
00fff1c2f0 Docs: Basalt.md update
Changes:
* Rewording
* Add forgotten methods
* Sort methods
2022-09-12 20:09:14 +02:00
Erlend
140f1b0014 Reword Quick-Start.md 2022-09-12 12:23:31 +02:00
Erlend
153f2b9146 docs: rephrase installer.md 2022-09-12 12:20:24 +02:00
Erlend
21467fe4f4 Merge pull request #1 from Pyroxenium/master
fetch latest
2022-09-12 11:49:10 +02:00
Robert Jelic
6f372fa070 docs update 2022-09-11 11:40:49 +02:00
Robert Jelic
3ca6ac5af0 small docs fix
someone is watching me
2022-09-10 21:02:56 +02:00
Robert Jelic
859303e7a1 documentated multi-monitor support 2022-09-08 20:36:36 +02:00
Erlend
ab767e16dd Fix _footer 2022-09-07 16:53:51 +02:00
Erb3
93a0c738fa Make the footer work 2022-09-07 16:51:32 +02:00
Erb3
04d85b633c Undo adding title to sidebar and navbar 2022-09-07 16:29:17 +02:00
Erb3
4d83697537 Update navbar to be consistant 2022-09-07 16:11:53 +02:00
Erb3
ff12c040df Fix formatting in _sidebar.md 2022-09-07 16:07:15 +02:00
Erb3
897b7018a1 [WIKI] Edit wiki home page
Changed made:
* Updated CC:T download link
* Fix <img> into markdown
* Change underscores into astrix
* Fix <a> into markdown
* Remove unnecessary <br>
2022-09-07 16:02:11 +02:00
Robert Jelic
51f6ebe7ce docs updates 2022-09-06 17:43:03 +02:00
Robert Jelic
4d227af9d9 fixed removeObject 2022-09-06 16:21:54 +02:00
Robert Jelic
cf4f15e659 added multimonitor support
- cursor fix @input
- now you are able to add bigger monitors - still in beta
Some features are still missing: checking if monitors are connected/disconnected,
resizing by destroying the blocks
2022-09-05 23:00:38 +02:00
Robert Jelic
a3291544ac small input fixed
Used the old way of receiving x position
2022-09-04 17:44:06 +02:00
Robert Jelic
0503aa1274 Update process.lua 2022-09-03 20:41:16 +02:00
Robert Jelic
299b23a6c2 Border fix
fixed the way borders are drawn
2022-09-02 19:38:38 +02:00
Robert Jelic
8b3b6f3490 Update Frame.lua
fixed small focus issue
2022-09-01 21:05:13 +02:00
Robert Jelic
d1792ac537 Merge pull request #27 from Erb3/patch-2
Fix typo in Animations - changeBackground.md
2022-09-01 19:43:53 +02:00
Erlend
709cf66ce8 Fix typo in Animations - changeBackground.md 2022-09-01 18:57:39 +02:00
Robert Jelic
ae14d85a6b Input fix
fixed a bug in input fields while drag event is happening - now the input object loses the focus when dragging outside of its position+size
2022-08-30 22:51:26 +02:00
Robert Jelic
896e8179a6 oops 2022-08-30 20:52:28 +02:00
Robert Jelic
2dd3bf648b Some docs updates 2022-08-30 20:49:25 +02:00
Robert Jelic
c977410a41 Small bugfix
Fixed a bug where frames incorrectly remove their own events in parent frames
2022-08-30 20:17:00 +02:00
Robert Jelic
23b94d076b Frame drag fix
Fixed a dragging bug on frames
2022-08-29 18:50:18 +02:00
Robert Jelic
b10ec1770c fixed wrong links for labels 2022-08-29 18:26:59 +02:00
Robert Jelic
001e8c4ef6 Small bugfix
Forgot to add a check - if it has a parent or not
2022-08-28 20:27:07 +02:00
Robert Jelic
18601d54f7 Some updates 2022-08-28 20:25:42 +02:00
Robert Jelic
4d614372a1 Updated docs
There is still stuff to do
2022-08-28 18:18:26 +02:00
Robert Jelic
53d7b9f70c smallest bugfix 2022-08-26 23:22:25 +02:00
Robert Jelic
92e91b7d6b Update Animation.lua 2022-08-26 21:18:02 +02:00
Robert Jelic
b6c5531290 example changes and cursor bugfix 2022-08-26 21:13:19 +02:00
Robert Jelic
b637e65983 Update Frame.lua 2022-08-26 19:34:23 +02:00
Robert Jelic
5d12e0db74 Merge branch 'master' of https://github.com/Pyroxenium/Basalt 2022-08-26 19:32:43 +02:00
Robert Jelic
41bbe19de1 small quick fix 2022-08-26 19:31:27 +02:00
Robert Jelic
537d37c21b Update Frame.lua
quick fix for removing events
2022-08-25 23:15:00 +02:00
Robert Jelic
de84dbf406 New example for resizeable frames 2022-08-25 22:38:04 +02:00
Robert Jelic
8ab06dbc17 1.6.0 Release
Release version of basalt 1.6.0
2022-08-25 22:22:47 +02:00
Robert Jelic
14643193b9 Update mouseEvents.md 2022-08-24 20:24:51 +02:00
Robert Jelic
9d7c7d8a85 Merge pull request #26 from Yarillo4/master
Fix nil dereferencing exception in Frames.lua
2022-08-16 20:24:22 +02:00
Yarillo4
6809f9991b Fix nil dereferencing exception 2022-08-16 15:06:36 +02:00
Robert Jelic
b64f3ef87c updated the example
people are still using :show() and supply a id but never use them, probably because the example was not up2date
2022-08-12 19:03:13 +02:00
Robert Jelic
fb227445df Update Frame.md 2022-08-10 19:59:20 +02:00
Robert Jelic
10c25e7615 Update Frame.md 2022-08-10 19:58:17 +02:00
Robert Jelic
dfed9a5512 Merge pull request #25 from toastonrye/master
Example - Controlling Redstone output with a slider
2022-08-09 03:10:08 +02:00
toastonrye
fac7e221b3 Update redstoneAnalogOutput.lua
Add comments
2022-08-08 19:44:24 -05:00
toastonrye
c775958254 Update redstoneAnalogOutput.lua
Uploaded from pastebin
2022-08-08 19:33:51 -05:00
toastonrye
1c76130086 Update redstoneAnalogOutput.lua 2022-08-08 17:09:35 -05:00
toastonrye
57b303f538 Update redstoneAnalogOutput.lua 2022-08-08 16:58:28 -05:00
toastonrye
74071cb4bd Create redstoneAnalogOutput.lua 2022-08-08 16:47:24 -05:00
toastonrye
0cbded634a Delete redstoneAnalogOutput.lua 2022-08-08 16:46:57 -05:00
toastonrye
6ae0242b00 Create redstoneAnalogOutput.lua 2022-08-08 16:45:39 -05:00
Robert Jelic
ad6bf96124 Merge pull request #24 from EmmaKnijn/master
Issues in the documentation that might've caused confusion
2022-08-08 17:27:52 +02:00
EmmaKnijn
039782ec0e Add clarification
IDs for all objects were recently changed to be optional, but this was not reflected in the example script
2022-08-08 17:12:18 +02:00
EmmaKnijn
878e45bf8c Fix require file names
The default install script offered in docs\home\installer.md would install to the file `basalt.lua` instead of `Basalt.lua`, directly following instructions would cause the example script to error because of this.
2022-08-08 17:10:13 +02:00
Robert Jelic
cf387cab5a Merge pull request #23 from Erb3/patch-1
Readme badges + readme demo
2022-08-08 17:02:03 +02:00
Erlend
bcbca630f8 Readme badges + readme demo resizing
I added some cool™ badges to the README, with the help of shields.io.
I also resized the demo so the readme works better on mobile.
2022-08-08 16:59:35 +02:00
Robert Jelic
cfa2f561e4 Merge pull request #22 from Erb3/master
Improved README + Changelog
2022-08-07 10:25:01 +02:00
Erlend
1bc6cb80d2 Improved README + Changelog 2022-08-07 10:21:38 +02:00
Robert Jelic
323b521ddc Update discordCC.lua 2022-08-06 17:26:40 +02:00
Robert Jelic
80e2ed1c33 Merge pull request #21 from toastonrye/patch-2
Patch 2
2022-08-06 17:23:36 +02:00
toastonrye
46bb1c53f2 Update basaltPreview2.lua
typo
2022-08-06 10:07:21 -05:00
toastonrye
e6717c8648 Update basaltPreview.lua
Copied from the Basalt wiki example
2022-08-06 10:04:22 -05:00
Robert Jelic
5b422905fe Fixed file handle bug
Now it should work on CraftOS PC without any errors
2022-07-29 23:56:55 +02:00
Robert Jelic
00e70c8b4e Update basaltPackager.lua 2022-07-29 23:08:16 +02:00
Robert Jelic
ca38c7d560 -fixed file handle is not closing
Never forget to close file handle guys.
2022-07-29 23:05:22 +02:00
Robert Jelic
a3c2e7a043 Delete oldVersions directory
Not necessary anymore, if you are looking for different versions go and look into the release section.
2022-07-29 14:32:52 +02:00
Robert Jelic
c36690da00 Update main.lua 2022-07-28 22:52:53 +02:00
318 changed files with 8302 additions and 20084 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -13,20 +13,25 @@ return function(name)
local anchor = "topLeft" local anchor = "topLeft"
local ignOffset = false local ignOffset = false
local isVisible = true local isVisible = true
local initialized = false
local isHovered = false
local isClicked = false
local shadow = false local shadow = false
local borderLeft = false local borderColors = {
local borderTop = false left = false,
local borderRight = false right = false,
local borderBottom = false top = false,
bottom = false
}
local shadowColor = colors.black local shadowColor = colors.black
local borderColor = colors.black
local isEnabled = true local isEnabled = true
local isDragging = false local isDragging = false
local dragStartX, dragStartY, dragXOffset, dragYOffset = 0, 0, 0, 0 local dragStartX, dragStartY, dragXOffset, dragYOffset = 0, 0, 0, 0
local visualsChanged = true local draw = true
local activeEvents = {}
local eventSystem = basaltEvent() local eventSystem = basaltEvent()
@@ -36,31 +41,38 @@ return function(name)
width = 1, width = 1,
height = 1, height = 1,
bgColor = colors.black, bgColor = colors.black,
bgSymbol = " ",
bgSymbolColor = colors.black,
fgColor = colors.white, fgColor = colors.white,
transparentColor = false,
name = name or "Object", name = name or "Object",
parent = nil, parent = nil,
show = function(self) show = function(self)
isVisible = true isVisible = true
visualsChanged = true self:updateDraw()
return self return self
end; end;
hide = function(self) hide = function(self)
isVisible = false isVisible = false
visualsChanged = true self:updateDraw()
return self return self
end; end,
enable = function(self) enable = function(self)
isEnabled = true isEnabled = true
return self return self
end; end,
disable = function(self) disable = function(self)
isEnabled = false isEnabled = false
return self return self
end; end,
isEnabled = function(self)
return isEnabled
end,
generateXMLEventFunction = function(self, func, val) generateXMLEventFunction = function(self, func, val)
local createF = function(str) local createF = function(str)
@@ -96,19 +108,20 @@ return function(name)
if(xmlValue("enabled", data)~=nil)then if(xmlValue("enabled", data))then self:enable() else self:disable() end end if(xmlValue("enabled", data)~=nil)then if(xmlValue("enabled", data))then self:enable() else self:disable() end end
if(xmlValue("zIndex", data)~=nil)then self:setZIndex(xmlValue("zIndex", data)) end if(xmlValue("zIndex", data)~=nil)then self:setZIndex(xmlValue("zIndex", data)) end
if(xmlValue("anchor", data)~=nil)then self:setAnchor(xmlValue("anchor", data)) end if(xmlValue("anchor", data)~=nil)then self:setAnchor(xmlValue("anchor", data)) end
if(xmlValue("shadow", data)~=nil)then if(xmlValue("shadow", data))then self:showShadow(true) end end
if(xmlValue("shadowColor", data)~=nil)then self:setShadow(colors[xmlValue("shadowColor", data)]) end if(xmlValue("shadowColor", data)~=nil)then self:setShadow(colors[xmlValue("shadowColor", data)]) end
if(xmlValue("border", data)~=nil)then if(xmlValue("border", data))then borderLeft,borderTop,borderRight,borderBottom = true,true,true,true end end if(xmlValue("border", data)~=nil)then self:setBorder(colors[xmlValue("border", data)]) end
if(xmlValue("borderLeft", data)~=nil)then if(xmlValue("borderLeft", data))then borderLeft = true else borderLeft = false end end if(xmlValue("borderLeft", data)~=nil)then borderColors["left"] = xmlValue("borderLeft", data) end
if(xmlValue("borderTop", data)~=nil)then if(xmlValue("borderTop", data))then borderTop = true else borderTop = false end end if(xmlValue("borderTop", data)~=nil)then borderColors["top"] = xmlValue("borderTop", data) end
if(xmlValue("borderRight", data)~=nil)then if(xmlValue("borderRight", data))then borderRight = true else borderRight = false end end if(xmlValue("borderRight", data)~=nil)then borderColors["right"] = xmlValue("borderRight", data) end
if(xmlValue("borderBottom", data)~=nil)then if(xmlValue("borderBottom", data))then borderBottom = true else borderBottom = false end end if(xmlValue("borderBottom", data)~=nil)then borderColors["bottom"] = xmlValue("borderBottom", data) end
if(xmlValue("borderColor", data)~=nil)then self:setBorder(colors[xmlValue("borderColor", data)]) end if(xmlValue("borderColor", data)~=nil)then self:setBorder(colors[xmlValue("borderColor", data)]) end
if(xmlValue("ignoreOffset", data)~=nil)then if(xmlValue("ignoreOffset", data))then self:ignoreOffset(true) end end if(xmlValue("ignoreOffset", data)~=nil)then if(xmlValue("ignoreOffset", data))then self:ignoreOffset(true) end end
if(xmlValue("onClick", data)~=nil)then self:generateXMLEventFunction(self.onClick, xmlValue("onClick", data)) end if(xmlValue("onClick", data)~=nil)then self:generateXMLEventFunction(self.onClick, xmlValue("onClick", data)) end
if(xmlValue("onClickUp", data)~=nil)then self:generateXMLEventFunction(self.onClickUp, xmlValue("onClickUp", data)) end if(xmlValue("onClickUp", data)~=nil)then self:generateXMLEventFunction(self.onClickUp, xmlValue("onClickUp", data)) end
if(xmlValue("onScroll", data)~=nil)then self:generateXMLEventFunction(self.onScroll, xmlValue("onScroll", data)) end if(xmlValue("onScroll", data)~=nil)then self:generateXMLEventFunction(self.onScroll, xmlValue("onScroll", data)) end
if(xmlValue("onDrag", data)~=nil)then self:generateXMLEventFunction(self.onDrag, xmlValue("onDrag", data)) end if(xmlValue("onDrag", data)~=nil)then self:generateXMLEventFunction(self.onDrag, xmlValue("onDrag", data)) end
if(xmlValue("onHover", data)~=nil)then self:generateXMLEventFunction(self.onHover, xmlValue("onHover", data)) end
if(xmlValue("onLeave", data)~=nil)then self:generateXMLEventFunction(self.onLeave, xmlValue("onLeave", data)) end
if(xmlValue("onKey", data)~=nil)then self:generateXMLEventFunction(self.onKey, xmlValue("onKey", data)) end if(xmlValue("onKey", data)~=nil)then self:generateXMLEventFunction(self.onKey, xmlValue("onKey", data)) end
if(xmlValue("onKeyUp", data)~=nil)then self:generateXMLEventFunction(self.onKeyUp, xmlValue("onKeyUp", data)) end if(xmlValue("onKeyUp", data)~=nil)then self:generateXMLEventFunction(self.onKeyUp, xmlValue("onKeyUp", data)) end
if(xmlValue("onChange", data)~=nil)then self:generateXMLEventFunction(self.onChange, xmlValue("onChange", data)) end if(xmlValue("onChange", data)~=nil)then self:generateXMLEventFunction(self.onChange, xmlValue("onChange", data)) end
@@ -117,9 +130,7 @@ return function(name)
if(xmlValue("onEvent", data)~=nil)then self:generateXMLEventFunction(self.onEvent, xmlValue("onEvent", data)) end if(xmlValue("onEvent", data)~=nil)then self:generateXMLEventFunction(self.onEvent, xmlValue("onEvent", data)) end
if(xmlValue("onGetFocus", data)~=nil)then self:generateXMLEventFunction(self.onGetFocus, xmlValue("onGetFocus", data)) end if(xmlValue("onGetFocus", data)~=nil)then self:generateXMLEventFunction(self.onGetFocus, xmlValue("onGetFocus", data)) end
if(xmlValue("onLoseFocus", data)~=nil)then self:generateXMLEventFunction(self.onLoseFocus, xmlValue("onLoseFocus", data)) end if(xmlValue("onLoseFocus", data)~=nil)then self:generateXMLEventFunction(self.onLoseFocus, xmlValue("onLoseFocus", data)) end
if(xmlValue("onBackgroundKey", data)~=nil)then self:generateXMLEventFunction(self.onBackgroundKey, xmlValue("onBackgroundKey", data)) end self:updateDraw()
if(xmlValue("onBackgroundKeyUp", data)~=nil)then self:generateXMLEventFunction(self.onBackgroundKeyUp, xmlValue("onBackgroundKeyUp", data)) end
return self return self
end, end,
@@ -139,9 +150,19 @@ return function(name)
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:removeObject(self) self.parent:removeObject(self)
self.parent:addObject(self) self.parent:addObject(self)
self:updateEventHandlers()
end end
return self return self
end; end,
updateEventHandlers = function(self)
for k,v in pairs(activeEvents)do
if(v)then
self.parent:addEvent(k, self)
end
end
end,
getZIndex = function(self) getZIndex = function(self)
return zIndex; return zIndex;
@@ -159,6 +180,7 @@ return function(name)
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:removeObject(self) self.parent:removeObject(self)
end end
self:updateDraw()
return self return self
end; end;
@@ -176,7 +198,7 @@ return function(name)
setValue = function(self, _value) setValue = function(self, _value)
if (value ~= _value) then if (value ~= _value) then
value = _value value = _value
visualsChanged = true self:updateDraw()
self:valueChangedHandler() self:valueChangedHandler()
end end
return self return self
@@ -186,13 +208,14 @@ return function(name)
return value return value
end; end;
getVisualChanged = function(self) getDraw = function(self)
return visualsChanged return draw
end; end;
setVisualChanged = function(self, change) updateDraw = function(self, change)
visualsChanged = change or true draw = change
if(change == nil)then visualsChanged = true end if(change == nil)then draw = true end
if(draw)then if(self.parent~=nil)then self.parent:updateDraw() end end
return self return self
end; end;
@@ -206,10 +229,6 @@ return function(name)
return self.parent return self.parent
end; end;
getObjectReferencesForDynVal = function(self, str)
end,
setPosition = function(self, xPos, yPos, rel) setPosition = function(self, xPos, yPos, rel)
if(type(xPos)=="number")then if(type(xPos)=="number")then
self.x = rel and self:getX()+xPos or xPos self.x = rel and self:getX()+xPos or xPos
@@ -227,7 +246,7 @@ return function(name)
self.parent:recalculateDynamicValues() self.parent:recalculateDynamicValues()
end end
eventSystem:sendEvent("basalt_reposition", self) eventSystem:sendEvent("basalt_reposition", self)
visualsChanged = true self:updateDraw()
return self return self
end; end;
@@ -249,16 +268,16 @@ return function(name)
setVisibility = function(self, _isVisible) setVisibility = function(self, _isVisible)
isVisible = _isVisible or not isVisible isVisible = _isVisible or not isVisible
visualsChanged = true self:updateDraw()
return self return self
end; end;
setSize = function(self, width, height, rel) setSize = function(self, width, height, rel)
if(type(width)=="number")then if(type(width)=="number")then
self.width = rel and self.width+width or width self.width = rel and self:getWidth()+width or width
end end
if(type(height)=="number")then if(type(height)=="number")then
self.height = rel and self.height+height or height self.height = rel and self:getHeight()+height or height
end end
if(self.parent~=nil)then if(self.parent~=nil)then
if(type(width)=="string")then if(type(width)=="string")then
@@ -270,7 +289,7 @@ return function(name)
self.parent:recalculateDynamicValues() self.parent:recalculateDynamicValues()
end end
eventSystem:sendEvent("basalt_resize", self) eventSystem:sendEvent("basalt_resize", self)
visualsChanged = true self:updateDraw()
return self return self
end; end;
@@ -291,12 +310,23 @@ return function(name)
if(type(self.height)=="table")then self.height:calculate() end if(type(self.height)=="table")then self.height:calculate() end
if(type(self.x)=="table")then self.x:calculate() end if(type(self.x)=="table")then self.x:calculate() end
if(type(self.y)=="table")then self.y:calculate() end if(type(self.y)=="table")then self.y:calculate() end
self:updateDraw()
return self return self
end, end,
setBackground = function(self, color) setBackground = function(self, color, symbol, symbolCol)
self.bgColor = color or false self.bgColor = color or false
visualsChanged = true self.bgSymbol = symbol or (self.bgColor~=false and self.bgSymbol or false)
self.bgSymbolColor = symbolCol or self.bgSymbolColor
self:updateDraw()
return self
end;
setTransparent = function(self, color)
self.transparentColor = color or false
self.bgSymbol = false
self.bgSymbolColor = false
self:updateDraw()
return self return self
end; end;
@@ -306,7 +336,7 @@ return function(name)
setForeground = function(self, color) setForeground = function(self, color)
self.fgColor = color or false self.fgColor = color or false
visualsChanged = true self:updateDraw()
return self return self
end; end;
@@ -314,13 +344,14 @@ return function(name)
return self.fgColor return self.fgColor
end; end;
showShadow = function(self, show)
shadow = show or (not shadow)
return self
end;
setShadow = function(self, color) setShadow = function(self, color)
shadowColor = color if(color==false)then
shadow = false
else
shadowColor = color
shadow = true
end
self:updateDraw()
return self return self
end; end;
@@ -328,26 +359,25 @@ return function(name)
return shadow; return shadow;
end; end;
showBorder = function(self, ...) setBorder = function(self, ...)
for _,v in pairs(table.pack(...))do if(...~=nil)then
if(v=="left")then local t = {...}
borderLeft = true for k,v in pairs(t)do
end if(v=="left")or(#t==1)then
if(v=="top")then borderColors["left"] = t[1]
borderTop = true end
end if(v=="top")or(#t==1)then
if(v=="right")then borderColors["top"] = t[1]
borderRight = true end
end if(v=="right")or(#t==1)then
if(v=="bottom")then borderColors["right"] = t[1]
borderBottom = true end
if(v=="bottom")or(#t==1)then
borderColors["bottom"] = t[1]
end
end end
end end
return self self:updateDraw()
end;
setBorder = function(self, color)
borderColor = color
return self return self
end; end;
@@ -367,52 +397,75 @@ return function(name)
end; end;
draw = function(self) draw = function(self)
if (isVisible) then if (isVisible)then
if(self.parent~=nil)then if(self.parent~=nil)then
local x, y = self:getAnchorPosition() local x, y = self:getAnchorPosition()
local w,h = self:getSize() local w,h = self:getSize()
local wP,hP = self.parent:getSize()
if(x+w<1)or(x>wP)or(y+h<1)or(y>hP)then return false end
if(self.transparentColor~=false)then
self.parent:drawForegroundBox(x, y, w, h, self.transparentColor)
end
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(x, y, w, h, self.bgColor)
end
if(self.bgSymbol~=false)then
self.parent:drawTextBox(x, y, w, h, self.bgSymbol)
if(self.bgSymbol~=" ")then
self.parent:drawForegroundBox(x, y, w, h, self.bgSymbolColor)
end
end
if(shadow)then if(shadow)then
self.parent:drawBackgroundBox(x+1, y+h, w, 1, shadowColor) self.parent:drawBackgroundBox(x+1, y+h, w, 1, shadowColor)
self.parent:drawBackgroundBox(x+w, y+1, 1, h, shadowColor) self.parent:drawBackgroundBox(x+w, y+1, 1, h, shadowColor)
self.parent:drawForegroundBox(x+1, y+h, w, 1, shadowColor) self.parent:drawForegroundBox(x+1, y+h, w, 1, shadowColor)
self.parent:drawForegroundBox(x+w, y+1, 1, h, shadowColor) self.parent:drawForegroundBox(x+w, y+1, 1, h, shadowColor)
end end
if(borderLeft)then
self.parent:drawTextBox(x-1, y, 1, h, "\149") local bgCol = self.bgColor
self.parent:drawForegroundBox(x-1, y, 1, h, borderColor) if(borderColors["left"]~=false)then
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y, 1, h, self.bgColor) end self.parent:drawTextBox(x, y, 1, h, "\149")
if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, 1, h, self.bgColor) end
self.parent:drawForegroundBox(x, y, 1, h, borderColors["left"])
end end
if(borderLeft)and(borderTop)then if(borderColors["top"]~=false)then
self.parent:drawTextBox(x-1, y-1, 1, 1, "\151")
self.parent:drawForegroundBox(x-1, y-1, 1, 1, borderColor) self.parent:drawTextBox(x, y, w, 1, "\131")
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y-1, 1, 1, self.bgColor) end if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, w, 1, self.bgColor) end
self.parent:drawForegroundBox(x, y, w, 1, borderColors["top"])
end end
if(borderTop)then if(borderColors["left"]~=false)and(borderColors["top"]~=false)then
self.parent:drawTextBox(x, y-1, w, 1, "\131") self.parent:drawTextBox(x, y, 1, 1, "\151")
self.parent:drawForegroundBox(x, y-1, w, 1, borderColor) if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, 1, 1, self.bgColor) end
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x, y-1, w, 1, self.bgColor) end self.parent:drawForegroundBox(x, y, 1, 1, borderColors["left"])
end end
if(borderTop)and(borderRight)then if(borderColors["right"]~=false)then
self.parent:drawTextBox(x+w, y-1, 1, 1, "\149") self.parent:drawTextBox(x+w-1, y, 1, h, "\149")
self.parent:drawForegroundBox(x+w, y-1, 1, 1, borderColor) if(bgCol~=false)then self.parent:drawForegroundBox(x+w-1, y, 1, h, self.bgColor) end
self.parent:drawBackgroundBox(x+w-1, y, 1, h, borderColors["right"])
end end
if(borderRight)then if(borderColors["bottom"]~=false)then
self.parent:drawTextBox(x+w, y, 1, h, "\149") self.parent:drawTextBox(x, y+h-1, w, 1, "\143")
self.parent:drawForegroundBox(x+w, y, 1, h, borderColor) if(bgCol~=false)then self.parent:drawForegroundBox(x, y+h-1, w, 1, self.bgColor) end
self.parent:drawBackgroundBox(x, y+h-1, w, 1, borderColors["bottom"])
end end
if(borderRight)and(borderBottom)then if(borderColors["top"]~=false)and(borderColors["right"]~=false)then
self.parent:drawTextBox(x+w, y+h, 1, 1, "\129") self.parent:drawTextBox(x+w-1, y, 1, 1, "\148")
self.parent:drawForegroundBox(x+w, y+h, 1, 1, borderColor) if(bgCol~=false)then self.parent:drawForegroundBox(x+w-1, y, 1, 1, self.bgColor) end
self.parent:drawBackgroundBox(x+w-1, y, 1, 1, borderColors["right"])
end end
if(borderBottom)then if(borderColors["right"]~=false)and(borderColors["bottom"]~=false)then
self.parent:drawTextBox(x, y+h, w, 1, "\131") self.parent:drawTextBox(x+w-1, y+h-1, 1, 1, "\133")
self.parent:drawForegroundBox(x, y+h, w, 1, borderColor) if(bgCol~=false)then self.parent:drawForegroundBox(x+w-1, y+h-1, 1, 1, self.bgColor) end
self.parent:drawBackgroundBox(x+w-1, y+h-1, 1, 1, borderColors["right"])
end end
if(borderBottom)and(borderLeft)then if(borderColors["bottom"]~=false)and(borderColors["left"]~=false)then
self.parent:drawTextBox(x-1, y+h, 1, 1, "\131") self.parent:drawTextBox(x, y+h-1, 1, 1, "\138")
self.parent:drawForegroundBox(x-1, y+h, 1, 1, borderColor) if(bgCol~=false)then self.parent:drawForegroundBox(x-1, y+h-1, 1, 1, self.bgColor) end
self.parent:drawBackgroundBox(x, y+h-1, 1, 1, borderColors["left"])
end end
end end
draw = false
return true return true
end end
return false return false
@@ -487,7 +540,7 @@ return function(name)
setAnchor = function(self, newAnchor) setAnchor = function(self, newAnchor)
anchor = newAnchor anchor = newAnchor
visualsChanged = true self:updateDraw()
return self return self
end; end;
@@ -505,24 +558,49 @@ return function(name)
end; end;
onClick = function(self, ...) onClick = function(self, ...)
for _,v in pairs(table.pack(...))do for _,v in pairs(table.pack(...))do
if(type(v)=="function")then if(type(v)=="function")then
self:registerEvent("mouse_click", v) self:registerEvent("mouse_click", v)
self:registerEvent("monitor_touch", v) end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
self.parent:addEvent("mouse_up", self)
activeEvents["mouse_up"] = true
end end
end
return self return self
end; end;
onClickUp = function(self, ...) onClickUp = function(self, ...)
for _,v in pairs(table.pack(...))do for _,v in pairs(table.pack(...))do
if(type(v)=="function")then if(type(v)=="function")then
self:registerEvent("mouse_up", v) self:registerEvent("mouse_up", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
self.parent:addEvent("mouse_up", self)
activeEvents["mouse_up"] = true
end end
end
return self return self
end; end;
onRelease = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_release", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
self.parent:addEvent("mouse_up", self)
activeEvents["mouse_up"] = true
end
return self
end;
onScroll = function(self, ...) onScroll = function(self, ...)
for _,v in pairs(table.pack(...))do for _,v in pairs(table.pack(...))do
@@ -530,34 +608,94 @@ return function(name)
self:registerEvent("mouse_scroll", v) self:registerEvent("mouse_scroll", v)
end end
end end
if(self.parent~=nil)then
self.parent:addEvent("mouse_scroll", self)
activeEvents["mouse_scroll"] = true
end
return self
end;
onHover = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_hover", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_move", self)
activeEvents["mouse_move"] = true
end
return self
end;
onLeave = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_leave", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_move", self)
activeEvents["mouse_move"] = true
end
return self return self
end; end;
onDrag = function(self, ...) onDrag = function(self, ...)
if(isEnabled)then for _,v in pairs(table.pack(...))do
for _,v in pairs(table.pack(...))do if(type(v)=="function")then
if(type(v)=="function")then self:registerEvent("mouse_drag", v)
self:registerEvent("mouse_drag", v)
end
end end
end end
if(self.parent~=nil)then
self.parent:addEvent("mouse_drag", self)
activeEvents["mouse_drag"] = true
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
self.parent:addEvent("mouse_up", self)
activeEvents["mouse_up"] = true
end
return self return self
end; end;
onEvent = function(self, ...) onEvent = function(self, ...)
for _,v in pairs(table.pack(...))do for _,v in pairs(table.pack(...))do
if(type(v)=="function")then if(type(v)=="function")then
self:registerEvent("custom_event_handler", v) self:registerEvent("other_event", v)
end end
end end
if(self.parent~=nil)then
self.parent:addEvent("other_event", self)
activeEvents["other_event"] = true
end
return self return self
end; end;
onKey = function(self, ...) onKey = function(self, ...)
for _,v in pairs(table.pack(...))do if(isEnabled)then
if(type(v)=="function")then for _,v in pairs(table.pack(...))do
self:registerEvent("key", v) if(type(v)=="function")then
self:registerEvent("char", v) self:registerEvent("key", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("key", self)
activeEvents["key"] = true
end
end
return self
end;
onChar = function(self, ...)
if(isEnabled)then
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("char", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("char", self)
activeEvents["char"] = true
end end
end end
return self return self
@@ -582,30 +720,15 @@ return function(name)
end; end;
onKeyUp = function(self, ...) onKeyUp = function(self, ...)
for _,v in pairs(table.pack(...))do for _,v in pairs(table.pack(...))do
if(type(v)=="function")then if(type(v)=="function")then
self:registerEvent("key_up", v) self:registerEvent("key_up", v)
end
end end
end if(self.parent~=nil)then
return self self.parent:addEvent("key_up", self)
end; activeEvents["key_up"] = true
onBackgroundKey = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("background_key", v)
self:registerEvent("background_char", v)
end end
end
return self
end;
onBackgroundKeyUp = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("background_key_up", v)
end
end
return self return self
end; end;
@@ -622,6 +745,10 @@ return function(name)
self:registerEvent("get_focus", v) self:registerEvent("get_focus", v)
end end
end end
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
end
return self return self
end; end;
@@ -631,6 +758,10 @@ return function(name)
self:registerEvent("lose_focus", v) self:registerEvent("lose_focus", v)
end end
end end
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
end
return self return self
end; end;
@@ -646,79 +777,139 @@ return function(name)
return eventSystem:sendEvent(event, self, ...) return eventSystem:sendEvent(event, self, ...)
end; end;
mouseHandler = function(self, event, button, x, y) isCoordsInObject = function(self, x, y)
if(isEnabled)and(isVisible)then if(isVisible)and(isEnabled)then
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) if(x==nil)or(y==nil)then return false end
local w, h = self:getSize() local objX, objY = self:getAbsolutePosition()
local yOff = false local w, h = self:getSize()
if(objY-1 == y)and(self:getBorder("top"))then
y = y+1
yOff = true
end
if(event=="mouse_up")then
isDragging = false
end
if(isDragging)and(event=="mouse_drag")then
local xO, yO, parentX, parentY = 0, 0, 1, 1
if (self.parent ~= nil) then
xO, yO = self.parent:getOffsetInternal()
xO = xO < 0 and math.abs(xO) or -xO
yO = yO < 0 and math.abs(yO) or -yO
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
end
local dX, dY = x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO
local val = eventSystem:sendEvent(event, self, event, button, dX, dY, dragStartX, dragStartY, x, y)
end
if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) then if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) then
if(event=="mouse_click")then
isDragging = true
dragStartX, dragStartY = x, y
dragXOffset, dragYOffset = objX - x, objY - y
end
if(event~="mouse_drag")then
if(event~="mouse_up")then
if (self.parent ~= nil) then
self.parent:setFocusedObject(self)
end
end
local val = eventSystem:sendEvent(event, self, event, button, x, y)
if(val~=nil)then return val end
end
return true return true
end end
end end
return false return false
end; end,
keyHandler = function(self, event, key) mouseHandler = function(self, button, x, y, isMon)
if(isEnabled)then if(self:isCoordsInObject(x, y))then
if (self:isFocused()) then local objX, objY = self:getAbsolutePosition()
local val = eventSystem:sendEvent(event, self, event, key) local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x - (objX-1), y - (objY-1), isMon)
if(val~=nil)then return val end if(val==false)then return false end
return true if(self.parent~=nil)then
self.parent:setFocusedObject(self)
end end
isClicked = true
isDragging = true
dragStartX, dragStartY = x, y
return true
end end
return false return false
end; end,
backgroundKeyHandler = function(self, event, key) mouseUpHandler = function(self, button, x, y)
if(isEnabled)then isDragging = false
local val = eventSystem:sendEvent("background_"..event, self, event, key) if(isClicked)then
local objX, objY = self:getAbsolutePosition()
local val = eventSystem:sendEvent("mouse_release", self, "mouse_release", button, x - (objX-1), y - (objY-1))
isClicked = false
end
if(self:isCoordsInObject(x, y))then
local objX, objY = self:getAbsolutePosition()
local val = eventSystem:sendEvent("mouse_up", self, "mouse_up", button, x - (objX-1), y - (objY-1))
if(val==false)then return false end
return true
end
return false
end,
dragHandler = function(self, button, x, y)
if(isDragging)then
local objX, objY = self:getAbsolutePosition()
local val = eventSystem:sendEvent("mouse_drag", self, "mouse_drag", button, x - (objX-1), y - (objY-1), dragStartX-x, dragStartY-y, x, y)
dragStartX, dragStartY = x, y
if(val~=nil)then return val end if(val~=nil)then return val end
if(self.parent~=nil)then
self.parent:setFocusedObject(self)
end
return true
end end
return true
if(self:isCoordsInObject(x, y))then
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
dragStartX, dragStartY = x, y
dragXOffset, dragYOffset = objX - x, objY - y
end
return false
end,
scrollHandler = function(self, dir, x, y)
if(self:isCoordsInObject(x, y))then
local objX, objY = self:getAbsolutePosition()
local val = eventSystem:sendEvent("mouse_scroll", self, "mouse_scroll", dir, x - (objX-1), y - (objY-1))
if(val==false)then return false end
if(self.parent~=nil)then
self.parent:setFocusedObject(self)
end
return true
end
return false
end,
hoverHandler = function(self, x, y, stopped)
if(self:isCoordsInObject(x, y))then
local val = eventSystem:sendEvent("mouse_hover", self, "mouse_hover", x, y, stopped)
if(val==false)then return false end
isHovered = true
return true
end
if(isHovered)then
local val = eventSystem:sendEvent("mouse_leave", self, "mouse_leave", x, y, stopped)
if(val==false)then return false end
isHovered = false
end
return false
end,
keyHandler = function(self, key, isHolding)
if(isEnabled)and(isVisible)then
if (self:isFocused()) then
local val = eventSystem:sendEvent("key", self, "key", key, isHolding)
if(val==false)then return false end
return true
end
end
return false
end; end;
keyUpHandler = function(self, key)
if(isEnabled)and(isVisible)then
if (self:isFocused()) then
local val = eventSystem:sendEvent("key_up", self, "key_up", key)
if(val==false)then return false end
return true
end
end
return false
end;
charHandler = function(self, char)
if(isEnabled)and(isVisible)then
if (self:isFocused()) then
local val = eventSystem:sendEvent("char", self, "char", char)
if(val==false)then return false end
return true
end
end
return false
end,
valueChangedHandler = function(self) valueChangedHandler = function(self)
eventSystem:sendEvent("value_changed", self) eventSystem:sendEvent("value_changed", self, value)
end; end;
eventHandler = function(self, event, p1, p2, p3, p4) eventHandler = function(self, event, p1, p2, p3, p4)
eventSystem:sendEvent("custom_event_handler", self, event, p1, p2, p3, p4) local val = eventSystem:sendEvent("other_event", self, event, p1, p2, p3, p4)
if(val~=nil)then return val end
return true
end; end;
getFocusHandler = function(self) getFocusHandler = function(self)
@@ -728,11 +919,26 @@ return function(name)
end; end;
loseFocusHandler = function(self) loseFocusHandler = function(self)
isDragging = false
local val = eventSystem:sendEvent("lose_focus", self) local val = eventSystem:sendEvent("lose_focus", self)
if(val~=nil)then return val end if(val~=nil)then return val end
return true return true
end; end;
init = function(self)
if(self.parent~=nil)then
for k,v in pairs(activeEvents)do
if(v)then
self.parent:addEvent(k, self)
end
end
end
if not(initialized)then
initialized = true
return true
end
return false
end
} }

View File

@@ -28,6 +28,7 @@ return function(drawTerm)
createEmptyLines() createEmptyLines()
local function recreateWindowArray() local function recreateWindowArray()
createEmptyLines()
local emptyText = emptySpaceLine local emptyText = emptySpaceLine
local emptyFG = emptyColorLines[colors.white] local emptyFG = emptyColorLines[colors.white]
local emptyBG = emptyColorLines[colors.black] local emptyBG = emptyColorLines[colors.black]
@@ -126,6 +127,11 @@ return function(drawTerm)
end end
local drawHelper = { local drawHelper = {
setSize = function(w, h)
width, height = w, h
recreateWindowArray()
end,
setMirror = function(mirror) setMirror = function(mirror)
mirrorTerm = mirror mirrorTerm = mirror
end, end,
@@ -157,11 +163,15 @@ return function(drawTerm)
end end
end; end;
writeText = function(x, y, text, bgCol, fgCol) writeText = function(x, y, text, bgCol, fgCol)
bgCol = bgCol or terminal.getBackgroundColor() if(text~=nil)then
fgCol = fgCol or terminal.getTextColor() setText(x, y, text)
setText(x, y, text) if(bgCol~=nil)and(bgCol~=false)then
setBG(x, y, rep(tHex[bgCol], text:len())) setBG(x, y, rep(tHex[bgCol], text:len()))
setFG(x, y, rep(tHex[fgCol], text:len())) end
if(fgCol~=nil)and(fgCol~=false)then
setFG(x, y, rep(tHex[fgCol], text:len()))
end
end
end; end;
update = function() update = function()
@@ -171,7 +181,7 @@ return function(drawTerm)
isBlinking = terminal.getCursorBlink() isBlinking = terminal.getCursorBlink()
end end
terminal.setCursorBlink(false) terminal.setCursorBlink(false)
if(mirrorTerm~=nil)then terminal.setCursorBlink(false) end if(mirrorTerm~=nil)then mirrorTerm.setCursorBlink(false) end
for n = 1, height do for n = 1, height do
terminal.setCursorPos(1, n) terminal.setCursorPos(1, n)
terminal.blit(cacheT[n], cacheFG[n], cacheBG[n]) terminal.blit(cacheT[n], cacheFG[n], cacheBG[n])

View File

@@ -0,0 +1,20 @@
local logDir = ""
local logFileName = "basaltLog.txt"
local defaultLogType = "Debug"
fs.delete(logDir~="" and logDir.."/"..logFileName or logFileName)
local mt = {
__call = function(_,text, typ)
if(text==nil)then return end
local dirStr = logDir~="" and logDir.."/"..logFileName or logFileName
local handle = fs.open(dirStr, fs.exists(dirStr) and "a" or "w")
handle.writeLine("[Basalt]["..(typ and typ or defaultLogType).."]: "..tostring(text))
handle.close()
end,
}
return setmetatable({}, mt)
--Work in progress

View File

@@ -0,0 +1,199 @@
-- Right now this doesn't support scroll(n)
-- Because this lbirary is mainly made for basalt - it doesn't need scroll support, maybe i will add it in the future
local tHex = {
[colors.white] = "0",
[colors.orange] = "1",
[colors.magenta] = "2",
[colors.lightBlue] = "3",
[colors.yellow] = "4",
[colors.lime] = "5",
[colors.pink] = "6",
[colors.gray] = "7",
[colors.lightGray] = "8",
[colors.cyan] = "9",
[colors.purple] = "a",
[colors.blue] = "b",
[colors.brown] = "c",
[colors.green] = "d",
[colors.red] = "e",
[colors.black] = "f",
}
local type,len,rep,sub = type,string.len,string.rep,string.sub
return function (monitorNames)
local monitors = {}
for k,v in pairs(monitorNames)do
monitors[k] = {}
for a,b in pairs(v)do
local mon = peripheral.wrap(b)
if(mon==nil)then
error("Unable to find monitor "..b)
end
monitors[k][a] = mon
monitors[k][a].name = b
end
end
local x,y,monX,monY,monW,monH,w,h = 1,1,1,1,0,0,0,0
local blink,scale = false,1
local fg,bg = colors.white,colors.black
local function calcSize()
local maxW,maxH = 0,0
for k,v in pairs(monitors)do
local _maxW,_maxH = 0,0
for a,b in pairs(v)do
local nw,nh = b.getSize()
_maxW = _maxW + nw
_maxH = nh > _maxH and nh or _maxH
end
maxW = maxW > _maxW and maxW or _maxW
maxH = maxH + _maxH
end
w,h = maxW,maxH
end
calcSize()
local function calcPosition()
local relY = 0
local mX,mY = 0,0
for k,v in pairs(monitors)do
local relX = 0
local _mh = 0
for a,b in pairs(v)do
local mw,mh = b.getSize()
if(x-relX>=1)and(x-relX<=mw)then
mX = a
end
b.setCursorPos(x-relX, y-relY)
relX = relX + mw
if(_mh<mh)then _mh = mh end
end
if(y-relY>=1)and(y-relY<=_mh)then
mY = k
end
relY = relY + _mh
end
monX,monY = mX,mY
end
calcPosition()
local function call(f, ...)
local t = {...}
return function()
for k,v in pairs(monitors)do
for a,b in pairs(v)do
b[f](table.unpack(t))
end
end
end
end
local function cursorBlink()
call("setCursorBlink", false)()
if not(blink)then return end
if(monitors[monY]==nil)then return end
local mon = monitors[monY][monX]
if(mon==nil)then return end
mon.setCursorBlink(blink)
end
local function blit(text, tCol, bCol)
if(monitors[monY]==nil)then return end
local mon = monitors[monY][monX]
if(mon==nil)then return end
mon.blit(text, tCol, bCol)
local mW, mH = mon.getSize()
if(len(text)+x>mW)then
local monRight = monitors[monY][monX+1]
if(monRight~=nil)then
monRight.blit(text, tCol, bCol)
monX = monX + 1
x = x + len(text)
end
end
calcPosition()
end
return {
clear = call("clear"),
setCursorBlink = function(_blink)
blink = _blink
cursorBlink()
end,
getCursorBlink = function()
return blink
end,
getCursorPos = function()
return x, y
end,
setCursorPos = function(newX,newY)
x, y = newX, newY
calcPosition()
cursorBlink()
end,
setTextScale = function(_scale)
call("setTextScale", _scale)()
calcSize()
calcPosition()
scale = _scale
end,
getTextScale = function()
return scale
end,
blit = function(text,fgCol,bgCol)
blit(text,fgCol,bgCol)
end,
write = function(text)
text = tostring(text)
local l = len(text)
blit(text, rep(tHex[fg], l), rep(tHex[bg], l))
end,
getSize = function()
return w,h
end,
setBackgroundColor = function(col)
call("setBackgroundColor", col)()
bg = col
end,
setTextColor = function(col)
call("setTextColor", col)()
fg = col
end,
calculateClick = function(name, xClick, yClick)
local relY = 0
for k,v in pairs(monitors)do
local relX = 0
local maxY = 0
for a,b in pairs(v)do
local wM,hM = b.getSize()
if(b.name==name)then
return xClick + relX, yClick + relY
end
relX = relX + wM
if(hM > maxY)then maxY = hM end
end
relY = relY + maxY
end
return xClick, yClick
end,
}
end

View File

@@ -1,197 +0,0 @@
local function line(x1,y1,x2,y2)
local points = {}
if x1 == x2 and y1 == y2 then return {x=x1,y=x2} end
local minX = math.min(x1, x2)
local maxX, minY, maxY
if minX == x1 then minY,maxX,maxY = y1,x2,y2
else minY,maxX,maxY = y2,x1,y1 end
local xDiff,yDiff = maxX - minX,maxY - minY
if xDiff > math.abs(yDiff) then
local y = minY
local dy = yDiff / xDiff
for x = minX, maxX do
table.insert(points,{x=x,y=math.floor(y + 0.5)})
y = y + dy
end
else
local x,dx = minX,xDiff / yDiff
if maxY >= minY then
for y = minY, maxY do
table.insert(points,{x=math.floor(x + 0.5),y=y})
x = x + dx
end
else
for y = minY, maxY, -1 do
table.insert(points,{x=math.floor(x + 0.5),y=y})
x = x - dx
end
end
end
return points
end
local function filledCircle(xC, yC, r)
local points = {}
for x=-r, r+1 do
local dy = math.floor(math.sqrt(r*r - x*x))
for y=-dy, dy+1 do
table.insert(points, {x=xC+x, y=yC+y})
end
end
return points
end
local function ellipse(xC, yC, r1, r2, filled)
local rx,ry = math.ceil(math.floor(r1-0.5)/2),math.ceil(math.floor(r2-0.5)/2)
local x,y=0,ry
local d1 = ((ry * ry) - (rx * rx * ry) + (0.25 * rx * rx))
local dx = 2*ry^2*x
local dy = 2*rx^2*y
local points = {}
while dx < dy do
table.insert(points,{x=x+xC,y=y+yC})
table.insert(points,{x=-x+xC,y=y+yC})
table.insert(points,{x=x+xC,y=-y+yC})
table.insert(points,{x=-x+xC,y=-y+yC})
if filled then
for y=-y+yC+1,y+yC-1 do
table.insert(points,{x=x+xC,y=y})
table.insert(points,{x=-x+xC,y=y})
end
end
if d1 < 0 then
x = x + 1
dx = dx + 2*ry^2
d1 = d1 + dx + ry^2
else
x,y = x+1,y-1
dx = dx + 2*ry^2
dy = dy - 2*rx^2
d1 = d1 + dx - dy + ry^2
end
end
local d2 = (((ry * ry) * ((x + 0.5) * (x + 0.5))) + ((rx * rx) * ((y - 1) * (y - 1))) - (rx * rx * ry * ry))
while y >= 0 do
table.insert(points,{x=x+xC,y=y+yC})
table.insert(points,{x=-x+xC,y=y+yC})
table.insert(points,{x=x+xC,y=-y+yC})
table.insert(points,{x=-x+xC,y=-y+yC})
if filled then
for y=-y+yC,y+yC do
table.insert(points,{x=x+xC,y=y})
table.insert(points,{x=-x+xC,y=y})
end
end
if d2 > 0 then
y = y - 1
dy = dy - 2*rx^2
d2 = d2 + rx^2 - dy
else
y = y - 1
x = x + 1
dy = dy - 2*rx^2
dx = dx + 2*ry^2
d2 = d2 + dx - dy + rx^2
end
end
return points
end
local function circle(xC, yC, r, filled)
return ellipse(xC, yC, r, r, filled)
end
return {
circle = function(x, y, radius, filled)
return circle(x, y, radius, filled)
end,
rectangle = function(x1, y1, x2, y2, filled)
local points = {}
if(filled)then
for y=y1,y2 do
for x=x1,x2 do
table.insert(points, {x=x,y=y})
end
end
else
for y=y1,y2 do
for x=x1,x2 do
if(x==x1)or(x==x2)or(y==y1)or(y==y2)then
table.insert(points, {x=x,y=y})
end
end
end
end
return points
end,
triangle = function(x1, y1, x2, y2, x3, y3, filled)
local function drawFlatTopTriangle(points,x1,y1,x2,y2,x3,y3)
local m1 = (x3 - x1) / (y3 - y1)
local m2 = (x3 - x2) / (y3 - y2)
local yStart = math.ceil(y1 - 0.5)
local yEnd = math.ceil(y3 - 0.5)-1
for y = yStart, yEnd do
local px1 = m1 * (y + 0.5 - y1) + x1
local px2 = m2 * (y + 0.5 - y2) + x2
local xStart = math.ceil(px1 - 0.5)
local xEnd = math.ceil(px2 - 0.5)
for x=xStart,xEnd do
table.insert(points,{x=x,y=y})
end
end
end
local function drawFlatBottomTriangle(points,x1,y1,x2,y2,x3,y3)
local m1 = (x2 - x1) / (y2 - y1)
local m2 = (x3 - x1) / (y3 - y1)
local yStart = math.ceil(y1-0.5)
local yEnd = math.ceil(y3-0.5)-1
for y = yStart, yEnd do
local px1 = m1 * (y + 0.5 - y1) + x1
local px2 = m2 * (y + 0.5 - y1) + x1
local xStart = math.ceil(px1 - 0.5)
local xEnd = math.ceil(px2 - 0.5)
for x=xStart,xEnd do
table.insert(points,{x=x,y=y})
end
end
end
local points = {}
if(filled)then
if y2 < y1 then x1,y1,x2,y2 = x2,y2,x1,y1 end
if y3 < y2 then x2,y2,x3,y3 = x3,y3,x2,y2 end
if y2 < y2 then x1,y1,x2,y2 = x2,y2,x1,y1 end
if y1 == y2 then
if x2 < x1 then x1,y1,x2,y2 = x2,y2,x1,y1 end
drawFlatTopTriangle(points,x1,y1,x2,y2,x3,y3)
elseif y2 == y3 then
if x3 < x2 then x3,y3,x2,y2 = x2,y2,x3,y3 end
drawFlatBottomTriangle(points,x1,y1,x2,y2,x3,y3)
else
local alphaSplit = (y2-y1)/(y3-y1)
local x = x1 + ((x3 - x1) * alphaSplit)
local y = y1 + ((y3 - y1) * alphaSplit)
if x2 < x then
drawFlatBottomTriangle(points,x1,y1,x2,y2,x, y)
drawFlatTopTriangle(points,x2,y2,x,y,x3,y3)
else
drawFlatBottomTriangle(points,x1,y1,x,y,x1,y1)
drawFlatTopTriangle(points,x,y,x2,y2,x3,y3)
end
end
else
points = line(x1,y1,x2,y2)
for k,v in pairs(line(x2,y2,x3,y3))do table.insert(points, v) end
for k,v in pairs(line(x3,y3,x1,y1))do table.insert(points, v) end
end
return points
end,
line = line,
ellipse = function(xCenter, yCenter, radius1, radius2, filled)
return ellipse(xCenter, yCenter, radius1, radius2, filled)
end
}

View File

@@ -0,0 +1,4 @@
return function(path)
local exists, content = pcall(require, path)
return exists and content or nil
end

View File

@@ -3,13 +3,21 @@ local process = {}
local processId = 0 local processId = 0
function process:new(path, window, ...) function process:new(path, window, ...)
local args = table.pack(...) local args = {...}
local newP = setmetatable({ path = path }, { __index = self }) local newP = setmetatable({ path = path }, { __index = self })
newP.window = window newP.window = window
newP.processId = processId newP.processId = processId
if(type(path)=="string")then
newP.coroutine = coroutine.create(function() newP.coroutine = coroutine.create(function()
os.run({ }, path, table.unpack(args)) shell.execute(path, table.unpack(args))
end) end)
elseif(type(path)=="function")then
newP.coroutine = coroutine.create(function()
path(table.unpack(args))
end)
else
return
end
processes[processId] = newP processes[processId] = newP
processId = processId + 1 processId = processId + 1
return newP return newP
@@ -17,12 +25,15 @@ end
function process:resume(event, ...) function process:resume(event, ...)
term.redirect(self.window) term.redirect(self.window)
if(self.filter~=nil)then
if(event~=self.filter)then return end
self.filter=nil
end
local ok, result = coroutine.resume(self.coroutine, event, ...) local ok, result = coroutine.resume(self.coroutine, event, ...)
self.window = term.current()
if ok then if ok then
self.filter = result self.filter = result
else else
basalt.debug(result) error(result)
end end
end end

View File

@@ -48,6 +48,16 @@ rpairs = function(t)
end, t, #t + 1 end, t, #t + 1
end, end,
tableCount = function(t)
local n = 0
if(t~=nil)then
for k,v in pairs(t)do
n = n + 1
end
end
return n
end,
splitString = splitString, splitString = splitString,
createText = function(str, width) createText = function(str, width)

View File

@@ -2,26 +2,66 @@ local basaltEvent = require("basaltEvent")()
local Frame = require("Frame") local Frame = require("Frame")
local theme = require("theme") local theme = require("theme")
local utils = require("utils") local utils = require("utils")
local log = require("basaltLogs")
local uuid = utils.uuid local uuid = utils.uuid
local createText = utils.createText local createText = utils.createText
local count = utils.tableCount
local moveThrottle = 300
local dragThrottle = 50
local baseTerm = term.current() local baseTerm = term.current()
local version = 5 local version = "1.6.2"
local debugger = true
local projectDirectory = fs.getDir(table.pack(...)[2] or "") local projectDirectory = fs.getDir(table.pack(...)[2] or "")
local activeKey, frames, monFrames, variables, schedules = {}, {}, {}, {}, {} local activeKey, frames, monFrames, monGroups, variables, schedules = {}, {}, {}, {}, {}, {}
local mainFrame, activeFrame, focusedObject, updaterActive local mainFrame, activeFrame, focusedObject, updaterActive
local basalt = {}
if not term.isColor or not term.isColor() then if not term.isColor or not term.isColor() then
error('Basalt requires an advanced (golden) computer to run.', 0) error('Basalt requires an advanced (golden) computer to run.', 0)
end end
local function stop() local function stop()
updaterActive = false
baseTerm.clear()
baseTerm.setCursorPos(1, 1)
end
local basaltError = function(errMsg)
baseTerm.clear()
baseTerm.setBackgroundColor(colors.black)
baseTerm.setTextColor(colors.red)
local w,h = baseTerm.getSize()
if(basalt.logging)then
log(errMsg, "Error")
end
local text = createText("Basalt error: "..errMsg, w)
local yPos = 1
for k,v in pairs(text)do
baseTerm.setCursorPos(1,yPos)
baseTerm.write(v)
yPos = yPos + 1
end
baseTerm.setCursorPos(1,yPos+1)
updaterActive = false updaterActive = false
end end
local function schedule(f)
assert(f~="function", "Schedule needs a function in order to work!")
return function(...)
local co = coroutine.create(f)
local ok, result = coroutine.resume(co, ...)
if(ok)then
table.insert(schedules, co)
else
basaltError(result)
end
end
end
local setVariable = function(name, var) local setVariable = function(name, var)
variables[name] = var variables[name] = var
end end
@@ -68,17 +108,27 @@ local bInstance = {
end, end,
getMonitorFrame = function(name) getMonitorFrame = function(name)
return monFrames[name] return monFrames[name] or monGroups[name][1]
end, end,
setMonitorFrame = function(name, frame) setMonitorFrame = function(name, frame, isGroupedMon)
monFrames[name] = frame if(mainFrame == frame)then mainFrame = nil end
if(isGroupedMon)then
monGroups[name] = {frame, sides}
else
monFrames[name] = frame
end
if(frame==nil)then
monGroups[name] = nil
end
end, end,
getBaseTerm = function() getBaseTerm = function()
return baseTerm return baseTerm
end, end,
schedule = schedule,
stop = stop, stop = stop,
newFrame = Frame, newFrame = Frame,
@@ -87,41 +137,6 @@ local bInstance = {
end end
} }
local basaltError = function(errMsg)
baseTerm.clear()
baseTerm.setBackgroundColor(colors.black)
baseTerm.setTextColor(colors.red)
local w,h = baseTerm.getSize()
local splitString = function(str, sep)
if sep == nil then
sep = "%s"
end
local t={}
for v in string.gmatch(str, "([^"..sep.."]+)") do
table.insert(t, v)
end
return t
end
local words = splitString(errMsg, " ")
local line = "Basalt error: "
local yPos = 1
for n=1,#words do
baseTerm.setCursorPos(1,yPos)
if(#line+#words[n]<w)then
line = line.." "..words[n]
else
baseTerm.write(line)
line = words[n]
yPos = yPos + 1
end
if(n==#words)then
baseTerm.write(line)
end
end
baseTerm.setCursorPos(1,yPos+1)
end
local function handleSchedules(event, p1, p2, p3, p4) local function handleSchedules(event, p1, p2, p3, p4)
if(#schedules>0)then if(#schedules>0)then
local finished = {} local finished = {}
@@ -144,14 +159,51 @@ local function handleSchedules(event, p1, p2, p3, p4)
end end
local function drawFrames() local function drawFrames()
if(updaterActive)then if(updaterActive==false)then return end
if(mainFrame~=nil)then if(mainFrame~=nil)then
mainFrame:draw() mainFrame:draw()
mainFrame:drawUpdate() mainFrame:updateTerm()
end end
for _,v in pairs(monFrames)do for _,v in pairs(monFrames)do
v:draw() v:draw()
v:drawUpdate() v:updateTerm()
end
for _,v in pairs(monGroups)do
v[1]:draw()
v[1]:updateTerm()
end
end
local stopped, moveX, moveY = nil, nil, nil
local moveTimer = nil
local function mouseMoveEvent(stp, x, y)
stopped, moveX, moveY = stopped, x, y
if(moveTimer==nil)then
moveTimer = os.startTimer(moveThrottle/1000)
end
end
local function moveHandlerTimer()
moveTimer = nil
mainFrame:hoverHandler(moveX, moveY, stopped)
activeFrame = mainFrame
end
local btn, dragX, dragY = nil, nil, nil
local dragTimer = nil
local function dragHandlerTimer()
dragTimer = nil
mainFrame:dragHandler(btn, dragX, dragY)
activeFrame = mainFrame
end
local function mouseDragEvent(b, x, y)
btn, dragX, dragY = b, x, y
if(dragThrottle<50)then
dragHandlerTimer()
else
if(dragTimer==nil)then
dragTimer = os.startTimer(dragThrottle/1000)
end end
end end
end end
@@ -160,51 +212,78 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
if(basaltEvent:sendEvent("basaltEventCycle", event, p1, p2, p3, p4)==false)then return end if(basaltEvent:sendEvent("basaltEventCycle", event, p1, p2, p3, p4)==false)then return end
if(mainFrame~=nil)then if(mainFrame~=nil)then
if (event == "mouse_click") then if (event == "mouse_click") then
mainFrame:mouseHandler(event, p1, p2, p3, p4) mainFrame:mouseHandler(p1, p2, p3, false)
activeFrame = mainFrame activeFrame = mainFrame
elseif (event == "mouse_drag") then elseif (event == "mouse_drag") then
mainFrame:mouseHandler(event, p1, p2, p3, p4) mouseDragEvent(p1, p2, p3)
activeFrame = mainFrame
elseif (event == "mouse_up") then elseif (event == "mouse_up") then
mainFrame:mouseHandler(event, p1, p2, p3, p4) mainFrame:mouseUpHandler(p1, p2, p3, p4)
activeFrame = mainFrame activeFrame = mainFrame
elseif (event == "mouse_scroll") then elseif (event == "mouse_scroll") then
mainFrame:mouseHandler(event, p1, p2, p3, p4) mainFrame:scrollHandler(p1, p2, p3, p4)
activeFrame = mainFrame activeFrame = mainFrame
elseif (event == "monitor_touch") then elseif (event == "mouse_move") then
if(monFrames[p1]~=nil)then mouseMoveEvent(p1, p2, p3)
monFrames[p1]:mouseHandler(event, p1, p2, p3, p4) end
activeFrame = monFrames[p1] end
if(event == "monitor_touch") then
if(monFrames[p1]~=nil)then
monFrames[p1]:mouseHandler(1, p2, p3, true)
activeFrame = monFrames[p1]
end
if(count(monGroups)>0)then
for k,v in pairs(monGroups)do
v[1]:mouseHandler(1, p2, p3, true, p1)
end end
end end
end end
if(event == "key") or (event == "char") then
if(event == "char")then
if(activeFrame~=nil)then if(activeFrame~=nil)then
activeFrame:keyHandler(event, p1) activeFrame:charHandler(p1)
activeFrame:backgroundKeyHandler(event, p1)
end end
end end
if(event == "key")then
activeKey[p1] = true
end
if(event == "key_up")then if(event == "key_up")then
if(activeFrame~=nil)then
activeFrame:keyUpHandler(p1)
end
activeKey[p1] = false activeKey[p1] = false
end end
if(event == "key")then
for _, v in pairs(frames) do if(activeFrame~=nil)then
v:eventHandler(event, p1, p2, p3, p4) activeFrame:keyHandler(p1, p2)
end
activeKey[p1] = true
end
if(event == "terminate")then
if(activeFrame~=nil)then
activeFrame:eventHandler(event)
if(updaterActive==false)then return end
end
end
if(event~="mouse_click")and(event~="mouse_up")and(event~="mouse_scroll")and(event~="mouse_drag")and(event~="mouse_move")and(event~="key")and(event~="key_up")and(event~="char")and(event~="terminate")then
if(event=="timer")and(p1==moveTimer)then
moveHandlerTimer()
elseif(event=="timer")and(p1==dragTimer)then
dragHandlerTimer()
else
for k, v in pairs(frames) do
v:eventHandler(event, p1, p2, p3, p4)
end
end
end end
handleSchedules(event, p1, p2, p3, p4) handleSchedules(event, p1, p2, p3, p4)
drawFrames() drawFrames()
end end
local basalt = {}
basalt = { basalt = {
logging = false,
setTheme = setTheme, setTheme = setTheme,
getTheme = getTheme, getTheme = getTheme,
drawFrames = drawFrames,
getVersion = function() getVersion = function()
return version return version
end, end,
@@ -216,14 +295,51 @@ basalt = {
baseTerm = _baseTerm baseTerm = _baseTerm
end, end,
log = function(...)
log(...)
end,
setMouseMoveThrottle = function(amount)
if(_HOST:find("CraftOS%-PC"))then
if(config.get("mouse_move_throttle")~=10)then config.set("mouse_move_throttle", 10) end
if(amount<100)then
moveThrottle = 100
else
moveThrottle = amount
end
return true
end
return false
end,
setMouseDragThrottle = function(amount)
if(amount<=0)then
dragThrottle = 0
else
dragTimer = nil
dragThrottle = amount
end
end,
autoUpdate = function(isActive) autoUpdate = function(isActive)
local pCall = pcall
updaterActive = isActive updaterActive = isActive
if(isActive==nil)then updaterActive = true end if(isActive==nil)then updaterActive = true end
drawFrames() local function f()
while updaterActive do drawFrames()
local event, p1, p2, p3, p4 = os.pullEventRaw() while updaterActive do
local ok, err = pCall(basaltUpdateEvent, event, p1, p2, p3, p4) basaltUpdateEvent(os.pullEventRaw())
end
end
local ok, err = xpcall(f, debug.traceback)
if not(ok)then
basaltError(err)
return
end
end,
update = function(event, p1, p2, p3, p4)
if (event ~= nil) then
local ok, err = xpcall(basaltUpdateEvent, debug.traceback, event, p1, p2, p3, p4)
if not(ok)then if not(ok)then
basaltError(err) basaltError(err)
return return
@@ -231,13 +347,8 @@ basalt = {
end end
end, end,
update = function(event, p1, p2, p3, p4)
if (event ~= nil) then
basaltUpdateEvent(event, p1, p2, p3, p4)
end
end,
stop = stop, stop = stop,
stopUpdate = stop,
isKeyDown = function(key) isKeyDown = function(key)
if(activeKey[key]==nil)then return false end if(activeKey[key]==nil)then return false end
@@ -272,18 +383,7 @@ basalt = {
end end
end, end,
schedule = function(f) schedule = schedule,
assert(f~="function", "Schedule needs a function in order to work!")
return function(...)
local co = coroutine.create(f)
local ok, result = coroutine.resume(co, ...)
if(ok)then
table.insert(schedules, co)
else
basaltError(result)
end
end
end,
createFrame = function(name) createFrame = function(name)
name = name or uuid() name = name or uuid()
@@ -293,6 +393,7 @@ basalt = {
end end
end end
local newFrame = Frame(name,nil,nil,bInstance) local newFrame = Frame(name,nil,nil,bInstance)
newFrame:init()
table.insert(frames, newFrame) table.insert(frames, newFrame)
if(mainFrame==nil)and(newFrame:getName()~="basaltDebuggingFrame")then if(mainFrame==nil)and(newFrame:getName()~="basaltDebuggingFrame")then
newFrame:show() newFrame:show()
@@ -310,6 +411,7 @@ basalt = {
debug = function(...) debug = function(...)
local args = { ... } local args = { ... }
if(mainFrame==nil)then print(...) return end
if (mainFrame.name ~= "basaltDebuggingFrame") then if (mainFrame.name ~= "basaltDebuggingFrame") then
if (mainFrame ~= basalt.debugFrame) then if (mainFrame ~= basalt.debugFrame) then
basalt.debugLabel:setParent(mainFrame) basalt.debugLabel:setParent(mainFrame)
@@ -336,7 +438,7 @@ basalt = {
basalt.debugFrame = basalt.createFrame("basaltDebuggingFrame"):showBar():setBackground(colors.lightGray):setBar("Debug", colors.black, colors.gray) basalt.debugFrame = basalt.createFrame("basaltDebuggingFrame"):showBar():setBackground(colors.lightGray):setBar("Debug", colors.black, colors.gray)
basalt.debugFrame:addButton("back"):setAnchor("topRight"):setSize(1, 1):setText("\22"):onClick(function() if(basalt.oldFrame~=nil)then basalt.oldFrame:show() end end):setBackground(colors.red):show() basalt.debugFrame:addButton("back"):setAnchor("topRight"):setSize(1, 1):setText("\22"):onClick(function() if(basalt.oldFrame~=nil)then basalt.oldFrame:show() end end):setBackground(colors.red):show()
basalt.debugList = basalt.debugFrame:addList("debugList"):setSize(basalt.debugFrame.width - 2, basalt.debugFrame.height - 3):setPosition(2, 3):setScrollable(true):show() basalt.debugList = basalt.debugFrame:addList("debugList"):setSize("parent.w - 2", "parent.h - 3"):setPosition(2, 3):setScrollable(true):show()
basalt.debugLabel = basalt.debugFrame:addLabel("debugLabel"):onClick(function() basalt.oldFrame = mainFrame basalt.debugFrame:show() end):setBackground(colors.black):setForeground(colors.white):setAnchor("bottomLeft"):ignoreOffset():setZIndex(20):show() basalt.debugLabel = basalt.debugFrame:addLabel("debugLabel"):onClick(function() basalt.oldFrame = mainFrame basalt.debugFrame:show() end):setBackground(colors.black):setForeground(colors.white):setAnchor("bottomLeft"):ignoreOffset():setZIndex(20):show()
return basalt return basalt

View File

@@ -1,8 +1,9 @@
local xmlValue = require("utils").getValueFromXML local xmlValue = require("utils").getValueFromXML
local basaltEvent = require("basaltEvent") local basaltEvent = require("basaltEvent")
local floor = math.floor local floor,sin,cos,pi,sqrt,pow = math.floor,math.sin,math.cos,math.pi,math.sqrt,math.pow
-- You can find the easing curves here https://easings.net
local lerp = function(s, e, pct) local lerp = function(s, e, pct)
return s + (e - s) * pct return s + (e - s) * pct
@@ -12,8 +13,8 @@ local linear = function (t)
return t return t
end end
local flip = function (x) local flip = function (t)
return 1 - x return 1 - t
end end
local easeIn = function (t) local easeIn = function (t)
@@ -28,15 +29,199 @@ local easeInOut = function(t)
return lerp(easeIn(t), easeOut(t), t) return lerp(easeIn(t), easeOut(t), t)
end end
local easeOutSine = function(t)
return sin((t * pi) / 2);
end
local easeInSine = function(t)
return flip(cos((t * pi) / 2))
end
local easeInOutSine = function(t)
return -(cos(pi * x) - 1) / 2
end
local easeInBack = function(t)
local c1 = 1.70158;
local c3 = c1 + 1
return c3*t^3-c1*t^2
end
local easeInCubic = function(t)
return t^3
end
local easeInElastic = function(t)
local c4 = (2*pi)/3;
return t == 0 and 0 or (t == 1 and 1 or (
-2^(10*t-10)*sin((t*10-10.75)*c4)
))
end
local function easeInExpo(t)
return t == 0 and 0 or 2^(10*t-10)
end
local function easeInExpo(t)
return t == 0 and 0 or 2^(10*t-10)
end
local function easeInOutBack(t)
local c1 = 1.70158;
local c2 = c1 * 1.525;
return t < 0.5 and ((2*t)^2*((c2+1)*2*t-c2))/2 or ((2*t-2)^2*((c2+1)*(t*2-2)+c2)+2)/2
end
local function easeInOutCubic(t)
return t < 0.5 and 4 * t^3 or 1-(-2*t+2)^3 / 2
end
local function easeInOutElastic(t)
local c5 = (2*pi) / 4.5
return t==0 and 0 or (t == 1 and 1 or (t < 0.5 and -(2^(20*t-10) * sin((20*t - 11.125) * c5))/2 or (2^(-20*t+10) * sin((20*t - 11.125) * c5))/2 + 1))
end
local function easeInOutExpo(t)
return t == 0 and 0 or (t == 1 and 1 or (t < 0.5 and 2^(20*t-10)/2 or (2-2^(-20*t+10)) /2))
end
local function easeInOutQuad(t)
return t < 0.5 and 2*t^2 or 1-(-2*t+2)^2/2
end
local function easeInOutQuart(t)
return t < 0.5 and 8*t^4 or 1 - (-2*t+2)^4 / 2
end
local function easeInOutQuint(t)
return t < 0.5 and 16*t^5 or 1-(-2*t+2)^5 / 2
end
local function easeInQuad(t)
return t^2
end
local function easeInQuart(t)
return t^4
end
local function easeInQuint(t)
return t^5
end
local function easeOutBack(t)
local c1 = 1.70158;
local c3 = c1 + 1
return 1+c3*(t-1)^3+c1*(t-1)^2
end
local function easeOutCubic(t)
return 1 - (1-t)^3
end
local function easeOutElastic(t)
local c4 = (2*pi)/3;
return t == 0 and 0 or (t == 1 and 1 or (2^(-10*t)*sin((t*10-0.75)*c4)+1))
end
local function easeOutExpo(t)
return t == 1 and 1 or 1-2^(-10*t)
end
local function easeOutQuad(t)
return 1 - (1 - t) * (1 - t)
end
local function easeOutQuart(t)
return 1 - (1-t)^4
end
local function easeOutQuint(t)
return 1 - (1 - t)^5
end
local function easeInCirc(t)
return 1 - sqrt(1 - pow(t, 2))
end
local function easeOutCirc(t)
return sqrt(1 - pow(t - 1, 2))
end
local function easeInOutCirc(t)
return t < 0.5 and (1 - sqrt(1 - pow(2 * t, 2))) / 2 or (sqrt(1 - pow(-2 * t + 2, 2)) + 1) / 2;
end
local function easeOutBounce(t)
local n1 = 7.5625;
local d1 = 2.75;
if (t < 1 / d1)then
return n1 * t * t
elseif (t < 2 / d1)then
local a = t - 1.5 / d1
return n1 * a * a + 0.75;
elseif (t < 2.5 / d1)then
local a = t - 2.25 / d1
return n1 * a * a + 0.9375;
else
local a = t - 2.625 / d1
return n1 * a * a + 0.984375;
end
end
local function easeInBounce(t)
return 1 - easeOutBounce(1 - t)
end
local function easeInOutBounce(t)
return x < 0.5 and (1 - easeOutBounce(1 - 2 * t)) / 2 or (1 + easeOutBounce(2 * t - 1)) / 2;
end
local lerp = { local lerp = {
linear = linear, linear = linear,
lerp = lerp, lerp = lerp,
flip=flip, flip=flip,
easeIn=easeIn, easeIn=easeIn,
easeInSine = easeInSine,
easeInBack=easeInBack,
easeInCubic=easeInCubic,
easeInElastic=easeInElastic,
easeInExpo=easeInExpo,
easeInQuad=easeInQuad,
easeInQuart=easeInQuart,
easeInQuint=easeInQuint,
easeInCirc=easeInCirc,
easeInBounce=easeInBounce,
easeOut=easeOut, easeOut=easeOut,
easeOutSine = easeOutSine,
easeOutBack=easeOutBack,
easeOutCubic=easeOutCubic,
easeOutElastic=easeOutElastic,
easeOutExpo=easeOutExpo,
easeOutQuad=easeOutQuad,
easeOutQuart=easeOutQuart,
easeOutQuint=easeOutQuint,
easeOutCirc=easeOutCirc,
easeOutBounce=easeOutBounce,
easeInOut=easeInOut, easeInOut=easeInOut,
easeInOutSine = easeInOutSine,
easeInOutBack=easeInOutBack,
easeInOutCubic=easeInOutCubic,
easeInOutElastic=easeInOutElastic,
easeInOutExpo=easeInOutExpo,
easeInOutQuad=easeInOutQuad,
easeInOutQuart=easeInOutQuart,
easeInOutQuint=easeInOutQuint,
easeInOutCirc=easeInOutCirc,
easeInOutBounce=easeInOutBounce,
} }
local activeAnimations = {}
return function(name) return function(name)
local object = {} local object = {}
local objectType = "Animation" local objectType = "Animation"
@@ -117,16 +302,36 @@ return function(name)
end end
local function predefinedLerp(v1,v2,d,t,get,set) local function predefinedLerp(v1,v2,d,t,get,set,typ,self)
local obj = _OBJ
local x,y local x,y
local name = ""
if(obj.parent~=nil)then name = obj.parent:getName() end
name = name..obj:getName()
addAnimationPart(t+0.05, function() addAnimationPart(t+0.05, function()
x,y = get(_OBJ) if(typ~=nil)then
if(activeAnimations[typ]==nil)then activeAnimations[typ] = {} end
if(activeAnimations[typ][name]~=nil)then
if(activeAnimations[typ][name]~=self)then
activeAnimations[typ][name]:cancel()
end
end
activeAnimations[typ][name] = self
end
x,y = get(obj)
end) end)
for n=0.05,d,0.05 do for n=0.05,d+0.01,0.05 do
addAnimationPart(t+n, function() addAnimationPart(t+n, function()
local _x = math.floor(lerp.lerp(x, v1, lerp[mode](n / d))+0.5) local _x = math.floor(lerp.lerp(x, v1, lerp[mode](n / d))+0.5)
local _y = math.floor(lerp.lerp(y, v2, lerp[mode](n / d))+0.5) local _y = math.floor(lerp.lerp(y, v2, lerp[mode](n / d))+0.5)
set(_OBJ, _x,_y) set(obj, _x,_y)
if(typ~=nil)then
if(n>=d-0.01)then
if(activeAnimations[typ][name]==self)then
activeAnimations[typ][name] = nil
end
end
end
end) end)
end end
end; end;
@@ -149,6 +354,11 @@ return function(name)
return self return self
end, end,
addMode = function(self, modeId, modeF)
lerp[modeId] = modeF
return self
end,
generateXMLEventFunction = function(self, func, val) generateXMLEventFunction = function(self, func, val)
local createF = function(str) local createF = function(str)
if(str:sub(1,1)=="#")then if(str:sub(1,1)=="#")then
@@ -274,19 +484,19 @@ return function(name)
move = function(self, x, y, duration, timer, obj) move = function(self, x, y, duration, timer, obj)
_OBJ = obj or _OBJ _OBJ = obj or _OBJ
predefinedLerp(x,y,duration,timer or 0,_OBJ.getPosition,_OBJ.setPosition) predefinedLerp(x,y,duration,timer or 0,_OBJ.getPosition,_OBJ.setPosition, "position", self)
return self return self
end, end,
offset = function(self, x, y, duration, timer, obj) offset = function(self, x, y, duration, timer, obj)
_OBJ = obj or _OBJ _OBJ = obj or _OBJ
predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffset,_OBJ.setOffset) predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffset,_OBJ.setOffset, "offset", self)
return self return self
end, end,
size = function(self, w, h, duration, timer, obj) size = function(self, w, h, duration, timer, obj)
_OBJ = obj or _OBJ _OBJ = obj or _OBJ
predefinedLerp(w,h,duration,timer or 0,_OBJ.getSize,_OBJ.setSize) predefinedLerp(w,h,duration,timer or 0,_OBJ.getSize,_OBJ.setSize, "size", self)
return self return self
end, end,
@@ -326,9 +536,9 @@ return function(name)
return self return self
end, end,
add = function(self, func, wait) add = function(self, func, timer)
lastFunc = func lastFunc = func
addAnimationPart((wait or nextWaitTimer) + (animations[#animations]~=nil and animations[#animations].t or 0), func) addAnimationPart((timer or nextWaitTimer) + (animations[#animations]~=nil and animations[#animations].t or 0), func)
return self return self
end; end;
@@ -363,6 +573,7 @@ return function(name)
animationDoneHandler = function(self) animationDoneHandler = function(self)
eventSystem:sendEvent("animation_done", self) eventSystem:sendEvent("animation_done", self)
self.parent:removeEvent("other_event", self)
if(autoDestroy)then if(autoDestroy)then
self.parent:removeObject(self) self.parent:removeObject(self)
self = nil self = nil
@@ -393,11 +604,12 @@ return function(name)
if (animations[index].t > 0) then if (animations[index].t > 0) then
timerObj = os.startTimer(animations[index].t) timerObj = os.startTimer(animations[index].t)
else else
onPlay() onPlay(self)
end end
else else
self:animationDoneHandler() self:animationDoneHandler()
end end
self.parent:addEvent("other_event", self)
return self return self
end; end;
@@ -407,6 +619,7 @@ return function(name)
infinitePlay = false infinitePlay = false
end end
animationActive = false animationActive = false
self.parent:removeEvent("other_event", self)
return self return self
end; end;

View File

@@ -1,6 +1,7 @@
local Object = require("Object") local Object = require("Object")
local utils = require("utils") local utils = require("utils")
local xmlValue = utils.getValueFromXML local xmlValue = utils.getValueFromXML
local tHex = require("tHex")
return function(name) return function(name)
-- Button -- Button
@@ -16,22 +17,29 @@ return function(name)
local object = { local object = {
init = function(self) init = function(self)
self.bgColor = self.parent:getTheme("ButtonBG") if(base.init(self))then
self.fgColor = self.parent:getTheme("ButtonText") self.bgColor = self.parent:getTheme("ButtonBG")
self.fgColor = self.parent:getTheme("ButtonText")
end
end, end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
setHorizontalAlign = function(self, pos) setHorizontalAlign = function(self, pos)
textHorizontalAlign = pos textHorizontalAlign = pos
self:updateDraw()
return self
end; end;
setVerticalAlign = function(self, pos) setVerticalAlign = function(self, pos)
textVerticalAlign = pos textVerticalAlign = pos
self:updateDraw()
return self
end; end;
setText = function(self, text) setText = function(self, text)
base:setValue(text) base:setValue(text)
self:updateDraw()
return self return self
end; end;
@@ -50,20 +58,15 @@ return function(name)
local w,h = self:getSize() local w,h = self:getSize()
local verticalAlign = utils.getTextVerticalAlign(h, textVerticalAlign) local verticalAlign = utils.getTextVerticalAlign(h, textVerticalAlign)
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
self.parent:drawTextBox(obx, oby, w, h, " ")
end
if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor) end
for n = 1, h do for n = 1, h do
if (n == verticalAlign) then if (n == verticalAlign) then
self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), w, textHorizontalAlign)) self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), w, textHorizontalAlign))
self.parent:setFG(obx, oby + (n - 1), utils.getTextHorizontalAlign(tHex[self.fgColor]:rep(self:getValue():len()), w, textHorizontalAlign))
end end
end end
end end
self:setVisualChanged(false)
end end
end; end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -12,31 +12,38 @@ return function(name)
base.width = 1 base.width = 1
base.height = 1 base.height = 1
local object = { local symbol = "\42"
symbol = "\42",
init = function(self) local object = {
self.bgColor = self.parent:getTheme("CheckboxBG")
self.fgColor = self.parent:getTheme("CheckboxText")
end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
mouseHandler = function(self, event, button, x, y) setSymbol = function(self, sym)
if (base.mouseHandler(self, event, button, x, y)) then symbol = sym
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then self:updateDraw()
return self
end,
mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, button, x, y)) then
if(button == 1)then
if (self:getValue() ~= true) and (self:getValue() ~= false) then if (self:getValue() ~= true) and (self:getValue() ~= false) then
self:setValue(false) self:setValue(false)
else else
self:setValue(not self:getValue()) self:setValue(not self:getValue())
end end
end self:updateDraw()
return true return true
end
end end
return false return false
end; end,
touchHandler = function(self, x, y)
return self:mouseHandler(1, x, y)
end,
setValuesByXMLData = function(self, data) setValuesByXMLData = function(self, data)
base.setValuesByXMLData(self, data) base.setValuesByXMLData(self, data)
@@ -54,17 +61,24 @@ return function(name)
for n = 1, h do for n = 1, h do
if (n == verticalAlign) then if (n == verticalAlign) then
if (self:getValue() == true) then if (self:getValue() == true) then
self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self.symbol, w, "center"), self.bgColor, self.fgColor) self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(symbol, w, "center"), self.bgColor, self.fgColor)
else else
self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(" ", w, "center"), self.bgColor, self.fgColor) self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(" ", w, "center"), self.bgColor, self.fgColor)
end end
end end
end end
end end
self:setVisualChanged(false)
end end
end; end,
init = function(self)
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_up", self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("CheckboxBG")
self.fgColor = self.parent:getTheme("CheckboxText")
end
end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -26,12 +26,6 @@ return function(name)
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
init = function(self)
self.bgColor = self.parent:getTheme("DropdownBG")
self.fgColor = self.parent:getTheme("DropdownText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
end,
setValuesByXMLData = function(self, data) setValuesByXMLData = function(self, data)
base.setValuesByXMLData(self, data) base.setValuesByXMLData(self, data)
@@ -51,6 +45,7 @@ return function(name)
setOffset = function(self, yOff) setOffset = function(self, yOff)
yOffset = yOff yOffset = yOff
self:updateDraw()
return self return self
end; end;
@@ -60,6 +55,7 @@ return function(name)
addItem = function(self, text, bgCol, fgCol, ...) addItem = function(self, text, bgCol, fgCol, ...)
table.insert(list, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } }) table.insert(list, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
self:updateDraw()
return self return self
end; end;
@@ -69,6 +65,7 @@ return function(name)
removeItem = function(self, index) removeItem = function(self, index)
table.remove(list, index) table.remove(list, index)
self:updateDraw()
return self return self
end; end;
@@ -88,6 +85,7 @@ return function(name)
clear = function(self) clear = function(self)
list = {} list = {}
self:setValue({}) self:setValue({})
self:updateDraw()
return self return self
end; end;
@@ -98,11 +96,13 @@ return function(name)
editItem = function(self, index, text, bgCol, fgCol, ...) editItem = function(self, index, text, bgCol, fgCol, ...)
table.remove(list, index) table.remove(list, index)
table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } }) table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
self:updateDraw()
return self return self
end; end;
selectItem = function(self, index) selectItem = function(self, index)
self:setValue(list[index] or {}) self:setValue(list[index] or {})
self:updateDraw()
return self return self
end; end;
@@ -110,55 +110,90 @@ return function(name)
itemSelectedBG = bgCol or self.bgColor itemSelectedBG = bgCol or self.bgColor
itemSelectedFG = fgCol or self.fgColor itemSelectedFG = fgCol or self.fgColor
selectionColorActive = active selectionColorActive = active
self:updateDraw()
return self return self
end; end;
setDropdownSize = function(self, width, height) setDropdownSize = function(self, width, height)
dropdownW, dropdownH = width, height dropdownW, dropdownH = width, height
self:updateDraw()
return self return self
end; end,
mouseHandler = function(self, event, button, x, y) mouseHandler = function(self, button, x, y)
if (isOpened) then if (isOpened) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then if(button==1)then
if (#list > 0) then if (#list > 0) then
for n = 1, dropdownH do for n = 1, dropdownH do
if (list[n + yOffset] ~= nil) then if (list[n + yOffset] ~= nil) then
if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then
self:setValue(list[n + yOffset]) self:setValue(list[n + yOffset])
self:updateDraw()
local val = self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", dir, x, y)
if(val==false)then return val end
return true return true
end end
end end
end end
end end
end end
end
if (base.mouseHandler(self, button, x, y)) then
isOpened = (not isOpened)
self:updateDraw()
return true
else
if(isOpened)then
self:updateDraw()
isOpened = false
end
return false
end
end,
if (event == "mouse_scroll") then mouseUpHandler = function(self, button, x, y)
yOffset = yOffset + button if (isOpened) then
if (yOffset < 0) then local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
yOffset = 0 if(button==1)then
end if (#list > 0) then
if (button == 1) then for n = 1, dropdownH do
if (#list > dropdownH) then if (list[n + yOffset] ~= nil) then
if (yOffset > #list - dropdownH) then if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then
yOffset = #list - dropdownH isOpened = false
self:updateDraw()
local val = self:getEventSystem():sendEvent("mouse_up", self, "mouse_up", dir, x, y)
if(val==false)then return val end
return true
end
end end
else
yOffset = math.min(#list - 1, 0)
end end
end end
return true
end end
self:setVisualChanged()
end end
if (base.mouseHandler(self, event, button, x, y)) then end,
isOpened = true
else scrollHandler = function(self, dir, x, y)
isOpened = false if (isOpened)and(self:isFocused()) then
yOffset = yOffset + dir
if (yOffset < 0) then
yOffset = 0
end
if (dir == 1) then
if (#list > dropdownH) then
if (yOffset > #list - dropdownH) then
yOffset = #list - dropdownH
end
else
yOffset = math.min(#list - 1, 0)
end
end
local val = self:getEventSystem():sendEvent("mouse_scroll", self, "mouse_scroll", dir, x, y)
if(val==false)then return val end
self:updateDraw()
return true
end end
end; end,
draw = function(self) draw = function(self)
if (base.draw(self)) then if (base.draw(self)) then
@@ -186,9 +221,20 @@ return function(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end,
init = function(self)
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_up", self)
self.parent:addEvent("mouse_scroll", self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("DropdownBG")
self.fgColor = self.parent:getTheme("DropdownText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
end
end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -1,471 +0,0 @@
local Object = require("Object")
local geometric = require("geometricPoints")
local tHex = require("tHex")
local xmlValue = require("utils").getValueFromXML
local sub,len,max,min = string.sub,string.len,math.max,math.min
return function(name)
-- Graphic
local base = Object(name)
local objectType = "Graphic"
base:setZIndex(2)
local graphicObjects = {}
local graphic = {}
local shrinkedGraphic = {}
local isGraphicShrinked = false
local xOffset, yOffset = 0, 0
local dragable = false
local xMouse,yMouse
local w, h = 40, 15
local canvasSizeChanged = false
local tColourLookup = {}
for n=1,16 do
tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1)
end
local function stringToTable(str)
local t = {}
for i = 1, #str do
t[i] = str:sub(i, i)
end
return t
end
local function setBG(x, y, width, height, colorStr)
if (y >= 1) and (y <= height) then
if (x + len(colorStr) > 0) and (x <= width) then
local oldCache = graphic[y]
local newCache
local nEnd = x + #colorStr - 1
if (x < 1) then
colorStr = sub(colorStr, 1 - x + 1, width - x + 1)
elseif (nEnd > width) then
colorStr = sub(colorStr, 1, width - x + 1)
end
if (x > 1) then
newCache = sub(oldCache, 1, x - 1) .. colorStr
else
newCache = colorStr
end
if nEnd < width then
newCache = newCache .. sub(oldCache, nEnd + 1, width)
end
graphic[y] = newCache
end
end
end
local function redrawCanvasSize()
local w,h = w,h
if(isGraphicShrinked)then w = w*2 h = h*3 end
for y=1,h do
if(graphic[y]~=nil)then
if(w>graphic[y]:len())then
graphic[y] = graphic[y]..(tHex[base.bgColor]):rep(w-graphic[y]:len())
else
graphic[y] = graphic[y]:sub(1,w)
end
else
graphic[y] = (tHex[base.bgColor]):rep(w)
end
end
end
redrawCanvasSize()
local function shrink()
local function parseLine( tImageArg, sLine )
local tLine = {}
for x=1,sLine:len() do
tLine[x] = tColourLookup[ string.byte(sLine,x,x) ] or 0
end
table.insert( tImageArg, tLine )
end
function parseImage( sRawData )
if type( sRawData ) ~= "string" then
error( "bad argument #1 (expected string, got " .. type( sRawData ) .. ")" )
end
local tImage = {}
for sLine in ( sRawData .. "\n" ):gmatch( "(.-)\n" ) do
parseLine( tImage, sLine )
end
return tImage
end
local rawImg = ""
for y=1,#graphic do
if(y==#graphic)then
rawImg = rawImg..graphic[y]
else
rawImg = rawImg..graphic[y].."\n"
end
end
local img = parseImage(rawImg)
-- shrinkSystem is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/
local relations = { [0] = { 8, 4, 3, 6, 5 }, { 4, 14, 8, 7 }, { 6, 10, 8, 7 }, { 9, 11, 8, 0 }, { 1, 14, 8, 0 }, { 13, 12, 8, 0 }, { 2, 10, 8, 0 }, { 15, 8, 10, 11, 12, 14 },
{ 0, 7, 1, 9, 2, 13 }, { 3, 11, 8, 7 }, { 2, 6, 7, 15 }, { 9, 3, 7, 15 }, { 13, 5, 7, 15 }, { 5, 12, 8, 7 }, { 1, 4, 7, 15 }, { 7, 10, 11, 12, 14 } }
local colourNum, exponents, colourChar = {}, {}, {}
for i = 0, 15 do
exponents[2 ^ i] = i
end
do
local hex = "0123456789abcdef"
for i = 1, 16 do
colourNum[hex:sub(i, i)] = i - 1
colourNum[i - 1] = hex:sub(i, i)
colourChar[hex:sub(i, i)] = 2 ^ (i - 1)
colourChar[2 ^ (i - 1)] = hex:sub(i, i)
local thisRel = relations[i - 1]
for i = 1, #thisRel do
thisRel[i] = 2 ^ thisRel[i]
end
end
end
local function getBestColourMatch(usage)
local lastCol = relations[exponents[usage[#usage][1]]]
for j = 1, #lastCol do
local thisRelation = lastCol[j]
for i = 1, #usage - 1 do
if usage[i][1] == thisRelation then
return i
end
end
end
return 1
end
local function colsToChar(pattern, totals)
if not totals then
local newPattern = {}
totals = {}
for i = 1, 6 do
local thisVal = pattern[i]
local thisTot = totals[thisVal]
totals[thisVal], newPattern[i] = thisTot and (thisTot + 1) or 1, thisVal
end
pattern = newPattern
end
local usage = {}
for key, value in pairs(totals) do
usage[#usage + 1] = { key, value }
end
if #usage > 1 then
-- Reduce the chunk to two colours:
while #usage > 2 do
table.sort(usage, function(a, b)
return a[2] > b[2]
end)
local matchToInd, usageLen = getBestColourMatch(usage), #usage
local matchFrom, matchTo = usage[usageLen][1], usage[matchToInd][1]
for i = 1, 6 do
if pattern[i] == matchFrom then
pattern[i] = matchTo
usage[matchToInd][2] = usage[matchToInd][2] + 1
end
end
usage[usageLen] = nil
end
-- Convert to character. Adapted from oli414's function:
-- http://www.computercraft.info/forums2/index.php?/topic/25340-cc-176-easy-drawing-characters/
local data = 128
for i = 1, #pattern - 1 do
if pattern[i] ~= pattern[6] then
data = data + 2 ^ (i - 1)
end
end
return string.char(data), colourChar[usage[1][1] == pattern[6] and usage[2][1] or usage[1][1]], colourChar[pattern[6]]
else
-- Solid colour character:
return "\128", colourChar[pattern[1]], colourChar[pattern[1]]
end
end
local results, width, height, bgCol = { {}, {}, {} }, 0, #img + #img % 3, base.bgColor or colors.black
for i = 1, #img do
if #img[i] > width then
width = #img[i]
end
end
for y = 0, height - 1, 3 do
local cRow, tRow, bRow, counter = {}, {}, {}, 1
for x = 0, width - 1, 2 do
-- Grab a 2x3 chunk:
local pattern, totals = {}, {}
for yy = 1, 3 do
for xx = 1, 2 do
pattern[#pattern + 1] = (img[y + yy] and img[y + yy][x + xx]) and (img[y + yy][x + xx] == 0 and bgCol or img[y + yy][x + xx]) or bgCol
totals[pattern[#pattern]] = totals[pattern[#pattern]] and (totals[pattern[#pattern]] + 1) or 1
end
end
cRow[counter], tRow[counter], bRow[counter] = colsToChar(pattern, totals)
counter = counter + 1
end
results[1][#results[1] + 1], results[2][#results[2] + 1], results[3][#results[3] + 1] = table.concat(cRow), table.concat(tRow), table.concat(bRow)
end
results.width, results.height = #results[1][1], #results[1]
shrinkedGraphic = results
end
local function redraw()
local w,h = w,h
if(isGraphicShrinked)then w = w*2 h = h*3 end
for k,v in pairs(graphicObjects)do
for a,b in pairs(v[1])do
setBG(b.x, b.y, w, h, v[2])
end
end
if(isGraphicShrinked)then
shrink()
end
end
local object = {
init = function(self)
self.bgColor = self.parent:getTheme("GraphicBG")
end,
getType = function(self)
return objectType
end;
setSize = function(self, width, height, rel)
base.setSize(self, width, height, rel)
if not(canvasSizeChanged)then
w = width
h = height
redrawCanvasSize()
end
redraw()
return self
end,
setOffset = function(self, x, y)
xOffset = x or xOffset
yOffset = y or yOffset
return self
end,
setCanvasSize = function(self, width, height)
w,h = width,height
canvasSizeChanged = true
redrawCanvasSize()
return self
end,
clearCanvas = function(self)
graphicObjects = {}
graphic = {}
redrawCanvasSize()
end,
getOffset = function(self)
return xOffset,yOffset
end,
setValuesByXMLData = function(self, data)
base.setValuesByXMLData(self, data)
if(xmlValue("text", data)~=nil)then self:setText(xmlValue("text", data)) end
if(xmlValue("xOffset", data)~=nil)then self:setOffset(xmlValue("xOffset", data), yOffset) end
if(xmlValue("yOffset", data)~=nil)then self:setOffset(xOffset, xmlValue("yOffset", data)) end
if(xmlValue("wCanvas", data)~=nil)then w = xmlValue("wCanvas", data) end
if(xmlValue("hCanvas", data)~=nil)then h = xmlValue("hCanvas", data) end
if(xmlValue("shrink", data)~=nil)then if(xmlValue("shrink", data))then self:shrink() end end
if(xmlValue("dragable", data)~=nil)then if(xmlValue("dragable", data))then dragable = true end end
if(data["ellipse"]~=nil)then
local tab = data["ellipse"]
if(tab.properties~=nil)then tab = {tab} end
for k,v in pairs(tab)do
local col = colors[xmlValue("color", v)]
local rad1 = xmlValue("radius", v)
local rad2 = xmlValue("radius2", v)
local x = xmlValue("x", v)
local y = xmlValue("y", v)
local filled = xmlValue("filled", v)
self:addEllipse(col, rad1, rad2, x, y, filled)
end
end
if(data["circle"]~=nil)then
local tab = data["circle"]
if(tab.properties~=nil)then tab = {tab} end
for k,v in pairs(tab)do
local col = colors[xmlValue("color", v)]
local rad = tonumber(xmlValue("radius", v))
local x = tonumber(xmlValue("x", v))
local y = tonumber(xmlValue("y", v))
local filled = xmlValue("filled", v)
self:addCircle(col, rad, x, y, filled)
end
end
if(data["line"]~=nil)then
local tab = data["line"]
if(tab.properties~=nil)then tab = {tab} end
for k,v in pairs(tab)do
local col = colors[xmlValue("color", v)]
local x = tonumber(xmlValue("x", v))
local x2 = tonumber(xmlValue("x2", v))
local y = tonumber(xmlValue("y", v))
local y2 = tonumber(xmlValue("y2", v))
self:addLine(col, x, y, x2, y2)
end
end
if(data["rectangle"]~=nil)then
local tab = data["rectangle"]
if(tab.properties~=nil)then tab = {tab} end
for k,v in pairs(tab)do
local col = colors[xmlValue("color", v)]
local x = tonumber(xmlValue("x", v))
local x2 = tonumber(xmlValue("x2", v))
local y = tonumber(xmlValue("y", v))
local y2 = tonumber(xmlValue("y2", v))
local filled = xmlValue("filled", v)=="true" and true or false
self:addRectangle(col, x, y, x2, y2, filled)
end
end
if(data["triangle"]~=nil)then
local tab = data["triangle"]
if(tab.properties~=nil)then tab = {tab} end
for k,v in pairs(tab)do
local col = colors[xmlValue("color", v)]
local x = tonumber(xmlValue("x", v))
local x2 = tonumber(xmlValue("x2", v))
local x3 = tonumber(xmlValue("x2", v))
local y = tonumber(xmlValue("y", v))
local y2 = tonumber(xmlValue("y2", v))
local y3 = tonumber(xmlValue("y3", v))
local filled = xmlValue("filled", v)
self:addTriangle(col, x, y, x2, y2, x3, y3, filled)
end
end
return self
end,
addCircle = function(self, color, rad, x, y, filled)
local col = tHex[color]
table.insert(graphicObjects, {geometric.circle(x or 1, y or 1, rad, filled), tHex[color]})
redraw()
return self
end;
addEllipse = function(self, color, rad, rad2, x, y, filled)
table.insert(graphicObjects, {geometric.ellipse(x or 1, y or 1, rad, rad2, filled), tHex[color]})
redraw()
return self
end;
addLine = function(self, color, x1, y1, x2, y2)
table.insert(graphicObjects, {geometric.line(x1 or 1, y1 or 1, x2 or 1, y2 or 1), tHex[color]})
redraw()
return self
end;
addTriangle = function(self, color, x1, y1, x2, y2, x3, y3, filled)
table.insert(graphicObjects, {geometric.triangle(x1 or 1, y1 or 1, x2 or 1, y2 or 1, x3 or 1, y3 or 1, filled), tHex[color]})
redraw()
return self
end;
addRectangle = function(self, color, x1, y1, x2, y2, filled)
table.insert(graphicObjects, {geometric.rectangle(x1 or 1, y1 or 1, x2 or 1, y2 or 1, filled), tHex[color]})
redraw()
return self
end;
shrink = function(self)
isGraphicShrinked = true
redrawCanvasSize()
shrink()
return self
end,
setDragable = function(self, drag)
dragable = drag == true and true or false
return self
end,
mouseHandler = function(self, event, button, x, y)
if(base.mouseHandler(self, event, button, x, y))then
if(dragable)then
if(event=="mouse_click")then
xMouse,yMouse = x,y
end
if(event=="mouse_drag")then
if(xMouse~=nil)and(yMouse~=nil)then
xOffset = max(min(xOffset+xMouse-x, w-self:getWidth()),0)
xMouse = x
yOffset = max(min(yOffset+yMouse-y, h-self:getHeight()),0)
yMouse = y
end
end
end
return true
end
return false
end,
draw = function(self)
if (base.draw(self)) then
if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition()
local w,h = self:getSize()
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
end
if (isGraphicShrinked) then
-- this is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/
local t, tC, bC = shrinkedGraphic[1], shrinkedGraphic[2], shrinkedGraphic[3]
for i = 1, shrinkedGraphic.height do
local x, y = obx+xOffset, oby + i - 1 + yOffset
if(y>oby-1)and(y<=oby+h-1)and(x<=w+obx)then
local tI = t[i]
local xpos,substart,subend = max(x, obx), max(1 - x + 1, 1), min(w - (x-obx), w)
if type(tI) == "string" then
self.parent:setText(xpos, y, sub(tI, substart, subend))
self.parent:setFG(xpos, y, sub(tC[i], substart, subend))
self.parent:setBG(xpos, y, sub(bC[i], substart, subend))
elseif type(tI) == "table" then
self.parent:setText(xpos, y, sub(tI[2], substart, subend))
self.parent:setFG(xpos, y, sub(tC[i], substart, subend))
self.parent:setBG(xpos, y, sub(bC[i], substart, subend))
end
end
end
else
for i = 1, #graphic do
local x, y = obx+xOffset, oby + i - 1 + yOffset
if(y>oby-1)and(y<=oby+h-1)and(x<=w+obx)then
local xpos,substart,subend = max(x, obx), max(1 - x + 1, 1), min(w - (x-obx), w)
self.parent:setBG(xpos, y, sub(graphic[i],substart,subend))
end
end
end
end
self:setVisualChanged(false)
end
end;
}
return setmetatable(object, base)
end

View File

@@ -142,6 +142,7 @@ return function(name)
loadImage = function(self, path) loadImage = function(self, path)
image = paintutils.loadImage(path) image = paintutils.loadImage(path)
imageGotShrinked = false imageGotShrinked = false
self:updateDraw()
return self return self
end; end;
@@ -149,6 +150,7 @@ return function(name)
shrink = function(self) shrink = function(self)
shrink() shrink()
imageGotShrinked = true imageGotShrinked = true
self:updateDraw()
return self return self
end; end;
@@ -192,9 +194,8 @@ return function(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -1,5 +1,6 @@
local Object = require("Object") local Object = require("Object")
local utils = require("utils") local utils = require("utils")
local log = require("basaltLogs")
local xmlValue = utils.getValueFromXML local xmlValue = utils.getValueFromXML
return function(name) return function(name)
@@ -24,10 +25,6 @@ return function(name)
local internalValueChange = false local internalValueChange = false
local object = { local object = {
init = function(self)
self.bgColor = self.parent:getTheme("InputBG")
self.fgColor = self.parent:getTheme("InputFG")
end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
@@ -36,6 +33,7 @@ return function(name)
if (iType == "password") or (iType == "number") or (iType == "text") then if (iType == "password") or (iType == "number") or (iType == "text") then
inputType = iType inputType = iType
end end
self:updateDraw()
return self return self
end; end;
@@ -48,6 +46,7 @@ return function(name)
else else
showingText = defaultText showingText = defaultText
end end
self:updateDraw()
return self return self
end; end;
@@ -58,8 +57,14 @@ return function(name)
setValue = function(self, val) setValue = function(self, val)
base.setValue(self, tostring(val)) base.setValue(self, tostring(val))
if not (internalValueChange) then if not (internalValueChange) then
textX = tostring(val):len() + 1 if(self:isFocused())then
textX = tostring(val):len() + 1
wIndex = math.max(1, textX-self:getWidth()+1)
local obx, oby = self:getAnchorPosition()
self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self:getHeight()/2), self.fgColor)
end
end end
self:updateDraw()
return self return self
end; end;
@@ -70,6 +75,7 @@ return function(name)
setInputLimit = function(self, limit) setInputLimit = function(self, limit)
inputLimit = tonumber(limit) or inputLimit inputLimit = tonumber(limit) or inputLimit
self:updateDraw()
return self return self
end; end;
@@ -93,25 +99,28 @@ return function(name)
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
showingText = "" showingText = ""
if (self.parent ~= nil) then if(defaultText~="")then
self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self.height/2), self.fgColor) self:updateDraw()
end end
self.parent:setCursor(true, obx + textX - wIndex, oby+math.max(math.ceil(self:getHeight()/2-1, 1)), self.fgColor)
end end
end; end;
loseFocusHandler = function(self) loseFocusHandler = function(self)
base.loseFocusHandler(self) base.loseFocusHandler(self)
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setCursor(false)
showingText = defaultText showingText = defaultText
if(defaultText~="")then
self:updateDraw()
end
self.parent:setCursor(false)
end end
end; end;
keyHandler = function(self, event, key) keyHandler = function(self, key)
if (base.keyHandler(self, event, key)) then if (base.keyHandler(self, key)) then
local w,h = self:getSize() local w,h = self:getSize()
internalValueChange = true internalValueChange = true
if (event == "key") then
if (key == keys.backspace) then if (key == keys.backspace) then
-- on backspace -- on backspace
local text = tostring(base.getValue()) local text = tostring(base.getValue())
@@ -167,52 +176,138 @@ return function(name)
wIndex = 1 wIndex = 1
end end
end end
local obx, oby = self:getAnchorPosition()
local val = tostring(base.getValue())
local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1)
local inpX = self:getX()
if (cursorX > inpX + w - 1) then
cursorX = inpX + w - 1
end end
if (self.parent ~= nil) then
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
end
self:updateDraw()
internalValueChange = false
return true
end
return false
end,
if (event == "char") then charHandler = function(self, char)
local text = base.getValue() if (base.charHandler(self, char)) then
if (text:len() < inputLimit or inputLimit <= 0) then internalValueChange = true
if (inputType == "number") then local w,h = self:getSize()
local cache = text local text = base.getValue()
if (key == ".") or (tonumber(key) ~= nil) then if (text:len() < inputLimit or inputLimit <= 0) then
self:setValue(text:sub(1, textX - 1) .. key .. text:sub(textX, text:len())) if (inputType == "number") then
textX = textX + 1 local cache = text
end if (#text==0 and char == "-") or (char == ".") or (tonumber(char) ~= nil) then
if (tonumber(base.getValue()) == nil) then self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
self:setValue(cache)
end
else
self:setValue(text:sub(1, textX - 1) .. key .. text:sub(textX, text:len()))
textX = textX + 1 textX = textX + 1
end end
if (textX >= w + wIndex) then if (tonumber(base.getValue()) == nil) then
wIndex = wIndex + 1 --self:setValue(cache)
end end
else
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
textX = textX + 1
end
if (textX >= w + wIndex) then
wIndex = wIndex + 1
end end
end end
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
local val = tostring(base.getValue()) local val = tostring(base.getValue())
local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1) local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1)
if (cursorX > self.x + w - 1) then local x = self:getX()
cursorX = self.x + w - 1 if (cursorX > x + w - 1) then
cursorX = x + w - 1
end end
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setCursor(true, obx + cursorX, oby+math.floor(h/2), self.fgColor) self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
end end
internalValueChange = false internalValueChange = false
end self:updateDraw()
end;
mouseHandler = function(self, event, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then
if (event == "mouse_click") and (button == 1) then
end
return true return true
end end
return false return false
end; end,
mouseHandler = function(self, button, x, y)
if(base.mouseHandler(self, button, x, y))then
local ax, ay = self:getAnchorPosition()
local obx, oby = self:getAbsolutePosition(ax, ay)
local w, h = self:getSize()
textX = x - obx + wIndex
local text = base.getValue()
if (textX > text:len()) then
textX = text:len() + 1
end
if (textX < wIndex) then
wIndex = textX - 1
if (wIndex < 1) then
wIndex = 1
end
end
self.parent:setCursor(true, ax + textX - wIndex, ay+math.max(math.ceil(h/2-1, 1)), self.fgColor)
return true
end
end,
dragHandler = function(self, btn, x, y, xOffset, yOffset)
if(self:isFocused())then
if(self:isCoordsInObject(x, y))then
if(base.dragHandler(self, btn, x, y, xOffset, yOffset))then
return true
end
end
self.parent:removeFocusedObject()
end
end,
eventHandler = function(self, event, paste, p2, p3, p4)
if(base.eventHandler(self, event, paste, p2, p3, p4))then
if(event=="paste")then
if(self:isFocused())then
local text = base.getValue()
local w, h = self:getSize()
internalValueChange = true
if (inputType == "number") then
local cache = text
if (paste == ".") or (tonumber(paste) ~= nil) then
self:setValue(text:sub(1, textX - 1) .. paste .. text:sub(textX, text:len()))
textX = textX + paste:len()
end
if (tonumber(base.getValue()) == nil) then
self:setValue(cache)
end
else
self:setValue(text:sub(1, textX - 1) .. paste .. text:sub(textX, text:len()))
textX = textX + paste:len()
end
if (textX >= w + wIndex) then
wIndex = (textX+1)-w
end
local obx, oby = self:getAnchorPosition()
local val = tostring(base.getValue())
local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1)
local x = self:getX()
if (cursorX > x + w - 1) then
cursorX = x + w - 1
end
if (self.parent ~= nil) then
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
end
self:updateDraw()
internalValueChange = false
end
end
end
end,
draw = function(self) draw = function(self)
if (base.draw(self)) then if (base.draw(self)) then
@@ -246,14 +341,30 @@ return function(name)
if (inputType == "password") and (val ~= "") then if (inputType == "password") and (val ~= "") then
text = string.rep("*", text:len()) text = string.rep("*", text:len())
end end
text = text .. string.rep(" ", space) text = text .. string.rep(self.bgSymbol, space)
self.parent:writeText(obx, oby + (n - 1), text, bCol, fCol) self.parent:writeText(obx, oby + (n - 1), text, bCol, fCol)
end end
end end
if(self:isFocused())then
self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self:getHeight()/2), self.fgColor)
end
end end
self:setVisualChanged(false)
end end
end; end,
init = function(self)
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("key", self)
self.parent:addEvent("char", self)
self.parent:addEvent("other_event", self)
self.parent:addEvent("mouse_drag", self)
end
if(base.init(self))then
self.bgColor = self.parent:getTheme("InputBG")
self.fgColor = self.parent:getTheme("InputText")
end
end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -31,29 +31,35 @@ return function(name)
text = tostring(text) text = tostring(text)
base:setValue(text) base:setValue(text)
if (autoSize) then if (autoSize) then
self.width = text:len() if(text:len()+self:getX()>self.parent:getWidth())then
local newW = self.parent:getWidth() - self:getX()
base.setSize(self, newW, #createText(text, newW))
else
base.setSize(self, text:len(), 1)
end
end end
if not(fgColChanged)then self.fgColor = self.parent:getForeground() or colors.white end self:updateDraw()
if not(bgColChanged)then self.bgColor = self.parent:getBackground() or colors.black end
return self return self
end; end;
setBackground = function(self, col) setBackground = function(self, col)
base.setBackground(self, col) base.setBackground(self, col)
bgColChanged = true bgColChanged = true
self:updateDraw()
return self return self
end, end,
setForeground = function(self, col) setForeground = function(self, col)
base.setForeground(self, col) base.setForeground(self, col)
fgColChanged = true fgColChanged = true
self:updateDraw()
return self return self
end, end,
setTextAlign = function(self, hor, vert) setTextAlign = function(self, hor, vert)
textHorizontalAlign = hor or textHorizontalAlign textHorizontalAlign = hor or textHorizontalAlign
textVerticalAlign = vert or textVerticalAlign textVerticalAlign = vert or textVerticalAlign
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
@@ -61,6 +67,7 @@ return function(name)
if(size>0)and(size<=4)then if(size>0)and(size<=4)then
fontsize = size-1 or 0 fontsize = size-1 or 0
end end
self:updateDraw()
return self return self
end; end;
@@ -77,60 +84,84 @@ return function(name)
return self return self
end, end,
setSize = function(self, width, height) setSize = function(self, width, height, rel)
base.setSize(self, width, height) base.setSize(self, width, height, rel)
autoSize = false autoSize = false
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
eventHandler = function(self, event)
if(event=="basalt_resize")then
if (autoSize) then
local text = self:getValue()
if(text:len()+self:getX()>self.parent:getWidth())then
local newW = self.parent:getWidth() - self:getX()
base.setSize(self, newW, #createText(text, newW))
else
base.setSize(self, text:len(), 1)
end
else
--self.parent:removeEvent("other_event", self)
end
end
end,
draw = function(self) draw = function(self)
if (base.draw(self)) then if (base.draw(self)) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
local w,h = self:getSize() local w,h = self:getSize()
local verticalAlign = utils.getTextVerticalAlign(h, textVerticalAlign) local verticalAlign = utils.getTextVerticalAlign(h, textVerticalAlign)
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
self.parent:drawTextBox(obx, oby, w, h, " ") end
if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor) end
if(fontsize==0)then if(fontsize==0)then
if not(autoSize)then if not(autoSize)then
local text = createText(self:getValue(), self:getWidth()) local text = createText(self:getValue(), self:getWidth())
for k,v in pairs(text)do for k,v in pairs(text)do
self.parent:setText(obx, oby+k-1, v) if(k<=h)then
self.parent:writeText(obx, oby+k-1, v, self.bgColor, self.fgColor)
end
end end
else else
for n = 1, h do if(#self:getValue()+obx>self.parent:getWidth())then
if (n == verticalAlign) then local text = createText(self:getValue(), self:getWidth())
self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), w, textHorizontalAlign)) for k,v in pairs(text)do
if(k<=h)then
self.parent:writeText(obx, oby+k-1, v, self.bgColor, self.fgColor)
end
end end
else
self.parent:writeText(obx, oby, self:getValue(), self.bgColor, self.fgColor)
end end
end end
else else
local tData = bigFont(fontsize, self:getValue(), self.fgColor, self.bgColor or colors.black) local tData = bigFont(fontsize, self:getValue(), self.fgColor, self.bgColor or colors.lightGray)
if(autoSize)then if(autoSize)then
self:setSize(#tData[1][1], #tData[1]-1) self:setSize(#tData[1][1], #tData[1]-1)
end end
for n = 1, h do local oX, oY = self.parent:getSize()
if (n == verticalAlign) then local cX, cY = #tData[1][1], #tData[1]
local oX, oY = self.parent:getSize() obx = obx or math.floor((oX - cX) / 2) + 1
local cX, cY = #tData[1][1], #tData[1] oby = oby or math.floor((oY - cY) / 2) + 1
obx = obx or math.floor((oX - cX) / 2) + 1
oby = oby or math.floor((oY - cY) / 2) + 1 for i = 1, cY do
self.parent:setFG(obx, oby + i - 1, tData[2][i])
for i = 1, cY do self.parent:setBG(obx, oby + i - 1, tData[3][i])
self.parent:setFG(obx, oby + i + n - 2, utils.getTextHorizontalAlign(tData[2][i], w, textHorizontalAlign)) self.parent:setText(obx, oby + i - 1, tData[1][i])
self.parent:setBG(obx, oby + i + n - 2, utils.getTextHorizontalAlign(tData[3][i], w, textHorizontalAlign, tHex[self.bgColor or colors.black]))
self.parent:setText(obx, oby + i + n - 2, utils.getTextHorizontalAlign(tData[1][i], w, textHorizontalAlign))
end
end end
end
end end
end end
self:setVisualChanged(false)
end end
end; end,
init = function(self)
self.parent:addEvent("other_event", self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("LabelBG")
self.fgColor = self.parent:getTheme("LabelText")
if(self.parent.bgColor==colors.black)and(self.fgColor==colors.black)then
self.fgColor = colors.lightGray
end
end
end
} }

View File

@@ -18,12 +18,6 @@ return function(name)
local scrollable = true local scrollable = true
local object = { local object = {
init = function(self)
self.bgColor = self.parent:getTheme("ListBG")
self.fgColor = self.parent:getTheme("ListText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
@@ -33,11 +27,13 @@ return function(name)
if (#list == 1) then if (#list == 1) then
self:setValue(list[1]) self:setValue(list[1])
end end
self:updateDraw()
return self return self
end; end;
setOffset = function(self, yOff) setOffset = function(self, yOff)
yOffset = yOff yOffset = yOff
self:updateDraw()
return self return self
end; end;
@@ -47,6 +43,7 @@ return function(name)
removeItem = function(self, index) removeItem = function(self, index)
table.remove(list, index) table.remove(list, index)
self:updateDraw()
return self return self
end; end;
@@ -70,6 +67,7 @@ return function(name)
clear = function(self) clear = function(self)
list = {} list = {}
self:setValue({}) self:setValue({})
self:updateDraw()
return self return self
end; end;
@@ -80,23 +78,28 @@ return function(name)
editItem = function(self, index, text, bgCol, fgCol, ...) editItem = function(self, index, text, bgCol, fgCol, ...)
table.remove(list, index) table.remove(list, index)
table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } }) table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
self:updateDraw()
return self return self
end; end;
selectItem = function(self, index) selectItem = function(self, index)
self:setValue(list[index] or {}) self:setValue(list[index] or {})
self:updateDraw()
return self return self
end; end;
setSelectedItem = function(self, bgCol, fgCol, active) setSelectedItem = function(self, bgCol, fgCol, active)
itemSelectedBG = bgCol or self.bgColor itemSelectedBG = bgCol or self.bgColor
itemSelectedFG = fgCol or self.fgColor itemSelectedFG = fgCol or self.fgColor
selectionColorActive = active selectionColorActive = active~=nil and active or true
self:updateDraw()
return self return self
end; end;
setScrollable = function(self, scroll) setScrollable = function(self, scroll)
scrollable = scroll scrollable = scroll
if(scroll==nil)then scrollable = true end
self:updateDraw()
return self return self
end; end;
@@ -116,29 +119,15 @@ return function(name)
return self return self
end, end,
mouseHandler = function(self, event, button, x, y) scrollHandler = function(self, dir, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) if(base.scrollHandler(self, dir, x, y))then
local w,h = self:getSize() if(scrollable)then
if (obx <= x) and (obx + w > x) and (oby <= y) and (oby + h > y) and (self:isVisible()) then local w,h = self:getSize()
if (((event == "mouse_click") or (event == "mouse_drag"))and(button==1))or(event=="monitor_touch") then yOffset = yOffset + dir
if (#list > 0) then
for n = 1, h do
if (list[n + yOffset] ~= nil) then
if (obx <= x) and (obx + w > 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
end
end
if (event == "mouse_scroll") and (scrollable) then
yOffset = yOffset + button
if (yOffset < 0) then if (yOffset < 0) then
yOffset = 0 yOffset = 0
end end
if (button >= 1) then if (dir >= 1) then
if (#list > h) then if (#list > h) then
if (yOffset > #list - h) then if (yOffset > #list - h) then
yOffset = #list - h yOffset = #list - h
@@ -150,11 +139,39 @@ return function(name)
yOffset = yOffset - 1 yOffset = yOffset - 1
end end
end end
self:updateDraw()
end end
self:setVisualChanged()
return true return true
end end
end; return false
end,
mouseHandler = function(self, button, x, y)
if(base.mouseHandler(self, button, x, y))then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local w,h = self:getSize()
if (#list > 0) then
for n = 1, h do
if (list[n + yOffset] ~= nil) then
if (obx <= x) and (obx + w > x) and (oby + n - 1 == y) then
self:setValue(list[n + yOffset])
self:updateDraw()
end
end
end
end
return true
end
return false
end,
dragHandler = function(self, button, x, y)
return self:mouseHandler(button, x, y)
end,
touchHandler = function(self, x, y)
return self:mouseHandler(1, x, y)
end,
draw = function(self) draw = function(self)
if (base.draw(self)) then if (base.draw(self)) then
@@ -178,9 +195,20 @@ return function(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end,
init = function(self)
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_drag", self)
self.parent:addEvent("mouse_scroll", self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("ListBG")
self.fgColor = self.parent:getTheme("ListText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
end
end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -40,13 +40,6 @@ return function(name)
end end
object = { object = {
init = function(self)
self.bgColor = self.parent:getTheme("MenubarBG")
self.fgColor = self.parent:getTheme("MenubarText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
@@ -56,6 +49,7 @@ return function(name)
if (#list == 1) then if (#list == 1) then
self:setValue(list[1]) self:setValue(list[1])
end end
self:updateDraw()
return self return self
end; end;
@@ -75,11 +69,13 @@ return function(name)
clear = function(self) clear = function(self)
list = {} list = {}
self:setValue({}) self:setValue({})
self:updateDraw()
return self return self
end; end;
setSpace = function(self, _space) setSpace = function(self, _space)
space = _space or space space = _space or space
self:updateDraw()
return self return self
end; end;
@@ -93,6 +89,7 @@ return function(name)
if (itemOffset > mScroll) then if (itemOffset > mScroll) then
itemOffset = mScroll itemOffset = mScroll
end end
self:updateDraw()
return self return self
end; end;
@@ -125,6 +122,7 @@ return function(name)
removeItem = function(self, index) removeItem = function(self, index)
table.remove(list, index) table.remove(list, index)
self:updateDraw()
return self return self
end; end;
@@ -139,11 +137,13 @@ return function(name)
editItem = function(self, index, text, bgCol, fgCol, ...) editItem = function(self, index, text, bgCol, fgCol, ...)
table.remove(list, index) table.remove(list, index)
table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } }) table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
self:updateDraw()
return self return self
end; end;
selectItem = function(self, index) selectItem = function(self, index)
self:setValue(list[index] or {}) self:setValue(list[index] or {})
self:updateDraw()
return self return self
end; end;
@@ -151,48 +151,49 @@ return function(name)
itemSelectedBG = bgCol or self.bgColor itemSelectedBG = bgCol or self.bgColor
itemSelectedFG = fgCol or self.fgColor itemSelectedFG = fgCol or self.fgColor
selectionColorActive = active selectionColorActive = active
self:updateDraw()
return self return self
end; end;
mouseHandler = function(self, event, button, x, y) mouseHandler = function(self, button, x, y)
if(base.mouseHandler(self, event, button, x, y))then if(base.mouseHandler(self, button, x, y))then
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
local w,h = self:getSize() local w,h = self:getSize()
if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) and (self:isVisible()) then local xPos = 0
if (self.parent ~= nil) then for n = 1, #list do
self.parent:setFocusedObject(self) if (list[n] ~= nil) then
end if (objX + xPos <= x + itemOffset) and (objX + xPos + list[n].text:len() + (space*2) > x + itemOffset) and (objY == y) then
if (event == "mouse_click") or (event == "monitor_touch") then self:setValue(list[n])
local xPos = 0 self:getEventSystem():sendEvent(event, self, event, 0, x, y, list[n])
for n = 1, #list do
if (list[n] ~= nil) then
if (objX + xPos <= x + itemOffset) and (objX + xPos + list[n].text:len() + (space*2) > x + itemOffset) and (objY == y) then
self:setValue(list[n])
self:getEventSystem():sendEvent(event, self, event, 0, x, y, list[n])
end
xPos = xPos + list[n].text:len() + space * 2
end end
end xPos = xPos + list[n].text:len() + space * 2
end
if (event == "mouse_scroll") and (scrollable) then
itemOffset = itemOffset + button
if (itemOffset < 0) then
itemOffset = 0
end
local mScroll = maxScroll()
if (itemOffset > mScroll) then
itemOffset = mScroll
end end
end end
self:setVisualChanged(true) self:updateDraw()
return true return true
end
end end
return false return false
end; end,
scrollHandler = function(self, dir, x, y)
if(base.scrollHandler(self, dir, x, y))then
if(scrollable)then
itemOffset = itemOffset + dir
if (itemOffset < 0) then
itemOffset = 0
end
local mScroll = maxScroll()
if (itemOffset > mScroll) then
itemOffset = mScroll
end
self:updateDraw()
end
return true
end
return false
end,
draw = function(self) draw = function(self)
if (base.draw(self)) then if (base.draw(self)) then
@@ -221,9 +222,19 @@ return function(name)
self.parent:setBG(obx, oby, textBGCol:sub(itemOffset+1, w+itemOffset)) self.parent:setBG(obx, oby, textBGCol:sub(itemOffset+1, w+itemOffset))
self.parent:setFG(obx, oby, textFGCol:sub(itemOffset+1, w+itemOffset)) self.parent:setFG(obx, oby, textFGCol:sub(itemOffset+1, w+itemOffset))
end end
self:setVisualChanged(false)
end end
end; end,
init = function(self)
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_scroll", self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("MenubarBG")
self.fgColor = self.parent:getTheme("MenubarText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
end
end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -1,4 +1,5 @@
local Object = require("Object") local Object = require("Object")
local log = require("basaltLogs")
return function(name) return function(name)
-- Pane -- Pane
@@ -6,26 +7,21 @@ return function(name)
local objectType = "Pane" local objectType = "Pane"
local object = { local object = {
init = function(self)
self.bgColor = self.parent:getTheme("PaneBG")
self.fgColor = self.parent:getTheme("PaneBG")
end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
draw = function(self) setBackground = function(self, col, sym, symC)
if (base.draw(self)) then base.setBackground(self, col, sym, symC)
if (self.parent ~= nil) then return self
local obx, oby = self:getAnchorPosition() end,
local w,h = self:getSize()
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor)
end
self:setVisualChanged(false)
end
end;
init = function(self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("PaneBG")
self.fgColor = self.parent:getTheme("PaneBG")
end
end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -11,8 +11,9 @@ return function(name, parent)
base:setZIndex(5) base:setZIndex(5)
local object local object
local cachedPath local cachedPath
local enviroment = {}
local function createBasaltWindow(x, y, width, height) local function createBasaltWindow(x, y, width, height, self)
local xCursor, yCursor = 1, 1 local xCursor, yCursor = 1, 1
local bgColor, fgColor = colors.black, colors.white local bgColor, fgColor = colors.black, colors.white
local cursorBlink = false local cursorBlink = false
@@ -51,6 +52,7 @@ return function(name, parent)
cacheFG[n] = sub(cacheFG[n] == nil and emptyFG or cacheFG[n] .. emptyFG:sub(1, width - cacheFG[n]:len()), 1, width) cacheFG[n] = sub(cacheFG[n] == nil and emptyFG or cacheFG[n] .. emptyFG:sub(1, width - cacheFG[n]:len()), 1, width)
cacheBG[n] = sub(cacheBG[n] == nil and emptyBG or cacheBG[n] .. emptyBG:sub(1, width - cacheBG[n]:len()), 1, width) cacheBG[n] = sub(cacheBG[n] == nil and emptyBG or cacheBG[n] .. emptyBG:sub(1, width - cacheBG[n]:len()), 1, width)
end end
base.updateDraw(base)
end end
recreateWindowArray() recreateWindowArray()
@@ -118,6 +120,7 @@ return function(name, parent)
cacheFG[yCursor] = sNewTextColor cacheFG[yCursor] = sNewTextColor
cacheBG[yCursor] = sNewBackgroundColor cacheBG[yCursor] = sNewBackgroundColor
end end
object:updateDraw()
end end
xCursor = nEnd + 1 xCursor = nEnd + 1
if (visible) then if (visible) then
@@ -133,6 +136,7 @@ return function(name, parent)
cacheT[_y] = sub(gText:sub(1, _x - 1) .. text .. gText:sub(_x + (text:len()), width), 1, width) cacheT[_y] = sub(gText:sub(1, _x - 1) .. text .. gText:sub(_x + (text:len()), width), 1, width)
end end
end end
object:updateDraw()
end end
local function setBG(_x, _y, colorStr) local function setBG(_x, _y, colorStr)
@@ -142,6 +146,7 @@ return function(name, parent)
cacheBG[_y] = sub(gBG:sub(1, _x - 1) .. colorStr .. gBG:sub(_x + (colorStr:len()), width), 1, width) cacheBG[_y] = sub(gBG:sub(1, _x - 1) .. colorStr .. gBG:sub(_x + (colorStr:len()), width), 1, width)
end end
end end
object:updateDraw()
end end
local function setFG(_x, _y, colorStr) local function setFG(_x, _y, colorStr)
@@ -151,6 +156,7 @@ return function(name, parent)
cacheFG[_y] = sub(gFG:sub(1, _x - 1) .. colorStr .. gFG:sub(_x + (colorStr:len()), width), 1, width) cacheFG[_y] = sub(gFG:sub(1, _x - 1) .. colorStr .. gFG:sub(_x + (colorStr:len()), width), 1, width)
end end
end end
object:updateDraw()
end end
local setTextColor = function(color) local setTextColor = function(color)
@@ -417,10 +423,57 @@ return function(name, parent)
local paused = false local paused = false
local queuedEvent = {} local queuedEvent = {}
local function updateCursor(self)
local xCur, yCur = pWindow.getCursorPos()
local obx, oby = self:getAnchorPosition()
local w,h = self:getSize()
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
self.parent:setCursor(self:isFocused() and pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
end
end
local function resumeProcess(self, event, ...)
local ok, result = curProcess:resume(event, ...)
if (ok==false)and(result~=nil)and(result~="Terminated")then
local val = self:sendEvent("program_error", result)
if(val~=false)then
error("Basalt Program - "..result)
end
end
if(curProcess:getStatus()=="dead")then
self:sendEvent("program_done")
end
end
local function mouseEvent(self, event, p1, x, y)
if (curProcess == nil) then
return false
end
if not (curProcess:isDead()) then
if not (paused) then
local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true))
resumeProcess(self, event, p1, x-absX+1, y-absY+1)
updateCursor(self)
end
end
end
local function keyEvent(self, event, key, isHolding)
if (curProcess == nil) then
return false
end
if not (curProcess:isDead()) then
if not (paused) then
if (self.draw) then
resumeProcess(self, event, key, isHolding)
updateCursor(self)
end
end
end
end
object = { object = {
init = function(self)
self.bgColor = self.parent:getTheme("ProgramBG")
end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
@@ -461,7 +514,7 @@ return function(name, parent)
setSize = function(self, width, height, rel) setSize = function(self, width, height, rel)
base.setSize(self, width, height, rel) base.setSize(self, width, height, rel)
pWindow.basalt_resize(self:getSize()) pWindow.basalt_resize(self:getWidth(), self:getHeight())
return self return self
end; end;
@@ -472,9 +525,14 @@ return function(name, parent)
return "inactive" return "inactive"
end; end;
setEnviroment = function(self, env)
enviroment = env or {}
return self
end,
execute = function(self, path, ...) execute = function(self, path, ...)
cachedPath = path or cachedPath cachedPath = path or cachedPath
curProcess = process:new(cachedPath, pWindow, ...) curProcess = process:new(cachedPath, pWindow, enviroment, ...)
pWindow.setBackgroundColor(colors.black) pWindow.setBackgroundColor(colors.black)
pWindow.setTextColor(colors.white) pWindow.setTextColor(colors.white)
pWindow.clear() pWindow.clear()
@@ -482,15 +540,26 @@ return function(name, parent)
pWindow.setBackgroundColor(self.bgColor) pWindow.setBackgroundColor(self.bgColor)
pWindow.setTextColor(self.fgColor) pWindow.setTextColor(self.fgColor)
pWindow.basalt_setVisible(true) pWindow.basalt_setVisible(true)
curProcess:resume()
resumeProcess(self)
paused = false paused = false
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_up", self)
self.parent:addEvent("mouse_drag", self)
self.parent:addEvent("mouse_scroll", self)
self.parent:addEvent("key", self)
self.parent:addEvent("key_up", self)
self.parent:addEvent("char", self)
self.parent:addEvent("other_event", self)
end
return self return self
end; end;
stop = function(self) stop = function(self)
if (curProcess ~= nil) then if (curProcess ~= nil) then
if not (curProcess:isDead()) then if not (curProcess:isDead()) then
curProcess:resume("terminate") resumeProcess(self, "terminate")
if (curProcess:isDead()) then if (curProcess:isDead()) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setCursor(false) self.parent:setCursor(false)
@@ -498,6 +567,7 @@ return function(name, parent)
end end
end end
end end
self.parent:removeEvents(self)
return self return self
end; end;
@@ -522,7 +592,7 @@ return function(name, parent)
if (curProcess ~= nil) then if (curProcess ~= nil) then
if not (curProcess:isDead()) then if not (curProcess:isDead()) then
if (paused == false) or (ign) then if (paused == false) or (ign) then
curProcess:resume(event, p1, p2, p3, p4) resumeProcess(self, event, p1, p2, p3, p4)
else else
table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } }) table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } })
end end
@@ -544,43 +614,68 @@ return function(name, parent)
if (curProcess ~= nil) then if (curProcess ~= nil) then
if not (curProcess:isDead()) then if not (curProcess:isDead()) then
for _, value in pairs(events) do for _, value in pairs(events) do
curProcess:resume(value.event, table.unpack(value.args)) resumeProcess(self, value.event, table.unpack(value.args))
end end
end end
end end
return self return self
end; end;
mouseHandler = function(self, event, button, x, y) mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then if (base.mouseHandler(self, button, x, y)) then
if (curProcess == nil) then mouseEvent(self, "mouse_click", button, x, y)
return false
end
if not (curProcess:isDead()) then
if not (paused) then
local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true))
curProcess:resume(event, button, x-absX+1, y-absY+1)
end
end
return true return true
end end
end; return false
end,
keyHandler = function(self, event, key) mouseUpHandler = function(self, button, x, y)
base.keyHandler(self, event, key) if (base.mouseUpHandler(self, button, x, y)) then
if (self:isFocused()) then mouseEvent(self, "mouse_up", button, x, y)
if (curProcess == nil) then return true
return false
end
if not (curProcess:isDead()) then
if not (paused) then
if (self.draw) then
curProcess:resume(event, key)
end
end
end
end end
end; return false
end,
scrollHandler = function(self, dir, x, y)
if (base.scrollHandler(self, dir, x, y)) then
mouseEvent(self, "mouse_scroll", dir, x, y)
return true
end
return false
end,
dragHandler = function(self, button, x, y)
if (base.dragHandler(self, button, x, y)) then
mouseEvent(self, "mouse_drag", button, x, y)
return true
end
return false
end,
keyHandler = function(self, key, isHolding)
if(base.keyHandler(self, key, isHolding))then
keyEvent(self, "key", key, isHolding)
return true
end
return false
end,
keyUpHandler = function(self, key)
if(base.keyUpHandler(self, key))then
keyEvent(self, "key_up", key)
return true
end
return false
end,
charHandler = function(self, char)
if(base.charHandler(self, char))then
keyEvent(self, "char", char)
return true
end
return false
end,
getFocusHandler = function(self) getFocusHandler = function(self)
base.getFocusHandler(self) base.getFocusHandler(self)
@@ -590,17 +685,15 @@ return function(name, parent)
if (self.parent ~= nil) then if (self.parent ~= nil) then
local xCur, yCur = pWindow.getCursorPos() local xCur, yCur = pWindow.getCursorPos()
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
if (self.parent ~= nil) then local w,h = self:getSize()
local w,h = self:getSize() if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
end
end end
end end
end end
end end
end end
end; end,
loseFocusHandler = function(self) loseFocusHandler = function(self)
base.loseFocusHandler(self) base.loseFocusHandler(self)
@@ -611,53 +704,98 @@ return function(name, parent)
end end
end end
end end
end; end,
eventHandler = function(self, event, p1, p2, p3, p4) eventHandler = function(self, event, p1, p2, p3, p4)
if (curProcess == nil) then if(base.eventHandler(self, event, p1, p2, p3, p4))then
return if (curProcess == nil) then
end return
if not (curProcess:isDead()) then end
if not (paused) then if(event=="dynamicValueEvent")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 local w, h = pWindow.getSize()
curProcess:resume(event, p1, p2, p3, p4) local pW, pH = self:getSize()
if(w~=pW)or(h~=pH)then
pWindow.basalt_resize(pW, pH)
if not (curProcess:isDead()) then
resumeProcess(self, "term_resize")
end
end end
if (self:isFocused()) then pWindow.basalt_reposition(self:getAnchorPosition())
local obx, oby = self:getAnchorPosition()
local xCur, yCur = pWindow.getCursorPos() end
if (self.parent ~= nil) then if not (curProcess:isDead()) then
local w,h = self:getSize() if not (paused) then
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then if(event ~= "terminate") then
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) resumeProcess(self, event, p1, p2, p3, p4)
end
if (self:isFocused()) then
local obx, oby = self:getAnchorPosition()
local xCur, yCur = pWindow.getCursorPos()
if (self.parent ~= nil) then
local w,h = self:getSize()
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
end
end
if (event == "terminate") then
resumeProcess(self, event)
self.parent:setCursor(false)
return true
end end
end end
else
if (event == "terminate") and (self:isFocused()) then
self:stop()
end
end
else
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 } }) table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } })
end end
end end
return false
end end
end; end,
draw = function(self) draw = function(self)
if (base.draw(self)) then if (base.draw(self)) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
local xCur, yCur = pWindow.getCursorPos()
local w,h = self:getSize() local w,h = self:getSize()
pWindow.basalt_reposition(obx, oby) pWindow.basalt_reposition(obx, oby)
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
end
pWindow.basalt_update() pWindow.basalt_update()
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
self.parent:setCursor(self:isFocused() and pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
end
end end
self:setVisualChanged(false)
end end
end; end,
onError = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("program_error", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("other_event", self)
end
return self
end,
onDone = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("program_done", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("other_event", self)
end
return self
end,
init = function(self)
if(base.init(self))then
elf.bgColor = self.parent:getTheme("ProgramBG")
end
end,
} }

View File

@@ -21,9 +21,11 @@ return function(name)
local object = { local object = {
init = function(self) init = function(self)
self.bgColor = self.parent:getTheme("ProgressbarBG") if(base.init(self))then
self.fgColor = self.parent:getTheme("ProgressbarText") self.bgColor = self.parent:getTheme("ProgressbarBG")
activeBarColor = self.parent:getTheme("ProgressbarActiveBG") self.fgColor = self.parent:getTheme("ProgressbarText")
activeBarColor = self.parent:getTheme("ProgressbarActiveBG")
end
end, end,
getType = function(self) getType = function(self)
return objectType return objectType
@@ -42,6 +44,7 @@ return function(name)
setDirection = function(self, dir) setDirection = function(self, dir)
direction = dir direction = dir
self:updateDraw()
return self return self
end; end;
@@ -49,11 +52,13 @@ return function(name)
activeBarColor = color or activeBarColor activeBarColor = color or activeBarColor
activeBarSymbol = symbol or activeBarSymbol activeBarSymbol = symbol or activeBarSymbol
activeBarSymbolCol = symbolcolor or activeBarSymbolCol activeBarSymbolCol = symbolcolor or activeBarSymbolCol
self:updateDraw()
return self return self
end; end;
setBackgroundSymbol = function(self, symbol) setBackgroundSymbol = function(self, symbol)
bgBarSymbol = symbol:sub(1, 1) bgBarSymbol = symbol:sub(1, 1)
self:updateDraw()
return self return self
end; end;
@@ -65,6 +70,7 @@ return function(name)
self:progressDoneHandler() self:progressDoneHandler()
end end
end end
self:updateDraw()
return self return self
end; end;
@@ -107,9 +113,8 @@ return function(name)
self.parent:drawTextBox(obx, oby, w / 100 * progress, h, activeBarSymbol) self.parent:drawTextBox(obx, oby, w / 100 * progress, h, activeBarSymbol)
end end
end end
self:setVisualChanged(false)
end end
end; end,
} }

View File

@@ -20,16 +20,6 @@ return function(name)
local align = "left" local align = "left"
local object = { local object = {
init = function(self)
self.bgColor = self.parent:getTheme("MenubarBG")
self.fgColor = self.parent:getTheme("MenubarFG")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
boxSelectedBG = self.parent:getTheme("MenubarBG")
boxSelectedFG = self.parent:getTheme("MenubarText")
end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
@@ -58,6 +48,7 @@ return function(name)
if (#list == 1) then if (#list == 1) then
self:setValue(list[1]) self:setValue(list[1])
end end
self:updateDraw()
return self return self
end; end;
@@ -67,6 +58,7 @@ return function(name)
removeItem = function(self, index) removeItem = function(self, index)
table.remove(list, index) table.remove(list, index)
self:updateDraw()
return self return self
end; end;
@@ -86,6 +78,7 @@ return function(name)
clear = function(self) clear = function(self)
list = {} list = {}
self:setValue({}) self:setValue({})
self:updateDraw()
return self return self
end; end;
@@ -96,16 +89,19 @@ return function(name)
editItem = function(self, index, text, x, y, bgCol, fgCol, ...) editItem = function(self, index, text, x, y, bgCol, fgCol, ...)
table.remove(list, index) table.remove(list, index)
table.insert(list, index, { x = x or 1, y = y or 1, text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } }) table.insert(list, index, { x = x or 1, y = y or 1, text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
self:updateDraw()
return self return self
end; end;
selectItem = function(self, index) selectItem = function(self, index)
self:setValue(list[index] or {}) self:setValue(list[index] or {})
self:updateDraw()
return self return self
end; end;
setActiveSymbol = function(self, sym) setActiveSymbol = function(self, sym)
symbol = sym:sub(1,1) symbol = sym:sub(1,1)
self:updateDraw()
return self return self
end, end,
@@ -115,23 +111,23 @@ return function(name)
boxSelectedBG = boxBG or boxSelectedBG boxSelectedBG = boxBG or boxSelectedBG
boxSelectedFG = boxFG or boxSelectedFG boxSelectedFG = boxFG or boxSelectedFG
selectionColorActive = active~=nil and active or true selectionColorActive = active~=nil and active or true
self:updateDraw()
return self return self
end; end;
mouseHandler = function(self, event, button, x, y) mouseHandler = function(self, button, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) if (#list > 0) then
if ((event == "mouse_click")and(button==1))or(event=="monitor_touch") then local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (#list > 0) then for _, value in pairs(list) do
for _, value in pairs(list) do if (obx + value.x - 1 <= x) and (obx + value.x - 1 + value.text:len() + 1 >= x) and (oby + value.y - 1 == y) then
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)
self:setValue(value) local val = self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", button, x, y)
if (self.parent ~= nil) then if(val==false)then return val end
self.parent:setFocusedObject(self) if(self.parent~=nil)then
end self.parent:setFocusedObject(self)
self:getEventSystem():sendEvent(event, self, event, button, x, y)
self:setVisualChanged()
return true
end end
self:updateDraw()
return true
end end
end end
end end
@@ -139,24 +135,34 @@ return function(name)
end; end;
draw = function(self) draw = function(self)
if (base.draw(self)) then if (self.parent ~= nil) then
if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition()
local obx, oby = self:getAnchorPosition() for _, value in pairs(list) do
for _, value in pairs(list) do if (value == self:getValue()) then
if (value == self:getValue()) then if (align == "left") then
if (align == "left") then self.parent:writeText(value.x + obx - 1, value.y + oby - 1, symbol, boxSelectedBG, boxSelectedFG)
self.parent:writeText(value.x + obx - 1, value.y + oby - 1, symbol, boxSelectedBG, boxSelectedFG) self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, itemSelectedBG, itemSelectedFG)
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, itemSelectedBG, itemSelectedFG)
end
else
self.parent:drawBackgroundBox(value.x + obx - 1, value.y + oby - 1, 1, 1, boxNotSelectedBG or self.bgColor)
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, value.bgCol, value.fgCol)
end end
else
self.parent:drawBackgroundBox(value.x + obx - 1, value.y + oby - 1, 1, 1, boxNotSelectedBG or self.bgColor)
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, value.bgCol, value.fgCol)
end end
end end
self:setVisualChanged(false) return true
end end
end; end,
init = function(self)
self.parent:addEvent("mouse_click", self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("MenubarBG")
self.fgColor = self.parent:getTheme("MenubarFG")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
boxSelectedBG = self.parent:getTheme("MenubarBG")
boxSelectedFG = self.parent:getTheme("MenubarText")
end
end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -18,19 +18,37 @@ return function(name)
local index = 1 local index = 1
local symbolSize = 1 local symbolSize = 1
local function mouseEvent(self, button, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local w,h = self:getSize()
if (barType == "horizontal") then
for _index = 0, w do
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
index = math.min(_index + 1, w - (symbolSize - 1))
self:setValue(maxValue / w * (index))
self:updateDraw()
end
end
end
if (barType == "vertical") then
for _index = 0, h do
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
index = math.min(_index + 1, h - (symbolSize - 1))
self:setValue(maxValue / h * (index))
self:updateDraw()
end
end
end
end
local object = { local object = {
init = function(self)
self.bgColor = self.parent:getTheme("ScrollbarBG")
self.fgColor = self.parent:getTheme("ScrollbarText")
symbolColor = self.parent:getTheme("ScrollbarSymbolColor")
end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
setSymbol = function(self, _symbol) setSymbol = function(self, _symbol)
symbol = _symbol:sub(1, 1) symbol = _symbol:sub(1, 1)
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
@@ -53,6 +71,7 @@ return function(name)
local w,h = self:getSize() local w,h = self:getSize()
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1)) index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index) self:setValue(maxValue / (barType == "vertical" and h or w) * index)
self:updateDraw()
return self return self
end, end,
@@ -68,67 +87,62 @@ return function(name)
elseif (barType == "horizontal") then elseif (barType == "horizontal") then
self:setValue(index - 1 * (maxValue / (w - (symbolSize - 1))) - (maxValue / (w - (symbolSize - 1)))) self:setValue(index - 1 * (maxValue / (w - (symbolSize - 1))) - (maxValue / (w - (symbolSize - 1))))
end end
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
setMaxValue = function(self, val) setMaxValue = function(self, val)
maxValue = val maxValue = val
self:updateDraw()
return self return self
end; end;
setBackgroundSymbol = function(self, _bgSymbol) setBackgroundSymbol = function(self, _bgSymbol)
bgSymbol = string.sub(_bgSymbol, 1, 1) bgSymbol = string.sub(_bgSymbol, 1, 1)
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
setSymbolColor = function(self, col) setSymbolColor = function(self, col)
symbolColor = col symbolColor = col
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
setBarType = function(self, _typ) setBarType = function(self, _typ)
barType = _typ:lower() barType = _typ:lower()
self:updateDraw()
return self return self
end; end;
mouseHandler = function(self, event, button, x, y) mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then if (base.mouseHandler(self, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) mouseEvent(self, button, x, y)
local w,h = self:getSize()
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
if (barType == "horizontal") then
for _index = 0, w do
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
index = math.min(_index + 1, w - (symbolSize - 1))
self:setValue(maxValue / w * (index))
self:setVisualChanged()
end
end
end
if (barType == "vertical") then
for _index = 0, h do
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
index = math.min(_index + 1, h - (symbolSize - 1))
self:setValue(maxValue / h * (index))
self:setVisualChanged()
end
end
end
end
if (event == "mouse_scroll") then
index = index + button
if (index < 1) then
index = 1
end
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
end
return true return true
end end
end; return false
end,
dragHandler = function(self, button, x, y)
if (base.dragHandler(self, button, x, y)) then
mouseEvent(self, button, x, y)
return true
end
return false
end,
scrollHandler = function(self, dir, x, y)
if(base.scrollHandler(self, dir, x, y))then
local w,h = self:getSize()
index = index + dir
if (index < 1) then
index = 1
end
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
self:updateDraw()
end
end,
draw = function(self) draw = function(self)
if (base.draw(self)) then if (base.draw(self)) then
@@ -155,9 +169,19 @@ return function(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end,
init = function(self)
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_drag", self)
self.parent:addEvent("mouse_scroll", self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("ScrollbarBG")
self.fgColor = self.parent:getTheme("ScrollbarText")
symbolColor = self.parent:getTheme("ScrollbarSymbolColor")
end
end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -1,4 +1,5 @@
local Object = require("Object") local Object = require("Object")
local log = require("basaltLogs")
local xmlValue = require("utils").getValueFromXML local xmlValue = require("utils").getValueFromXML
return function(name) return function(name)
@@ -17,19 +18,37 @@ return function(name)
local index = 1 local index = 1
local symbolSize = 1 local symbolSize = 1
local function mouseEvent(self, button, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local w,h = self:getSize()
if (barType == "horizontal") then
for _index = 0, w do
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
index = math.min(_index + 1, w - (symbolSize - 1))
self:setValue(maxValue / w * (index))
self:updateDraw()
end
end
end
if (barType == "vertical") then
for _index = 0, h do
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
index = math.min(_index + 1, h - (symbolSize - 1))
self:setValue(maxValue / h * (index))
self:updateDraw()
end
end
end
end
local object = { local object = {
init = function(self)
self.bgColor = self.parent:getTheme("SliderBG")
self.fgColor = self.parent:getTheme("SliderText")
symbolColor = self.parent:getTheme("SliderSymbolColor")
end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
setSymbol = function(self, _symbol) setSymbol = function(self, _symbol)
symbol = _symbol:sub(1, 1) symbol = _symbol:sub(1, 1)
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
@@ -52,6 +71,7 @@ return function(name)
local w,h = self:getSize() local w,h = self:getSize()
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1)) index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index) self:setValue(maxValue / (barType == "vertical" and h or w) * index)
self:updateDraw()
return self return self
end, end,
@@ -66,7 +86,7 @@ return function(name)
elseif (barType == "horizontal") then elseif (barType == "horizontal") then
self:setValue(index - 1 * (maxValue / (w - (symbolSize - 1))) - (maxValue / (w - (symbolSize - 1)))) self:setValue(index - 1 * (maxValue / (w - (symbolSize - 1))) - (maxValue / (w - (symbolSize - 1))))
end end
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
@@ -77,56 +97,52 @@ return function(name)
setBackgroundSymbol = function(self, _bgSymbol) setBackgroundSymbol = function(self, _bgSymbol)
bgSymbol = string.sub(_bgSymbol, 1, 1) bgSymbol = string.sub(_bgSymbol, 1, 1)
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
setSymbolColor = function(self, col) setSymbolColor = function(self, col)
symbolColor = col symbolColor = col
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
setBarType = function(self, _typ) setBarType = function(self, _typ)
barType = _typ:lower() barType = _typ:lower()
self:updateDraw()
return self return self
end; end;
mouseHandler = function(self, event, button, x, y) mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then if (base.mouseHandler(self, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) mouseEvent(self, button, x, y)
local w,h = self:getSize()
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
if (barType == "horizontal") then
for _index = 0, w do
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
index = math.min(_index + 1, w - (symbolSize - 1))
self:setValue(maxValue / w * (index))
self:setVisualChanged()
end
end
end
if (barType == "vertical") then
for _index = 0, h do
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
index = math.min(_index + 1, h - (symbolSize - 1))
self:setValue(maxValue / h * (index))
self:setVisualChanged()
end
end
end
end
if (event == "mouse_scroll") then
index = index + button
if (index < 1) then
index = 1
end
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
end
return true return true
end end
end; return false
end,
dragHandler = function(self, button, x, y)
if (base.dragHandler(self, button, x, y)) then
mouseEvent(self, button, x, y)
return true
end
return false
end,
scrollHandler = function(self, dir, x, y)
if(base.scrollHandler(self, dir, x, y))then
local w,h = self:getSize()
index = index + dir
if (index < 1) then
index = 1
end
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
self:updateDraw()
return true
end
return false
end,
draw = function(self) draw = function(self)
if (base.draw(self)) then if (base.draw(self)) then
@@ -141,7 +157,6 @@ return function(name)
if (barType == "vertical") then if (barType == "vertical") then
for n = 0, h - 1 do for n = 0, h - 1 do
if (index == n + 1) then if (index == n + 1) then
for curIndexOffset = 0, math.min(symbolSize - 1, h) do for curIndexOffset = 0, math.min(symbolSize - 1, h) do
self.parent:writeText(obx, oby + n + curIndexOffset, symbol, symbolColor, symbolColor) self.parent:writeText(obx, oby + n + curIndexOffset, symbol, symbolColor, symbolColor)
@@ -154,9 +169,19 @@ return function(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end,
init = function(self)
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_drag", self)
self.parent:addEvent("mouse_scroll", self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("SliderBG")
self.fgColor = self.parent:getTheme("SliderText")
symbolColor = self.parent:getTheme("SliderSymbolColor")
end
end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -17,32 +17,25 @@ return function(name)
local activeBG = colors.green local activeBG = colors.green
local object = { local object = {
init = function(self)
self.bgColor = self.parent:getTheme("SwitchBG")
self.fgColor = self.parent:getTheme("SwitchText")
bgSymbol = self.parent:getTheme("SwitchBGSymbol")
inactiveBG = self.parent:getTheme("SwitchInactive")
activeBG = self.parent:getTheme("SwitchActive")
end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
setSymbolColor = function(self, symbolColor) setSymbolColor = function(self, symbolColor)
bgSymbol = symbolColor bgSymbol = symbolColor
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
setActiveBackground = function(self, bgcol) setActiveBackground = function(self, bgcol)
activeBG = bgcol activeBG = bgcol
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
setInactiveBackground = function(self, bgcol) setInactiveBackground = function(self, bgcol)
inactiveBG = bgcol inactiveBG = bgcol
self:setVisualChanged() self:updateDraw()
return self return self
end; end;
@@ -54,12 +47,11 @@ return function(name)
end, end,
mouseHandler = function(self, event, button, x, y) mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then if (base.mouseHandler(self, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if ((event == "mouse_click") and (button == 1))or(event=="monitor_touch") then self:setValue(not self:getValue())
self:setValue(not self:getValue()) self:updateDraw()
end
return true return true
end end
end; end;
@@ -78,9 +70,19 @@ return function(name)
self.parent:drawBackgroundBox(obx+1, oby, 1, h, inactiveBG) self.parent:drawBackgroundBox(obx+1, oby, 1, h, inactiveBG)
end end
end end
self:setVisualChanged(false)
end end
end; end,
init = function(self)
self.parent:addEvent("mouse_click", self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("SwitchBG")
self.fgColor = self.parent:getTheme("SwitchText")
bgSymbol = self.parent:getTheme("SwitchBGSymbol")
inactiveBG = self.parent:getTheme("SwitchInactive")
activeBG = self.parent:getTheme("SwitchActive")
end
end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -1,7 +1,10 @@
local Object = require("Object") local Object = require("Object")
local tHex = require("tHex") local tHex = require("tHex")
local log = require("basaltLogs")
local xmlValue = require("utils").getValueFromXML local xmlValue = require("utils").getValueFromXML
local rep = string.rep
return function(name) return function(name)
local base = Object(name) local base = Object(name)
local objectType = "Textfield" local objectType = "Textfield"
@@ -65,6 +68,7 @@ return function(name)
end end
fgLines[l] = fgLine fgLines[l] = fgLine
bgLines[l] = bgLine bgLines[l] = bgLine
self:updateDraw()
end end
local function updateAllColors(self) local function updateAllColors(self)
@@ -74,10 +78,6 @@ return function(name)
end end
local object = { local object = {
init = function(self)
self.bgColor = self.parent:getTheme("TextfieldBG")
self.fgColor = self.parent:getTheme("TextfieldText")
end,
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
@@ -144,6 +144,8 @@ return function(name)
editLine = function(self, index, text) editLine = function(self, index, text)
lines[index] = text or lines[index] lines[index] = text or lines[index]
updateColors(self, index)
self:updateDraw()
return self return self
end; end;
@@ -152,6 +154,7 @@ return function(name)
bgLines = {""} bgLines = {""}
fgLines = {""} fgLines = {""}
hIndex, wIndex, textX, textY = 1, 1, 1, 1 hIndex, wIndex, textX, textY = 1, 1, 1, 1
self:updateDraw()
return self return self
end, end,
@@ -161,18 +164,21 @@ return function(name)
lines[1] = text lines[1] = text
bgLines[1] = tHex[self.bgColor]:rep(text:len()) bgLines[1] = tHex[self.bgColor]:rep(text:len())
fgLines[1] = tHex[self.fgColor]:rep(text:len()) fgLines[1] = tHex[self.fgColor]:rep(text:len())
updateColors(self, 1)
return self return self
end end
if (index ~= nil) then if (index ~= nil) then
table.insert(lines, index, text) table.insert(lines, index, text)
table.insert(bgLines, index, tHex[self.bgColor]:rep(text:len())) table.insert(bgLines, index, tHex[self.bgColor]:rep(text:len()))
table.insert(fgLines, tHex[self.fgColor]:rep(text:len())) table.insert(fgLines, index, tHex[self.fgColor]:rep(text:len()))
else else
table.insert(lines, text) table.insert(lines, text)
table.insert(bgLines, tHex[self.bgColor]:rep(text:len())) table.insert(bgLines, tHex[self.bgColor]:rep(text:len()))
table.insert(fgLines, tHex[self.fgColor]:rep(text:len())) table.insert(fgLines, tHex[self.fgColor]:rep(text:len()))
end end
end end
updateColors(self, index or #lines)
self:updateDraw()
return self return self
end; end;
@@ -183,11 +189,13 @@ return function(name)
for k,v in pairs(tab)do for k,v in pairs(tab)do
table.insert(keyWords[color], v) table.insert(keyWords[color], v)
end end
self:updateDraw()
return self return self
end; end;
addRule = function(self, rule, fg, bg) addRule = function(self, rule, fg, bg)
table.insert(rules, {rule, fg, bg}) table.insert(rules, {rule, fg, bg})
self:updateDraw()
return self return self
end; end;
@@ -198,6 +206,7 @@ return function(name)
rules[k][3] = bg rules[k][3] = bg
end end
end end
self:updateDraw()
return self return self
end; end;
@@ -207,11 +216,13 @@ return function(name)
table.remove(rules, k) table.remove(rules, k)
end end
end end
self:updateDraw()
return self return self
end; end;
setKeywords = function(self, color, tab) setKeywords = function(self, color, tab)
keyWords[color] = tab keyWords[color] = tab
self:updateDraw()
return self return self
end; end;
@@ -220,6 +231,7 @@ return function(name)
if (#lines <= 0) then if (#lines <= 0) then
table.insert(lines, "") table.insert(lines, "")
end end
self:updateDraw()
return self return self
end; end;
@@ -244,11 +256,10 @@ return function(name)
end end
end; end;
keyHandler = function(self, event, key) keyHandler = function(self, key)
if (base.keyHandler(self, event, key)) then if (base.keyHandler(self, event, key)) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
local w,h = self:getSize() local w,h = self:getSize()
if (event == "key") then
if (key == keys.backspace) then if (key == keys.backspace) then
-- on backspace -- on backspace
if (lines[textY] == "") then if (lines[textY] == "") then
@@ -361,7 +372,14 @@ return function(name)
if (textX > lines[textY]:len() + 1) then if (textX > lines[textY]:len() + 1) then
textX = lines[textY]:len() + 1 textX = lines[textY]:len() + 1
end end
if (wIndex > 1) then
if (textX < wIndex) then
wIndex = textX - w + 1
if (wIndex < 1) then
wIndex = 1
end
end
end
if (textY >= hIndex + h) then if (textY >= hIndex + h) then
hIndex = hIndex + 1 hIndex = hIndex + 1
end end
@@ -411,19 +429,6 @@ return function(name)
wIndex = 1 wIndex = 1
end end
end end
end
if (event == "char") then
lines[textY] = lines[textY]:sub(1, textX - 1) .. key .. lines[textY]:sub(textX, lines[textY]:len())
fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. tHex[self.fgColor] .. fgLines[textY]:sub(textX, fgLines[textY]:len())
bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. tHex[self.bgColor] .. bgLines[textY]:sub(textX, bgLines[textY]:len())
textX = textX + 1
if (textX >= w + wIndex) then
wIndex = wIndex + 1
end
updateColors(self)
self:setValue("")
end
local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1) local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1)
if (cursorX > self.x + w - 1) then if (cursorX > self.x + w - 1) then
@@ -434,17 +439,46 @@ return function(name)
cursorX = 0 cursorX = 0
end end
self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor) self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor)
self:updateDraw()
return true return true
end end
end; end,
mouseHandler = function(self, event, button, x, y) charHandler = function(self, char)
if (base.mouseHandler(self, event, button, x, y)) then if(base.charHandler(self, char))then
local obx, oby = self:getAnchorPosition()
local w,h = self:getSize()
lines[textY] = lines[textY]:sub(1, textX - 1) .. char .. lines[textY]:sub(textX, lines[textY]:len())
fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. tHex[self.fgColor] .. fgLines[textY]:sub(textX, fgLines[textY]:len())
bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. tHex[self.bgColor] .. bgLines[textY]:sub(textX, bgLines[textY]:len())
textX = textX + 1
if (textX >= w + wIndex) then
wIndex = wIndex + 1
end
updateColors(self)
self:setValue("")
local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1)
if (cursorX > self.x + w - 1) then
cursorX = self.x + w - 1
end
local cursorY = (textY - hIndex < h and textY - hIndex or textY - hIndex - 1)
if (cursorX < 1) then
cursorX = 0
end
self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor)
self:updateDraw()
return true
end
end,
dragHandler = function(self, button, x, y)
if (base.dragHandler(self, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition() local anchx, anchy = self:getAnchorPosition()
local w,h = self:getSize() local w,h = self:getSize()
if (event == "mouse_click")or(event=="monitor_touch") then if (lines[y - oby + hIndex] ~= nil) then
if (lines[y - oby + hIndex] ~= nil) then if(anchx+w > anchx + x - (obx+1)+ wIndex)and(anchx < anchx + x - obx+ wIndex)then
textX = x - obx + wIndex textX = x - obx + wIndex
textY = y - oby + hIndex textY = y - oby + hIndex
if (textX > lines[textY]:len()) then if (textX > lines[textY]:len()) then
@@ -459,61 +493,89 @@ return function(name)
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor) self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
end end
self:updateDraw()
end end
end end
if (event == "mouse_drag") then
if (lines[y - oby + hIndex] ~= nil) then
textX = x - obx + wIndex
textY = y - oby + hIndex
if (textX > lines[textY]:len()) then
textX = lines[textY]:len() + 1
end
if (textX < wIndex) then
wIndex = textX - 1
if (wIndex < 1) then
wIndex = 1
end
end
if (self.parent ~= nil) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
end
end
end
if (event == "mouse_scroll") then
hIndex = hIndex + button
if (hIndex > #lines - (h - 1)) then
hIndex = #lines - (h - 1)
end
if (hIndex < 1) then
hIndex = 1
end
if (self.parent ~= nil) then
if (obx + textX - wIndex >= obx and obx + textX - wIndex < obx + w) and (oby + textY - hIndex >= oby and oby + textY - hIndex < oby + h) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
else
self.parent:setCursor(false)
end
end
end
self:setVisualChanged()
return true return true
end end
end; end,
scrollHandler = function(self, dir, x, y)
if (base.scrollHandler(self, dir, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition()
local w,h = self:getSize()
hIndex = hIndex + dir
if (hIndex > #lines - (h - 1)) then
hIndex = #lines - (h - 1)
end
if (hIndex < 1) then
hIndex = 1
end
if (self.parent ~= nil) then
if (obx + textX - wIndex >= obx and obx + textX - wIndex < obx + w) and (oby + textY - hIndex >= oby and oby + textY - hIndex < oby + h) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
else
self.parent:setCursor(false)
end
end
self:updateDraw()
return true
end
end,
mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition()
if (lines[y - oby + hIndex] ~= nil) then
textX = x - obx + wIndex
textY = y - oby + hIndex
if (textX > lines[textY]:len()) then
textX = lines[textY]:len() + 1
end
if (textX < wIndex) then
wIndex = textX - 1
if (wIndex < 1) then
wIndex = 1
end
end
end
if (self.parent ~= nil) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
end
return true
end
end,
eventHandler = function(self, event, paste, p2, p3, p4)
if(base.eventHandler(self, event, paste, p2, p3, p4))then
if(event=="paste")then
if(self:isFocused())then
local w, h = self:getSize()
lines[textY] = lines[textY]:sub(1, textX - 1) .. paste .. lines[textY]:sub(textX, lines[textY]:len())
fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. tHex[self.fgColor]:rep(paste:len()) .. fgLines[textY]:sub(textX, fgLines[textY]:len())
bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. tHex[self.bgColor]:rep(paste:len()) .. bgLines[textY]:sub(textX, bgLines[textY]:len())
textX = textX + paste:len()
if (textX >= w + wIndex) then
wIndex = (textX+1)-w
end
local anchx, anchy = self:getAnchorPosition()
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
updateColors(self)
self:updateDraw()
end
end
end
end,
draw = function(self) draw = function(self)
if (base.draw(self)) then if (base.draw(self)) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
local w,h = self:getSize() local w,h = self:getSize()
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
end
if(self.fgColor~=false)then
self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor)
end
for n = 1, h do for n = 1, h do
local text = "" local text = ""
local bg = "" local bg = ""
@@ -530,17 +592,33 @@ return function(name)
if (space < 0) then if (space < 0) then
space = 0 space = 0
end end
text = text .. string.rep(" ", space) text = text .. rep(self.bgSymbol, space)
bg = bg .. string.rep(tHex[self.bgColor], space) bg = bg .. rep(tHex[self.bgColor], space)
fg = fg .. string.rep(tHex[self.fgColor], space) fg = fg .. rep(tHex[self.fgColor], space)
self.parent:setText(obx, oby + n - 1, text) self.parent:setText(obx, oby + n - 1, text)
self.parent:setBG(obx, oby + n - 1, bg) self.parent:setBG(obx, oby + n - 1, bg)
self.parent:setFG(obx, oby + n - 1, fg) self.parent:setFG(obx, oby + n - 1, fg)
end end
if(self:isFocused())then
local anchx, anchy = self:getAnchorPosition()
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
end
end end
self:setVisualChanged(false)
end end
end; end,
init = function(self)
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_scroll", self)
self.parent:addEvent("mouse_drag", self)
self.parent:addEvent("key", self)
self.parent:addEvent("char", self)
self.parent:addEvent("other_event", self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("TextfieldBG")
self.fgColor = self.parent:getTheme("TextfieldText")
end
end,
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -59,6 +59,7 @@ return function(name)
error("Thread Error Occurred - " .. result) error("Thread Error Occurred - " .. result)
end end
end end
self.parent:addEvent("other_event", self)
return self return self
end; end;
@@ -71,6 +72,7 @@ return function(name)
stop = function(self, f) stop = function(self, f)
isActive = false isActive = false
self.parent:removeEvent("other_event", self)
return self return self
end; end;

View File

@@ -74,6 +74,7 @@ return function(name)
repeats = savedRepeats repeats = savedRepeats
timerObj = os.startTimer(timer) timerObj = os.startTimer(timer)
timerIsActive = true timerIsActive = true
self.parent:addEvent("other_event", self)
return self return self
end; end;
@@ -86,6 +87,7 @@ return function(name)
os.cancelTimer(timerObj) os.cancelTimer(timerObj)
end end
timerIsActive = false timerIsActive = false
self.parent:removeEvent("other_event", self)
return self return self
end; end;

View File

@@ -31,7 +31,7 @@ return { -- The default main theme for basalt!
ScrollbarBG = colors.lightGray, ScrollbarBG = colors.lightGray,
ScrollbarText = colors.gray, ScrollbarText = colors.gray,
ScrollbarSymbolColor = colors.black, ScrollbarSymbolColor = colors.black,
SliderBG = colors.lightGray, SliderBG = false,
SliderText = colors.gray, SliderText = colors.gray,
SliderSymbolColor = colors.black, SliderSymbolColor = colors.black,
SwitchBG = colors.lightGray, SwitchBG = colors.lightGray,
@@ -39,5 +39,7 @@ return { -- The default main theme for basalt!
SwitchBGSymbol = colors.black, SwitchBGSymbol = colors.black,
SwitchInactive = colors.red, SwitchInactive = colors.red,
SwitchActive = colors.green, SwitchActive = colors.green,
LabelBG = false,
LabelText = colors.black
} }

23
CHANGELOG.md Normal file
View File

@@ -0,0 +1,23 @@
# Changelog
#### v. 1.5:
- You can now mirror a frame to a monitor by using :setMirror(side)
- with dynamic values you are able to use percentage values and even functions which get called everytime we need the size of that object
- XML got added to make design and logic seperate (you don't have to) - you are now able to use xml to create your UI design.
- Animations are now more advanced and provide many features to do cool stuff. They are also very easy to use now!
- Also some smaller bugfixes
- new bugs to explore
- fixed monitor support
- added :setIndex() for scrollbars
- added dynamic value system (not fully done)
- reworked the filesystem, now we use require instead of loadfile
- from now on the single file will be complied on the end users computer
- prepared everything for an advanced installer
#### v. 1:
- created Basalt
- added many objects (buttons, checkbox, labels, programs, switch, radio, lists, dropdowns, input, textfields, images, menubar, animations, threads, timers, progressbar, scrollbar, slider, pane)
- added bigfont
- added blittle
- added coroutine management
- added advanced event system

View File

@@ -1,39 +1,15 @@
# Basalt - A UI Framework for CC:Tweaked # Basalt - A UI Framework for CC:Tweaked
![GitHub Repo stars](https://img.shields.io/github/stars/Pyroxenium/Basalt?style=for-the-badge)
![GitHub commit activity](https://img.shields.io/github/commit-activity/y/Pyroxenium/Basalt?style=for-the-badge)
![GitHub Repo stars](https://img.shields.io/badge/Made%20for-CC%3AT-orange?style=for-the-badge)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/Pyroxenium/Basalt?style=for-the-badge)
[![Discord](https://img.shields.io/discord/976905222251233320?label=Discord&style=for-the-badge)](https://discord.gg/yNNnmBVBpE)
Basalt is still under developement and you may find bugs! Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (Also know as "ComputerCraft: Tweaked") - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's [wiki](https://tweaked.cc/) or [download](https://www.curseforge.com/minecraft/mc-mods/cc-tweaked).<br>
**Note:** Basalt is still under developement and you may find bugs!
## Information Check out the [wiki](https://basalt.madefor.cc/) for more information.<br>
If you have questions, feel free to join the discord server: [https://discord.gg/yNNnmBVBpE](https://discord.gg/yNNnmBVBpE).
Check out the [wiki](https://basalt.madefor.cc/) for information<br>
If you have questions, feel free to join the discord server: [https://discord.gg/yM7kndJdJJ](https://discord.gg/yM7kndJdJJ)
## Changelogs
From now on we will add changes:
#### Version 4:
- You can now mirror a frame to a monitor by using :setMirror(side)
- with dynamic values you are able to use percentage values and even functions which get called everytime we need the size of that object
- XML got added to make design and logic seperate (you don't have to) - you are now able to use xml to create your UI design.
- Animations are now more advanced and provide many features to do cool stuff. They are also very easy to use now!
- Also some smaller bugfixes
- new bugs to explore
#### Version 3:
- fixed monitor support
- added :setIndex() for scrollbars
- added dynamic value system (not fully done)
#### Version 2:
Note: You won't get any changes for now, so don't redownload the project! (:
- reworked the filesystem, now we use require instead of loadfile
- from now on the single file will be complied on the end users computer
- prepared everything for an advanced installer
#### Version 1:
- created Basalt
- added many objects (buttons, checkbox, labels, programs, switch, radio, lists, dropdowns, input, textfields, images, menubar, animations, threads, timers, progressbar, scrollbar, slider, pane)
- added bigfont
- added blittle
- added coroutine management
- added advanced event system
## Demo
<img src="https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/basaltPreview2.gif" width="300">

View File

@@ -464,7 +464,8 @@ outputFile:write("project['default'] = {}")
local function writeNewPackage(subdir, name, path) local function writeNewPackage(subdir, name, path)
if not(fs.isDir(path))then if not(fs.isDir(path))then
outputFile:write("project['"..subdir.."']['"..name.."'] = ".."function(...)") outputFile:write("project['"..subdir.."']['"..name.."'] = ".."function(...)")
local fileData = io.open(path, "r"):read("*all") local file = io.open(path, "r")
local fileData = file:read("*all")
if(minifyProject)then if(minifyProject)then
local success, data = minify(fileData) local success, data = minify(fileData)
if(success)then if(success)then
@@ -475,6 +476,7 @@ local function writeNewPackage(subdir, name, path)
else else
outputFile:write(fileData:gsub("]]", "] ]"):gsub("]]", "] ]").."\n") outputFile:write(fileData:gsub("]]", "] ]"):gsub("]]", "] ]").."\n")
end end
file:close()
outputFile:write("end; \n") outputFile:write("end; \n")
end end
end end
@@ -489,16 +491,17 @@ for _,v in pairs(projectFiles)do
end end
end end
local main = io.open(fs.combine(projectPath, mainFile), "r"):read("*all") local main = io.open(fs.combine(projectPath, mainFile), "r")
local mainData = main:read("*all")
if(minifyProject)then if(minifyProject)then
local success,data = minify(main) local success,data = minify(mainData)
if(success)then if(success)then
outputFile:write(data) outputFile:write(data)
else else
print("Error: Can't minify "..fs.combine(projectPath, mainFile)) print("Error: Can't minify "..fs.combine(projectPath, mainFile).." "..data)
end end
else else
outputFile:write(main) outputFile:write(mainData)
end end
main:close()
outputFile:close() outputFile:close()

View File

@@ -1,24 +1,19 @@
# Welcome to The Basalt Wiki! # Welcome to The Basalt Wiki!
*Note: The Basalt Wiki is a work in progress. Please treat Wiki errors the same as bugs and report them accordingly.* *Note: The Basalt Wiki is a work in progress. Please treat wiki errors the same as bugs and report them accordingly.*
Here you can find information about how to use Basalt as well as examples of functional Basalt code. The aim of Basalt is to improve user interaction through visual display. Here you can find information about how to use Basalt as well as examples of functional Basalt code. The aim of Basalt is to improve user interaction through visual display.
## About Basalt ## About Basalt
Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (Also know as "ComputerCraft: Tweaked") - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's [wiki](https://tweaked.cc/) or [download](https://www.curseforge.com/minecraft/mc-mods/cc-tweaked). Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (Also know as "ComputerCraft: Tweaked") - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's [wiki](https://tweaked.cc/) or [download](https://modrinth.com/mod/cc-tweaked).
## Quick Demo ## Quick Demo
<img src="https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/basaltPreview2.gif" width="600">
![Basalt Demo GIF](https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/basaltPreview2.gif)
## Questions & Bugs ## Questions & Bugs
Obviously NyoriE has implemented some easter eggs, *some people* call them "bugs". If you happen to discover one of these just make a new <a href="https://github.com/Pyroxenium/Basalt/issues">issue</a>. Obviously NyoriE has implemented some easter eggs, *some people* call them "bugs". If you happen to discover one of these just make a new [Github Issue](https://github.com/Pyroxenium/Basalt/issues)
Additionally, if you have questions about Basalt or how to make use of it, feel free to create a new discussion on <a href="https://github.com/Pyroxenium/Basalt/discussions">Basalt's Discussion Board</a>, or ask in our [discord](https://discord.gg/yNNnmBVBpE). Additionally, if you have questions about Basalt or how to make use of it, feel free to create a new discussion on [Basalt's Discussion Board (Github)](https://github.com/Pyroxenium/Basalt/discussions), or ask in our [discord](https://discord.gg/yNNnmBVBpE).
---
Feel free to join our [discord](https://discord.gg/yNNnmBVBpE)!
<br><br>

View File

@@ -1 +1,3 @@
Thanks for checking out our wiki, join our discord for more help: [discord.gg/yM7kndJdJJ](discord.gg/yM7kndJdJJ) ---
Thanks for checking out our wiki, join our discord for more help: [discord.gg/yM7kndJdJJ](discord.gg/yNNnmBVBpE)

View File

@@ -1,4 +1,4 @@
- Getting Started - Getting Started
- [Home](Home.md) - [Home](Home)
- [Quick Start](home/Quick-Start.md) - [Quick Start](home/Quick-Start)
- [Installer](home/installer) - [Installer](home/installer)

View File

@@ -1,35 +1,32 @@
- About - About
- [Home](Home.md) - [Home](Home.md)
- [Quick Start](home/Quick-Start.md) - [Quick Start](home/Quick-Start.md)
- [Installer](home/installer) - [Installer](home/installer)
- Objects - Objects
- [Basalt](objects/Basalt) - [Basalt](objects/Basalt.md)
- [Object](objects/Object) - [Object](objects/Object.md)
- [Button](objects/Button) - [Button](objects/Button.md)
- [Checkbox](objects/Checkbox) - [Checkbox](objects/Checkbox.md)
- [Dropdown](objects/Dropdown) - [Dropdown](objects/Dropdown.md)
- [Frame](objects/Frame) - [Frame](objects/Frame.md)
- [Image](objects/Image) - [Image](objects/Image.md)
- [Input](objects/Input) - [Input](objects/Input.md)
- [Label](objects/Label) - [Label](objects/Label.md)
- [List](objects/List) - [List](objects/List.md)
- [Menubar](objects/Menubar) - [Menubar](objects/Menubar.md)
- [Pane](objects/Pane) - [Pane](objects/Pane.md)
- [Program](objects/Program) - [Program](objects/Program.md)
- [Progressbar](objects/Progressbar) - [Progressbar](objects/Progressbar.md)
- [Radio](objects/Radio) - [Radio](objects/Radio.md)
- [Scrollbar](objects/Scrollbar) - [Scrollbar](objects/Scrollbar.md)
- [Slider](objects/Slider) - [Slider](objects/Slider.md)
- [Textfield](objects/Textfield) - [Textfield](objects/Textfield.md)
- [Animation](objects/Animation.md) - [Animation](objects/Animation.md)
- [Thread](objects/Thread) - [Thread](objects/Thread.md)
- [Timer](objects/Timer) - [Timer](objects/Timer.md)
- Events
- [Mouse Events](events/mouseEvents.md)
- [Keyboard Events](events/keyEvents.md)
- [Other Events](events/otherEvents.md)
- Tips & Tricks - Tips & Tricks
- [Component Logic](tips/logic) - [Your Logic](tips/logic.md)
- [Changing Button Color](tips/buttons) - [Button coloring](tips/buttonColoring.md)
- [Advanced usage of Events](tips/events.md) - [Designing/Animating](tips/design.md)
- [Example Designs](tips/design.md) - [Dynamic Values](tips/dynamicvalues.md)
- [XML](tips/xml.md)

View File

@@ -1,39 +0,0 @@
Here we will talk about keyboard events and how you can manipulate them. There are 2 possible key events you can add to almost every visual object.
# onKey
`onKey(self, event, key)`<br>
The computercraft event which triggers this method is `key`.
Any visual object can register onKey events.
Here is a example on how to add a onKey event to your frame:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local subFrame = mainFrame:addFrame("subFrame"):setPosition(3,3):setSize(18,6):setBar("Sub Frame",colors.black):showBar():show()
function openSubFrame()
subFrame:show()
end
mainFrame:onKey(openSubFrame)
```
# onKeyUp
`onKeyUp(self, event, key)`<br>
The computercraft event which triggers this method is `key_up`.
Any visual object can register onKeyUp events.
Here is a example on how to add a onKeyUp event to your frame:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local subFrame = mainFrame:addFrame("subFrame"):setPosition(3,3):setSize(18,6):setBar("Sub Frame",colors.black):showBar():show()
function openSubFrame()
subFrame:show()
end
mainFrame:onKeyUp(openSubFrame)
```

View File

@@ -1,82 +0,0 @@
Here we will talk about mouse events and how you can use them. You can register custom mouse events to all visual objects
# onClick
`onClick(self, event, button, x, y)`<br>
The computercraft event which triggers this method is `mouse_click` and `monitor_touch`.
Any visual object can register onClick events.
Here is a example on how to add a onClick event to your button:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnClick()
basalt.debug("Button got clicked!")
end
button:onClick(buttonOnClick())
```
# onClickUp
`onClickUp(self, event, button, x, y)`<br>
The computercraft event which triggers this method is `mouse_up`.
Any visual object can register onClickUp events.
Here is a example on how to add a onClickUp event to your button:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnClick(self, button, x, y)
basalt.debug("Button got clicked!")
end
button:onClick(buttonOnClick)
function buttonOnRelease(self, button, x, y)
basalt.debug("Button got released!")
end
button:onClickUp(buttonOnRelease)
```
# onScroll
`onScroll(self, event, direction, x, y)`<br>
The computercraft event which triggers this method is `mouse_scroll`.
Any visual object can register onScroll events.
Here is a example on how to add a onScroll event to your button:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnScroll(self, direction, x, y)
basalt.debug("Someone scrolls on me!")
end
button:onScroll(buttonOnScroll)
```
# onDrag
`onDrag(self, event, button, x, y)`<br>
The computercraft event which triggers this method is `mouse_drag`.
Any visual object can register onDrag events.
Here is a example on how to add a onDrag event to your button:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnDrag(self, button, x, y)
basalt.debug("Someone drags me (i know i wont reposition myself)!")
end
button:onDrag(buttonOnDrag)
```

View File

@@ -1,79 +0,0 @@
There are also other useful events you can listen to:
# onChange
`onChange(self)`<br>
This is a custom event which gets triggered as soon as the function :setValue() is called. This function is also called by basalt, for example if you change the input, textfield or checkbox (or all the different types of lists) objects.
Here is a example on how to add a onChange event to your input, and also another example for your checkbox:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local aInput = mainFrame:addInput("specialInput"):setPosition(3,3):show()
local aCheckbox = mainFrame:addCheckbox("specialCheckbox"):setPosition(3,5):show()
local function checkInput(input)
if(string.lower(input:getValue())=="hello")then
basalt.debug("Hello back!")
end
end
local function checkCheckbox(checkbox)
if(checkbox:getValue()==true)then -- or if(checkbox:getValue())then
basalt.debug("Checkbox is active, let us do something!")
end
end
aInput:onChange(checkInput)
aCheckbox:onChange(checkCheckbox)
```
# onResize
`onResize(self)`<br>
This is a custom event which gets triggered as soon as the parent frame gets resized.
Here is a example on how to add a onResize event to your button:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local aButton = mainFrame:addButton("myButton"):setPosition(3,3):show()
local function onButtonResize(button)
local width = mainFrame:getWidth()
button:setSize()
end
aButton:onResize(onButtonResize)
```
# onLoseFocus
`onLoseFocus(self)`<br>
This event gets triggered as soon as the object loses its focus.
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("exampleButton"):setPosition(3,3):onLoseFocus(
function(self)
basalt.debug("Please come back... :(")
end
):show()
```
# onGetFocus
`onGetFocus(self)`<br>
This event gets triggered as soon as the object is the currently focused object.
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("exampleButton"):setPosition(3,3):onGetFocus(
function(self)
basalt.debug("Welcome back!")
end
):show()
```

View File

@@ -1,18 +1,21 @@
## HowTo Use # Quick Start
To load the framework into your project, make use of the following code on top of your code. ## How to use
To load Basalt into your project, make use of the following code on top of your code.
```lua ```lua
local basalt = require("Basalt") local basalt = require("basalt")
``` ```
It does not matter if you have installed the single file version or the full folder project. <br> It does not matter if you have installed the single file version or the full folder project.
Both versions can be loaded by using `require("Basalt")`, you dont need to add `.lua`. Both versions can be loaded by using `require("Basalt")`, you dont need to add `.lua`.
## Download ## Download
### Download the folder version ### Download the folder version
This version is for people who'd like to work with Basalt, change something in Basalt or checkout the project.<br> This version is for people who'd like to work with Basalt, change something in Basalt, or checkout the project.
But you are also able to just use it to create your own UI.<br> But you are also able to just use it to create your own UI.
To install the full project to your CC:Tweaked Computer, use the following command on your CC:Tweaked shell: To install the full project to your CC:Tweaked Computer, use the following command on your CC:Tweaked shell:
@@ -30,7 +33,7 @@ This will download the project as a single file called "basalt.lua". You are imm
### Basalt Package Manager ### Basalt Package Manager
The Basalt Package Manager is still in alpha!<br><br> **The Basalt Package Manager is still in alpha!**
The Basalt Package Manager is a visual installer, you are able to change some settings, also to choose which objects are necessary for your projects and which are not. The Basalt Package Manager is a visual installer, you are able to change some settings, also to choose which objects are necessary for your projects and which are not.
To install the BPM (Basalt Package Manager) use the following command on your CC:Tweaked shell: To install the BPM (Basalt Package Manager) use the following command on your CC:Tweaked shell:
@@ -43,11 +46,10 @@ The true keyword in the end is optional and would simply start BPM immediately.
Here is a fully functioning example of Basalt code Here is a fully functioning example of Basalt code
```lua ```lua
local basalt = require("Basalt") --> Load the Basalt framework local basalt = require("basalt") --> Load the Basalt framework
--> Create the first frame. Please note that Basalt needs at least one active "non-parent" frame to properly supply events --> Create the first frame. Please note that Basalt needs at least one active "non-parent" frame to properly supply events
--> When Basalt#createFrame makes use of unique identifiers (commonly referred to as UIDs), meaning that the supplied value must be UNIQUE --> When Basalt#createFrame makes use of unique identifiers (commonly referred to as UIDs), meaning that the supplied value must be UNIQUE
--> If the supplied UID is ambiguous, Basalt#createFrame returns a nil value
local mainFrame = basalt.createFrame("mainFrame") local mainFrame = basalt.createFrame("mainFrame")
--> Show the frame to the user --> Show the frame to the user
@@ -76,7 +78,7 @@ basalt.autoUpdate() --> Basalt#autoUpdate starts the event listener to detect us
``` ```
If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above: If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above:
```lua ```lua
local basalt = require("Basalt") local basalt = require("basalt")
local mainFrame = basalt.createFrame("mainFrame"):show() local mainFrame = basalt.createFrame("mainFrame"):show()
local button = mainFrame --> Basalt returns an instance of the object on most methods, to make use of "call-chaining" local button = mainFrame --> Basalt returns an instance of the object on most methods, to make use of "call-chaining"

View File

@@ -1,12 +1,12 @@
# Installer # Installer
This is just a script which helps you to setup your program to automatically install the Basalt UI Framework, if it doesn't exists. Means, you create your program (which requires basalt) and add this on the top of your program. Now, everytime you execute your program it checks if basalt.lua (or your custom filepath) exists or not, if not it installs it, or if you are using the advanced installer, it asks the user if the program is allowed to install basalt for you. This is just a script which helps you to setup your program to automatically install the Basalt UI Framework if it doesn't exist. Which means you create your program (which requires basalt), and add this on the top of your program. Now everytime you execute your program it checks if basalt.lua (or your custom filepath) exists or not. If it dosent exist it installs it, or if you are using the advanced installer it asks the user if the program is allowed to install basalt for you.
## Basic Installer ## Basic Installer
Here is a very basic one which just installs basalt.lua if don't exist: Here is a very basic installer which just installs basalt.lua if it dosen't exist:
```lua ```lua
--Basalt configurated installer --Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt local filePath = "basalt.lua" --here you can change the file path that it installs to. default: /basalt.lua
if not(fs.exists(filePath))then if not(fs.exists(filePath))then
shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end end
@@ -18,8 +18,8 @@ This is a visual version, it asks the user if he wants to install basalt.lua (if
![](https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/installer.png) ![](https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/installer.png)
```lua ```lua
--Basalt configurated installer --Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt local filePath = "basalt.lua" --here you can change the file path it installs to. Default: /basalt.lua
if not(fs.exists(filePath))then if not fs.exists(filePath) then
local w,h = term.getSize() local w,h = term.getSize()
term.clear() term.clear()
local _installerWindow = window.create(term.current(),w/2-8,h/2-3,18,6) local _installerWindow = window.create(term.current(),w/2-8,h/2-3,18,6)
@@ -68,7 +68,4 @@ if not(fs.exists(filePath))then
term.setCursorPos(1,1) term.setCursorPos(1,1)
term.clear() term.clear()
end end
local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt
------------------------------
``` ```

View File

@@ -38,8 +38,9 @@
logo: '/_media/logo.png', logo: '/_media/logo.png',
loadNavbar: true, loadNavbar: true,
loadSidebar: true, loadSidebar: true,
loadFooter: '_footer.md',
autoHeader: true, autoHeader: true,
subMaxLevel: 2, subMaxLevel: 3,
homepage: 'Home.md', homepage: 'Home.md',
name: 'Basalt', name: 'Basalt',
repo: 'https://github.com/Pyroxenium/Basalt', repo: 'https://github.com/Pyroxenium/Basalt',
@@ -50,5 +51,7 @@
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script> <script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
<script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/js/docsify-themeable.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/js/docsify-themeable.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1.28.0/components/prism-lua.min.js"></script> <script src="//cdn.jsdelivr.net/npm/prismjs@1.28.0/components/prism-lua.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/@alertbox/docsify-footer/dist/docsify-footer.min.js"></script>
</body> </body>
</html> </html>

295
docs/install.lua Normal file
View File

@@ -0,0 +1,295 @@
-- this file can download the project or other tools from github
local args = table.pack(...)
local installer = {printStatus=true}
installer.githubPath = "https://raw.githubusercontent.com/Pyroxenium/Basalt/"
-- Creates a filetree based on my github project, ofc you can use this in your projects if you'd like to
function installer.createTableTree(page, branch, dirName)
dirName = dirName or ""
if(installer.printStatus)then print("Receiving file tree for "..dirName) end
local tree = {}
local request = http.get(page, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY})
if not(page)then return end
if(request==nil)then error("API rate limit exceeded. It will be available again in a couple of hours.") end
for _,v in pairs(textutils.unserialiseJSON(request.readAll()).tree)do
if(v.type=="blob")then
table.insert(tree, {name = v.path, path=fs.combine(dirName, v.path), url=installer.githubPath..branch.."/Basalt/"..fs.combine(dirName, v.path), size=v.size})
elseif(v.type=="tree")then
tree[v.path] = installer.createTree(v.url, branch, fs.combine(dirName, v.path))
end
end
return tree
end
function installer.createTree(page, branch, dirName)
dirName = dirName or ""
if(installer.printStatus)then print("Receiving file tree for "..dirName) end
local tree = {}
local request = http.get(page, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY})
if not(page)then return end
if(request==nil)then error("API rate limit exceeded. It will be available again in a couple of hours.") end
for _,v in pairs(textutils.unserialiseJSON(request.readAll()).tree)do
if(v.type=="blob")then
table.insert(tree, {name = v.path, path=fs.combine(dirName, v.path), url=installer.githubPath..branch.."/Basalt/"..fs.combine(dirName, v.path), size=v.size})
elseif(v.type=="tree")then
for k,v in pairs(installer.createTree(v.url, branch, fs.combine(dirName, v.path)))do
table.insert(tree, v)
end
end
end
return tree
end
local function splitString(str, sep)
if sep == nil then
sep = "%s"
end
local t={}
for v in string.gmatch(str, "([^"..sep.."]+)") do
table.insert(t, v)
end
return t
end
function installer.get(url)
local httpReq = http.get(url, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY})
if(installer.printStatus)then print("Downloading "..url) end
if(httpReq~=nil)then
local content = httpReq.readAll()
if not content then
error("Could not connect to website")
end
return content
end
end
function installer.createIgnoreList(str)
local files = splitString(str, ":")
local ignList = {}
for k,v in pairs(files)do
local a = splitString(v, "/")
if(#a>1)then
if(ignList[a[1]]==nil)then ignList[a[1]] = {} end
table.insert(ignList[a[1]], a[2])
else
table.insert(ignList, v)
end
end
end
function installer.download(url, file)
local content = installer.get(url)
if(content~=nil)then
local f = fs.open(file, "w")
f.write(content)
f.close()
end
end
function installer.getPackedProject(branch, ignoreList)
installer.printStatus = false
if (ignoreList==nil)then
ignoreList = {"init.lua"}
else
table.insert(ignoreList, "init.lua")
end
local projTree = installer.createTableTree("https://api.github.com/repos/Pyroxenium/Basalt/git/trees/"..branch..":Basalt", branch, "")
local filteredList = {}
local project = {}
local function isInIgnoreList(file, ign)
if(ign~=nil)then
for k,v in pairs(ign)do
if(v==file.name)then
return true
end
end
end
return false
end
for k,v in pairs(projTree)do
if(type(k)=="string")then
for a,b in pairs(v)do
if not(isInIgnoreList(b, ignoreList~=nil and ignoreList[k] or nil))then
if(filteredList[k]==nil)then filteredList[k] = {} end
table.insert(filteredList[k], b)
end
end
else
if not(isInIgnoreList(v, ignoreList))then
table.insert(filteredList, v)
end
end
end
local fList = {}
local delay = 0
for k,v in pairs(filteredList)do
if(type(k)=="string")then
for a,b in pairs(v)do
table.insert(fList, function() sleep(delay)
if(project[k]==nil)then project[k] = {} end
table.insert(project[k], {content=installer.get(b.url), name=b.name, path=b.path, size = b.size, url = b.url})
delay = delay + 0.05
end)
end
else
table.insert(fList, function() sleep(delay) table.insert(project, {content=installer.get(v.url), name=v.name, path=v.path, size = v.size, url = v.url}) delay = delay + 0.05 end)
end
end
parallel.waitForAll(table.unpack(fList))
local projectContent =
[[
local project = {}
local packaged = true
local baseRequire = require
local require = function(path)
for k,v in pairs(project)do
if(type(v)=="table")then
for name,b in pairs(v)do
if(name==path)then
return b()
end
end
else
if(k==path)then
return v()
end
end
end
return baseRequire(path);
end
local getProject = function(subDir)
if(subDir~=nil)then
return project[subDir]
end
return project
end
]]
for k,v in pairs(project)do
if(type(k)=="string")then
local newSubDir = 'project["'..k..'"] = {}\n'
projectContent = projectContent.."\n"..newSubDir
for a,b in pairs(v)do
local newFile = 'project["'..k..'"]["'..b.name:gsub(".lua", "")..'"] = function(...)\n'..b.content..'\nend'
projectContent = projectContent.."\n"..newFile
end
else
local newFile = 'project["'..v.name:gsub(".lua", "")..'"] = function(...)\n'..v.content..'\nend'
projectContent = projectContent.."\n"..newFile
end
end
projectContent = projectContent..'\n return project["main"]()'
return projectContent
end
function installer.getProjectFiles(branch, ignoreList)
local projTree = installer.createTree("https://api.github.com/repos/Pyroxenium/Basalt/git/trees/"..branch..":Basalt", branch, "")
local filteredList = {}
local project = {}
local function isInIgnoreList(file)
if(ignoreList~=nil)then
for k,v in pairs(ignoreList)do
if(v==file)then
return true
end
end
end
return false
end
for k,v in pairs(projTree)do
if not(isInIgnoreList(v))then
table.insert(filteredList, v)
end
end
local function downloadFile(url, path)
project[path] = installer.get(url)
end
local fList = {}
local delay = 0
for k,v in pairs(filteredList)do
table.insert(fList, function() sleep(delay) downloadFile(v.url, v.path) delay = delay + 0.05 end)
end
parallel.waitForAll(table.unpack(fList))
return project
end
function installer.downloadPacked(filename, branch, ignoreList, minify)
local projectContent = installer.getPackedProject(branch, ignoreList)
if(minify)then
local min
if(fs.exists("packager.lua"))then
min = require("packager")
else
min = load(installer.get("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/packager.lua"))()
end
if(min~=nil)then
success, data = min(projectContent)
if(success)then
projectContent = data
else
error(data)
end
end
end
local f = fs.open(filename, "w")
f.write(projectContent)
f.close()
end
function installer.downloadProject(projectDir, branch, ignoreList)
local projectFiles = installer.getProjectFiles(branch, ignoreList)
projectDir = projectDir or "basalt"
branch = branch or "master"
local function downloadFile(url, path)
print("Downloading "..path)
local files = splitString(path)
if(#files>1)then
local folderPath = ""
for a,b in pairs(files)do
if(a<#files)then
folderPath = fs.combine(folderPath, b)
else
if not (fs.exists(folderPath))then fs.makeDir(folderPath) end
installer.download(url, fs.combine(projectDir, path))
end
end
else
installer.download(url, fs.combine(projectDir, path))
end
end
local fList = {}
local delay = 0
for k,v in pairs(projectFiles)do
table.insert(fList, function() sleep(delay) downloadFile(v.url, v.path) delay = delay + 0.05 end)
end
parallel.waitForAll(table.unpack(fList))
end
if(#args>0)then
if(string.lower(args[1])=="bpm")or(string.lower(args[1])=="basaltpackagemanager")or(string.lower(args[1])=="gui")then
installer.download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/basaltPackageManager.lua", "basaltPackageManager.lua")
if(args[2]=="true")then shell.run("basaltPackageManager.lua") fs.delete("basaltPackageManager.lua") end
elseif(string.lower(args[1])=="packed")then
installer.downloadPacked(args[2] or "basalt.lua", args[3] or "master", args[4]~=nil and installer.createIgnoreList(args[4]) or nil, args[5] == "false" and false or true)
elseif(string.lower(args[1])=="source")then
installer.downloadProject(args[2] or "basalt", args[3] or "master", args[4]~=nil and installer.createIgnoreList(args[4]) or nil)
end
end
return installer

View File

@@ -1,303 +1,21 @@
With animations, you can create a beautiful experience for users while interacting with objects.<br> With animations, you can create a beautiful experience for users while interacting with your program.<br>
For now the animation class is very basic, it will be expanded in the future, but we have to say you can already do almost everything you can imagine!
Right now animation is a class which makes use of the timer event.<br> | | |
You can find more information below: |---|---|
|[add](objects/Animation/add.md)|Adds a new custom function to call at the current time
`The animation object is still a WIP and the way you use it right now could change in the future!` |[wait](objects/Animation/wait.md)|Adds a amount to the animation time
|[play](objects/Animation/play.md)|Plays the animation
## add |[cancel](objects/Animation/cancel.md)|Cancels the animation
Adds a new function to an animation |[setObject](objects/Animation/setObject.md)|Sets an object on which predefined animations should work on
#### Parameters: |[move](objects/Animation/move.md)|Predefined animation: moves the object to a new position
1. `function` The function containing animation logic |[offset](objects/Animation/offset.md)|Predefined animation: Changes the offset of that object
|[size](objects/Animation/size.md)|Predefined animation: Changes the size on a object
#### Returns: |[changeText](objects/Animation/changeText.md)|Predefined animation: Changes the text (object needs a setText method)
1. `animation` Animation in use |[changeTextColor](objects/Animation/changeTextColor.md)|Predefined animation: changes the foreground/textcolor on a object
|[changeBackground](objects/Animation/changeBackground.md)|Predefined animation: changes the background on a object
#### Usage:
* This will set the button position to 3,3, waits 1 second, then sets position to 4,4, waits 2 seconds, and then sets the position to 5,5
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
aAnimation:play()
```
## wait
Sets a wait timer for the next function after the previous function got executed, no wait timer calls the next function immediately
#### Parameters:
1. `number` The length of delay between the functions _(in seconds)_
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
aAnimation:play()
```
## play
Plays the animation
#### Parameters:
1. `boolean` Whether it will loop forever, will most likely be replaced with a count in the future
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() testButton:setBackground(colors.gray) end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
aAnimation:play() -- changes the background color of that button from black to gray and then to lightGray
```
## cancel
Cancels the animation
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() aAnimation:cancel() end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
aAnimation:play()
```
## setObject
Sets the object which the animation should reposition/resize
#### Parameters:
1. `table` object
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():setObject(testButton)
```
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
```
```xml
<animation object="buttonToAnimate" />
```
## move
Moves the object which got defined by setObject
#### Parameters:
1. `number` x coordinate
2. `number` y coordinate
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
* Takes 2 seconds to move the object from its current position to x15 y3
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):move(15,3,2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<move><x>15</x><y>6</y><duration>2</duration></move>
</animation>
```
## offset
Changes the offset on the object which got defined by setObject
#### Parameters:
1. `number` x offset
2. `number` y offset
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local subFrame = mainFrame:addFrame("frameToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(subFrame):offset(1,12,1):play()
```
```xml
<animation object="frameToAnimate" play="true">
<offset><x>1</x><y>12</y><duration>1</duration></offset>
</animation>
```
## size
Changes the size on the object which got defined by setObject
#### Parameters:
1. `number` width
2. `number` height
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):size(15,3,1):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<offset><w>15</w><h>3</h><duration>1</duration></offset>
</animation>
```
## changeText
Changes the text while animation is running
#### Parameters:
1. `table` multiple text strings - example: {"i", "am", "groot"}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeText({"i", "am", "groot"}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<text>
<text>i</text>
<text>am</text>
<text>groot</text>
<duration>2</duration>
</text>
</animation>
```
## changeTextColor
Changes the text color while the animation is running
#### Parameters:
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<textColor>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</textColor>
</animation>
```
## changeBackground
Changes the background color while the animation is running
#### Parameters:
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<background>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</background>
</animation>
```
# Events # Events
## onDone | | |
`onDone(self)`<br> |---|---|
This is a event which gets fired as soon as the animation has finished. |[onDone](objects/Animation/onDone.md)|Gets called as soon as the animation has finished
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
aAnimation:onDone(function()
basalt.debug("The animation is done")
end)
```
In XML you are also able to queue multiple animations, like this:
```xml
<animation id="anim2" object="buttonToAnimate">
<textColor>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</textColor>
</animation>
<animation onDone="#anim2" object="buttonToAnimate" play="true">
<background>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</background>
</animation>
```

View File

@@ -0,0 +1,17 @@
## add
Adds a new function to an animation
#### Parameters:
1. `function` The function containing animation logic
#### Returns:
1. `animation` Animation in use
#### Usage:
* This will set the button position to 3,3, waits 1 second, then sets position to 4,4, waits 2 seconds, and then sets the position to 5,5
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
aAnimation:play()
```

View File

@@ -0,0 +1,15 @@
## cancel
Cancels the animation
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() aAnimation:cancel() end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
aAnimation:play()
```

View File

@@ -0,0 +1,28 @@
## changeBackground
Changes the background color while the animation is running
#### Parameters:
1. `number` duration in seconds
2. `number` time - time when this part should begin (offset to when the animation starts - default 0)
3. `...` multiple color numbers - example: colors.red, colors.yellow, colors.green
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor(2, 0, colors.red, colors.yellow, colors.green):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<background>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</background>
</animation>
```

View File

@@ -0,0 +1,30 @@
## changeText
Changes the text while animation is running
#### Parameters:
1. `table` multiple text strings - example: {"i", "am", "groot"}
1. `number` duration in seconds
2. `number` time - time when this part should begin (offset to when the animation starts - default 0)
3. `...` multiple text strings - example: "i", "am", "groot"
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeText(2, 0, "i", "am", "groot"):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<text>
<text>i</text>
<text>am</text>
<text>groot</text>
<duration>2</duration>
</text>
</animation>
```

View File

@@ -0,0 +1,28 @@
## changeTextColor
Changes the text color while the animation is running
#### Parameters:
1. `number` duration in seconds
2. `number` time - time when this part should begin (offset to when the animation starts - default 0)
1. `...` multiple color numbers - example: colors.red, colors.yellow, colors.green
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor(2, 0, colors.red, colors.yellow, colors.green):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<textColor>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</textColor>
</animation>
```

View File

@@ -0,0 +1,25 @@
## move
Moves the object which got defined by setObject
#### Parameters:
1. `number` x coordinate
2. `number` y coordinate
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
* Takes 2 seconds to move the object from its current position to x15 y3
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):move(15,3,2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<move><x>15</x><y>6</y><duration>2</duration></move>
</animation>
```

View File

@@ -0,0 +1,25 @@
## offset
Changes the offset on the object which got defined by setObject
#### Parameters:
1. `number` x offset
2. `number` y offset
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local subFrame = mainFrame:addFrame("frameToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(subFrame):offset(1,12,1):play()
```
```xml
<animation object="frameToAnimate" play="true">
<offset><x>1</x><y>12</y><duration>1</duration></offset>
</animation>
```

View File

@@ -0,0 +1,35 @@
## onDone
`onDone(self)`<br>
This is a event which gets fired as soon as the animation has finished.
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
aAnimation:onDone(function()
basalt.debug("The animation is done")
end)
```
In XML you are also able to queue multiple animations, like this:
```xml
<animation id="anim2" object="buttonToAnimate">
<textColor>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</textColor>
</animation>
<animation onDone="#anim2" object="buttonToAnimate" play="true">
<background>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</background>
</animation>
```

View File

@@ -0,0 +1,16 @@
## play
Plays the animation
#### Parameters:
1. `boolean` Whether it will loop forever, will most likely be replaced with a count in the future
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() testButton:setBackground(colors.gray) end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
aAnimation:play() -- changes the background color of that button from black to gray and then to lightGray
```

View File

@@ -0,0 +1,24 @@
## setObject
Sets the object which the animation should reposition/resize
#### Parameters:
1. `table` object
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():setObject(testButton)
```
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
```
```xml
<animation object="buttonToAnimate" />
```

View File

@@ -0,0 +1,24 @@
## size
Changes the size on the object which got defined by setObject
#### Parameters:
1. `number` width
2. `number` height
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):size(15,3,1):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<offset><w>15</w><h>3</h><duration>1</duration></offset>
</animation>
```

View File

@@ -0,0 +1,16 @@
## wait
Sets a wait timer for the next function after the previous function got executed, no wait timer calls the next function immediately
#### Parameters:
1. `number` The length of delay between the functions _(in seconds)_
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
aAnimation:play()
```

View File

@@ -1,201 +1,46 @@
# Basalt
This is the UI Manager and the first thing you want to access.
Before you can access Basalt, you need to add the following code on top of your file: Before you can access Basalt, you need to add the following code on top of your file:
`local basalt = require("Basalt")`
Now you are able to access the following methods:
## basalt.createFrame
Create a base-frame (main frame)
#### Parameters:
1. `string` name
#### Returns:
1. `frame` object
#### Usage:
* Create and show a frame with id "myFirstFrame"
```lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame") local basalt = require("basalt")
``` ```
## basalt.removeFrame What this code does is it loads basalt into the basalt variable.
Removes a base frame You are now able to access the following list of methods:
#### Parameters: | | |
1. `string` name |---|---|
|[autoUpdate](objects/Basalt/autoUpdate.md)|Starts the event and draw listener
|[createFrame](objects/Basalt/createFrame.md)|Creates a new base frame
|[debug](objects/Basalt/debug.md)|Writes something into the debug console
|[getFrame](objects/Basalt/getFrame.md)|Returns a frame object by it's id
|[getActiveFrame](objects/Basalt/getActiveFrame.md)|Returns the currently active base frame
|[getTheme](objects/Basalt/getTheme.md)|Returns the currently active theme
|[getVariable](objects/Basalt/getVariable.md)|Returns a variable defined with setVariable
|[getVersion](objects/Basalt/getVersion.md)|Returns the Basalt version
|[isKeyDown](objects/Basalt/isKeyDown.md)|Returns if the key is held down
|[log](objects/Basalt/log.md)|Writes something into the log file
|[onEvent](objects/Basalt/onEvent.md)|Event listener
|[removeFrame](objects/Basalt/removeFrame.md)|Removes a previously created base frame
|[schedule](objects/Basalt/schedule.md)|Schedules a new task
|[setActiveFrame](objects/Basalt/setActiveFrame.md)|Sets the active frame
|[setTheme](objects/Basalt/setTheme.md)|Changes the base theme of basalt
|[setVariable](objects/Basalt/setVariable.md)|Sets a variable which you can access via XML
|[stopUpdate / stop](objects/Basalt/stopUpdate.md)|Stops the currently active event and draw listener
|[update](objects/Basalt/update.md)|Starts the event and draw listener once
## Examples
Here is a lua example on how to create a empty base frame and start basalt's listener.
#### Usage:
* Removes the previously created frame with id "myFirstFrame"
```lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame") local basalt = require("basalt") -- Loads Basalt into our project
basalt.removeFrame("myFirstFrame")
``` local main = basalt.createFrame() -- Creates a base frame. On that frame we are able to add object's
## basalt.getFrame -- Here we would add additional object's
Returns a base frame with the given name
#### Parameters: basalt.autoUpdate() -- Starts listening to incoming events and draw stuff on the screen. This should nearly always be the last line.
1. `string` name
#### Returns:
1. `frame` object
#### Usage:
* Creates, fetches and shows the "myFirstFrame" object
```lua
basalt.createFrame("myFirstFrame"):hide()
basalt.getFrame("myFirstFrame"):show()
```
## basalt.getActiveFrame
Returns the currently active base frame
#### Returns:
1. `frame` The current frame
#### Usage:
* Displays the active frame name in the debug console
```lua
basalt.createFrame()
basalt.debug(basalt.getActiveFrame():getName()) -- returns the uuid
```
## basalt.autoUpdate
Starts the draw and event handler until basalt.stopUpdate() is called
#### Usage:
* Enable the basalt updates, otherwise the screen will not continue to update
```lua
local mainFrame = basalt.createFrame()
basalt.autoUpdate()
```
## basalt.update
Calls the draw and event handler once - this gives more flexibility about which events basalt should process. For example you could filter the terminate event.
#### Parameters:
1. `string` The event to be received
2. `...` Additional event variables to capture
#### Usage:
* Creates and starts a custom update cycle
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setPosition(2,2)
while true do
basalt.update(os.pullEventRaw())
end
```
## basalt.stopUpdate
Stops the automatic draw and event handler which got started by basalt.autoUpdate()
#### Usage:
* When the quit button is clicked, the button stops basalt auto updates
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setPosition(2,2):setText("Stop Basalt!")
aButton:onClick(function()
basalt.stopUpdate()
end)
basalt.autoUpdate()
```
## basalt.isKeyDown
Checks if the user is currently holding a key
#### Parameters:
1. `number` key code (use the keys table for that)
#### Returns:
1. `boolean` true or false
#### Usage:
* Shows a debug message with true or false if the left ctrl key is down, as soon as you click on the button.
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setPosition(2,2):setText("Check Ctrl")
aButton:onClick(function()
basalt.debug(basalt.isKeyDown(keys.leftCtrl))
end)
basalt.autoUpdate()
```
## basalt.debug
creates a label with some information on the main frame on the bottom left, if you click on that label it will open a log view for you. See it as the new print for debugging
You can also edit the default debug Label (change position, change color or whatever you want) by accessing the variable basalt.debugLabel
which returns the debug Label.
Also basalt.debugFrame and basalt.debugList are available.
#### Parameters:
1. `...` (multiple parameters are possible, like print does)
#### Usage:
* Prints "Hello! ^-^" to the debug console
```lua
basalt.debug("Hello! ", "^-^")
```
## basalt.setTheme
Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua)
#### Parameters:
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
#### Usage:
* Sets the default theme of basalt.
```lua
basalt.setTheme({
ButtonBG = colors.yellow,
ButtonText = colors.red,
...,
})
```
## basalt.setVariable
This stores a variable which you're able to access via xml. You are also able to add a function, which then gets called by object events created in XML.
#### Parameters:
1. `string` a key name
1. `any` any variable
#### Usage:
* Adds a function to basalt.
```lua
basalt.setVariable("clickMe", function()
basalt.debug("I got clicked")
end)
```
```xml
<button onClick="clickMe" text="Click me" />
```
## basalt.schedule
Schedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
#### Parameters:
1. `function` a function which should get executed
#### Returns:
1. `function` it returns the function which you have to execute in order to start the coroutine
#### Usage:
* Creates a schedule which switches the color between red and gray
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setText("Click me")
aButton:onClick(basalt.schedule(function(self)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
os.sleep(0.1)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
os.sleep(0.1)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
end))
``` ```

View File

@@ -0,0 +1,18 @@
# Basalt
## autoUpdate
This starts the event and draw handler for you. The listeners will run until you stop them.
### Parameters
1. `boolean` optional - if you use false as the first parameter it would stop the listeners. Using false is a synonym for [`basalt.stopUpdate()`](objects/Basalt/stopUpdate.md).
### Usage
* Enables the basalt listeners, otherwise the screen will not continue to update
```lua
local main = basalt.createFrame()
basalt.autoUpdate()
```

View File

@@ -0,0 +1,35 @@
# Basalt
## createFrame
Creates a new base-frame, you can have as many base-frames as you want, but only 1 can be active (visible) at the same time.
You can always switch between your base frames.
Only the currently active base-frame listens to incoming events (except for some events like time-events and peripheral-events)
### Parameters
1. `string` id - optional (if you dont set a id it will automatically create a uuid for you)
### Returns
1. `frame` object
### Usage
* How to use multiple base frames:
```lua
local main1 = basalt.createFrame() -- Visible base frame on program start
local main2 = basalt.createFrame()
local main3 = basalt.createFrame()
main1:addButton()
:setPosition(2,2)
:setText("Switch")
:onClick(function()
main2:show() -- this function automatically "hides" the first one and shows the second one
end)
main2:addLabel()
:setText("We are currently on main2")
basalt.autoUpdate()
```

View File

@@ -0,0 +1,29 @@
# Basalt
## debug
Creates a label with some information on the main frame on the bottom left. When you click on that label it will open a log view for you. See it as the new print for debugging
You can also edit the default debug Label (change position, change color or whatever you want) by accessing the variable `basalt.debugLabel`
which returns the debug Label.
`basalt.debugFrame` and `basalt.debugList` are also available.
### Parameters
1. `...` (multiple parameters are possible, like print does)
### Usage
* Prints "Hello! ^-^" to the debug console
```lua
basalt.debug("Hello! ", "^-^")
```
* Changes the debug label's anchor
```lua
basalt.debugLabel:setAnchor("topLeft") -- default anchor is bottomLeft
basalt.debug("Hello!")
```

View File

@@ -0,0 +1,18 @@
# Basalt
## getActiveFrame
Returns the currently active/visible base frame.
### Returns
1. `frame` The current frame
### Usage
* Displays the active frame name in the debug console
```lua
local main = basalt.createFrame()
basalt.debug(basalt.getActiveFrame():getName()) -- returns the id
```

View File

@@ -0,0 +1,31 @@
# Basalt
## getFrame
Returns a base frame by the given id.
### Parameters
1. `string` id
### Returns
1. `frame` The frame with the supplied id.
### Usage
* Creates, fetches and shows the "myFirstFrame" object
```lua
local main = basalt.createFrame("firstBaseFrame")
local main2 = basalt.createFrame("secondBaseFrame")
main:addButton()
:setText("Show")
:onClick(function()
local frame2 = basalt.getFrame("secondBaseFrame")
if(frame2 ~= nil)then
frame2:show()
end
end)
basalt.autoUpdate()
```

View File

@@ -0,0 +1,18 @@
# Basalt
## basalt.getTheme
Returns the current base-theme. This base-theme can be set using setTheme.md.
A list of base-theme keys can be found [here](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua).
### Returns
1. `number` The color of the requested base-theme key.
### Usage
* Displays the color of the main background in the debug console
```lua
basalt.debug(basalt.getTheme("BasaltBG"))
```

View File

@@ -0,0 +1,26 @@
# Basalt
## getVariable
Returns a variable defined with [setVariable](objects/Basalt/setVariable)
### Returns
1. `variable` The variable stored
### Usage
* Displays the stored variable in the debug console
```lua
basalt.setVariable("abc", function()
basalt.debug("I got clicked")
return 1
end)
basalt.debug(basalt.getVariable("abc")()) -- Should debug log "I got clicked" and debug log 1 (which was returned from the function)
```
```xml
<button onClick="abc" text="Click me" />
```

View File

@@ -0,0 +1,17 @@
# Basalt
## getVersion
Returns the currently active/visible base frame.
### Returns
1. `string` The current version of Basalt
### Usage
* Displays the version of Basalt in the debug console
```lua
basalt.debug(basalt.getVersion()) -- Example: 1.6.2
```

View File

@@ -0,0 +1,28 @@
# Basalt
## isKeyDown
Checks if the user is currently holding a key
### Parameters
1. `number` key code (use the [keys table](https://tweaked.cc/module/keys.html) for that)
### Returns
1. `boolean` true or false
### Usage
* Shows a debug message with true or false if the left ctrl key is down, as soon as you click on the button.
```lua
local main = basalt.createFrame()
local aButton = mainFrame:addButton()
:setPosition(2,2)
:setText("Check Ctrl")
:onClick(function()
basalt.debug(basalt.isKeyDown(keys.leftCtrl))
end)
basalt.autoUpdate()
```

View File

@@ -0,0 +1,28 @@
# Basalt
## log
This writes something into a file. The main goal is to make debugging errors easier. Lets say you'r program is crashing and you don't know why, you could use basalt.log The log files will automatically removed after you start your program again.
### Parameters
1. `string` The text to write into the log file
2. `string` - optional (default: "Debug") - the type to write
### Usage
* Writes "Hello!" into the log file
```lua
basalt.log("Hello!")
```
This should result in there beeing a file called `basaltLog.txt`. In the file it should say `[Basalt][Debug]: Hello!`.
* Writes "Config file missing" into the log file, with warning as prefix.
```lua
basalt.log("Config file is missing", "WARNING")
```
This should result in there beeing a file called `basaltLog.txt`. In the file it should say `[Basalt][WARNING]: Config file is missing`.

View File

@@ -0,0 +1,21 @@
# Basalt
## onEvent
This is the top-level method to intercept an event before sending it to the object event handlers. If you use return false, the event is not passed to the event handlers.
### Parameters
1. `function` The function which should be called
### Usage
```lua
local basalt = require("basalt")
basalt.onEvent(function(event)
if(event=="terminate")then
return false
end
end)
```

View File

@@ -0,0 +1,37 @@
# Basalt
## removeFrame
Removes the base frame by it's id. **This only works for base-frames.**
### Parameters
1. `string` id - ID of the base-frame.
### Usage
* Removes the previously created frame with id "secondBaseFrame"
The frame id is gotten from a frame variable's `:getName()`
```lua
local main = basalt.createFrame("firstBaseFrame")
local main2 = basalt.createFrame("secondBaseFrame")
main:addButton()
:setText("Remove")
:onClick(function()
basalt.removeFrame(main2:getName())
end)
```
* Removes the previously created frame with id "secondBaseFrame", without frame stored in variable
The frame id is the frame's name
```lua
local main = basalt.createFrame("firstBaseFrame")
local main2 = basalt.createFrame("secondBaseFrame")
main:addButton()
:setText("Remove")
:onClick(function()
basalt.removeFrame("secondBaseFrame")
end)
```

View File

@@ -0,0 +1,36 @@
# Basalt
## schedule
Schedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
**A guide can be found [here](/tips/logic).**
### Parameters
1. `function` a function which should get executed
### Returns
1. `function` it returns the function which you have to execute in order to start the coroutine
### Usage
* Creates a schedule which switches the color between red and gray
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setText("Click me")
aButton:onClick(basalt.schedule(function(self)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
os.sleep(0.1)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
os.sleep(0.1)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
end))
```

View File

@@ -0,0 +1,13 @@
# Basalt
## setActiveFrame
Sets what should be the active baseframe.
### Parameters
1. `frame` frame - The frame that should be the active base-frame.
### Usage
TODO

View File

@@ -0,0 +1,21 @@
# Basalt
## setTheme
Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua). The theme can also be gotten with [`basalt.getTheme()`](objects/Basalt/getTheme)
### Parameters
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
### Usage
* Sets the default theme of basalt.
```lua
basalt.setTheme({
ButtonBG = colors.yellow,
ButtonText = colors.red,
...,
})
```

View File

@@ -0,0 +1,25 @@
# Basalt
## setVariable
This stores a variable which you're able to access via xml. You are also able to add a function, which then gets called by object events created in XML.
### Parameters
1. `string` a key name
2. `any` any variable
### Usage
* Adds a function to basalt.
```lua
basalt.setVariable("clickMe", function()
basalt.debug("I got clicked")
end)
```
```xml
<button onClick="clickMe" text="Click me" />
```

View File

@@ -0,0 +1,21 @@
# Basalt
## stopUpdate / stop
Stops the automatic draw and event handler which got started by `basalt.autoUpdate()`.
`basalt.autoUpdate(false)` also does the same.
### Usage
* When the quit button is clicked, the button stops basalt's event listeners and draw handlers
```lua
local main = basalt.createFrame()
main:addButton()
:setPosition(2,2)
:setText("Stop Basalt!")
:onClick(function()
basalt.stopUpdate()
end)
basalt.autoUpdate()
```

View File

@@ -0,0 +1,24 @@
# Basalt
## update
Calls the draw and event handler once - this gives more flexibility about which events basalt should process. For example you could filter the terminate event.
Which means you have to pass the events into basalt.update.
### Parameters
1. `string` The event to be received
2. `...` Additional event variables to capture
### Usage
* Creates and starts a custom update cycle
```lua
local mainFrame = basalt.createFrame()
mainFrame:addButton():setPosition(2,2)
while true do
local ev = table.pack(os.pullEventRaw())
basalt.update(table.unpack(ev))
end
```

View File

@@ -1,73 +1,19 @@
Buttons are objects, which execute something by clicking on them.<br> The button object is for creating buttons If you click on them, they should execute something. You decide what should happen when clicking on them.
Remember button also inherits from [Object](objects/Object.md) [Object](objects/Object.md) methods also apply for buttons.
## setText | | |
Sets the displayed button text |---|---|
#### Parameters: |[setText](objects/Button/setText.md)|Changes the button text
1. `string` the text the button should show |[setHorizontalAlign](objects/Button/setHorizontalAlign.md)|Changes the horizontal text position
|[setVerticalAlign](objects/Button/setVerticalAlign.md)|Changes the vertical text position
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a button with "Click me!" as text.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton():setText("Click me!")
```
```xml
<button text="Click me!" />
```
## setHorizontalAlign
Sets the horizontal align of the button text
#### Parameters:
1. `string` the position as string ("left", "center", "right") - default is center.
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button's horizontal text align to right.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
```
```xml
<button text="Click me!" horizontalAlign="right" />
```
## setVerticalAlign
Sets the vertical align of the button text
#### Parameters:
1. `string` the position as string ("top", "center", "bottom") - default is center.
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button's horizontal text align to right and the vertical text align to bottom.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
:setVerticalAlign("bottom")
```
```xml
<button text="Click me!" horizontalAlign="right" verticalAlign="bottom" />
```
# Example # Example
This is a example on how you would create a fully working button: This is a example on how you would create a fully working button:
```lua ```lua
local mainFrame = basalt.createFrame() local main = basalt.createFrame()
local aButton = mainFrame:addButton():setText("Click") local aButton = main:addButton():setText("Click")
aButton:onClick(function(self,event,button,x,y) aButton:onClick(function(self,event,button,x,y)
if(event=="mouse_click")and(button==1)then if(event=="mouse_click")and(button==1)then
@@ -76,15 +22,15 @@ aButton:onClick(function(self,event,button,x,y)
end) end)
``` ```
and this would be the xml way to do it: and this would be the xml way:
```lua ```lua
local mainFrame = basalt.createFrame():addLayout("example.xml")
basalt.setVariable("buttonClick", function(self,event,button,x,y) basalt.setVariable("buttonClick", function(self,event,button,x,y)
if(event=="mouse_click")and(button==1)then if(event=="mouse_click")and(button==1)then
basalt.debug("Left mousebutton got clicked!") basalt.debug("Left mousebutton got clicked!")
end end
end) end)
local main = basalt.createFrame():addLayout("example.xml")
``` ```
```xml ```xml
<button onClick="buttonClick" text="Click" /> <button onClick="buttonClick" text="Click" />

View File

@@ -0,0 +1,20 @@
## setHorizontalAlign
Sets the horizontal align of the button text
#### Parameters:
1. `string` the position as string ("left", "center", "right") - default is center.
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button's horizontal text align to right.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
```
```xml
<button text="Click me!" horizontalAlign="right" />
```

View File

@@ -0,0 +1,17 @@
## setText
Sets the displayed button text
#### Parameters:
1. `string` the text the button should show
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a button with "Click me!" as text.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton():setText("Click me!")
```
```xml
<button text="Click me!" />
```

View File

@@ -0,0 +1,21 @@
## setVerticalAlign
Sets the vertical align of the button text
#### Parameters:
1. `string` the position as string ("top", "center", "bottom") - default is center.
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button's horizontal text align to right and the vertical text align to bottom.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
:setVerticalAlign("bottom")
```
```xml
<button text="Click me!" horizontalAlign="right" verticalAlign="bottom" />
```

View File

@@ -1,14 +1,17 @@
With checkbox objects the user can set a bool to true or false With checkboxes the user can set a boolean to true or false by clicking on them.
Remember checkbox also inherits from [Object](objects/Object.md) [Object](objects/Object.md) methods also apply for checkboxes.
| | |
|---|---|
|[setSymbol](objects/Checkbox/setSymbol.md)|Changes the symbol when checkbox is checked
A checkbox does not have any custom methods. All required methods are provided by the base [object](objects/Object.md) class.
# Example # Example
This is how you would create a event which gets fired as soon as the value gets changed: This is how you would create a event which gets fired as soon as the value gets changed:
```lua ```lua
local mainFrame = basalt.createFrame() local main = basalt.createFrame()
local aCheckbox = mainFrame:addCheckbox() local aCheckbox = main:addCheckbox()
local function checkboxChange(self) local function checkboxChange(self)
local checked = self:getValue() local checked = self:getValue()
@@ -19,7 +22,7 @@ aCheckbox:onChange(checkboxChange)
also possible via xml: also possible via xml:
```lua ```lua
local mainFrame = basalt.createFrame():addLayout("example.xml") local main = basalt.createFrame():addLayout("example.xml")
basalt.setVariable("checkboxChange", function(self) basalt.setVariable("checkboxChange", function(self)
local checked = self:getValue() local checked = self:getValue()

View File

@@ -0,0 +1,18 @@
## setSymbol
Changes the checkbox symbol, default is "\42"
#### Parameters:
1. `string` symbol
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a new checkbox and changes the symbol to o
```lua
local main = basalt.createFrame()
local checkbox = main:addCheckbox():setSymbol("o")
```
```xml
<checkbox symbol="o" />
```

View File

@@ -1,307 +1,31 @@
Dropdowns are objects where the user can click on a button, this will open a list where the user can choose from. Dropdowns are objects where the user can click on a button, this will open a list where the user can choose from.
If you want to access values inside items this is how the table for single items is made (just a example): [Object](objects/Object.md) methods also apply for dropdowns.
| | |
|---|---|
|[addItem](objects/Dropdown/addItem.md)|Adds a new item into the list
|[removeItem](objects/Dropdown/removeItem.md)|Removes a item from the list
|[editItem](objects/Dropdown/editItem.md)|Changes a already existing item in the list
|[getItem](objects/Dropdown/getItem.md)|Returns a item by its index
|[getItemCount](objects/Dropdown/getItemCount.md)|Returns the item count
|[getAll](objects/Dropdown/getAll.md)|Returns the entire list as a table
|[selectItem](objects/Dropdown/selectItem.md)|Selects a item
|[clear](objects/Dropdown/clear.md)|Makes the entire list empty
|[getItemIndex](objects/Dropdown/getItemIndex.md)|Returns the currently active item index
|[setSelectedItem](objects/Dropdown/setSelectedItem.md)|Changes the default bg and fg, when the user selects a item
|[setOffset](objects/Dropdown/setOffset.md)|Changes the list offset
|[getOffset](objects/Dropdown/getOffset.md)|Returns the current offset
|[setDropdownSize](objects/Dropdown/setDropdownSize.md)|Changes the dropdown size
A item-table in dropdowns looks like the following example:
```lua ```lua
item = { item = {
text="1. Entry", text="1. Entry", -- the text its showing
bgCol=colors.black, bgCol=colors.black, -- the background color
fgCol=colors.white fgCol=colors.white -- the foreground color
args = {} args = {} -- custom args you want to pass, which you will be able to access in for example onChange events
} }
``` ```
Remember Dropdown also inherits from [Object](objects/Object.md)
## addItem
Adds a item into the dropdown
#### Parameters:
1. `string` The entry name
2. `number|color` unique default background color - optional
3. `number|color` unique default text color - optional
4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
```
```xml
<dropdown>
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>3. Entry</text><bg>yellow</bg><fg>green</fg></item>
</dropdown>
```
## removeItem
Removes a item from the dropdown
#### Parameters:
1. `number` The index which should get removed
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and removes the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:removeItem(2)
```
## editItem
Edits a item from the dropdown
#### Parameters:
1. `number` The index which should be edited
2. `string` The new item name
3. `number` the new item background color - optional
4. `number` The new item text color - optional
5. `any` New additional information - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:editItem(2, "Still 2. Entry", colors.red)
```
## getItem
Returns a item by index
#### Parameters:
1. `number` The index which should be returned
#### Returns:
1. `table` The item table example: {text="1. Entry", bgCol=colors.black, fgCol=colors.white}
#### Usage:
* Creates a default dropdown with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getItem(2).text)
```
## getItemCount
Returns the current item count
#### Returns:
1. `number` The item list count
#### Usage:
* Creates a default dropdown with 3 entries and prints the current item count.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getItemCount())
```
## getAll
Returns all items as table
#### Returns:
1. `table` All items
#### Usage:
* Creates a default menubar with 3 entries and prints a table.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getAll())
```
## selectItem
selects a item in the dropdown (same as a player would click on a item)
#### Parameters:
1. `number` The index which should get selected
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and selects the second entry.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:selectItem(2)
```
## clear
Removes all items.
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and removes them immediatley. Which makes no sense.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:clear()
```
## getItemIndex
returns the item index of the currently selected item
#### Returns:
1. `number` The current index
#### Usage:
* Creates a default dropdown with 3 entries selects the second entry and prints the currently selected index.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:selectItem(2)
basalt.debug(aDropdown:getItemIndex())
```
## setSelectedItem
Sets the background and the foreground of the item which is currently selected
#### Parameters:
1. `number|color` The background color which should be used
2. `number|color` The text color which should be used
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 4 entries and sets the selection background color to green.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:addItem("4. Entry")
aDropdown:setSelectedItem(colors.green, colors.red)
```
```xml
<dropdown selectionBG="green" selectionFG="red">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>2. Entry</text><bg>yellow</bg><fg>green</fg></item>
</dropdown>
```
## setOffset
Sets the offset of the dropdown (the same as you would scroll) - default is 0
#### Parameters:
1. `number` The offset value
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 6 entries and sets the offset to 3.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
```
```xml
<dropdown offset="3">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
<item><text>4. Entry</text></item>
<item><text>5. Entry</text></item>
<item><text>6. Entry</text></item>
</dropdown>
```
## getOffset
Returns the current index offset
#### Returns:
1. `number` offset value
#### Usage:
* Creates a default dropdown with 6 entries and sets the offset to 3, also prints the current offset.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
basalt.debug(aDropdown:getOffset())
```
## setDropdownSize
Sets the size of the opened dropdown
#### Parameters:
1. `number` The width value
2. `number` The height value
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown, adds 3 entries and sets the dropdown size to 15w, 8h
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown():setDropdownSize(15,8)
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry")
aDropdown:addItem("3. Entry")
```
```xml
<dropdown dropdownWidth="15" dropdownHeight="8">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
</dropdown>
```

View File

@@ -0,0 +1,28 @@
## addItem
Adds a item into the dropdown
#### Parameters:
1. `string` The entry name
2. `number|color` unique default background color - optional
3. `number|color` unique default text color - optional
4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
```
```xml
<dropdown>
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>3. Entry</text><bg>yellow</bg><fg>green</fg></item>
</dropdown>
```

View File

@@ -0,0 +1,16 @@
## clear
Removes all items.
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and removes them immediatley. Which makes no sense.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:clear()
```

View File

@@ -0,0 +1,23 @@
## editItem
Edits a item from the dropdown
#### Parameters:
1. `number` The index which should be edited
2. `string` The new item name
3. `number` the new item background color - optional
4. `number` The new item text color - optional
5. `any` New additional information - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:editItem(2, "Still 2. Entry", colors.red)
```

View File

@@ -0,0 +1,16 @@
## getAll
Returns all items as table
#### Returns:
1. `table` All items
#### Usage:
* Creates a default menubar with 3 entries and prints a table.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getAll())
```

View File

@@ -0,0 +1,19 @@
## getItem
Returns a item by index
#### Parameters:
1. `number` The index which should be returned
#### Returns:
1. `table` The item table example: {text="1. Entry", bgCol=colors.black, fgCol=colors.white}
#### Usage:
* Creates a default dropdown with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getItem(2).text)
```

View File

@@ -0,0 +1,16 @@
## getItemCount
Returns the current item count
#### Returns:
1. `number` The item list count
#### Usage:
* Creates a default dropdown with 3 entries and prints the current item count.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getItemCount())
```

View File

@@ -0,0 +1,17 @@
## getItemIndex
returns the item index of the currently selected item
#### Returns:
1. `number` The current index
#### Usage:
* Creates a default dropdown with 3 entries selects the second entry and prints the currently selected index.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:selectItem(2)
basalt.debug(aDropdown:getItemIndex())
```

View File

@@ -0,0 +1,20 @@
## getOffset
Returns the current index offset
#### Returns:
1. `number` offset value
#### Usage:
* Creates a default dropdown with 6 entries and sets the offset to 3, also prints the current offset.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
basalt.debug(aDropdown:getOffset())
```

View File

@@ -0,0 +1,19 @@
## removeItem
Removes a item from the dropdown
#### Parameters:
1. `number` The index which should get removed
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and removes the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:removeItem(2)
```

View File

@@ -0,0 +1,19 @@
## selectItem
selects a item in the dropdown (same as a player would click on a item)
#### Parameters:
1. `number` The index which should get selected
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and selects the second entry.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:selectItem(2)
```

View File

@@ -0,0 +1,26 @@
## setDropdownSize
Sets the size of the opened dropdown
#### Parameters:
1. `number` The width value
2. `number` The height value
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown, adds 3 entries and sets the dropdown size to 15w, 8h
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown():setDropdownSize(15,8)
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry")
aDropdown:addItem("3. Entry")
```
```xml
<dropdown dropdownWidth="15" dropdownHeight="8">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
</dropdown>
```

View File

@@ -0,0 +1,32 @@
## setOffset
Sets the offset of the dropdown (the same as you would scroll) - default is 0
#### Parameters:
1. `number` The offset value
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 6 entries and sets the offset to 3.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
```
```xml
<dropdown offset="3">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
<item><text>4. Entry</text></item>
<item><text>5. Entry</text></item>
<item><text>6. Entry</text></item>
</dropdown>
```

View File

@@ -0,0 +1,28 @@
## setSelectedItem
Sets the background and the foreground of the item which is currently selected
#### Parameters:
1. `number|color` The background color which should be used
2. `number|color` The text color which should be used
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 4 entries and sets the selection background color to green.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:addItem("4. Entry")
aDropdown:setSelectedItem(colors.green, colors.red)
```
```xml
<dropdown selectionBG="green" selectionFG="red">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>2. Entry</text><bg>yellow</bg><fg>green</fg></item>
</dropdown>
```

View File

@@ -1,409 +1,40 @@
<a href="https://i.imgur.com/aikc0K1.png"><img src="https://i.imgur.com/aikc0K1.png" height="500" /></a> Frames are like groups or windows. You can add objects on them and if you move the frame, all its children objects will also be moved. Frames also have
some special functionality to create very advanced programs.
Frames are like containers, but are also normal objects.
In other words, you can add other objects _(even frames)_ to a frame; if the frame itself is visible [Object](objects/Object.md) methods also apply for frames.
all sub-objects _(if they are set as visible)_ are also visible. A better description will follow.
| | |
## basalt.createFrame |---|---|
Creates a new non-parent frame - in most cases it is the first thing you'll need. |[addObject](objects/Frame/addObject.md)|Adds a new object
|[setBar](objects/Frame/setBar.md)|Sets the top bar text and colors - deprecated
#### Parameters: |[setBarTextAlign](objects/Frame/setBarTextAlign.md)|Sets the top bars text align - deprecated
1. `string` name (should be unique) |[showBar](objects/Frame/showBar.md)|Shows the top bar - deprecated
|[setMonitor](objects/Frame/setMonitor.md)|Sets the frame to be a monitor frame (only for base frames)
#### Returns: |[setMonitorScale](objects/Frame/setMonitorScale.md)|Sets the monitor scale (same as monitor.setTextScale)
1. `frame | nil` The frame created by createFrame, or `nil` if there is already a frame with the given name. |[setMirror](objects/Frame/setMirror.md)|Sets the frame to mirror onto a monitor (only for base frames)
|[getObject](objects/Frame/getObject.md)|Returns the object by its name (or id)
#### Usage: |[removeObject](objects/Frame/removeObject.md)|Removes the object by its name (or id)
* Create a frame with an id "myFirstFrame", stored in a variable named frame |[setFocusedObject](objects/Frame/setFocusedObject.md)|Sets the currently focused object by this frame
```lua |[removeFocusedObject](objects/Frame/removeFocusedObject.md)|Removes the currenlty focused object (it only removes beeing focused)
local myFrame = basalt.createFrame("myFirstFrame") |[getFocusedObject](objects/Frame/getFocusedObject.md)|Returns the currently focused object
``` |[setMovable](objects/Frame/setMovable.md)|Makes the frame movable (only for sub frames)
|[setOffset](objects/Frame/setOffset.md)|Sets the frames offset (will be added to the childrens x and y positions)
## addFrame |[getOffset](objects/Frame/getOffset.md)|Returns the current x and y offset
Creates a child frame on the frame, the same as [basalt.createFrame](https://github.com/Pyroxenium/Basalt/wiki/Frame#basaltcreateframe) except the frames are given a parent-child relationship automatically |[addLayout](objects/Frame/addLayout.md)|Adds a new XML Layout into the frame
|[addLayoutFromString](objects/Frame/addLayoutFromString.md)|Adds a new XML Layout via string into the frame
#### Parameters: |[getLastLayout](objects/Frame/getLastLayout.md)|Returns a table of all objects generated by the last addLayout/FromString method
1. `string` name (should be unique) |[setTheme](objects/Frame/setTheme.md)|Sets the theme of that frame and all its childrens
|[setScrollable](objects/Frame/setScrollable.md)|Makes the frame scrollable via mousewheel (internally this uses setOffset)
#### Returns: |[setScrollAmount](objects/Frame/setScrollAmount.md)|Sets how far the user is allowed to scroll
1. `frame | nil` The frame created by addFrame, or `nil` if there is already a child frame with the given name.<br>
This is how you would implement frames via xml:
#### Usage:
* Create a new main frame and adds a child frame to it
```lua
local mainFrame = basalt.createFrame()
local myFrame = mainFrame:addFrame()
```
```xml
<frame></frame>
```
## setBar
Sets the text, background, and foreground of the upper bar of the frame, accordingly.
#### Parameters:
1. `string` The title text to set the bar to
2. `number` The background color
2. `number` The foreground color
#### Returns:
1. `frame` The frame being used
#### Usage:
* Set the title to "My first frame!", with a background of black and a foreground of light gray.
```lua
frame:setBar("My first Frame!", colors.black, colors.lightGray)
```
* Store the frame, use the named frame variable after assigning.
```lua
local mainFrame = basalt.createFrame()
local myFrame = MainFrame:addFrame()
myFrame:setBar("My first Frame!")
```
* This abuses the call-chaining that Basalt uses.
```lua
local mainFrame = basalt.createFrame()
local myFrame = mainFrame:addFrame():setBar("My first Frame!")
```
```xml
<frame barText="My first Frame!" barBG="black" barFG="lightGray"></frame>
```
## setBarTextAlign
Sets the frame's bar-text alignment
#### Parameters:
1. `string` Can be supplied with "left", "center", or "right"
#### Returns:
1. `frame` The frame being used
#### Usage:
* Set the title of myFrame to "My first frame!", and align it to the right.
```lua
myFrame:setBar("My first Frame!"):setBarTextAlign("right")
```
```xml
<frame barAlign="right"></frame>
```
## showBar
Toggles the frame's upper bar
#### Parameters:
1. `boolean | nil` Whether the frame's bar is visible or if supplied `nil`, is automatically visible
#### Returns:
1. `frame` The frame being used
#### Usage:
* Sets myFrame to have a bar titled "Hello World!" and subsequently displays it.
```lua
myFrame:setBar("Hello World!"):showBar()
```
```xml
<frame bar="true"></frame>
```
## setMonitor
Sets this frame as a monitor frame
#### Parameters:
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new monitor frame, you can use to show objects on a monitor.
```lua
local mainFrame = basalt.createFrame()
local monitorFrame = basalt.createFrame():setMonitor("right")
monitorFrame:setBar("Monitor 1"):showBar()
```
```xml
<frame monitor="right"></frame>
```
## setMirror
mirrors this frame to another peripheral monitor object.
#### Parameters:
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates mirror of your main frame to a monitor on the left side.
```lua
local mainFrame = basalt.createFrame():setMirror("left")
```
```xml
<frame mirror="left"></frame>
```
## getObject
Returns a child object of the frame
#### Parameters:
1. `string` The name of the child object
#### Returns:
1. `object | nil` The object with the supplied name, or `nil` if there is no object present with the given name
#### Usage:
* Adds a button with id "myFirstButton", then retrieves it again through the frame object
```lua
myFrame:addButton("myFirstButton")
local aButton = myFrame:getObject("myFirstButton")
```
## removeObject
Removes a child object from the frame
#### Parameters:
1. `string` The name of the child object
#### Returns:
1. `boolean` Whether the object with the given name was properly removed
#### Usage:
* Adds a button with the id "myFirstButton", then removes it with the aforementioned id
```lua
myFrame:addButton("myFirstButton")
myFrame:removeObject("myFirstButton")
```
## setFocusedObject
Sets the currently focused object
#### Parameters:
1. `object` The child object to focus on
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new button, sets the focused object to the previously mentioned button
```lua
local aButton = myFrame:addButton()
myFrame:setFocusedObject(aButton)
```
## removeFocusedObject
Removes the focus of the supplied object
#### Parameters:
1. `object` The child object to remove focus from
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new button then removes the focus from that button when clicking on it
```lua
local aButton = myFrame:addButton():setFocus():onClick(function()
myFrame:removeFocusedObject(aButton)
end)
```
## getFocusedObject
Gets the currently focused object
#### Returns:
1. `object` The currently focused object
#### Usage:
* Gets the currently focused object from the frame, storing it in a variable
```lua
local focusedObject = myFrame:getFocusedObject()
```
## setMovable
Sets whether the frame can be moved. _In order to move the frame click and drag the upper bar of the frame_
#### Parameters:
1. `boolean` Whether the object is movable
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a frame with id "myFirstFrame" and makes it movable
```lua
local myFrame = basalt.createFrame():setMovable(true)
```
```xml
<frame moveable="true"></frame>
```
## setOffset
Sets the frame's coordinate offset. The frame's child objects will receive the frame's coordinate offset. For example, when using a scrollbar, if you use its value to add an offset to a frame, you will get a scrollable frame.
Objects are also able to ignore the offset by using :ignoreOffset() (For example, you may want to ignore the offset on the scrollbar itself)
The function can also be supplied with negative values
#### Parameters:
1. `number` The x direction offset (+/-)
2. `number` The y direction offset (+/-)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame with x offset of 5 and a y offset of 3
```lua
local myFrame = basalt.createFrame():setOffset(5, 3)
```
* Creates with x offset of 5 and a y offset of -5 (Meaning if you added a button with y position 5, it would be at y position 0)
```lua
local myFrame = basalt.createFrame():setOffset(5, -5)
```
```xml
<frame xOffset="5" yOffset="-5"></frame>
```
## addLayout
Adds a new XML Layout into your frame.
#### Parameters:
1. `string` Path to your layout
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds the mainframe.xml layout
```lua
local myFrame = basalt.createFrame():addLayout("mainframe.xml")
```
```xml
<frame layout="mainframe.xml"></frame>
```
## addLayoutFromString
Adds a new XML Layout as string into your frame.
#### Parameters:
1. `string` xml
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds the mainframe.xml layout
```lua
local myFrame = basalt.createFrame():addLayoutFromString("<button x='12' y='5' bg='black' />")
```
## getLastLayout
returns a table of all objects this frame has created via xml (useful if you'd like to access all of them for some reason)
#### Returns:
1. `table` table with objects
## setTheme
Sets the default theme of that frame children objects always try to get the theme of its parent frame, if it does not exist it goes to its parent parent frame, and so on until it reaches the basalt managers theme - which is sotred in theme.lua (Please checkout [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for how it could look like.
#### Parameters:
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds a new theme which only changes the default color of buttons.
```lua
local myFrame = basalt.createFrame():setTheme({
ButtonBG = colors.yellow,
ButtonText = colors.red,
})
```
## setScrollable
Makes the frame scrollable with mousewheel.
#### Parameters:
1. `bool` scrollable or not
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable
```lua
local myFrame = basalt.createFrame():setScrollable()
```
```xml
<frame scrollable="true"></frame>
```
## setMinScroll
Sets the minimum offset it is allowed to scroll (default 0)
#### Parameters:
1. `number` minimum y offset
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable and sets the minimum amount to -5
```lua
local myFrame = basalt.createFrame():setScrollable():setMinScroll(-5)
```
```xml
<frame minScroll="-5"></frame>
```
## setMaxScroll
Sets the maximum offset it is allowed to scroll (default 10)
#### Parameters:
1. `number` maximum y offset
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable and sets the maximum amount to 25
```lua
local myFrame = basalt.createFrame():setScrollable():setMaxScroll(25)
```
```xml
<frame maxScroll="25"></frame>
```
## setImportantScroll
By default if you hovering your mouse over children objects, you wont scroll the frame, if you set this to true the frame scrolling becomes more important
#### Parameters:
1. `bool` important or not
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable and defines it as important
```lua
local myFrame = basalt.createFrame():setScrollable():setImportantScroll(true)
```
```xml
<frame importantScroll="true"></frame>
```
# XML Example
*This is how you would implement frames via xml:
```xml ```xml
<frame> <frame>
<frame width="50%" bg="red"> <frame width="parent.w * 0.5" bg="red">
<button x="2" y="2" width="17" text="Example Button!"/> <button x="2" y="2" width="17" text="Example Button!"/>
</frame> </frame>
<frame x="50%+1" width="50%+1" bg="black"> <frame x="parent.w * 0.5 + 1" width="parent.w * 0.5 +1" bg="black">
<textfield bg="green" x="2" width="100%-2" /> <textfield bg="green" x="2" width="parent.w-2" />
</frame> </frame>
</frame> </frame>
``` ```

View File

@@ -0,0 +1,17 @@
## addLayout
Adds a new XML Layout into your frame.
#### Parameters:
1. `string` Path to your layout
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds the mainframe.xml layout
```lua
local myFrame = basalt.createFrame():addLayout("mainframe.xml")
```
```xml
<frame layout="mainframe.xml"></frame>
```

View File

@@ -0,0 +1,14 @@
## addLayoutFromString
Adds a new XML Layout as string into your frame.
#### Parameters:
1. `string` xml
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds the mainframe.xml layout
```lua
local myFrame = basalt.createFrame():addLayoutFromString("<button x='12' y='5' bg='black' />")
```

Some files were not shown because too many files have changed in this diff Show More