Skip to content

Commit

Permalink
avm1: Hook up TextField.filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone committed Aug 13, 2023
1 parent b2c334b commit b274d53
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion core/src/avm1/globals/text_field.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::avm1::activation::Activation;
use crate::avm1::error::Error;
use crate::avm1::globals::bitmap_filter;
use crate::avm1::object::NativeObject;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{globals, Object, ScriptObject, TObject, Value};
use crate::avm1::{globals, ArrayObject, Object, ScriptObject, TObject, Value};
use crate::context::GcContext;
use crate::display_object::{AutoSizeMode, EditText, TDisplayObject, TextSelection};
use crate::font::round_down_to_pixel;
Expand Down Expand Up @@ -66,6 +67,7 @@ const PROTO_DECLS: &[Declaration] = declare_properties! {
"borderColor" => property(tf_getter!(border_color), tf_setter!(set_border_color));
"bottomScroll" => property(tf_getter!(bottom_scroll));
"embedFonts" => property(tf_getter!(embed_fonts), tf_setter!(set_embed_fonts));
"filters" => property(tf_getter!(filters), tf_setter!(set_filters); DONT_DELETE | DONT_ENUM | VERSION_8);
"getDepth" => method(globals::get_depth; DONT_ENUM | DONT_DELETE | READ_ONLY | VERSION_6);
"hscroll" => property(tf_getter!(hscroll), tf_setter!(set_hscroll));
"html" => property(tf_getter!(html), tf_setter!(set_html));
Expand Down Expand Up @@ -800,3 +802,37 @@ pub fn set_sharpness<'gc>(

Ok(())
}

fn filters<'gc>(
this: EditText<'gc>,
activation: &mut Activation<'_, 'gc>,
) -> Result<Value<'gc>, Error<'gc>> {
Ok(ArrayObject::new(
activation.context.gc_context,
activation.context.avm1.prototypes().array,
this.filters()
.into_iter()
.map(|filter| bitmap_filter::filter_to_avm1(activation, filter)),
)
.into())
}

fn set_filters<'gc>(
this: EditText<'gc>,
activation: &mut Activation<'_, 'gc>,
value: Value<'gc>,
) -> Result<(), Error<'gc>> {
let mut filters = vec![];
if let Value::Object(value) = value {
for index in value.get_keys(activation, false).into_iter().rev() {
let filter_object = value.get(index, activation)?.coerce_to_object(activation);
if let Some(filter) =
bitmap_filter::avm1_to_filter(filter_object, &mut activation.context)
{
filters.push(filter);
}
}
}
this.set_filters(activation.context.gc_context, filters);
Ok(())
}

0 comments on commit b274d53

Please sign in to comment.