Skip to content

Commit 54cded1

Browse files
adrian17Herschel
authored andcommitted
text: Implement TextField.background, disable it by default
1 parent 85aa383 commit 54cded1

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

core/src/avm1/globals/text_field.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ pub fn create_proto<'gc>(
122122
with_text_field_props!(
123123
object, gc_context, fn_proto,
124124
"autoSize" => [auto_size, set_auto_size],
125+
"background" => [background, set_background],
125126
"backgroundColor" => [background_color, set_background_color],
126127
"border" => [border, set_border],
127128
"borderColor" => [border_color, set_border_color],
@@ -391,6 +392,23 @@ pub fn set_html_text<'gc>(
391392
Ok(())
392393
}
393394

395+
pub fn background<'gc>(
396+
this: EditText<'gc>,
397+
_activation: &mut Activation<'_, 'gc, '_>,
398+
) -> Result<Value<'gc>, Error<'gc>> {
399+
Ok(this.has_background().into())
400+
}
401+
402+
pub fn set_background<'gc>(
403+
this: EditText<'gc>,
404+
activation: &mut Activation<'_, 'gc, '_>,
405+
value: Value<'gc>,
406+
) -> Result<(), Error<'gc>> {
407+
let has_background = value.as_bool(activation.current_swf_version());
408+
this.set_has_background(activation.context.gc_context, has_background);
409+
Ok(())
410+
}
411+
394412
pub fn background_color<'gc>(
395413
this: EditText<'gc>,
396414
_activation: &mut Activation<'_, 'gc, '_>,

core/src/display_object/edit_text.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ pub struct EditTextData<'gc> {
9090
/// If this is a password input field
9191
is_password: bool,
9292

93-
/// The color of the background fill. Only applied when has_border.
93+
/// If the text field should have a background. Only applied when has_border.
94+
has_background: bool,
95+
96+
/// The color of the background fill. Only applied when has_border and has_background.
9497
background_color: u32,
9598

9699
/// If the text field should have a border.
@@ -195,6 +198,7 @@ impl<'gc> EditText<'gc> {
195198
swf_tag.is_device_font,
196199
);
197200

201+
let has_background = false;
198202
let background_color = 0xFFFFFF; // Default is white
199203
let has_border = swf_tag.has_border;
200204
let border_color = 0; // Default is black
@@ -252,6 +256,7 @@ impl<'gc> EditText<'gc> {
252256
is_editable,
253257
is_word_wrap,
254258
is_password,
259+
has_background,
255260
background_color,
256261
has_border,
257262
border_color,
@@ -513,6 +518,15 @@ impl<'gc> EditText<'gc> {
513518
self.relayout(context);
514519
}
515520

521+
pub fn has_background(self) -> bool {
522+
self.0.read().has_background
523+
}
524+
525+
pub fn set_has_background(self, context: MutationContext<'gc, '_>, has_background: bool) {
526+
self.0.write(context).has_background = has_background;
527+
self.redraw_border(context);
528+
}
529+
516530
pub fn background_color(self) -> u32 {
517531
self.0.read().background_color
518532
}
@@ -673,12 +687,16 @@ impl<'gc> EditText<'gc> {
673687
Twips::new(1),
674688
swf::Color::from_rgb(border_color, 0xFF),
675689
)));
676-
write
677-
.drawing
678-
.set_fill_style(Some(swf::FillStyle::Color(swf::Color::from_rgb(
679-
background_color,
680-
0xFF,
681-
))));
690+
if write.has_background {
691+
write
692+
.drawing
693+
.set_fill_style(Some(swf::FillStyle::Color(swf::Color::from_rgb(
694+
background_color,
695+
0xFF,
696+
))));
697+
} else {
698+
write.drawing.set_fill_style(None);
699+
}
682700
write.drawing.draw_command(DrawCommand::MoveTo {
683701
x: Twips::new(0),
684702
y: Twips::new(0),

0 commit comments

Comments
 (0)