-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from cedricduriau/42-numberreciprocal
implement NumberReciprocal
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
-- ============================================================================ | ||
-- constants | ||
-- ============================================================================ | ||
FUSE_NAME = "NumberReciprocal" | ||
DATATYPE = "Number" | ||
|
||
-- ============================================================================ | ||
-- fuse | ||
-- ============================================================================ | ||
FuRegisterClass(FUSE_NAME, CT_Tool, { | ||
REGID_DataType = DATATYPE, | ||
REGID_InputDataType = DATATYPE, | ||
REG_NoCommonCtrls = true, | ||
REGS_Category = "Vonk\\Number", | ||
REGS_Name = FUSE_NAME, | ||
REGS_OpDescription = "Returns the reciprocal of a number.", | ||
REGS_OpIconString = FUSE_NAME | ||
}) | ||
|
||
function Create() | ||
-- [[ Creates the user interface. ]] | ||
InNumber = self:AddInput("Number" , "Number" , { | ||
LINKID_DataType = "Number", | ||
INPID_InputControl = "SliderControl", | ||
LINK_Main = 1, | ||
INP_MinScale = -100, | ||
INP_MaxScale = 100, | ||
INP_Default = 1 | ||
}) | ||
|
||
InShowInput = self:AddInput("Show Input", "ShowInput", { | ||
LINKID_DataType = "Number", | ||
INPID_InputControl = "CheckboxControl", | ||
INP_Integer = true, | ||
INP_Default = 0.0, | ||
INP_External = false, | ||
INP_DoNotifyChanged = true | ||
}) | ||
|
||
OutNumber = self:AddOutput("Output", "Output", { | ||
LINKID_DataType = "Number", | ||
LINK_Main = 1 | ||
}) | ||
end | ||
|
||
function NotifyChanged(inp, param, time) | ||
--[[ | ||
Handles all input control events. | ||
|
||
:param inp: Input that triggered a signal. | ||
:type inp: Input | ||
|
||
:param param: Parameter object holding the (new) value. | ||
:type param: Parameter | ||
|
||
:param time: Current frame number. | ||
:type time: float | ||
]] | ||
if inp == InShowInput then | ||
local visible | ||
if param.Value == 1.0 then visible = true else visible = false end | ||
InNumber:SetAttrs({LINK_Visible = visible}) | ||
end | ||
end | ||
|
||
function Process(req) | ||
-- [[ Creates the output. ]] | ||
local n = InNumber:GetValue(req).Value | ||
|
||
local result = 1 / n | ||
local out = Number(result) | ||
OutNumber:Set(req, out) | ||
end |