create VmcExtSettingColor

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-30 11:44:28 -05:00
parent c274f7925b
commit 0df7475f57

View File

@ -1029,3 +1029,44 @@ impl MessageBehavior for VmcExtOpt {
}
}
}
struct VmcExtSettingColor {
color: Color,
}
impl MessageBehavior for VmcExtSettingColor {
fn to_osc_message(&self) -> OscMessage {
return OscMessage {
addr: String::from("/VMC/Ext/Setting/Color"),
args: vec![
OscType::from(self.color.r),
OscType::from(self.color.g),
OscType::from(self.color.b),
OscType::from(self.color.a),
],
};
}
fn from_osc_message(msg: OscMessage) -> Result<Self, String> {
if msg.args.len() != 4 {
return Err(String::from("argj count invalid"));
}
let mut color = Color::from_rgba(0.0, 0.0, 0.0, 0.0);
match msg.args[0] {
OscType::Float(f) => color.r = f,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[1] {
OscType::Float(f) => color.g = f,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[2] {
OscType::Float(f) => color.b = f,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[3] {
OscType::Float(f) => color.a = f,
_ => return Err(String::from("arg type invalid")),
}
return Ok(VmcExtSettingColor { color });
}
}