|
| 1 | +#include "capi/rive_api.h" |
| 2 | + |
| 3 | +#include "rive/file.hpp" |
| 4 | +#include "rive/artboard.hpp" |
| 5 | +#include "rive/span.hpp" |
| 6 | +#include "rive/scene.hpp" |
| 7 | +#include "rive/animation/linear_animation_instance.hpp" |
| 8 | +#include "rive/animation/state_machine_instance.hpp" |
| 9 | +#include "rive/math/aabb.hpp" |
| 10 | + |
| 11 | +static inline rive_file_t* toC(rive::File* file) { return (rive_file_t*)file; } |
| 12 | +static inline rive_artboard_t* toC(rive::ArtboardInstance* abi) { return (rive_artboard_t*)abi; } |
| 13 | +static inline rive_scene_t* toC(rive::Scene* scene) { return (rive_scene_t*)scene; } |
| 14 | +static inline rive_animation_t* toC(rive::LinearAnimationInstance* anim) { |
| 15 | + return (rive_animation_t*)anim; |
| 16 | +} |
| 17 | +static inline rive_statemachine_t* toC(rive::StateMachineInstance* smi) { |
| 18 | + return (rive_statemachine_t*)smi; |
| 19 | +} |
| 20 | + |
| 21 | +static inline rive::Factory* toRive(rive_factory_t* factory) { return (rive::Factory*)factory; } |
| 22 | +static inline rive::Renderer* toRive(rive_renderer_t* renderer) { return (rive::Renderer*)renderer; } |
| 23 | + |
| 24 | +static inline rive::File* toRive(rive_file_t* file) { return (rive::File*)file; } |
| 25 | +static inline rive::ArtboardInstance* toRive(rive_artboard_t* abi) { return (rive::ArtboardInstance*)abi; } |
| 26 | +static inline rive::Scene* toRive(rive_scene_t* scene) { return (rive::Scene*)scene; } |
| 27 | + |
| 28 | +#if 0 |
| 29 | +static inline rive_factory_t* toC(rive::Factory* factory) { return (rive_factory_t*)factory; } |
| 30 | +static inline rive_renderer_t* toC(rive::Renderer* renderer) { return (rive_renderer_t*)renderer; } |
| 31 | +static inline rive::LinearAnimationInstance* toRive(rive_animation_t* anim) { |
| 32 | + return (rive::LinearAnimationInstance*)anim; |
| 33 | +} |
| 34 | +static inline rive::StateMachineInstance* toRive(rive_statemachine_t* smi) { |
| 35 | + return (rive::StateMachineInstance*)smi; |
| 36 | +} |
| 37 | +#endif |
| 38 | + |
| 39 | +////////////////////////////////////// |
| 40 | + |
| 41 | +void rive_file_delete(rive_file_t* file) { delete toRive(file); } |
| 42 | +void rive_artboard_delete(rive_artboard_t* abi) { delete toRive(abi); } |
| 43 | +void rive_scene_delete(rive_scene_t* scene) { delete toRive(scene); } |
| 44 | + |
| 45 | +rive_file_t* rive_file_import(rive_span_t cspan, rive_factory_t* factory) { |
| 46 | + rive::Span<const uint8_t> span((const uint8_t*)cspan.buffer, cspan.size); |
| 47 | + return toC(rive::File::import(span, toRive(factory)).release()); |
| 48 | +} |
| 49 | + |
| 50 | +int32_t rive_file_artboard_count(rive_file_t* file) { |
| 51 | + return toRive(file)->artboardCount(); |
| 52 | +} |
| 53 | + |
| 54 | +rive_artboard_t* rive_file_artboard_default(rive_file_t* file) { |
| 55 | + return toC(toRive(file)->artboardDefault().release()); |
| 56 | +} |
| 57 | + |
| 58 | +rive_artboard_t* rive_file_artboard_at(rive_file_t* file, int32_t index) { |
| 59 | + return toC(toRive(file)->artboardAt(index).release()); |
| 60 | +} |
| 61 | + |
| 62 | +rive_artboard_t* rive_file_artboard_named(rive_file_t* file, const char name[]) { |
| 63 | + return toC(toRive(file)->artboardNamed(name).release()); |
| 64 | +} |
| 65 | + |
| 66 | +/////////////////////////// |
| 67 | + |
| 68 | +int32_t rive_artboard_animation_count(rive_artboard_t* abi) { |
| 69 | + return toRive(abi)->animationCount(); |
| 70 | +} |
| 71 | + |
| 72 | +rive_animation_t* rive_artboard_animation_at(rive_artboard_t* abi, int32_t index) { |
| 73 | + return toC(toRive(abi)->animationAt(index).release()); |
| 74 | +} |
| 75 | + |
| 76 | +rive_animation_t* rive_artboard_animation_named(rive_artboard_t* abi, const char name[]) { |
| 77 | + return toC(toRive(abi)->animationNamed(name).release()); |
| 78 | +} |
| 79 | + |
| 80 | +int32_t rive_artboard_statemachine_count(rive_artboard_t* abi) { |
| 81 | + return toRive(abi)->stateMachineCount(); |
| 82 | +} |
| 83 | + |
| 84 | +rive_statemachine_t* rive_artboard_statemachine_at(rive_artboard_t* abi, int32_t index) { |
| 85 | + return toC(toRive(abi)->stateMachineAt(index).release()); |
| 86 | +} |
| 87 | + |
| 88 | +rive_statemachine_t* rive_artboard_statemachine_named(rive_artboard_t* abi, const char name[]) { |
| 89 | + return toC(toRive(abi)->stateMachineNamed(name).release()); |
| 90 | +} |
| 91 | + |
| 92 | +rive_statemachine_t* rive_artboard_statemachine_default(rive_artboard_t* abi) { |
| 93 | + return toC(toRive(abi)->defaultStateMachine().release()); |
| 94 | +} |
| 95 | + |
| 96 | +rive_scene_t* rive_artboard_scene_default(rive_artboard_t* abi) { |
| 97 | + return toC(toRive(abi)->defaultScene().release()); |
| 98 | +} |
| 99 | + |
| 100 | +//////////////////////////////// |
| 101 | + |
| 102 | +rive_aabb_t rive_scene_bounds(rive_scene_t* scene) { |
| 103 | + auto aabb = toRive(scene)->bounds(); |
| 104 | + return {aabb.left(), aabb.top(), aabb.right(), aabb.bottom()}; |
| 105 | +} |
| 106 | + |
| 107 | +void rive_scene_draw(rive_scene_t* scene, rive_renderer_t* renderer) { |
| 108 | + toRive(scene)->draw(toRive(renderer)); |
| 109 | +} |
| 110 | + |
| 111 | +bool rive_scene_advance(rive_scene_t* scene, float seconds) { |
| 112 | + return toRive(scene)->advanceAndApply(seconds); |
| 113 | +} |
0 commit comments