Skip to content

Commit

Permalink
Fix libjpg on Mac Sonoma
Browse files Browse the repository at this point in the history
Diffs=
dde676085 Fix libjpg on Mac Sonoma (#7329)
e0a786c90 Runtime API for Nested Inputs (#7316)

Co-authored-by: Gordon Hayes <[email protected]>
Co-authored-by: Philip Chung <[email protected]>
  • Loading branch information
3 people committed May 31, 2024
1 parent b9ea052 commit a89a447
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b96bea79bda334c8ce25f91727d47aa0394304b2
dde676085908d492af545660cbbb19ee0d10d91d
2 changes: 1 addition & 1 deletion .rive_renderer
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13410e662550cd7ffd9c568d3880c3325f953314
f1ec43c82b136c33edfd71ec9759249d9fb5b182
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<activity android:name=".RiveFragmentActivity" />
<activity android:name=".LowLevelActivity" />
<activity android:name=".SimpleStateMachineActivity" />
<activity android:name=".NestedInputActivity" />
<activity android:name=".HttpActivity" />
<activity android:name=".ButtonActivity" />
<activity android:name=".BlendActivity" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/app/rive/runtime/example/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MainActivity : AppCompatActivity() {
Pair(R.id.go_low_level, LowLevelActivity::class.java),
Pair(R.id.go_http, HttpActivity::class.java),
Pair(R.id.go_simple_state_machine, SimpleStateMachineActivity::class.java),
Pair(R.id.go_nested_input, NestedInputActivity::class.java),
Pair(R.id.go_button, ButtonActivity::class.java),
Pair(R.id.go_blend, BlendActivity::class.java),
Pair(R.id.go_metrics, MetricsActivity::class.java),
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/app/rive/runtime/example/NestedInputActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package app.rive.runtime.example

import android.os.Bundle
import android.view.View
import android.widget.RadioButton
import androidx.appcompat.app.AppCompatActivity
import app.rive.runtime.kotlin.RiveAnimationView

class NestedInputActivity : AppCompatActivity() {

private val animationView by lazy(LazyThreadSafetyMode.NONE) {
findViewById<RiveAnimationView>(R.id.nested_input)
}

fun onSetInput(view: View) {
if (view is RadioButton && view.isChecked) {
// Check which radio button was clicked
when (view.getId()) {

R.id.outer_circle_on ->
animationView.setBooleanStateAtPath("CircleOuterState", true, "CircleOuter")
R.id.outer_circle_off ->
animationView.setBooleanStateAtPath("CircleOuterState", false, "CircleOuter")
R.id.inner_circle_on ->
animationView.setBooleanStateAtPath("CircleInnerState", true, "CircleOuter/CircleInner")
R.id.inner_circle_off ->
animationView.setBooleanStateAtPath("CircleInnerState", false, "CircleOuter/CircleInner")

}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.nested_input)
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@
android:text="State Machine"
android:textColor="@color/textColorPrimary" />

<Button
android:id="@+id/go_nested_input"
style="@style/Widget.Material3.Button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="4dp"
android:text="Nested Inputs"
android:textColor="@color/textColorPrimary" />

<Button
android:id="@+id/go_button"
style="@style/Widget.Material3.Button"
Expand Down
60 changes: 60 additions & 0 deletions app/src/main/res/layout/nested_input.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<app.rive.runtime.kotlin.RiveAnimationView
android:id="@+id/nested_input"
android:layout_width="match_parent"
android:layout_height="400dp"
app:riveResource="@raw/runtime_nested_inputs"
app:riveStateMachine="MainStateMachine" />

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:orientation="vertical">

<RadioButton
android:id="@+id/outer_circle_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onSetInput"
android:text="Outer Circle on" />

<RadioButton
android:id="@+id/outer_circle_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onSetInput"
android:text="Outer Circle off" />

<RadioButton
android:id="@+id/inner_circle_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onSetInput"
android:text="Inner Circle on" />

<RadioButton
android:id="@+id/inner_circle_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onSetInput"
android:text="Inner Circle off" />

</RadioGroup>
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
Binary file added app/src/main/res/raw/runtime_nested_inputs.riv
Binary file not shown.
11 changes: 11 additions & 0 deletions kotlin/src/main/cpp/src/bindings/bindings_artboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ extern "C"
return (jint)artboard->stateMachineCount();
}

JNIEXPORT jlong JNICALL
Java_app_rive_runtime_kotlin_core_Artboard_cppInputByNameAtPath(JNIEnv* env,
jobject thisObj,
jlong ref,
jstring name,
jstring path)
{
auto artboard = reinterpret_cast<rive::ArtboardInstance*>(ref);
return (jlong)artboard->input(JStringToString(env, name), JStringToString(env, path));
}

JNIEXPORT jlong JNICALL
Java_app_rive_runtime_kotlin_core_Artboard_cppFindTextValueRun(JNIEnv* env,
jobject thisObj,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,29 @@ open class RiveAnimationView(context: Context, attrs: AttributeSet? = null) :
controller.setNumberState(stateMachineName, inputName, value)
}

/**
* Fire the [SMITrigger] input called [inputName] on the nested artboard represented at [path]
*/
fun fireStateAtPath(inputName: String, path: String) {
controller.fireStateAtPath(inputName, path)
}

/**
* Update the state of the [SMIBoolean] input called [inputName] on the nested artboard represented at [path]
* to [value]
*/
fun setBooleanStateAtPath(inputName: String, value: Boolean, path: String) {
controller.setBooleanStateAtPath(inputName, value, path)
}

/**
* Update the state of the [SMINumber] input called [inputName] on the nested artboard represented at [path]
* to [value]
*/
fun setNumberStateAtPath(inputName: String, value: Float, path: String) {
controller.setNumberStateAtPath(inputName, value, path)
}

/**
* Update multiple states at once supplying one or more [inputs]
*/
Expand Down Expand Up @@ -1102,4 +1125,4 @@ sealed class ResourceType {
* Wraps the data necessary for grabbing an input with [name] with [value]
* [value] is necessary when wrapping [SMINumber] and [SMIBoolean] inputs.
*/
data class ChangedInput(val stateMachineName: String, val name: String, val value: Any? = null)
data class ChangedInput(val stateMachineName: String, val name: String, val value: Any? = null, val nestedArtboardPath: String? = null)
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ class RiveFileController(
* It also tries to start the thread if it's not started, which will internally cause advance
* to happen at least once.
*/
private fun queueInput(stateMachineName: String, inputName: String, value: Any? = null) {
queueInputs(ChangedInput(stateMachineName, inputName, value))
private fun queueInput(stateMachineName: String, inputName: String, value: Any? = null, path: String? = null) {
queueInputs(ChangedInput(stateMachineName, inputName, value, path))
}

internal fun queueInputs(vararg inputs: ChangedInput) {
Expand All @@ -519,29 +519,52 @@ class RiveFileController(
// No need to lock this: this is being called from `advance()` which is `synchronized(file)`
while (changedInputs.isNotEmpty()) {
val input = changedInputs.remove()
val stateMachines = getOrCreateStateMachines(input.stateMachineName)
stateMachines.forEach { stateMachineInstance ->
playableSet.add(stateMachineInstance)
when (val smiInput = stateMachineInstance.input(input.name)) {
is SMITrigger -> smiInput.fire()
is SMIBoolean -> smiInput.value = input.value as Boolean
is SMINumber -> smiInput.value = input.value as Float
if (input.nestedArtboardPath == null) {
val stateMachines = getOrCreateStateMachines(input.stateMachineName)
stateMachines.forEach { stateMachineInstance ->
playableSet.add(stateMachineInstance)
when (val smiInput = stateMachineInstance.input(input.name)) {
is SMITrigger -> smiInput.fire()
is SMIBoolean -> smiInput.value = input.value as Boolean
is SMINumber -> smiInput.value = input.value as Float
}
}
} else {
val smiInput = activeArtboard?.input(input.name, input.nestedArtboardPath)
if (smiInput is SMITrigger) {
smiInput.fire()
} else if (smiInput is SMIBoolean) {
smiInput.value = input.value as Boolean
} else if (smiInput is SMINumber) {
smiInput.value = input.value as Float
}
}
}
playableSet.forEach { play(it, settleStateMachineState = false) }
}

fun fireState(stateMachineName: String, inputName: String) {
queueInput(stateMachineName, inputName)
fun fireState(stateMachineName: String, inputName: String, path: String? = null) {
queueInput(stateMachineName, inputName, path)
}

fun setBooleanState(stateMachineName: String, inputName: String, value: Boolean, path: String? = null) {
queueInput(stateMachineName, inputName, value, path)
}

fun setNumberState(stateMachineName: String, inputName: String, value: Float, path: String? = null) {
queueInput(stateMachineName, inputName, value, path)
}

fun fireStateAtPath(inputName: String, path: String) {
queueInput("", inputName, path)
}

fun setBooleanState(stateMachineName: String, inputName: String, value: Boolean) {
queueInput(stateMachineName, inputName, value)
fun setBooleanStateAtPath(inputName: String, value: Boolean, path: String) {
queueInput("", inputName, value, path)
}

fun setNumberState(stateMachineName: String, inputName: String, value: Float) {
queueInput(stateMachineName, inputName, value)
fun setNumberStateAtPath(inputName: String, value: Float, path: String) {
queueInput("", inputName, value, path)
}

/**
Expand Down
26 changes: 26 additions & 0 deletions kotlin/src/main/java/app/rive/runtime/kotlin/core/Artboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.graphics.RectF
import app.rive.runtime.kotlin.core.errors.AnimationException
import app.rive.runtime.kotlin.core.errors.RiveException
import app.rive.runtime.kotlin.core.errors.StateMachineException
import app.rive.runtime.kotlin.core.errors.StateMachineInputException
import app.rive.runtime.kotlin.core.errors.TextValueRunException
import java.util.concurrent.locks.ReentrantLock

Expand Down Expand Up @@ -32,6 +33,8 @@ class Artboard(unsafeCppPointer: Long, private val lock: ReentrantLock) :
private external fun cppStateMachineCount(cppPointer: Long): Int
private external fun cppStateMachineNameByIndex(cppPointer: Long, index: Int): String

private external fun cppInputByNameAtPath(cppPointer: Long, name: String, path: String): Long

private external fun cppAdvance(cppPointer: Long, elapsedTime: Float): Boolean
private external fun cppFindTextValueRun(cppPointer: Long, name: String): Long

Expand Down Expand Up @@ -138,6 +141,19 @@ class Artboard(unsafeCppPointer: Long, private val lock: ReentrantLock) :
return smi
}

/**
* Get the input instance with a given [name] on the nested artboard represented at [path].
*/
@Throws(RiveException::class)
fun input(name: String, path: String): SMIInput {
val stateMachineInputPointer = cppInputByNameAtPath(cppPointer, name, path)
if (stateMachineInputPointer == NULL_POINTER) {
throw StateMachineInputException("No StateMachineInput found with name $name in nested artboard $path.")
}
val input = SMIInput(stateMachineInputPointer)
return convertInput(input)
}

/**
* Get a [RiveTextValueRun] with a given [name] in the [Artboard].
*/
Expand Down Expand Up @@ -212,4 +228,14 @@ class Artboard(unsafeCppPointer: Long, private val lock: ReentrantLock) :
*/
val stateMachineNames: List<String>
get() = (0 until stateMachineCount).map { cppStateMachineNameByIndex(cppPointer, it) }

private fun convertInput(input: SMIInput): SMIInput {
val convertedInput = when {
input.isBoolean -> SMIBoolean(input.cppPointer)
input.isTrigger -> SMITrigger(input.cppPointer)
input.isNumber -> SMINumber(input.cppPointer)
else -> throw StateMachineInputException("Unknown State Machine Input Instance for ${input.name}.")
}
return convertedInput
}
}
2 changes: 1 addition & 1 deletion submodules/rive-cpp

0 comments on commit a89a447

Please sign in to comment.