Skip to content

Commit

Permalink
webrender: show right divider
Browse files Browse the repository at this point in the history
  • Loading branch information
harryfei committed Aug 16, 2020
1 parent 945d37b commit 98c2c42
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 7 deletions.
54 changes: 54 additions & 0 deletions rust_src/src/webrender_backend/draw_canvas.rs
Expand Up @@ -230,4 +230,58 @@ impl DrawCanvas {
);
});
}

pub fn draw_window_divider(
&mut self,
color: u64,
color_first: u64,
color_last: u64,
x0: i32,
x1: i32,
y0: i32,
y1: i32,
) {
self.output.display(|builder, space_and_clip| {
if (y1 - y0 > x1 - x0) && (x1 - x0 >= 3) {
// A vertical divider, at least three pixels wide: Draw first and
// last pixels differently.

builder.push_rect(
&CommonItemProperties::new((x0, y0).to(x0 + 1, y1), space_and_clip),
pixel_to_color(color_first),
);
builder.push_rect(
&CommonItemProperties::new((x0 + 1, y0).to(x1 - 1, y1), space_and_clip),
pixel_to_color(color),
);
builder.push_rect(
&CommonItemProperties::new((x1 - 1, y0).to(x1, y1), space_and_clip),
pixel_to_color(color_last),
);
} else if (x1 - x0 > y1 - y0) && (y1 - y0 >= 3) {
// A horizontal divider, at least three pixels high: Draw first and
// last pixels differently.
builder.push_rect(
&CommonItemProperties::new((x0, y0).to(x1, 1), space_and_clip),
pixel_to_color(color_first),
);
builder.push_rect(
&CommonItemProperties::new((x0, y0 + 1).to(x1, y1 - 1), space_and_clip),
pixel_to_color(color),
);
builder.push_rect(
&CommonItemProperties::new((x0, y1 - 1).to(x1, y1), space_and_clip),
pixel_to_color(color_last),
);
} else {
// In any other case do not draw the first and last pixels
// differently.
let visible_rect = (x0, y0).to(x1, y1);
builder.push_rect(
&CommonItemProperties::new(visible_rect, space_and_clip),
pixel_to_color(color),
);
}
});
}
}
48 changes: 41 additions & 7 deletions rust_src/src/webrender_backend/term.rs
Expand Up @@ -17,8 +17,10 @@ use crate::{
},
remacs_sys::{
block_input, unblock_input, x_clear_end_of_line, x_clear_window_mouse_face,
x_draw_vertical_border, x_fix_overlapping_area, x_get_glyph_overhangs, x_produce_glyphs,
x_set_font, x_set_font_backend, x_set_left_fringe, x_set_right_fringe, x_write_glyphs,
x_draw_right_divider, x_draw_vertical_border, x_fix_overlapping_area,
x_get_glyph_overhangs, x_produce_glyphs, x_set_bottom_divider_width, x_set_font,
x_set_font_backend, x_set_left_fringe, x_set_right_divider_width, x_set_right_fringe,
x_write_glyphs,
},
windows::LispWindowRef,
};
Expand Down Expand Up @@ -58,8 +60,8 @@ fn get_frame_parm_handlers() -> [frame_parm_handler; 45] {
None,
None,
None,
None,
None,
Some(x_set_right_divider_width),
Some(x_set_bottom_divider_width),
None,
None,
None,
Expand Down Expand Up @@ -123,7 +125,7 @@ lazy_static! {
clear_frame_area: Some(clear_frame_area),
draw_window_cursor: None,
draw_vertical_window_border: Some(draw_vertical_window_border),
draw_window_divider: None,
draw_window_divider: Some(draw_window_divider),
shift_glyphs_for_insert: None,
show_hourglass: None,
hide_hourglass: None,
Expand All @@ -148,9 +150,11 @@ extern "C" fn update_window_end(
}

unsafe { block_input() };
if unsafe { draw_window_fringes(window.as_mut(), true) } {
if window.right_divider_width() > 0 {
unsafe { x_draw_right_divider(window.as_mut()) }
} else {
unsafe { x_draw_vertical_border(window.as_mut()) }
};
}
unsafe { unblock_input() };
}

Expand Down Expand Up @@ -189,6 +193,36 @@ extern "C" fn draw_fringe_bitmap(
output.canvas().draw_fringe_bitmap(row, p);
}

extern "C" fn draw_window_divider(window: *mut Lisp_Window, x0: i32, x1: i32, y0: i32, y1: i32) {
let window: LispWindowRef = window.into();
let frame: LispFrameRef = window.get_frame();

let output: OutputRef = unsafe { frame.output_data.wr.into() };

let face = frame.face_from_id(face_id::WINDOW_DIVIDER_FACE_ID);
let face_first = frame.face_from_id(face_id::WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID);
let face_last = frame.face_from_id(face_id::WINDOW_DIVIDER_LAST_PIXEL_FACE_ID);

let color = match face {
Some(f) => unsafe { (*f).foreground },
None => frame.foreground_pixel,
};

let color_first = match face_first {
Some(f) => unsafe { (*f).foreground },
None => frame.foreground_pixel,
};

let color_last = match face_last {
Some(f) => unsafe { (*f).foreground },
None => frame.foreground_pixel,
};

output
.canvas()
.draw_window_divider(color, color_first, color_last, x0, x1, y0, y1);
}

extern "C" fn draw_vertical_window_border(window: *mut Lisp_Window, x: i32, y0: i32, y1: i32) {
let window: LispWindowRef = window.into();
let frame: LispFrameRef = window.get_frame();
Expand Down

0 comments on commit 98c2c42

Please sign in to comment.