Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inset box shadow fixes #285

Merged
merged 3 commits into from Jun 9, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Take clip mode into account when calculating box shadow rectangle

A positive spread value makes an inset shadow smaller, so take the clip
mode into account when computing the box shadow size.

Fixes #183

v2: Don't introduce extra variable.
  • Loading branch information
anderco committed Jun 9, 2016
commit 7439fb779a8dfcbe59cf71934ea8b8eb7db1023e
@@ -642,7 +642,7 @@ impl<'a> BatchBuilder<'a> {
clip_mode: BoxShadowClipMode,
resource_cache: &ResourceCache,
frame_id: FrameId) {
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius);
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius, clip_mode);

// Fast path.
if blur_radius == 0.0 && spread_radius == 0.0 && clip_mode == BoxShadowClipMode::None {
@@ -732,7 +732,7 @@ impl<'a> BatchBuilder<'a> {
// |##| |##|
// +--+------------------+--+

let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius);
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius, clip_mode);
let metrics = BoxShadowMetrics::new(&rect, border_radius, blur_radius);

let clip_state = self.adjust_clip_for_box_shadow_clip_mode(box_bounds,
@@ -812,7 +812,7 @@ impl<'a> BatchBuilder<'a> {
clip_mode: BoxShadowClipMode,
resource_cache: &ResourceCache,
frame_id: FrameId) {
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius);
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius, clip_mode);
let metrics = BoxShadowMetrics::new(&rect, border_radius, blur_radius);

let clip_state = self.adjust_clip_for_box_shadow_clip_mode(box_bounds,
@@ -903,7 +903,7 @@ impl<'a> BatchBuilder<'a> {
border_radius: f32,
resource_cache: &ResourceCache,
frame_id: FrameId) {
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius);
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius, BoxShadowClipMode::Inset);
let metrics = BoxShadowMetrics::new(&rect, border_radius, blur_radius);

let clip_state = self.adjust_clip_for_box_shadow_clip_mode(box_bounds,
@@ -1884,11 +1884,17 @@ impl BoxShadowMetrics {

pub fn compute_box_shadow_rect(box_bounds: &Rect<f32>,
box_offset: &Point2D<f32>,
spread_radius: f32)
mut spread_radius: f32,
clip_mode: BoxShadowClipMode)
-> Rect<f32> {
let mut rect = (*box_bounds).clone();
rect.origin.x += box_offset.x;
rect.origin.y += box_offset.y;

if clip_mode == BoxShadowClipMode::Inset {
spread_radius = -spread_radius;
};

rect.inflate(spread_radius, spread_radius)
}

@@ -198,7 +198,8 @@ impl BuildRequiredResources for AABBTreeNode {

let box_rect = batch_builder::compute_box_shadow_rect(&info.box_bounds,
&info.offset,
info.spread_radius);
info.spread_radius,
info.clip_mode);
resource_list.add_box_shadow_corner(info.blur_radius,
info.border_radius,
&box_rect,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.