mirror of https://github.com/teverse/teverse
Compare commits
6 Commits
ef40aa99e4
...
279552d399
Author | SHA1 | Date |
---|---|---|
Sanjay Bhadra | 279552d399 | |
Sanjay Bhadra | 2961293ec0 | |
Sanjay Bhadra | 4b0a2d0d04 | |
Jay | 68f2c13278 | |
Sanjay Bhadra | 1b62b5147b | |
u-train | e78f01544d |
|
@ -0,0 +1,66 @@
|
|||
local clamp = function(x, min, max)
|
||||
--[[
|
||||
@description
|
||||
Clamps a value x with the given arguments.
|
||||
LuaJit doesn't have it... cringe!
|
||||
@parameters
|
||||
number, x
|
||||
number, min
|
||||
number max
|
||||
@return
|
||||
number, x
|
||||
]]
|
||||
return max <= x and max or (x <= min and min or x)
|
||||
end
|
||||
|
||||
--UI elements
|
||||
local container = teverse.construct("guiScrollView", {
|
||||
scrollbarAlpha = 0;
|
||||
scrollbarWidth = 0;
|
||||
canvasSize = guiCoord(1, 0, 1, 0);
|
||||
})
|
||||
|
||||
local textBox = teverse.construct("guiTextBox", {
|
||||
parent = container;
|
||||
size = container.canvasSize + guiCoord(0, container.absoluteSize.x, 0, 0);
|
||||
backgroundColour = colour(0.9, 0.9, 0.9);
|
||||
textColour = colour(0.5, 0.5, 0.5);
|
||||
textEditable = true;
|
||||
})
|
||||
|
||||
--Horizontial scrolling
|
||||
textBox:on("mouseWheel", function(change)
|
||||
local newLocation = container.canvasOffset + vector2(change.y, change.x) * 2
|
||||
container.canvasOffset = vector2(
|
||||
clamp(newLocation.x, 0, container.canvasSize.offset.x),
|
||||
clamp(newLocation.y, 0, container.canvasSize.offset.y))
|
||||
end)
|
||||
|
||||
--Adjusting canvas to fit the text.
|
||||
textBox:on("changed", function(propertyName)
|
||||
if propertyName == "text" then
|
||||
container.canvasSize = guiCoord(1, 0, 1, 0);
|
||||
textBox.size = container.canvasSize + guiCoord(0, container.absoluteSize.x, 0, 0)
|
||||
end
|
||||
end)
|
||||
|
||||
--Execute the code. If it is "1 + 1", print the result out.
|
||||
--If the code fails, print it out.
|
||||
textBox:on("keyDown", function(key)
|
||||
if key == "KEY_RETURN" or key == "KEY_KP_ENTER" then
|
||||
local success, valueReturned = pcall(loadstring(textBox.text))
|
||||
if not success then
|
||||
success, valueReturned = pcall(loadstring("return "..textBox.text))
|
||||
if not success then
|
||||
print("CONSOLE ERROR: "..valueReturned)
|
||||
else
|
||||
print(valueReturned or "Ran without error.")
|
||||
end
|
||||
else
|
||||
print(valueReturned or "Ran without error.")
|
||||
end
|
||||
textBox.text = ""
|
||||
end
|
||||
end)
|
||||
|
||||
return container
|
|
@ -1,75 +1,90 @@
|
|||
local shared = require("tevgit:core/teverseUI/shared.lua")
|
||||
local draggableUi = shared.draggableUi
|
||||
|
||||
--Generate the UI
|
||||
local container = teverse.construct("guiFrame", {
|
||||
parent = teverse.coreInterface,
|
||||
size = guiCoord(0.1, 150, 0.4, 200),
|
||||
position = guiCoord(0, 20, 0, 20),
|
||||
backgroundAlpha = 0.9,
|
||||
zIndex = 1000,
|
||||
strokeRadius = 2,
|
||||
strokeAlpha = 0.2,
|
||||
visible = false
|
||||
parent = teverse.coreInterface,
|
||||
size = guiCoord(0,
|
||||
math.max(teverse.coreInterface.absoluteSize.x / 3, 100),
|
||||
0,
|
||||
math.max(teverse.coreInterface.absoluteSize.y / 3, 200));
|
||||
position = guiCoord(0, 20, 0, 20);
|
||||
visible = false;
|
||||
strokeWidth = 2;
|
||||
strokeColour = colour(0.75,0.75,0.75);
|
||||
strokeAlpha = 1;
|
||||
strokeRadius = 2;
|
||||
})
|
||||
|
||||
local top = teverse.construct("guiTextBox", {
|
||||
parent = container,
|
||||
size = guiCoord(1, 0, 0, 20),
|
||||
position = guiCoord(0, 0, 0, 0),
|
||||
backgroundAlpha = 0.5,
|
||||
textSize = 20,
|
||||
textAlign = "middleLeft",
|
||||
-- bit hacky but works for slight indent
|
||||
text = " Console",
|
||||
backgroundColour = colour.rgb(112, 112, 112)
|
||||
|
||||
local topBar = teverse.construct("guiFrame", {
|
||||
parent = container;
|
||||
size = guiCoord(1, 0, 0, 20);
|
||||
backgroundColour = colour(0.75, 0.75, 0.75);
|
||||
})
|
||||
|
||||
local logContainer = teverse.construct("guiScrollView", {
|
||||
parent = container,
|
||||
size = guiCoord(1, -10, 1, -27),
|
||||
position = guiCoord(0, 5, 0, 20),
|
||||
backgroundAlpha = 0.0,
|
||||
canvasSize = guiCoord(1, -1, 10, 0),
|
||||
scrollbarWidth = 3,
|
||||
scrollbarRadius = 2
|
||||
local title = teverse.construct("guiTextBox", {
|
||||
parent = topBar;
|
||||
size = guiCoord(1, -24, 1, 0);
|
||||
position = guiCoord(0, 4, 0, 0);
|
||||
backgroundAlpha = 0;
|
||||
active = false;
|
||||
textSize = 20;
|
||||
text = "Console"
|
||||
})
|
||||
|
||||
local leave = teverse.construct("guiFrame", {
|
||||
parent = topBar;
|
||||
size = guiCoord(0, 14, 0, 14);
|
||||
position = guiCoord(1, -16, 0, 2);
|
||||
backgroundColour = colour(0.70, 0.35, 0.35);
|
||||
strokeRadius = 14
|
||||
})
|
||||
|
||||
draggableUi(container, top)
|
||||
local lastPos = 0
|
||||
function addLog (msg, time)
|
||||
local txt = teverse.construct("guiTextBox", {
|
||||
parent = logContainer,
|
||||
size = guiCoord(1, -10, 0, 25),
|
||||
position = guiCoord(0, 5, 0, lastPos),
|
||||
backgroundAlpha = 0,
|
||||
strokeAlpha = 0,
|
||||
textWrap = true,
|
||||
clip = false
|
||||
})
|
||||
txt.text = os.date("%H:%M:%S", time) .. " : " .. msg
|
||||
txt.size = guiCoord(1, -10, 0, txt.textDimensions.y)
|
||||
lastPos = lastPos + txt.textDimensions.y + 3
|
||||
local clear = teverse.construct("guiTextBox", {
|
||||
parent = topBar;
|
||||
text = "C";
|
||||
textColour = colour(0.5, 0.5, 0.5);
|
||||
textAlign = "middle";
|
||||
textSize = 15;
|
||||
size = guiCoord(0, 14, 0, 14);
|
||||
position = guiCoord(1, -32, 0, 2);
|
||||
backgroundColour = colour(0.8, 0.8, 0.8);
|
||||
strokeRadius = 14
|
||||
})
|
||||
|
||||
if string.find(msg, "ERROR:") then
|
||||
txt.textColour = colour.rgb(220, 50, 47)
|
||||
end
|
||||
local commandLine = require("tevgit:core/teverseUI/commandLine.lua")
|
||||
commandLine.parent = container
|
||||
commandLine.size = guiCoord(1, 0, 0, 20)
|
||||
commandLine.position = guiCoord(0, 0, 1, -20)
|
||||
|
||||
-- Update container size
|
||||
logContainer.canvasSize = guiCoord(1, -1, 0.5, lastPos)
|
||||
end
|
||||
-- TODO: Warn/error detection & colours
|
||||
teverse.debug:on("print", function(msg)
|
||||
pcall(function()
|
||||
addLog(msg)
|
||||
end)
|
||||
local log = require("tevgit:core/teverseUI/log.lua")({
|
||||
parent = container;
|
||||
size = guiCoord(1, 0, 1, -40);
|
||||
position = guiCoord(0, 0, 0, 20);
|
||||
scrollbarRadius = 0.01;
|
||||
scrollbarWidth = 4;
|
||||
scrollbarColour = colour(.8,.8,.8);
|
||||
})
|
||||
|
||||
--Allow users to move and resize the console
|
||||
require("tevgit:core/teverseUI/resize.lua")(container)
|
||||
require("tevgit:core/teverseUI/tabMove.lua")(topBar, container)
|
||||
|
||||
--Leave console
|
||||
leave:on("mouseLeftDown", function()
|
||||
container.visible = false
|
||||
end)
|
||||
|
||||
for _,v in pairs(teverse.debug:getOutputHistory()) do
|
||||
addLog(v.message, v.time)
|
||||
end
|
||||
logContainer.canvasOffset = vector2(0, lastPos - 200)
|
||||
--Clear console
|
||||
clear:on("mouseLeftDown", log.clear)
|
||||
|
||||
--Add new logs when a print occurs.
|
||||
teverse.debug:on("print", function(printOut)
|
||||
log.add(os.date("%H:%M:%S", os.time()) .. ": " .. printOut:gsub("\t", ""))
|
||||
end)
|
||||
|
||||
container:on("changed", log.reload)
|
||||
|
||||
--Add any missed debug logs.
|
||||
for _,v in pairs(teverse.debug:getOutputHistory()) do
|
||||
log.add(os.date("%H:%M:%S", v.time).. ": " .. v.message:gsub("\t", ""))
|
||||
end
|
||||
|
||||
return container
|
|
@ -0,0 +1,94 @@
|
|||
local MAX_LIST = 100
|
||||
|
||||
local new = function(properties)
|
||||
--[[
|
||||
@description
|
||||
Creates a new log. The log is displayed through a guiScrollView
|
||||
@parameter
|
||||
table, [properties]
|
||||
@return
|
||||
table, interface
|
||||
]]
|
||||
local viewScroll = teverse.construct("guiScrollView", properties or {})
|
||||
|
||||
local list = {}
|
||||
local interface = {}
|
||||
|
||||
interface.add = function(text)
|
||||
--[[
|
||||
@description
|
||||
Add a new log to the list and display.
|
||||
@parmeter
|
||||
string, text
|
||||
]]
|
||||
local location = #list + 1
|
||||
if (location or 0) > MAX_LIST then
|
||||
--Destroy the first one.
|
||||
local offset = list[1].absoluteSize.y + 2
|
||||
list[1]:destroy()
|
||||
table.remove(list, 1)
|
||||
|
||||
--Shift the items back in place.
|
||||
for _, item in next, list do
|
||||
item.position = item.position - guiCoord(0, 0, 0, offset)
|
||||
end
|
||||
--Shift the size back correctly
|
||||
viewScroll.canvasSize = viewScroll.canvasSize - guiCoord(0, 0, 0, offset)
|
||||
|
||||
location = MAX_LIST
|
||||
end
|
||||
|
||||
list[location] = teverse.construct("guiTextBox", {
|
||||
parent = viewScroll;
|
||||
text = text;
|
||||
textWrap = true;
|
||||
position = guiCoord(0, 0, 0, viewScroll.canvasSize.offset.y);
|
||||
size = guiCoord(1, 0, 1, 0);
|
||||
})
|
||||
|
||||
--Shift accordingly
|
||||
local textDimensions = list[location].textDimensions
|
||||
list[location].size = guiCoord(1, 0, 0, textDimensions.y)
|
||||
viewScroll.canvasSize = viewScroll.canvasSize + guiCoord(0, 0, 0, textDimensions.y + 2)
|
||||
end
|
||||
|
||||
interface.reload = function()
|
||||
--[[
|
||||
@description
|
||||
Rerenders the log.
|
||||
]]
|
||||
local offset = 0
|
||||
viewScroll.canvasSize = guiCoord(1, 0, 0, 0)
|
||||
|
||||
for _, child in next, list do
|
||||
child.position = guiCoord(0, 0, 0, viewScroll.canvasSize.offset.y);
|
||||
child.size = guiCoord(1, 0, 1, 0);
|
||||
|
||||
--Shift accordingly
|
||||
local textDimensions = child.textDimensions
|
||||
child.size = guiCoord(1, 0, 0, textDimensions.y)
|
||||
viewScroll.canvasSize = viewScroll.canvasSize + guiCoord(0, 0, 0, textDimensions.y + 2)
|
||||
offset = textDimensions.y + offset
|
||||
end
|
||||
end
|
||||
|
||||
interface.clear = function()
|
||||
--[[
|
||||
@description
|
||||
Clears the logs
|
||||
]]
|
||||
list = {}
|
||||
viewScroll:destroyChildren()
|
||||
interface.reload()
|
||||
viewScroll.canvasOffset = vector2()
|
||||
end
|
||||
|
||||
viewScroll:on("changed", function(changed)
|
||||
if changed == "canvasSize" then return end
|
||||
interface.reload()
|
||||
end)
|
||||
interface.viewScroll = viewScroll
|
||||
return interface
|
||||
end
|
||||
|
||||
return new
|
|
@ -0,0 +1,124 @@
|
|||
local directionOfResizeOfAxis = function(object, mousePosition, spacing, axis)
|
||||
--[[
|
||||
@description
|
||||
For a given axis, check the direction we are moving it.
|
||||
If we aren't moving it, set it to zero.
|
||||
@parameters
|
||||
guiObject, object
|
||||
vector2, mousePosition
|
||||
number, spacing
|
||||
string, axis
|
||||
@returns
|
||||
number, direction
|
||||
]]
|
||||
if mousePosition[axis] < object.absoluteSize[axis] + object.absolutePosition[axis] + spacing
|
||||
and mousePosition[axis] > object.absoluteSize[axis] + object.absolutePosition[axis] then
|
||||
return 1;
|
||||
elseif mousePosition[axis] < object.absolutePosition[axis]
|
||||
and mousePosition[axis] > object.absolutePosition[axis] - spacing then
|
||||
return -1
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
local directionOfResize = function(object, mousePosition, spacing)
|
||||
--[[
|
||||
@description
|
||||
Returns the direction of the resize for all axel.
|
||||
@parameters
|
||||
guiObject, object
|
||||
vector2, mousePosition
|
||||
number, spacing
|
||||
@return
|
||||
vector2, direction
|
||||
]]
|
||||
return vector2(
|
||||
directionOfResizeOfAxis(object, mousePosition, spacing, "x"),
|
||||
directionOfResizeOfAxis(object, mousePosition, spacing, "y")
|
||||
)
|
||||
end
|
||||
|
||||
local sizeAxisBy = function(object, mousePosition, direction, axis)
|
||||
--[[
|
||||
@description
|
||||
Returns a new size for the object for an axis.
|
||||
@parameters
|
||||
guiObject, object
|
||||
vector2, mousePosition
|
||||
number, direction
|
||||
axis, string
|
||||
@return
|
||||
number, newSize
|
||||
]]
|
||||
local size = mousePosition[axis] - object.absolutePosition[axis]
|
||||
if direction == 0 then
|
||||
size = object.absoluteSize[axis]
|
||||
elseif direction == -1 then
|
||||
size = object.absoluteSize[axis] + size * -1
|
||||
end
|
||||
return size
|
||||
end
|
||||
|
||||
local sizeBy = function(object, mousePosition, direction)
|
||||
--[[
|
||||
@description
|
||||
Return a new size guiCoord for the given object
|
||||
@parameters
|
||||
guiObject, object
|
||||
vector2, mousePosition
|
||||
vector2, direction
|
||||
@return
|
||||
guiCoord, newSize
|
||||
]]
|
||||
return guiCoord(
|
||||
0,
|
||||
sizeAxisBy(object, mousePosition, direction.x, "x"),
|
||||
0,
|
||||
sizeAxisBy(object, mousePosition, direction.y , "y")
|
||||
)
|
||||
end
|
||||
|
||||
local new = function(object, spacing)
|
||||
--[[
|
||||
@description
|
||||
Spacing is a defined padding around the object.
|
||||
Allows given object to be resized like a window.
|
||||
So, whenever a user hovers over a vaild area (defined by the padding aformentioned)
|
||||
they can click and hold to resize in that direction.
|
||||
@parameters
|
||||
guiObject, object
|
||||
number, [spacing]
|
||||
@return
|
||||
function, destructor
|
||||
]]
|
||||
spacing = spacing or 5
|
||||
|
||||
local debounce = false
|
||||
local onMouseLeftDown = teverse.input:on("mouseLeftDown", function()
|
||||
if debounce then return end
|
||||
debounce = true
|
||||
|
||||
local mousePosition = teverse.input.mousePosition
|
||||
local direction = directionOfResize(object, mousePosition, spacing)
|
||||
|
||||
local onMouseMoved
|
||||
local onMouseLeftUp
|
||||
|
||||
onMouseMoved = teverse.input:on("mouseMoved", function()
|
||||
local newMousePosition = teverse.input.mousePosition
|
||||
object.size = sizeBy(object, newMousePosition, direction)
|
||||
if direction.x == -1 then object.position = guiCoord(0, newMousePosition.x, 0, object.absolutePosition.y) end
|
||||
if direction.y == -1 then object.position = guiCoord(0, object.absolutePosition.x, 0, newMousePosition.y) end
|
||||
end)
|
||||
onMouseLeftUp = teverse.input:on("mouseLeftUp", function()
|
||||
teverse.disconnect(onMouseMoved)
|
||||
teverse.disconnect(onMouseLeftUp)
|
||||
debounce = false
|
||||
end)
|
||||
end)
|
||||
|
||||
return function() teverse.disconnect(onMouseLeftDown) end
|
||||
end
|
||||
|
||||
return new
|
|
@ -1,33 +0,0 @@
|
|||
function draggableUi (uiToMove, activator)
|
||||
local mouseIsDown = false
|
||||
if not uiToMove then
|
||||
return error("Failed to create draggableUi: No UI provided!")
|
||||
end
|
||||
if not activator then
|
||||
activator = uiToMove
|
||||
end
|
||||
local evA = activator:on("mouseLeftDown", function( mousePos )
|
||||
mouseIsDown = true
|
||||
local startPos = uiToMove.position:get2D(teverse.input.screenSize)
|
||||
local offset = teverse.input.mousePosition - startPos
|
||||
|
||||
spawn(function ()
|
||||
while mouseIsDown do
|
||||
-- Calculate new position relative to the mouse pointer
|
||||
local mousePos = teverse.input.mousePosition
|
||||
local targetPos = mousePos - offset
|
||||
|
||||
uiToMove.position = guiCoord(0, targetPos.x, 0, targetPos.y)
|
||||
sleep()
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
local evB = teverse.input:on("mouseLeftUp", function( mousePosition )
|
||||
mouseIsDown = false
|
||||
end)
|
||||
end
|
||||
return {
|
||||
draggableUi = draggableUi
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
local new = function(targetObject, movingObject)
|
||||
--[[
|
||||
@description
|
||||
Given a targetObject, whenever the user holds down and move,
|
||||
it will also move another object. It will move by the delta
|
||||
of the mouse.
|
||||
@parameter
|
||||
guiObject, targetObject
|
||||
guiObject, movingObject
|
||||
@return
|
||||
function, destructor
|
||||
]]
|
||||
|
||||
local debounce = false
|
||||
local onMouseLeftDown = targetObject:on("mouseLeftDown", function(startingMousePosition)
|
||||
if debounce then return end
|
||||
debounce = true
|
||||
|
||||
local offset = startingMousePosition - targetObject.absolutePosition
|
||||
local onMove
|
||||
local onRelease
|
||||
|
||||
onMove = teverse.input:on("mouseMoved", function()
|
||||
local mousePosition = teverse.input.mousePosition
|
||||
movingObject.position = guiCoord(0, mousePosition.x - offset.x, 0, mousePosition.y - offset.y)
|
||||
end)
|
||||
|
||||
onRelease = teverse.input:on("mouseLeftUp", function()
|
||||
teverse.disconnect(onMove)
|
||||
teverse.disconnect(onRelease)
|
||||
debounce = false
|
||||
end)
|
||||
end)
|
||||
|
||||
return function() teverse.disconnect(onMouseLeftDown) end
|
||||
end
|
||||
|
||||
|
||||
return new
|
|
@ -10,13 +10,7 @@ $output v_normal, v_colour, v_position, v_pbr
|
|||
*/
|
||||
|
||||
#include <teverse.sh>
|
||||
#define __BUFFER_XX(_name, _type, _reg, _access) \
|
||||
layout(std430, binding=_reg) _access buffer _name ## Buffer \
|
||||
{ \
|
||||
_type _name[]; \
|
||||
}
|
||||
|
||||
#define BUFFER_RO(_name, _type, _reg) __BUFFER_XX(_name, _type, _reg, readonly)
|
||||
#include <teverse_compute.sh>
|
||||
|
||||
BUFFER_RO(normalData, vec4, 2);
|
||||
|
||||
|
|
Loading…
Reference in New Issue