rusty_spine/event.rs
1use crate::{
2 c::{spEvent, spEventData},
3 c_interface::{NewFromPtr, SyncPtr},
4 TrackEntry,
5};
6
7#[allow(unused_imports)]
8use crate::AnimationState;
9
10/// A wrapper for [`Event`] that makes events slightly nicer to work with in Rust.
11///
12/// To receive events, see [`AnimationState::set_listener`].
13pub enum AnimationEvent<'a> {
14 Start {
15 /// The track this event originated from.
16 track_entry: TrackEntry,
17 },
18 Interrupt {
19 /// The track this event originated from.
20 track_entry: TrackEntry,
21 },
22 End {
23 /// The track this event originated from.
24 track_entry: TrackEntry,
25 },
26 Complete {
27 /// The track this event originated from.
28 track_entry: TrackEntry,
29 },
30 Dispose {
31 /// The track this event originated from.
32 track_entry: TrackEntry,
33 },
34 Event {
35 /// The track this event originated from.
36 track_entry: TrackEntry,
37 /// The name of the event, which is unique across all events in the skeleton.
38 name: &'a str,
39 /// The animation time this event was keyed.
40 time: f32,
41 /// The event's int value.
42 int: i32,
43 /// The event's float value.
44 float: f32,
45 /// The event's string value or an empty string.
46 string: &'a str,
47 /// The event's audio path or an empty string.
48 audio_path: &'a str,
49 /// The event's audio volume.
50 volume: f32,
51 /// The event's audio balance.
52 balance: f32,
53 /// The raw event data.
54 event: Event,
55 },
56}
57
58/// Events fired from animations.
59///
60/// [Spine API Reference](http://esotericsoftware.com/spine-api-reference#Event)
61///
62/// To receive events, see [`AnimationState::set_listener`].
63#[derive(Debug)]
64pub struct Event {
65 c_event: SyncPtr<spEvent>,
66}
67
68impl NewFromPtr<spEvent> for Event {
69 unsafe fn new_from_ptr(c_event: *mut spEvent) -> Self {
70 Self {
71 c_event: SyncPtr(c_event),
72 }
73 }
74}
75
76impl Event {
77 c_accessor_tmp_ptr_mut!(
78 /// The events's setup pose data.
79 data,
80 /// The events's mutable setup pose data.
81 data_mut,
82 data,
83 EventData,
84 spEventData
85 );
86 c_accessor!(
87 /// The animation time this event was keyed.
88 time,
89 time,
90 f32
91 );
92 c_accessor!(
93 /// The event's int value.
94 int_value,
95 intValue,
96 i32
97 );
98 c_accessor!(
99 /// The event's float value.
100 float_value,
101 floatValue,
102 f32
103 );
104 c_accessor_string!(
105 /// The event's string value or an empty string.
106 string_value,
107 stringValue
108 );
109 c_accessor!(
110 /// The event's audio volume value.
111 volume,
112 volume,
113 f32
114 );
115 c_accessor!(
116 /// The event's audio balance value.
117 balance,
118 balance,
119 f32
120 );
121 c_ptr!(c_event, spEvent);
122}
123
124/// Static event data imported from Spine.
125///
126/// [Spine API Reference](http://esotericsoftware.com/spine-api-reference#EventData)
127#[derive(Debug)]
128pub struct EventData {
129 c_event_data: SyncPtr<spEventData>,
130}
131
132impl NewFromPtr<spEventData> for EventData {
133 unsafe fn new_from_ptr(c_event_data: *mut spEventData) -> Self {
134 Self {
135 c_event_data: SyncPtr(c_event_data),
136 }
137 }
138}
139
140impl EventData {
141 c_accessor_string!(
142 ///The name of the event, which is unique across all events in the skeleton.
143 name,
144 name
145 );
146 c_accessor!(
147 /// The event's int value.
148 int_value,
149 intValue,
150 i32
151 );
152 c_accessor!(
153 /// The event's float value.
154 float_value,
155 floatValue,
156 f32
157 );
158 c_accessor_string!(
159 /// The event's string value or an empty string.
160 string_value,
161 stringValue
162 );
163 c_accessor_string!(
164 /// The event's audio path.
165 audio_path,
166 audioPath
167 );
168 c_accessor!(
169 /// The event's audio volume value.
170 volume,
171 volume,
172 f32
173 );
174 c_accessor!(
175 /// The event's audio balance value.
176 balance,
177 balance,
178 f32
179 );
180 c_ptr!(c_event_data, spEventData);
181}