Skip to content

Commit 1f61fec

Browse files
committed
add cpp bindings for layerstates
1 parent 951a6ca commit 1f61fec

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include "jni_refs.hpp"
2+
#include "helpers/general.hpp"
3+
4+
// From rive-cpp
5+
#include "animation/layer_state.hpp"
6+
#include "animation/exit_state.hpp"
7+
#include "animation/entry_state.hpp"
8+
#include "animation/any_state.hpp"
9+
#include "animation/animation_state.hpp"
10+
11+
#ifdef __cplusplus
12+
extern "C"
13+
{
14+
#endif
15+
16+
// ANIMATION
17+
JNIEXPORT jboolean JNICALL Java_app_rive_runtime_kotlin_core_LayerState_cppIsExitState(
18+
JNIEnv *env,
19+
jobject thisObj,
20+
jlong ref)
21+
{
22+
23+
rive::LayerState *layerState = (rive::LayerState *)ref;
24+
return layerState->is<rive::ExitState>();
25+
}
26+
27+
JNIEXPORT jboolean JNICALL Java_app_rive_runtime_kotlin_core_LayerState_cppIsAnyState(
28+
JNIEnv *env,
29+
jobject thisObj,
30+
jlong ref)
31+
{
32+
33+
rive::LayerState *layerState = (rive::LayerState *)ref;
34+
return layerState->is<rive::AnyState>();
35+
}
36+
37+
JNIEXPORT jboolean JNICALL Java_app_rive_runtime_kotlin_core_LayerState_cppIsEntryState(
38+
JNIEnv *env,
39+
jobject thisObj,
40+
jlong ref)
41+
{
42+
43+
rive::LayerState *layerState = (rive::LayerState *)ref;
44+
return layerState->is<rive::EntryState>();
45+
}
46+
47+
JNIEXPORT jboolean JNICALL Java_app_rive_runtime_kotlin_core_LayerState_cppIsAnimationState(
48+
JNIEnv *env,
49+
jobject thisObj,
50+
jlong ref)
51+
{
52+
53+
rive::LayerState *layerState = (rive::LayerState *)ref;
54+
return layerState->is<rive::AnimationState>();
55+
}
56+
57+
JNIEXPORT jlong JNICALL Java_app_rive_runtime_kotlin_core_AnimationState_cppAnimation(
58+
JNIEnv *env,
59+
jobject thisObj,
60+
jlong ref)
61+
{
62+
63+
rive::AnimationState *animationState = (rive::AnimationState *)ref;
64+
return (long)animationState->animation();
65+
}
66+
67+
#ifdef __cplusplus
68+
}
69+
#endif

cpp/src/bindings/bindings_linear_animation_instance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern "C"
2424
rive::LinearAnimation *animation = (rive::LinearAnimation *)animationRef;
2525

2626
// TODO: delete this object?
27-
auto animationInstance = new rive::LinearAnimationInstance(animation);
27+
rive::LinearAnimationInstance *animationInstance = new rive::LinearAnimationInstance(animation);
2828

2929
return (jlong)animationInstance;
3030
}
@@ -44,7 +44,7 @@ extern "C"
4444

4545
if (didLoop)
4646
{
47-
auto loopType = animationInstance->animation()->loop();
47+
rive::Loop loopType = animationInstance->animation()->loop();
4848
switch (loopType)
4949
{
5050
case rive::Loop::oneShot:

cpp/src/bindings/bindings_state_machine_instance.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern "C"
2222
rive::StateMachine *animation = (rive::StateMachine *)stateMachineRef;
2323

2424
// TODO: delete this object?
25-
auto stateMachineInstance = new rive::StateMachineInstance(animation);
25+
rive::StateMachineInstance *stateMachineInstance = new rive::StateMachineInstance(animation);
2626

2727
return (jlong)stateMachineInstance;
2828
}
@@ -37,6 +37,25 @@ extern "C"
3737
return stateMachineInstance->advance(elapsedTime);
3838
}
3939

40+
JNIEXPORT jint JNICALL Java_app_rive_runtime_kotlin_core_StateMachineInstance_cppStateChangedCount(
41+
JNIEnv *env,
42+
jobject thisObj,
43+
jlong ref)
44+
{
45+
rive::StateMachineInstance *stateMachineInstance = (rive::StateMachineInstance *)ref;
46+
return stateMachineInstance->stateChangedCount();
47+
}
48+
49+
JNIEXPORT jlong JNICALL Java_app_rive_runtime_kotlin_core_StateMachineInstance_cppStateChangedByIndex(
50+
JNIEnv *env,
51+
jobject thisObj,
52+
jlong ref,
53+
jint index)
54+
{
55+
rive::StateMachineInstance *stateMachineInstance = (rive::StateMachineInstance *)ref;
56+
return (jlong)stateMachineInstance->stateChangedByIndex(index);
57+
}
58+
4059
JNIEXPORT void JNICALL Java_app_rive_runtime_kotlin_core_StateMachineInstance_cppApply(
4160
JNIEnv *env,
4261
jobject thisObj,

0 commit comments

Comments
 (0)