Skip to content

Commit

Permalink
core: Apply a mask when rendering text, fixes parts of ruffle-rs#1167
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone committed Sep 15, 2020
1 parent 6a4da95 commit f80dc89
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions core/src/display_object/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,16 +986,31 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
let transform = self.transform().clone();
context.transform_stack.push(&transform);

let edit_text = self.0.read();
context.transform_stack.push(&Transform {
matrix: Matrix {
tx: self.0.read().bounds.x_min,
ty: self.0.read().bounds.y_min,
tx: edit_text.bounds.x_min,
ty: edit_text.bounds.y_min,
..Default::default()
},
..Default::default()
});

self.0.read().drawing.render(context);
edit_text.drawing.render(context);

context.renderer.push_mask();
let mask = Matrix::create_box(
edit_text.bounds.width().to_pixels() as f32,
edit_text.bounds.height().to_pixels() as f32,
0.0,
Twips::zero(),
Twips::zero(),
);
context.renderer.draw_rect(
Color::from_rgb(0, 0xff),
&(context.transform_stack.transform().matrix * mask),
);
context.renderer.activate_mask();

// TODO: Where does this come from? How is this different than INTERNAL_PADDING? Does this apply to y as well?
// If this is actually right, offset the border in `redraw_border` instead of doing an extra push.
Expand All @@ -1008,10 +1023,12 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
..Default::default()
});

for layout_box in self.0.read().layout.iter() {
for layout_box in edit_text.layout.iter() {
self.render_layout_box(context, layout_box);
}

context.renderer.pop_mask();

context.transform_stack.pop();
context.transform_stack.pop();
context.transform_stack.pop();
Expand Down

0 comments on commit f80dc89

Please sign in to comment.