-- Click selects a point, dragging moves its position (w), double-click on empty space adds a point. local RS = game:GetService("ReplicatedStorage") local G = require(RS:WaitForChild("ImGui")) local ImGradient = require(RS:WaitForChild("ImGradient"))(G) local ImGui, ImVec2, ImVec4 = G.ImGui, G.ImVec2, G.ImVec4 ImGui.CreateContext() G.ImGui_ImplRoblox.Init() local io = ImGui.GetIO() local D = { Points = { ImVec4(1, 0, 0, 0), ImVec4(0, 0, 1, 0.5) }, Added = nil } function D:GetPointCount() return #self.Points end function D:GetPoints() return self.Points end function D:EditPoint(i, v) self.Points[i] = v; return i end function D:GetPoint(t) return ImVec4(0, 1, 0, t) end function D:AddPoint(v) self.Added = v; table.insert(self.Points, v) end local Size = ImVec2(400, 20) local frame, done, origin = 0, false, nil local selection, changed = -1, false local function pt(w) -- center of the point square at position w return ImVec2(origin.x + (Size.x - Size.y) * w + Size.y / 2, origin.y + Size.y / 2) end game:GetService("RunService").Stepped:Connect(function() if done then return end frame += 1 G.ImGui_ImplRoblox.NewFrame() io.DeltaTime = 1 / 60 if frame == 3 then local p = pt(0.5); io:AddMousePosEvent(p.x, p.y) elseif frame == 4 then io:AddMouseButtonEvent(0, true) elseif frame >= 6 and frame <= 9 then local p = pt(0.5); io:AddMousePosEvent(p.x + (frame - 5) * 8, p.y) -- frame 5: held still (picks the point) elseif frame == 10 then io:AddMouseButtonEvent(0, false) elseif frame == 14 then io:AddMousePosEvent(origin.x + Size.x * 0.9, origin.y + 5) elseif frame == 15 or frame == 17 then io:AddMouseButtonEvent(0, true) elseif frame == 16 or frame == 18 then io:AddMouseButtonEvent(0, false) end ImGui.NewFrame() ImGui.SetNextWindowPos(ImVec2(0, 0)) ImGui.SetNextWindowSize(ImVec2(500, 200)) ImGui.Begin("Gradient") origin = ImGui.GetCursorScreenPos() changed, selection = ImGradient.Edit(D, Size, selection) ImGui.End() ImGui.Render() G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData()) if frame == 4 then assert(selection == 2, "click did not select point 2: " .. selection) elseif frame == 12 then local w = D.Points[2].w assert(w > 0.55 and w <= 1, "drag did not move point 2: " .. w) assert(D.Points[1].w == 0, "point 1 moved") elseif frame == 20 then done = true assert(D.Added and math.abs(D.Added.w - 0.9) < 0.01, "double-click did not add a point at 0.9") assert(#D.Points == 3) print("OK") end end)