Files

66 lines
2.6 KiB
Luau

-- ImCurveEdit: the RampEdit delegate from upstream's example (3 smooth curves). Drag points, box-select with the
-- left mouse, Shift to add to the selection, double-click a curve to add a point, drag a curve to move it,
-- mouse wheel zooms Y, middle mouse scrolls Y.
local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local G = require(RS:WaitForChild("ImGui"))
local ImCurveEdit = require(RS:WaitForChild("ImCurveEdit"))(G)
local ImGui, ImVec2 = G.ImGui, G.ImVec2
local RampEdit = {
mPts = {
{ ImVec2(-10, 0), ImVec2(20, 0.6), ImVec2(25, 0.2), ImVec2(70, 0.4), ImVec2(120, 1) },
{ ImVec2(-50, 0.2), ImVec2(33, 0.7), ImVec2(80, 0.2), ImVec2(82, 0.8) },
{ ImVec2(40, 0), ImVec2(60, 0.1), ImVec2(90, 0.82), ImVec2(150, 0.24), ImVec2(200, 0.34), ImVec2(250, 0.12) },
},
mbVisible = { true, true, true },
mMin = ImVec2(-100, 0),
mMax = ImVec2(300, 1),
}
function RampEdit:GetCurveCount() return 3 end
function RampEdit:IsVisible(c) return self.mbVisible[c] end
function RampEdit:GetPointCount(c) return #self.mPts[c] end
function RampEdit:GetCurveColor(c) return ({ 0xFF0000FF, 0xFF00FF00, 0xFFFF0000 })[c] end
function RampEdit:GetPoints(c) return self.mPts[c] end
function RampEdit:GetCurveType(c) return ImCurveEdit.CurveSmooth end
function RampEdit:SortValues(c) table.sort(self.mPts[c], function(a, b) return a.x < b.x end) end
function RampEdit:EditPoint(c, p, value)
self.mPts[c][p] = ImVec2(value.x, value.y)
self:SortValues(c)
for i, pt in self.mPts[c] do
if pt.x == value.x then return i end
end
return p
end
function RampEdit:AddPoint(c, value)
if #self.mPts[c] >= 8 then return end
table.insert(self.mPts[c], value)
self:SortValues(c)
end
function RampEdit:GetMax() return self.mMax end
function RampEdit:GetMin() return self.mMin end
function RampEdit:GetBackgroundColor() return 0 end
local selectedPoints = {}
local labels = { "Translation", "Rotation", "Scale" }
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init() -- defaults to LocalPlayer.PlayerGui
RunService.RenderStepped:Connect(function()
G.ImGui_ImplRoblox.NewFrame()
ImGui.NewFrame()
ImGui.SetNextWindowSize(ImVec2(700, 400), G.ImGuiCond.FirstUseEver)
ImGui.Begin("ImCurveEdit")
for i = 1, 3 do
_, RampEdit.mbVisible[i] = ImGui.Checkbox(labels[i], RampEdit.mbVisible[i])
ImGui.SameLine()
end
ImGui.Text("selected: %d", #selectedPoints)
local avail = ImGui.GetContentRegionAvail()
local _
_, selectedPoints = ImCurveEdit.Edit(RampEdit, ImVec2(avail.x, avail.y), 137, nil, selectedPoints)
ImGui.End()
ImGui.Render()
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
end)