Skip to content

Commit

Permalink
Event triggering
Browse files Browse the repository at this point in the history
Explores an API for triggering events and querying them at runtime.

For Flutter we expose an onEvent callback that you can add a callback to on the StateMachineController:
```dart
final controller = StateMachineController.fromArtboard(artboard, 'bumpy', onEvent: {);
controller.onEvent = (event) {
  // Do something with event. Like:
  if(event is OpenURLEvent) {
    launchUrl(event.url);
  }
};
artboard.addController(controller!);
```

Note that I haven't piped onEvent to the Flutter runtime yet but you'll see it in the StateMachineController in core.

In C++:
```c++
auto count = stateMachineInstance->firedEventCount();
for(auto i = 0; i < count; i++) {
  auto event = stateMachineInstance->firedEventAt(i);
  if(event->is<OpenURLEvent>()) {
    // Do something with the url.
    auto url = event->as<OpenURLEvent>()->url();
  }
}
```

You can see some of this in action in the state_machine_event_test.cpp.

You can also see the events in the console in the editor:
<img width="717" alt="CleanShot 2023-08-10 at 18 03 22@2x" src="https://github.com/rive-app/rive/assets/454182/af21902a-424d-435b-b5b0-2a43701fe186">

In a follow up PR:
- Ability to trigger events from State (in/out) and Transition (start/end).
- Add custom properties to Events C++ API (currently they are loaded but not tracked against their respective events).

Diffs=
8caa7d377 Event triggering (#5793)

Co-authored-by: Luigi Rosso <[email protected]>
  • Loading branch information
luigi-rosso and luigi-rosso committed Aug 14, 2023
1 parent 00866e5 commit 7a06c74
Show file tree
Hide file tree
Showing 48 changed files with 1,292 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e71ae68ba09767f246bf3d779f38bb731cf7da9a
8caa7d377f368af8c667ca209a2ce7aef8679be2
21 changes: 21 additions & 0 deletions dev/defs/animation/listener_fire_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "ListenerFireEvent",
"key": {
"int": 168,
"string": "listenerfireevent"
},
"extends": "animation/listener_action.json",
"properties": {
"eventId": {
"type": "Id",
"typeRuntime": "uint",
"initialValue": "Core.missingId",
"initialValueRuntime": "-1",
"key": {
"int": 389,
"string": "eventid"
},
"description": "Id of the Event referenced."
}
}
}
12 changes: 11 additions & 1 deletion dev/defs/animation/state_machine_component.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
},
"description": "Order of this component in the state machine. Exported in order for runtime",
"runtime": false
},
"folderId": {
"type": "Id",
"initialValue": "Core.missingId",
"key": {
"int": 311,
"string": "folderid"
},
"description": "Id of the folder this state machine component belongs to",
"runtime": false
}
}
}
}
9 changes: 9 additions & 0 deletions dev/defs/animation/state_machine_component_folder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "StateMachineComponentFolder",
"key": {
"int": 151,
"string": "statemachinecomponentfolder"
},
"extends": "animation/state_machine_component.json",
"runtime": false
}
9 changes: 9 additions & 0 deletions dev/defs/animation/state_machine_input_folder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "StateMachineInputFolder",
"key": {
"int": 149,
"string": "statemachineinputfolder"
},
"extends": "animation/state_machine_component_folder.json",
"runtime": false
}
9 changes: 9 additions & 0 deletions dev/defs/animation/state_machine_listener_folder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "StateMachineListenerFolder",
"key": {
"int": 150,
"string": "statemachinelistenerfolder"
},
"extends": "animation/state_machine_component_folder.json",
"runtime": false
}
6 changes: 3 additions & 3 deletions dev/defs/artboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@
"runtime": false,
"coop": false
},
"expandedAnimationFolders": {
"expandedFolders": {
"type": "List<Id>",
"initialValue": "[]",
"key": {
"int": 283,
"string": "expandedanimationfolders"
},
"description": "List of expanded animation folders",
"description": "List of expanded folders",
"runtime": false,
"coop": false
},
Expand All @@ -125,4 +125,4 @@
"coop": false
}
}
}
}
36 changes: 34 additions & 2 deletions dev/defs/assets/font_asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,37 @@
"int": 141,
"string": "fontasset"
},
"extends": "assets/file_asset.json"
}
"extends": "assets/file_asset.json",
"properties": {
"isCustom": {
"type": "bool",
"initialValue": "true",
"key": {
"int": 309,
"string": "iscustom"
},
"description": "True if the font is a custom font, i.e the user has uploaded it",
"runtime": false
},
"includeTypeValue": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 360,
"string": "includetypevalue"
},
"description": "Which characters of the font to include for export: all, used or custom.",
"runtime": false
},
"includedUnicodes": {
"type": "String",
"initialValue": "''",
"key": {
"int": 361,
"string": "includedunicodes"
},
"description": "Included unicodes when exporting, in U+0040-0080, format.",
"runtime": false
}
}
}
158 changes: 157 additions & 1 deletion dev/defs/backboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
"description": "The background color.",
"runtime": false
},
"animateColorValue": {
"type": "Color",
"initialValue": "0xFF1D1D1D",
"key": {
"int": 354,
"string": "animatecolorvalue"
},
"description": "The background color while in Animate mode",
"runtime": false,
"coop": false
},
"editorMode": {
"type": "uint",
"initialValue": "0",
Expand Down Expand Up @@ -146,6 +157,61 @@
"runtime": false,
"coop": false
},
"targetsEnabled": {
"type": "bool",
"initialValue": "true",
"key": {
"int": 379,
"string": "targetsenabled"
},
"description": "If targets and empty groups are enabled for this file",
"runtime": false,
"coop": false
},
"motionPathsEnabled": {
"type": "bool",
"initialValue": "true",
"key": {
"int": 351,
"string": "motionpathsenabled"
},
"description": "If motion paths are enabled for this file",
"runtime": false,
"coop": false
},
"showFinalPlaybackEnabled": {
"type": "bool",
"initialValue": "true",
"key": {
"int": 355,
"string": "showfinalplaybackenabled"
},
"description": "If final playback (hiding gizmos during playback) are enabled for this file",
"runtime": false,
"coop": false
},
"showModifierRange": {
"type": "bool",
"initialValue": "true",
"key": {
"int": 374,
"string": "showmodifierrange"
},
"description": "Whether text modifier ranges show on the stage",
"runtime": false,
"coop": false
},
"showModifierRangeValues": {
"type": "bool",
"initialValue": "false",
"key": {
"int": 375,
"string": "showmodifierrangevalues"
},
"description": "Whether text modifier range values show on the stage",
"runtime": false,
"coop": false
},
"toolbarOutputAction": {
"type": "uint",
"initialValue": "0",
Expand All @@ -156,6 +222,96 @@
"description": "Primary output action in the toolbar (share, publish, download)",
"runtime": false,
"coop": false
},
"assetsPanelState": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 315,
"string": "assetspanelstate"
},
"runtime": false,
"coop": false
},
"defaultFontFamily": {
"type": "String",
"initialValue": "'Inter'",
"key": {
"int": 343,
"string": "defaultfontfamily"
},
"runtime": false,
"coop": false
},
"isDefaultFontFamilyCustom": {
"type": "bool",
"initialValue": "false",
"key": {
"int": 352,
"string": "isdefaultfontfamilycustom"
},
"runtime": false,
"coop": false
},
"defaultFontStyle": {
"type": "String",
"initialValue": "'Regular'",
"key": {
"int": 344,
"string": "defaultfontstyle"
},
"runtime": false,
"coop": false
},
"defaultFontSize": {
"type": "double",
"initialValue": "20.0",
"key": {
"int": 345,
"string": "defaultfontsize"
},
"runtime": false,
"coop": false
},
"defaultTextAlign": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 346,
"string": "defaulttextalign"
},
"runtime": false,
"coop": false
},
"defaultTextOverflow": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 347,
"string": "defaulttextoverflow"
},
"runtime": false,
"coop": false
},
"defaultTextHighlightTextRuns": {
"type": "bool",
"initialValue": "false",
"key": {
"int": 348,
"string": "defaulttexthighlighttextruns"
},
"runtime": false,
"coop": false
},
"defaultCollapseTags": {
"type": "bool",
"initialValue": "false",
"key": {
"int": 387,
"string": "defaultcollapsetags"
},
"runtime": false,
"coop": false
}
}
}
}
40 changes: 40 additions & 0 deletions dev/defs/clipboard_header.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "ClipboardHeader",
"key": {
"int": 146,
"string": "clipboardheader"
},
"runtime": false,
"properties": {
"fileId": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 293,
"string": "fileid"
},
"description": "File clipboard contents has come from.",
"runtime": false
},
"projectId": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 294,
"string": "projectid"
},
"description": "Project clipboard contents has come from.",
"runtime": false
},
"clipboardTypeValue": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 295,
"string": "clipboardtypevalue"
},
"description": "Type of clipboard used to read these bytes",
"runtime": false
}
}
}
10 changes: 10 additions & 0 deletions dev/defs/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
},
"description": "Identifier used to track parent ContainerComponent."
},
"tagIds": {
"type": "List<Id>",
"initialValue": "[]",
"key": {
"int": 382,
"string": "tagids"
},
"description": "Assigned tag ids.",
"runtime": false
},
"childOrder": {
"type": "FractionalIndex",
"initialValue": "FractionalIndex.invalid",
Expand Down
9 changes: 9 additions & 0 deletions dev/defs/custom_property.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "CustomProperty",
"key": {
"int": 167,
"string": "customproperty"
},
"abstract": true,
"extends": "component.json"
}
Loading

0 comments on commit 7a06c74

Please sign in to comment.