From df6aa85948941c62fc6ccea383f4463cc519f4d9 Mon Sep 17 00:00:00 2001 From: Adrian Wielgosik Date: Mon, 8 Feb 2021 21:41:34 +0100 Subject: [PATCH] text: Implement TextField.background, disable it by default --- core/src/avm1/globals/text_field.rs | 18 ++++++++++++++++ core/src/display_object/edit_text.rs | 32 ++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/core/src/avm1/globals/text_field.rs b/core/src/avm1/globals/text_field.rs index 5aaeba604..46a2bcde2 100644 --- a/core/src/avm1/globals/text_field.rs +++ b/core/src/avm1/globals/text_field.rs @@ -122,6 +122,7 @@ pub fn create_proto<'gc>( with_text_field_props!( object, gc_context, fn_proto, "autoSize" => [auto_size, set_auto_size], + "background" => [background, set_background], "backgroundColor" => [background_color, set_background_color], "border" => [border, set_border], "borderColor" => [border_color, set_border_color], @@ -391,6 +392,23 @@ pub fn set_html_text<'gc>( Ok(()) } +pub fn background<'gc>( + this: EditText<'gc>, + _activation: &mut Activation<'_, 'gc, '_>, +) -> Result, Error<'gc>> { + Ok(this.has_background().into()) +} + +pub fn set_background<'gc>( + this: EditText<'gc>, + activation: &mut Activation<'_, 'gc, '_>, + value: Value<'gc>, +) -> Result<(), Error<'gc>> { + let has_background = value.as_bool(activation.current_swf_version()); + this.set_has_background(activation.context.gc_context, has_background); + Ok(()) +} + pub fn background_color<'gc>( this: EditText<'gc>, _activation: &mut Activation<'_, 'gc, '_>, diff --git a/core/src/display_object/edit_text.rs b/core/src/display_object/edit_text.rs index 4875e3de8..1c01dad10 100644 --- a/core/src/display_object/edit_text.rs +++ b/core/src/display_object/edit_text.rs @@ -90,7 +90,10 @@ pub struct EditTextData<'gc> { /// If this is a password input field is_password: bool, - /// The color of the background fill. Only applied when has_border. + /// If the text field should have a background. Only applied when has_border. + has_background: bool, + + /// The color of the background fill. Only applied when has_border and has_background. background_color: u32, /// If the text field should have a border. @@ -195,6 +198,7 @@ impl<'gc> EditText<'gc> { swf_tag.is_device_font, ); + let has_background = false; let background_color = 0xFFFFFF; // Default is white let has_border = swf_tag.has_border; let border_color = 0; // Default is black @@ -252,6 +256,7 @@ impl<'gc> EditText<'gc> { is_editable, is_word_wrap, is_password, + has_background, background_color, has_border, border_color, @@ -513,6 +518,15 @@ impl<'gc> EditText<'gc> { self.relayout(context); } + pub fn has_background(self) -> bool { + self.0.read().has_background + } + + pub fn set_has_background(self, context: MutationContext<'gc, '_>, has_background: bool) { + self.0.write(context).has_background = has_background; + self.redraw_border(context); + } + pub fn background_color(self) -> u32 { self.0.read().background_color } @@ -673,12 +687,16 @@ impl<'gc> EditText<'gc> { Twips::new(1), swf::Color::from_rgb(border_color, 0xFF), ))); - write - .drawing - .set_fill_style(Some(swf::FillStyle::Color(swf::Color::from_rgb( - background_color, - 0xFF, - )))); + if write.has_background { + write + .drawing + .set_fill_style(Some(swf::FillStyle::Color(swf::Color::from_rgb( + background_color, + 0xFF, + )))); + } else { + write.drawing.set_fill_style(None); + } write.drawing.draw_command(DrawCommand::MoveTo { x: Twips::new(0), y: Twips::new(0),