Skip to content

Commit

Permalink
Implement asymmetric border colors
Browse files Browse the repository at this point in the history
  • Loading branch information
sammykim committed Aug 20, 2013
1 parent 89c5083 commit 0e863b3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/gfx/display_list.rs
Expand Up @@ -104,7 +104,7 @@ pub struct BorderDisplayItem<E> {
border: SideOffsets2D<Au>,

/// The color of the border.
color: Color,
color: SideOffsets2D<Color>,
}

impl<E> DisplayItem<E> {
Expand Down
11 changes: 5 additions & 6 deletions src/components/gfx/render_context.rs
Expand Up @@ -37,8 +37,7 @@ impl<'self> RenderContext<'self> {
pub fn draw_border(&self,
bounds: &Rect<Au>,
border: SideOffsets2D<Au>,
color: Color) {
let pattern = ColorPattern(color);
color: SideOffsets2D<Color>) {
let draw_opts = DrawOptions(1 as AzFloat, 0 as uint16_t);
let stroke_fields = 2; // CAP_SQUARE
let mut stroke_opts = StrokeOptions(0 as AzFloat, 10 as AzFloat, stroke_fields);
Expand All @@ -53,28 +52,28 @@ impl<'self> RenderContext<'self> {
let y = rect.origin.y + border.top * 0.5;
let start = Point2D(rect.origin.x, y);
let end = Point2D(rect.origin.x + rect.size.width, y);
self.canvas.draw_target.stroke_line(start, end, &pattern, &stroke_opts, &draw_opts);
self.canvas.draw_target.stroke_line(start, end, &ColorPattern(color.top), &stroke_opts, &draw_opts);

// draw bottom border
stroke_opts.line_width = border.bottom;
let y = rect.origin.y + rect.size.height - border.bottom * 0.5;
let start = Point2D(rect.origin.x, y);
let end = Point2D(rect.origin.x + rect.size.width, y);
self.canvas.draw_target.stroke_line(start, end, &pattern, &stroke_opts, &draw_opts);
self.canvas.draw_target.stroke_line(start, end, &ColorPattern(color.bottom), &stroke_opts, &draw_opts);

// draw left border
stroke_opts.line_width = border.left;
let x = rect.origin.x + border.left * 0.5;
let start = Point2D(x, rect.origin.y);
let end = Point2D(x, rect.origin.y + rect.size.height);
self.canvas.draw_target.stroke_line(start, end, &pattern, &stroke_opts, &draw_opts);
self.canvas.draw_target.stroke_line(start, end, &ColorPattern(color.left), &stroke_opts, &draw_opts);

// draw right border
stroke_opts.line_width = border.right;
let x = rect.origin.x + rect.size.width - border.right * 0.5;
let start = Point2D(x, rect.origin.y);
let end = Point2D(x, rect.origin.y + rect.size.height);
self.canvas.draw_target.stroke_line(start, end, &pattern, &stroke_opts, &draw_opts);
self.canvas.draw_target.stroke_line(start, end, &ColorPattern(color.right), &stroke_opts, &draw_opts);
}

pub fn draw_image(&self, bounds: Rect<Au>, image: Arc<~Image>) {
Expand Down
28 changes: 22 additions & 6 deletions src/components/main/layout/box.rs
Expand Up @@ -639,7 +639,11 @@ impl RenderBox {
extra: ExtraDisplayListData::new(*self),
},
border: debug_border,
color: rgb(0, 0, 200).to_gfx_color(),
color: SideOffsets2D::new(rgb(0, 0, 200).to_gfx_color(),
rgb(0, 0, 200).to_gfx_color(),
rgb(0, 0, 200).to_gfx_color(),
rgb(0, 0, 200).to_gfx_color())

};
list.append_item(BorderDisplayItemClass(border_display_item))
}
Expand All @@ -659,7 +663,11 @@ impl RenderBox {
extra: ExtraDisplayListData::new(*self),
},
border: debug_border,
color: rgb(0, 200, 0).to_gfx_color(),
color: SideOffsets2D::new(rgb(0, 200, 0).to_gfx_color(),
rgb(0, 200, 0).to_gfx_color(),
rgb(0, 200, 0).to_gfx_color(),
rgb(0, 200, 0).to_gfx_color())

};
list.append_item(BorderDisplayItemClass(border_display_item))
}
Expand Down Expand Up @@ -687,7 +695,11 @@ impl RenderBox {
extra: ExtraDisplayListData::new(*self),
},
border: debug_border,
color: rgb(0, 0, 200).to_gfx_color(),
color: SideOffsets2D::new(rgb(0, 0, 200).to_gfx_color(),
rgb(0, 0, 200).to_gfx_color(),
rgb(0, 0, 200).to_gfx_color(),
rgb(0, 0, 200).to_gfx_color())

};
list.append_item(BorderDisplayItemClass(border_display_item))
}
Expand Down Expand Up @@ -914,9 +926,10 @@ impl RenderBox {
return
}

// FIXME: all colors set to top color. this is obviously not right.
let top_color = self.style().border_top_color();
let color = top_color.to_gfx_color();
let right_color = self.style().border_right_color();
let bottom_color = self.style().border_bottom_color();
let left_color = self.style().border_left_color();

// Append the border to the display list.
do list.with_mut_ref |list| {
Expand All @@ -929,7 +942,10 @@ impl RenderBox {
border.right,
border.bottom,
border.left),
color: color,
color: SideOffsets2D::new(top_color.to_gfx_color(),
right_color.to_gfx_color(),
bottom_color.to_gfx_color(),
left_color.to_gfx_color())
};

list.append_item(BorderDisplayItemClass(border_display_item))
Expand Down

0 comments on commit 0e863b3

Please sign in to comment.