### Example: Get Artboard Instance and State Machine Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Shows how to obtain the default artboard instance from a Rive file and then retrieve a specific state machine by its name. ```cpp auto artboardInstance = riveFile->artboardDefault(); auto stateMachine = artboardInstance->stateMachineNamed("PlayerController"); ``` -------------------------------- ### Example: Reset State Machine and Advance Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Illustrates resetting a state machine instance to its initial state and then immediately advancing it by zero time. This ensures the animation starts from its default configuration. ```cpp stateMachineInstance->resetState(); stateMachineInstance->advance(0); ``` -------------------------------- ### Example: Setting a Boolean Input Value Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Demonstrates how to get a boolean input by name and set its value. This is a common pattern for controlling animation playback based on application logic. ```cpp SMIBool* isRunning = stateMachineInstance->getBool("isRunning"); if (isRunning) { isRunning->value(true); } ``` -------------------------------- ### Complete Rive Pipeline Setup Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/factory.md Illustrates the creation of a complete Rive rendering pipeline, including factory instantiation, file loading, artboard and state machine setup, rendering object creation, and a basic render loop. ```cpp // Create factory (implementation-specific) rcp factory = createMetalFactory(); // or Vulkan, DirectX, etc. // Load Rive file ImportResult result; rcp riveFile = File::import(fileData, factory.get(), &result); if (result != ImportResult::success) { return; // Handle error } // Create artboard instance auto artboardInstance = riveFile->artboardDefault(); auto stateMachine = artboardInstance->stateMachineNamed("MyStateMachine"); // Create rendering objects rcp fillPaint = factory->makeRenderPaint(); fillPaint->style(RenderPaintStyle::fill); fillPaint->color(0x000000FF); // Black rcp strokePaint = factory->makeRenderPaint(); strokePaint->style(RenderPaintStyle::stroke); strokePaint->color(0xFFFFFFFF); // White strokePaint->thickness(2.0f); // Main loop while (running) { // Update stateMachine->advance(deltaTime); // Render renderer->save(); renderer->drawPath(path, fillPaint.get()); renderer->restore(); } ``` -------------------------------- ### Example: Get Animation Duration and Playback Time Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Shows how to retrieve the animation definition and then access its duration in seconds. ```cpp const LinearAnimation* definition = linearAnimationInstance->animation(); float duration = definition->durationSeconds(); ``` -------------------------------- ### Complete Player Controller Example with State Machine Inputs Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/inputs.md This example demonstrates how to control a player character's animation states by setting various input types (boolean, number, trigger) on a state machine instance. It requires including the Rive file header and assumes an input handler is available. ```cpp #include "rive/file.hpp" #include // Create a player controller example void updatePlayerController(StateMachineInstance* sm, float deltaTime) { // Boolean inputs SMIBool* isMoving = sm->getBool("isMoving"); SMIBool* isJumping = sm->getBool("isJumping"); // Numeric inputs SMINumber* direction = sm->getNumber("direction"); // -1, 0, 1 SMINumber* speed = sm->getNumber("speed"); // 0-10 // Trigger inputs SMITrigger* attack = sm->getTrigger("attack"); SMITrigger* dash = sm->getTrigger("dash"); // Update based on player input if (inputHandler.isKeyDown(Key::Left)) { isMoving->value(true); direction->value(-1.0f); speed->value(3.0f); } else if (inputHandler.isKeyDown(Key::Right)) { isMoving->value(true); direction->value(1.0f); speed->value(3.0f); } else { isMoving->value(false); direction->value(0.0f); speed->value(0.0f); } // Handle jump if (inputHandler.wasKeyPressed(Key::Space)) { isJumping->value(true); } // Handle attack if (inputHandler.wasKeyPressed(Key::Mouse1)) { attack->fire(); } // Handle dash if (inputHandler.wasKeyPressed(Key::Shift)) { dash->fire(); } // Advance the state machine sm->advance(deltaTime); } ``` -------------------------------- ### Install clang-format on MacOS Source: https://github.com/rive-app/rive-runtime/blob/main/README.md Use Homebrew to install clang-format for code formatting. ```bash brew install clang-format ``` -------------------------------- ### Install Valgrind on MacOS Source: https://github.com/rive-app/rive-runtime/blob/main/README.md Follow these steps to install Valgrind for memory checks on MacOS. ```bash brew tap LouisBrunner/valgrind brew install --HEAD LouisBrunner/valgrind/valgrind ``` -------------------------------- ### Scripting Setup Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/README.md Initialize and set a scripting virtual machine to enable Lua scripting within animations. ```cpp rcp vm = createScriptingVM(); riveFile->setScriptingVM(vm); // Scripts in .riv file now execute ``` -------------------------------- ### ImageSampler Usage Example Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/types.md Shows how to apply an ImageSampler when drawing an image. This example uses linear interpolation for smoother rendering. ```cpp renderer->drawImage(image, ImageSampler::linear, BlendMode::srcOver, 1.0f); ``` -------------------------------- ### Mat2D Usage Example Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/utilities.md Shows how to create, compose, and apply 2D transformations using Mat2D. ```cpp // Create transformations Mat2D translation = Mat2D::fromTranslate(10, 20); Mat2D scale = Mat2D::fromScale(2.0f, 2.0f); Mat2D rotation = Mat2D::fromRotation(3.14159f / 4); // 45 degrees // Compose Mat2D combined = translation * rotation; // Apply to vector Vec2D point(1, 0); Vec2D transformed = combined * point; // Invert Mat2D inverse = combined; if (inverse.invert()) { // Successfully inverted } ``` -------------------------------- ### Get Animation Start Time Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Retrieves the start time of a linear animation in seconds. ```cpp float startSeconds() const; ``` -------------------------------- ### Data Binding Setup Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/README.md Bind a data context to the state machine to enable driving and reading bound data. ```cpp rcp dataContext = createDataContext(); stateMachine->bindDataContext(dataContext); // Now state machine can drive/read bound data ``` -------------------------------- ### Runtime Artboard and State Machine Setup Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/README.md Configure artboard properties like frame origin and volume, and set up the state machine with data context and focus manager. ```cpp // Artboard setup artboardInstance->frameOrigin(false); // World-space composition artboardInstance->volume(0.5f); // Audio volume // State machine setup stateMachine->bindDataContext(dataContext); stateMachine->setExternalFocusManager(parentFocusManager); stateMachine->enableSemantics(); ``` -------------------------------- ### Build and Run Rive Renderer (Release) Source: https://github.com/rive-app/rive-runtime/blob/main/renderer/README.md Build the Rive Renderer in release mode and run the path_fiddle example. Provide the path to your .riv file as an argument. ```bash build_rive.sh release out/release/path_fiddle [/path/to/my.riv] ``` -------------------------------- ### Create Render Path with Fill Rule Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/types.md Example of creating a render path with a specified fill rule. The 'factory' object must be initialized. ```cpp rcp path = factory->makeRenderPath(rawPath, FillRule::evenOdd); ``` -------------------------------- ### Get All Artboards Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/artboard.md Retrieves all Artboard definitions from the containing file. ```cpp std::vector artboards(); ``` -------------------------------- ### dragStart() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Processes a drag start event. This method initiates a drag operation, typically when a pointer is moved after a press. ```APIDOC ## dragStart() ### Description Processes a drag start event. ### Method ```cpp HitResult dragStart(Vec2D position, float timeStamp = 0, bool disablePointer = true, int pointerId = 0) ``` ### Parameters #### Path Parameters - **position** (Vec2D) - Required - Pointer position - **timeStamp** (float) - Optional - The time stamp of the event. Defaults to 0. - **disablePointer** (bool) - Optional - Whether to disable pointer events during drag. Defaults to true. - **pointerId** (int) - Optional - ID for multi-touch support. Defaults to 0. ### Returns - **HitResult** ``` -------------------------------- ### Vec2D Usage Example Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/utilities.md Demonstrates basic usage of Vec2D for position calculations and length determination. ```cpp Vec2D pos1(10, 20); Vec2D pos2(30, 40); Vec2D distance = pos2 - pos1; float length = distance.length(); ``` -------------------------------- ### Example: Play Animation Backwards Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Illustrates how to set the animation direction to play backwards by passing a negative value to the direction setter. ```cpp // Play animation backwards linearAnimationInstance->direction(-1); ``` -------------------------------- ### Accessibility Semantics Setup Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/README.md Enable semantics for the state machine to build accessible UIs and access the semantic manager for screen reader integration. ```cpp stateMachine->enableSemantics(); SemanticManager* semMgr = stateMachine->semanticManager(); // Semantic tree available for screen readers ``` -------------------------------- ### Custom Asset Loader Example Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/configuration.md Implement a custom `FileAssetLoader` to handle loading of assets like images, fonts, or audio from various sources such as memory or network. The default loader uses the filesystem. ```cpp // Use default file-based asset loader class FileAssetLoader { virtual ~FileAssetLoader() = default; // Loads assets from filesystem }; // Custom loader example class CustomAssetLoader : public FileAssetLoader { // Override to load from memory, network, etc. }; rcp loader = new CustomAssetLoader(); rcp file = File::import(data, factory, nullptr, loader); ``` -------------------------------- ### Example: Advancing State Machine Animation Loop Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Demonstrates a typical animation loop where the state machine is advanced on each frame. The loop continues as long as the animation is running. ```cpp float deltaTime = 0.016f; // 60 FPS while (running) { stateMachineInstance->advance(deltaTime); artboardInstance->draw(renderer); } ``` -------------------------------- ### Span Usage Example Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/types.md Demonstrates how to create and use a Span to pass file data to the File::import function. Ensure the data source outlives the Span. ```cpp std::vector fileData = loadFile("animation.riv"); rcp file = File::import( rive::Span(fileData.data(), fileData.size()), factory ); ``` -------------------------------- ### Example: Play Animation and Render Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md A common pattern for playing a linear animation, advancing it over time, applying its state, and rendering the artboard until the animation completes. ```cpp while (animating) { bool shouldContinue = linearAnimationInstance->advance(0.016f); linearAnimationInstance->apply(); renderer->drawArtboard(artboardInstance.get()); if (!shouldContinue) { animating = false; } } ``` -------------------------------- ### AABB Usage Example Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/utilities.md Illustrates how to use AABB for visibility checks, intersections, and point containment. ```cpp AABB viewport(0, 0, 1920, 1080); AABB content = artboard->bounds(); if (viewport.contains(Vec2D(100, 100))) { // Point is visible } AABB visible = viewport.intersection(content); ``` -------------------------------- ### Example: Seek to Midpoint Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Demonstrates how to seek to a specific time within an animation, in this case, the halfway point, and then apply the animation state. ```cpp // Jump to halfway through the animation linearAnimationInstance->time(linearAnimationInstance->animation()->durationSeconds() / 2.0f); linearAnimationInstance->apply(); ``` -------------------------------- ### Check Artboard and Animation Existence with Fallbacks Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/errors.md Verify that an artboard and its animations exist by name. If a specific animation is not found, this example shows how to fall back to an alternative animation or the first available one. ```cpp auto artboard = file->artboardNamed("GameScene"); if (!artboard) { // Handle missing artboard return; } auto animation = artboard->animationNamed("Idle"); if (!animation) { // Try alternative or use default animation = artboard->animationAt(0); } ``` -------------------------------- ### Import File with rcp Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/types.md Example of using 'rcp' to manage a file object obtained from an import operation. The 'rcp' ensures the file is properly deallocated. ```cpp rcp file = File::import(data, factory); if (file) { auto artboard = file->artboardDefault(); } // file automatically destroyed here ``` -------------------------------- ### Handle Missing Artboards with Fallbacks Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/errors.md Provide fallback mechanisms when a specific artboard is not found. This example demonstrates trying to load a default artboard or the first available artboard if the named one is missing. ```cpp // Always provide fallback Artboard* artboard = file->artboard("MainScene"); if (!artboard) { artboard = file->artboardDefault(); // Use default if (!artboard) { artboard = file->artboard(0); // Use first if (!artboard) { // No artboards at all return; } } } ``` -------------------------------- ### Handle Pointer Down Event Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/types.md Example of performing a hit test with a pointer down event and checking the result. The 'stateMachine' must be initialized. ```cpp HitResult result = stateMachine->pointerDown(Vec2D(100, 50)); if (result.hit) { std::cout << "Hit component: " << result.hitComponentId << std::endl; } ``` -------------------------------- ### Reference Counted Object Example Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/types.md Demonstrates how to create a class that inherits from RefCnt for automatic memory management. Objects are deleted when their reference count drops to zero. ```cpp class MyObject : public RefCnt { // Automatically managed lifetime }; rcp obj = new MyObject(); // Object is deleted when rcp goes out of scope ``` -------------------------------- ### Get State Machine Instance by Name Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/artboard.md Creates a StateMachineInstance for the state machine with the specified name. Returns nullptr if the state machine is not found. ```cpp std::unique_ptr stateMachineNamed(const std::string& name); ``` ```cpp auto playerSM = artboardInstance->stateMachineNamed("PlayerController"); if (playerSM) { playerSM->getBool("isJumping")->value(true); } ``` -------------------------------- ### Create a Linear Gradient Shader Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/factory.md Creates a linear gradient shader for rendering. Specify start and end points, colors, and their positions. ```cpp ColorInt colors[] = {0xFF0000FF, 0x0000FFFF}; // Red to blue float stops[] = {0.0f, 1.0f}; rcp gradient = factory->makeLinearGradient( 0, 0, // Start at (0, 0) 100, 100, // End at (100, 100) colors, stops, 2 ); renderPaint->shader(gradient); ``` -------------------------------- ### Get State Machine Instance by Index Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/artboard.md Creates a StateMachineInstance for the state machine at the specified index. Returns nullptr if the index is out of range. ```cpp std::unique_ptr stateMachineAt(size_t index); ``` ```cpp auto stateMachine = artboardInstance->stateMachineAt(0); if (stateMachine) { auto input = stateMachine->getNumber("speed"); if (input) input->value(1.5f); } ``` -------------------------------- ### Process Drag Start Event Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Processes a drag start event. This is called when a drag operation begins, typically after a pointer down and move. ```cpp HitResult dragStart(Vec2D position, float timeStamp = 0, bool disablePointer = true, int pointerId = 0); ``` -------------------------------- ### Get Scripting VM Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/file.md Retrieve the Lua scripting virtual machine if it has been set. Returns a pointer to the ScriptingVM or nullptr if no VM is configured. ```cpp #ifdef WITH_RIVE_SCRIPTING ScriptingVM* scriptingVM(); #endif ``` -------------------------------- ### Get Artboard Bounds Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/artboard.md Retrieves the axis-aligned bounding box of the artboard. Use this to get the dimensions and position of the artboard's content. ```cpp AABB bounds = artboardInstance->bounds(); // bounds.minX, bounds.minY, bounds.maxX, bounds.maxY ``` -------------------------------- ### Configuring WebGPU Port with Wagyu Extensions Source: https://github.com/rive-app/rive-runtime/blob/main/renderer/src/webgpu/wagyu-port/README.md Configure the port by passing options to --use-port, such as enabling Wagyu extensions using 'wagyu=true'. ```bash --use-port=webgpu-remoteport.py:wagyu=true ``` -------------------------------- ### Rive Player Canvas and Communication Setup Source: https://github.com/rive-app/rive-runtime/blob/main/tests/player/player.html Sets up the Rive player's canvas and defines functions for printing messages to the Rive runtime. This includes handling console logging and sending messages to the server via WebAssembly. ```javascript html, body { width: 100%; height: 100%; margin: 0; padding: 0; background-color: black; } window.onhashchange = function() { location.reload(); } function printMessageOnServer(text) { const lengthBytes = lengthBytesUTF8(text) + 1; const stringOnWasmHeap = Module['_malloc'](lengthBytes); stringToUTF8(text, stringOnWasmHeap, lengthBytes); Module['_rive_print_message_on_server'](stringOnWasmHeap); Module['_free'](stringOnWasmHeap); } var Module = { 'canvas': document.getElementById("canvas"), 'print': function(text) { // Log 1st in case we're in a state where printMessageOnServer crashes. console.log(text); printMessageOnServer(text + '\n'); }, 'printErr': function(text) { // Log 1st in case we're in a state where printMessageOnServer crashes. console.error(text); printMessageOnServer(text + '\n'); }, }; ``` -------------------------------- ### Align Content with Fit Mode Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/types.md Example of aligning content within a frame using a specific Fit mode and Alignment. The 'renderer', 'frame', and 'content' objects must be valid. ```cpp renderer->align(Fit::contain, Alignment::center, frame, content); ``` -------------------------------- ### Get Trigger Input by Name Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Retrieves a trigger input from the state machine by its name. Use this to get a reference to a trigger input for later activation. ```cpp SMITrigger* getTrigger(const std::string& name) const override; ``` ```cpp SMITrigger* jump = stateMachineInstance->getTrigger("jump"); if (jump) { jump->fire(); } ``` -------------------------------- ### Get Numeric Input by Name Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Retrieves a numeric input from the state machine by its name. Use this to get a reference to a numeric input for later modification. ```cpp SMINumber* getNumber(const std::string& name) const override; ``` ```cpp SMINumber* speed = stateMachineInstance->getNumber("speed"); if (speed) { speed->value(2.5f); } ``` -------------------------------- ### Basic Rive Animation Playback and Interaction Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/README.md This snippet demonstrates the fundamental pattern for loading a .riv file, setting up an artboard and state machine, updating inputs, advancing the animation, and rendering the scene in a loop. It requires a factory, renderer, and input handler. ```cpp #include "rive/file.hpp" #include "rive/factory.hpp" #include "rive/renderer.hpp" // 1. Load file std::vector fileData = readFile("animation.riv"); rcp factory = createMetalFactory(); // or other platform ImportResult result; rcp riveFile = File::import( rive::Span(fileData.data(), fileData.size()), factory.get(), &result ); if (result != ImportResult::success) return; // 2. Get artboard and state machine auto artboardInstance = riveFile->artboardDefault(); auto stateMachine = artboardInstance->stateMachineNamed("Controller"); // 3. Main loop float deltaTime = 1.0f / 60.0f; // 60 FPS while (running) { // Update inputs if (inputHandler.jumpPressed()) { stateMachine->getTrigger("jump")->fire(); } // Update animation stateMachine->advance(deltaTime); // Render renderer->save(); renderer->align(Fit::contain, Alignment::center, viewport, artboardInstance->bounds()); artboardInstance->draw(renderer); renderer->restore(); } ``` -------------------------------- ### reportedEventAt() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Gets a reported event by index. ```APIDOC ## reportedEventAt() ### Description Gets a reported event by index. ### Method `const EventReport reportedEventAt(std::size_t index) const` ### Parameters #### Path Parameters - **index** (std::size_t) - Required - Index of the event ### Response #### Success Response - **EventReport** - EventReport structure ``` -------------------------------- ### Draw Image with Blend Mode Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/types.md Example of drawing an image using a specific blend mode. Ensure the BlendMode enum is in scope. ```cpp renderer->drawImage(image, sampler, BlendMode::screen, 1.0f); ``` -------------------------------- ### Get RenderImage Height Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/renderer.md Returns the height of the RenderImage in pixels. ```cpp int height() const; ``` -------------------------------- ### Get RenderImage Width Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/renderer.md Returns the width of the RenderImage in pixels. ```cpp int width() const; ``` -------------------------------- ### Get RenderBuffer Flags Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/renderer.md Returns the flags associated with the RenderBuffer. ```cpp RenderBufferFlags flags() const; ``` -------------------------------- ### Get Artboard Height Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/artboard.md Returns the height of the artboard in pixels. ```cpp float height() const; ``` -------------------------------- ### Get Artboard Width Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/artboard.md Returns the width of the artboard in pixels. ```cpp float width() const; ``` ```cpp float w = artboardInstance->width(); float h = artboardInstance->height(); ``` -------------------------------- ### Basic Rive File Import Error Handling with Switch Statement Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/errors.md A comprehensive example using a switch statement to handle all possible ImportResult values after attempting to import a Rive file. ```cpp #include "rive/file.hpp" ImportResult result; rcp riveFile = File::import(fileData, factory, &result); switch (result) { case ImportResult::success: // File loaded successfully break; case ImportResult::unsupportedVersion: std::cerr << "Rive file version not supported by this runtime" << std::endl; break; case ImportResult::malformed: std::cerr << "Rive file is corrupted or invalid" << std::endl; break; } ``` -------------------------------- ### Iterate Reported Events Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/types.md Example of iterating through reported events from a state machine. Accesses event details like object ID and property key. ```cpp for (size_t i = 0; i < stateMachine->reportedEventCount(); ++i) { EventReport event = stateMachine->reportedEventAt(i); std::cout << "Event from object " << event.objectId << std::endl; } ``` -------------------------------- ### LinearAnimation::startSeconds Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Retrieves the start time of the linear animation in seconds. ```APIDOC ## LinearAnimation::startSeconds ### Description Returns the start time of the animation in seconds. ### Method `float startSeconds() const;` ### Returns Start time in seconds ``` -------------------------------- ### Instantiate Default Artboard Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/file.md Creates an instance of the default artboard from the Rive file. Returns a unique pointer to the ArtboardInstance, or nullptr if no default artboard exists. ```cpp auto artboardInstance = riveFile->artboardDefault(); if (artboardInstance) { // Render the artboard } ``` -------------------------------- ### reportedEventCount() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Gets the number of events that reported since the last advance. ```APIDOC ## reportedEventCount() ### Description Gets the number of events that reported since the last advance. ### Method `std::size_t reportedEventCount() const` ### Response #### Success Response - **std::size_t** - Count of reported events ``` -------------------------------- ### Reset State Machine to Initial State Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Resets the state machine to its default starting state. This is often followed by a zero-time advance to ensure the initial state is correctly applied. ```cpp void resetState(); ``` -------------------------------- ### Get All File Assets Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/file.md Retrieve a collection of all assets within the Rive file, including images, fonts, and audio. Iterate through the returned span to process each asset. ```cpp Span> assets() const; ``` ```cpp auto allAssets = riveFile->assets(); for (const auto& asset : allAssets) { // Process asset } ``` -------------------------------- ### Create ArtboardInstance Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/artboard.md Default constructor for ArtboardInstance. Instances are typically created using factory methods like File::artboardDefault(). ```cpp ArtboardInstance(); ``` -------------------------------- ### Get RenderBuffer Size in Bytes Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/renderer.md Returns the size of the RenderBuffer in bytes. ```cpp size_t sizeInBytes() const; ``` -------------------------------- ### Instantiate Artboard by Index Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/file.md Creates an instance of an artboard using its 0-based index. Returns a unique pointer to the ArtboardInstance, or nullptr if the index is out of range. ```cpp auto artboardInstance = riveFile->artboardAt(0); ``` -------------------------------- ### LinearAnimationInstance::direction() (getter) Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Gets the current playback direction of the animation. ```APIDOC ## LinearAnimationInstance::direction() (getter) ### Description Gets the playback direction of the animation. ### Method ```cpp float direction() const; ``` ### Returns 1.0 for forward, -1.0 for backward ### Example: ```cpp if (linearAnimationInstance->direction() < 0) { // Playing backwards } ``` ``` -------------------------------- ### Create OpenGL Factory Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/configuration.md Create a Factory for OpenGL rendering, used on Windows, Linux, and macOS. ```cpp // OpenGL (Windows, Linux, macOS) rcp factory = createOpenGLFactory(); ``` -------------------------------- ### Get RenderImage UV Transform Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/renderer.md Returns the UV transformation matrix for the RenderImage. ```cpp const Mat2D& uvTransform() const; ``` -------------------------------- ### LinearAnimationInstance::time() (getter) Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Gets the current playback time of the animation in seconds. ```APIDOC ## LinearAnimationInstance::time() (getter) ### Description Gets the current playback time of the animation. ### Method ```cpp float time() const; ``` ### Returns Current time in seconds ### Example: ```cpp float currentTime = linearAnimationInstance->time(); ``` ``` -------------------------------- ### Instantiate Artboard by Name Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/file.md Creates an instance of an artboard using its string name. Returns a unique pointer to the ArtboardInstance, or nullptr if an artboard with the specified name does not exist. ```cpp auto artboardInstance = riveFile->artboardNamed("MainScene"); ``` -------------------------------- ### Initialize State Machine Instance Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Constructs a StateMachineInstance, which is a runtime representation of a StateMachine. It requires the state machine definition and the artboard instance it will control. ```cpp StateMachineInstance(const StateMachine* machine, ArtboardInstance* instance); ``` -------------------------------- ### Get Animation Loop Mode Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Retrieves the loop mode of a linear animation. ```cpp Loop loop() const; ``` -------------------------------- ### Get Animation Duration Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Retrieves the total duration of a linear animation in seconds. ```cpp float durationSeconds() const; ``` -------------------------------- ### Get Data Context Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Retrieves the current data context bound to the state machine. ```cpp rcp dataContext() const; ``` -------------------------------- ### Create View Model Instance Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/file.md Instantiate a view model from a Rive file, either by its name, associated artboard, or a specific view model object. You can also create a named instance of a named view model or by index. ```cpp rcp createViewModelInstance(std::string name) const; rcp createViewModelInstance(Artboard* artboard) const; rcp createViewModelInstance(ViewModel* viewModel) const; rcp createViewModelInstance( const std::string& name, const std::string& instanceName) const; rcp createViewModelInstance(size_t index, size_t instanceIndex) const; ``` ```cpp // By name rcp viewModel = riveFile->createViewModelInstance("MyViewModel"); // Attached to artboard auto artboardInstance = riveFile->artboardDefault(); rcp vmInstance = riveFile->createViewModelInstance(artboardInstance.get()); ``` -------------------------------- ### Using WebGPU Port as a Local Port Source: https://github.com/rive-app/rive-runtime/blob/main/renderer/src/webgpu/wagyu-port/README.md Directly use the local port file from the webgpu-port repository with your Emscripten build commands. ```bash --use-port=[your_path]/webgpu-port.py ``` -------------------------------- ### Get Scene Name Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Retrieves the name of the scene. This can be used for identification or debugging purposes. ```cpp virtual std::string name() const = 0; ``` -------------------------------- ### Get Animation End Time Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Retrieves the end time of a linear animation in seconds. ```cpp float endSeconds() const; ``` -------------------------------- ### Create Vulkan Factory Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/configuration.md Create a Factory for Vulkan rendering, used on Windows, Linux, and Android. ```cpp // Vulkan (Windows, Linux, Android) rcp factory = createVulkanFactory(); ``` -------------------------------- ### Create WebGL Factory Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/configuration.md Create a Factory for WebGL/WASM rendering, used in browsers. ```cpp // WebGL/WASM (Browser) rcp factory = createWebGLFactory(); ``` -------------------------------- ### File::artboardAt() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/file.md Creates an instance of an artboard at a specified index within the Rive file. ```APIDOC ## File::artboardAt() ### Description Creates an instance of the artboard at the given index. ### Method std::unique_ptr artboardAt(size_t index) const ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **index** (size_t) - Required - Index of the artboard (0-based) ### Request Example ```cpp auto artboardInstance = riveFile->artboardAt(0); ``` ### Response #### Success Response (200) `std::unique_ptr` - A unique pointer to a new ArtboardInstance, or nullptr if index is out of range #### Response Example (See Request Example for usage) ``` -------------------------------- ### Get RenderPath Pointer Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/renderer.md Returns a pointer to this object as a RenderPath. Overloaded for const and non-const instances. ```cpp RenderPath* renderPath() override; const RenderPath* renderPath() const override; ``` -------------------------------- ### Get RenderBuffer Type Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/renderer.md Returns the type of the RenderBuffer, indicating whether it is a vertex or index buffer. ```cpp RenderBufferType type() const; ``` -------------------------------- ### Enum Bitset Helper Usage Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/utilities.md Demonstrates checking and combining flags using the enum bitset helper functions. ```cpp // Bitwise operations on flag enums RenderBufferFlags flags = RenderBufferFlags::mappedOnceAtInitialization; if (enums::is_flag_set(flags, RenderBufferFlags::mappedOnceAtInitialization)) { // Flag is set } flags |= RenderBufferFlags::none; // Combine flags if (enums::any_flag_set(flags)) { // At least one flag is set } ``` -------------------------------- ### ArtboardInstance::stateMachineAt() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/artboard.md Creates and returns a runtime instance for a state machine at a specific index. ```APIDOC ## ArtboardInstance::stateMachineAt() ### Description Creates a state machine instance for the state machine at the given index. ### Method std::unique_ptr stateMachineAt(size_t index) ### Parameters #### Path Parameters - **index** (size_t) - Required - Index of the state machine (0-based) ### Returns A unique pointer to a new StateMachineInstance, or nullptr if index is out of range ### Example ```cpp auto stateMachine = artboardInstance->stateMachineAt(0); if (stateMachine) { auto input = stateMachine->getNumber("speed"); if (input) input->value(1.5f); } ``` ### Source `include/rive/artboard.hpp` ``` -------------------------------- ### focusManager() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Gets the focus manager for this state machine. This can be used to interact with the focus system of the state machine. ```APIDOC ## focusManager() ### Description Gets the focus manager for this state machine. ### Method ```cpp FocusManager* focusManager() ``` ### Returns - **FocusManager*** - Pointer to internal or external FocusManager ``` -------------------------------- ### Get Focus Manager Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Retrieves the focus manager associated with this state machine. This can be an internal or external manager. ```cpp FocusManager* focusManager(); ``` -------------------------------- ### stateChangedByIndex() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Gets a state that changed in the last advance. Returns a pointer to LayerState or nullptr if the index is out of range. ```APIDOC ## stateChangedByIndex() ### Description Gets a state that changed in the last advance. ### Method `const LayerState* stateChangedByIndex(size_t index) const` ### Parameters #### Path Parameters - **index** (size_t) - Required - Index of the changed state ### Response #### Success Response - **const LayerState*** - Pointer to LayerState or nullptr if index out of range ``` -------------------------------- ### StateMachineInstance: Interactive state-driven animations Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/INDEX.md Enables interactive, state-driven animations. Allows for updating the state machine, handling user inputs, querying current states, and managing events, hit testing, and data binding. ```APIDOC ## StateMachineInstance: Interactive state-driven animations ### Description Manages interactive animations driven by states. Allows for updating the state machine, processing inputs, querying current states and animations, handling reported events, performing hit testing, and managing data contexts and focus. ### Methods - `StateMachineInstance()`: Constructor. - `advance()`: Update the state machine. - `needsAdvance()`: Check if the state machine needs an update. - `markNeedsAdvance()`: Mark the state machine for an update. - `resetState()`: Reset to the initial state. - `reset()`: Reset the state machine. - `stateMachine()`: Access the state machine definition. - `inputCount()`: Get the number of inputs. - `input(index)`: Get an input by its index. - `getBool(input_name)`: Get a boolean input value. - `getNumber(input_name)`: Get a number input value. - `getTrigger(input_name)`: Get a trigger input value. - `currentAnimationCount()`: Get the number of currently playing animations. - `currentAnimationByIndex(index)`: Get a currently playing animation by index. - `stateChangedCount()`: Get the number of states that have changed. - `stateChangedByIndex(index)`: Get a changed state by index. - `reportedEventCount()`: Get the number of reported events. - `reportedEventAt(index)`: Get a reported event by index. - `reportEvent(input_name)`: Report an event. - `applyEvents()`: Apply all reported events. - `hitTest(x, y)`: Perform hit testing at the given coordinates. - `pointerDown(x, y)`: Simulate a pointer down event. - `pointerMove(x, y)`: Simulate a pointer move event. - `pointerUp(x, y)`: Simulate a pointer up event. - `pointerExit(x, y)`: Simulate a pointer exit event. - `dragStart(x, y)`: Simulate a drag start event. - `dragEnd()`: Simulate a drag end event. - `bindDataContext(data_context)`: Bind a data context. - `dataContext()`: Get the bound data context. - `clearDataContext()`: Clear the data context. - `focusManager()`: Get the focus manager. - `setExternalFocusManager(manager)`: Set an external focus manager. - `focusNext()`: Move focus to the next element. - `focusPrevious()`: Move focus to the previous element. - `setFocus(element)`: Set focus to a specific element. - `focusState()`: Get the current focus state. - `semanticManager()`: Get the semantic manager. - `setExternalSemanticManager(manager)`: Set an external semantic manager. - `enableSemantics()`: Enable semantics for accessibility. - `dispose()`: Clean up resources. ``` -------------------------------- ### currentAnimationByIndex() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Gets a currently playing animation by index. Returns a pointer to the LinearAnimationInstance or nullptr if the index is out of range. ```APIDOC ## currentAnimationByIndex() ### Description Gets a currently playing animation by index. ### Method `const LinearAnimationInstance* currentAnimationByIndex(size_t index) const` ### Parameters #### Path Parameters - **index** (size_t) - Required - Index in the current animations ### Response #### Success Response - **const LinearAnimationInstance*** - Pointer to LinearAnimationInstance or nullptr ``` -------------------------------- ### File::artboardDefault() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/file.md Creates an instance of the default artboard from the Rive file. This is often the primary animation or scene. ```APIDOC ## File::artboardDefault() ### Description Creates an instance of the default artboard. ### Method std::unique_ptr artboardDefault() const ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters None ### Request Example ```cpp auto artboardInstance = riveFile->artboardDefault(); if (artboardInstance) { // Render the artboard } ``` ### Response #### Success Response (200) `std::unique_ptr` - A unique pointer to a new ArtboardInstance of the default artboard, or nullptr if no default exists #### Response Example (See Request Example for usage) ``` -------------------------------- ### frameOrigin() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/artboard.md Gets whether the artboard's origin is centered within its bounds or set to the top-left corner. ```APIDOC ## frameOrigin() ### Description Gets whether the artboard shifts the origin from top-left to its relative center. ### Returns true if origin is framed relative to artboard bounds, false if at top-left ### Example ```cpp artboardInstance->frameOrigin(false); ``` ``` -------------------------------- ### createViewModelInstance() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/file.md Creates an instance of a view model, with overloads supporting creation by name, associated artboard, specific view model object, or by index. ```APIDOC ## createViewModelInstance() ### Description Creates an instance of a view model. ### Method `rcp createViewModelInstance(std::string name) const;` `rcp createViewModelInstance(Artboard* artboard) const;` `rcp createViewModelInstance(ViewModel* viewModel) const;` `rcp createViewModelInstance(const std::string& name, const std::string& instanceName) const;` `rcp createViewModelInstance(size_t index, size_t instanceIndex) const;` ### Parameters - `std::string name`: Create view model instance by name. - `Artboard* artboard`: Create view model instance attached to artboard. - `ViewModel* viewModel`: Create instance of specific view model. - `const std::string& name, const std::string& instanceName`: Create named instance of named view model. - `size_t index, size_t instanceIndex`: Create by view model index and instance index. ### Returns Reference-counted pointer to ViewModelInstance. ### Example ```cpp // By name rcp viewModel = riveFile->createViewModelInstance("MyViewModel"); // Attached to artboard auto artboardInstance = riveFile->artboardDefault(); rcp vmInstance = riveFile->createViewModelInstance(artboardInstance.get()); ``` ``` -------------------------------- ### Get Current Animation Time Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/animation.md Retrieves the current playback time of the linear animation instance in seconds. ```cpp float time() const; ``` -------------------------------- ### Artboard and ArtboardInstance: Animation containers Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/INDEX.md Manages animation containers, allowing for the creation and rendering of artboards. Supports advancing animation state, drawing to the screen, and handling pointer events. ```APIDOC ## Artboard and ArtboardInstance: Animation containers ### Description Represents an animation container and its instances. Allows for updating animation states, rendering the artboard, creating animation and state machine instances, and handling user input events. ### Methods - `ArtboardInstance` constructor and lifecycle management. - `advance(elapsed_time)`: Update the artboard's state by the given time delta. - `draw()`: Render the artboard to the screen. - `animationAt(index)`: Create a linear animation instance by index. - `animationNamed(name)`: Create a linear animation instance by name. - `stateMachineAt(index)`: Create a state machine instance by index. - `stateMachineNamed(name)`: Create a state machine instance by name. - `width()`: Get the width of the artboard. - `height()`: Get the height of the artboard. - `bounds()`: Get the bounding box of the artboard. - `isInstance()`: Check if the object is an instance. - `frameOrigin()`: Configure the origin mode for frames. - `volume()`: Control the audio volume. - `clone()`: Create a deep copy of the artboard instance. - `pointerDown(x, y)`: Simulate a pointer down event. - `pointerMove(x, y)`: Simulate a pointer move event. - `pointerUp(x, y)`: Simulate a pointer up event. - `pointerExit(x, y)`: Simulate a pointer exit event. - `audioEngine()`: Access the custom audio engine (optional). ### Properties - `width`: Width of the artboard. - `height`: Height of the artboard. - `bounds`: Bounding box of the artboard. ``` -------------------------------- ### dataContext() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Gets the current data context associated with the state machine. This allows retrieval of the currently bound data. ```APIDOC ## dataContext() ### Description Gets the current data context. ### Method ```cpp rcp dataContext() const ``` ### Returns - **rcp** - Reference-counted pointer to DataContext ``` -------------------------------- ### Build and Serve Rive Renderer for WebGL2 Source: https://github.com/rive-app/rive-runtime/blob/main/renderer/README.md Build the Rive Renderer for WebGL2 using Ninja and Python's http.server. This is useful for web-based Rive content. ```bash build_rive.sh ninja wasm release cd out/wasm_release python3 -m http.server 5555 ``` -------------------------------- ### Get Internal Focus Manager Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Retrieves the internal focus manager, which is always owned by this state machine instance. ```cpp FocusManager* internalFocusManager(); ``` -------------------------------- ### Run rive-cpp tests Source: https://github.com/rive-app/rive-runtime/blob/main/README.md Navigate to the unit tests directory and execute this script to compile and run all tests. ```bash cd tests/unit_tests ./test.sh ``` -------------------------------- ### getTrigger() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Gets a trigger input by name. Returns a pointer to the SMITrigger object if found, otherwise returns nullptr. ```APIDOC ## getTrigger() ### Description Gets a trigger input by name. ### Method `const SMITrigger* getTrigger(const std::string& name) const` ### Parameters #### Path Parameters - **name** (std::string) - Required - Name of the trigger ### Response #### Success Response - **SMITrigger*** - Pointer to SMITrigger, or nullptr if not found ``` -------------------------------- ### getNumber() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Gets a numeric input by name. Returns a pointer to the SMINumber object if found, otherwise returns nullptr. ```APIDOC ## getNumber() ### Description Gets a numeric input by name. ### Method `const SMINumber* getNumber(const std::string& name) const` ### Parameters #### Path Parameters - **name** (std::string) - Required - Name of the input ### Response #### Success Response - **SMINumber*** - Pointer to SMINumber, or nullptr if not found ``` -------------------------------- ### File::import() Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/file.md Imports a Rive file from a binary buffer. This is the primary method for loading .riv files into the Rive runtime. ```APIDOC ## File::import() ### Description Imports a Rive file from a binary buffer. ### Method static rcp import(Span data, Factory* factory, ImportResult* result = nullptr, FileAssetLoader* assetLoader = nullptr, ScriptingVM* vm = nullptr) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **data** (Span) - Required - Raw binary data of the .riv file - **factory** (Factory*) - Required - Factory instance for creating renderer objects - **result** (ImportResult*) - Optional - Optional output parameter indicating import success/failure - **assetLoader** (FileAssetLoader*) - Optional - Optional helper for loading assets not embedded in the file - **vm** (ScriptingVM*) - Optional - Optional Lua scripting VM for script execution ### Request Example ```cpp #include "rive/file.hpp" #include // Read file from disk std::ifstream file("animation.riv", std::ios::binary); std::vector data((std::istreambuf_iterator(file)), std::istreambuf_iterator()); // Import the file ImportResult importResult; rcp riveFile = File::import(rive::Span(data.data(), data.size()), factory, &importResult); if (importResult != ImportResult::success) { // Handle error return; } // Use the file auto artboard = riveFile->artboardDefault(); ``` ### Response #### Success Response (200) `rcp` - A reference-counted pointer to the imported File, or nullptr if import fails. #### Response Example (See Request Example for usage, return value is `rcp`) ERROR HANDLING: Failures are indicated via the `result` parameter. ``` -------------------------------- ### Create Direct3D11 Factory Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/configuration.md Create a Factory for Direct3D 11 rendering, used on Windows. ```cpp // Direct3D 11 (Windows) rcp factory = createDirect3D11Factory(); ``` -------------------------------- ### Get Reported Event by Index Source: https://github.com/rive-app/rive-runtime/blob/main/_autodocs/state-machine.md Retrieves a reported event by its index. This allows access to specific events that have occurred. ```cpp const EventReport reportedEventAt(std::size_t index) const; ```