(
&mut self,
x1y1: PixelsXY,
x2y2: PixelsXY,
size: SizeInPixels,
)
| 243 | } |
| 244 | |
| 245 | fn move_pixels( |
| 246 | &mut self, |
| 247 | x1y1: PixelsXY, |
| 248 | x2y2: PixelsXY, |
| 249 | size: SizeInPixels, |
| 250 | ) -> io::Result<()> { |
| 251 | // TODO(jmmv): This is much faster to do than reading and putting pixels... but means we |
| 252 | // cannot use the "_size" parameter to move just a portion of the image. This is fine |
| 253 | // for now because this is only used for console scrolling... but highlights that this |
| 254 | // generic interface may need tweaking. |
| 255 | // |
| 256 | // https://stackoverflow.com/questions/8376534/shift-canvas-contents-to-the-left |
| 257 | debug_assert_eq!(0, x1y1.x); |
| 258 | debug_assert_eq!(0, x2y2.x); |
| 259 | debug_assert_eq!(self.size_pixels.width, size.width); |
| 260 | debug_assert!(x1y1.y >= x2y2.y); |
| 261 | debug_assert!(x2y2.y >= 0); |
| 262 | debug_assert!( |
| 263 | i32::from(x1y1.y) + i32::from(size.height) <= i32::from(self.size_pixels.height) |
| 264 | ); |
| 265 | |
| 266 | let saved = self.context.global_composite_operation().map_err(js_value_to_io_error)?; |
| 267 | self.context.set_global_composite_operation("copy").map_err(js_value_to_io_error)?; |
| 268 | |
| 269 | self.context |
| 270 | .draw_image_with_html_canvas_element( |
| 271 | self.context.canvas().as_ref().expect("Canvas must be present in context"), |
| 272 | f64::from(x2y2.x - x1y1.x), |
| 273 | f64::from(x2y2.y - x1y1.y), |
| 274 | ) |
| 275 | .map_err(js_value_to_io_error)?; |
| 276 | |
| 277 | self.context.set_global_composite_operation(&saved).map_err(js_value_to_io_error)?; |
| 278 | |
| 279 | let delta_y = i32::from(x1y1.y) - i32::from(x2y2.y); |
| 280 | debug_assert_eq!(x1y1.x, x2y2.x); |
| 281 | debug_assert!(delta_y >= 0); |
| 282 | if delta_y > 0 { |
| 283 | self.context.fill_rect( |
| 284 | f64::from(x1y1.x), |
| 285 | f64::from(x2y2.y) + f64::from(size.height), |
| 286 | f64::from(size.width), |
| 287 | f64::from(delta_y), |
| 288 | ); |
| 289 | } |
| 290 | Ok(()) |
| 291 | } |
| 292 | |
| 293 | fn write_text(&mut self, xy: PixelsXY, text: &str) -> io::Result<()> { |
| 294 | draw_text(self, self.font, xy, text) |
no outgoing calls
no test coverage detected