1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
/* Copyright (c) 2024 Li Jin, dragon-fly@qq.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
extern "C" {
fn actiondef_release(raw: i64);
fn actiondef_prop(duration: f32, start: f32, stop: f32, prop: i32, easing: i32) -> i64;
fn actiondef_tint(duration: f32, start: i32, stop: i32, easing: i32) -> i64;
fn actiondef_roll(duration: f32, start: f32, stop: f32, easing: i32) -> i64;
fn actiondef_spawn(defs: i64) -> i64;
fn actiondef_sequence(defs: i64) -> i64;
fn actiondef_delay(duration: f32) -> i64;
fn actiondef_show() -> i64;
fn actiondef_hide() -> i64;
fn actiondef_event(event_name: i64, msg: i64) -> i64;
fn actiondef_move_to(duration: f32, start: i64, stop: i64, easing: i32) -> i64;
fn actiondef_scale(duration: f32, start: f32, stop: f32, easing: i32) -> i64;
}
pub struct ActionDef { raw: i64 }
impl Drop for ActionDef {
fn drop(&mut self) { unsafe { actiondef_release(self.raw); } }
}
impl ActionDef {
pub(crate) fn raw(&self) -> i64 {
self.raw
}
pub(crate) fn from(raw: i64) -> ActionDef {
ActionDef { raw: raw }
}
/// Creates a new Action object to change a property of a node.
///
/// # Arguments
///
/// * `duration` - The duration of the action.
/// * `start` - The starting value of the property.
/// * `stop` - The ending value of the property.
/// * `prop` - The property to change.
/// * `easing` - The easing function to use.
///
/// # Returns
///
/// * `Action` - A new Action object.
pub fn prop(duration: f32, start: f32, stop: f32, prop: crate::dora::Property, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_prop(duration, start, stop, prop as i32, easing as i32)); }
}
/// Creates a new Action object to change the color of a node.
///
/// # Arguments
///
/// * `duration` - The duration of the action.
/// * `start` - The starting color.
/// * `stop` - The ending color.
/// * `easing` - The easing function to use.
///
/// # Returns
///
/// * `Action` - A new Action object.
pub fn tint(duration: f32, start: &crate::dora::Color3, stop: &crate::dora::Color3, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_tint(duration, start.to_rgb() as i32, stop.to_rgb() as i32, easing as i32)); }
}
/// Creates a new Action object to rotate a node by smallest angle.
///
/// # Arguments
///
/// * `duration` - The duration of the action.
/// * `start` - The starting angle.
/// * `stop` - The ending angle.
/// * `easing` - The easing function to use.
///
/// # Returns
///
/// * `Action` - A new Action object.
pub fn roll(duration: f32, start: f32, stop: f32, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_roll(duration, start, stop, easing as i32)); }
}
/// Creates a new Action object to run a group of actions in parallel.
///
/// # Arguments
///
/// * `defs` - The actions to run in parallel.
///
/// # Returns
///
/// * `Action` - A new Action object.
pub fn spawn(defs: &Vec<crate::dora::ActionDef>) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_spawn(crate::dora::Vector::from_action_def(defs))); }
}
/// Creates a new Action object to run a group of actions in sequence.
///
/// # Arguments
///
/// * `defs` - The actions to run in sequence.
///
/// # Returns
///
/// * `Action` - A new Action object.
pub fn sequence(defs: &Vec<crate::dora::ActionDef>) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_sequence(crate::dora::Vector::from_action_def(defs))); }
}
/// Creates a new Action object to delay the execution of following action.
///
/// # Arguments
///
/// * `duration` - The duration of the delay.
///
/// # Returns
///
/// * `Action` - A new Action object.
pub fn delay(duration: f32) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_delay(duration)); }
}
/// Creates a new Action object to show a node.
pub fn show() -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_show()); }
}
/// Creates a new Action object to hide a node.
pub fn hide() -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_hide()); }
}
/// Creates a new Action object to emit an event.
///
/// # Arguments
///
/// * `eventName` - The name of the event to emit.
/// * `msg` - The message to send with the event.
///
/// # Returns
///
/// * `Action` - A new Action object.
pub fn event(event_name: &str, msg: &str) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_event(crate::dora::from_string(event_name), crate::dora::from_string(msg))); }
}
/// Creates a new Action object to move a node.
///
/// # Arguments
///
/// * `duration` - The duration of the action.
/// * `start` - The starting position.
/// * `stop` - The ending position.
/// * `easing` - The easing function to use.
///
/// # Returns
///
/// * `Action` - A new Action object.
pub fn move_to(duration: f32, start: &crate::dora::Vec2, stop: &crate::dora::Vec2, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_move_to(duration, start.into_i64(), stop.into_i64(), easing as i32)); }
}
/// Creates a new Action object to scale a node.
///
/// # Arguments
///
/// * `duration` - The duration of the action.
/// * `start` - The starting scale.
/// * `stop` - The ending scale.
/// * `easing` - The easing function to use.
///
/// # Returns
///
/// * `Action` - A new Action object.
pub fn scale(duration: f32, start: f32, stop: f32, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_scale(duration, start, stop, easing as i32)); }
}
}