Draws the cursor at the current position and saves the previous contents of the screen so that `clear_cursor` can restore them. Does not present the canvas.
(&mut self)
| 385 | /// |
| 386 | /// Does not present the canvas. |
| 387 | fn draw_cursor(&mut self) -> io::Result<()> { |
| 388 | if !self.cursor_visible { |
| 389 | return Ok(()); |
| 390 | } |
| 391 | |
| 392 | let x1y1 = self.cursor_pos.clamped_mul(self.glyph_size); |
| 393 | |
| 394 | assert!(self.cursor_backup.is_none()); |
| 395 | self.cursor_backup = Some(self.raster_ops.read_pixels(x1y1, self.glyph_size)?); |
| 396 | |
| 397 | // TODO(jmmv): It would be nice to draw the cursor with alpha blending so that the letters |
| 398 | // under it are visible. This was done before in the HTML canvas but was lost when I added |
| 399 | // the GraphicsConsole abstraction. Maybe all RGB colors should switch to RGBA. Or maybe |
| 400 | // we should special-case the cursor drawing. |
| 401 | self.raster_ops.set_draw_color(self.fg_color); |
| 402 | self.raster_ops.draw_rect_filled(x1y1, self.glyph_size) |
| 403 | } |
| 404 | |
| 405 | /// Clears the cursor at the current position by restoring the contents of the screen saved by |
| 406 | /// an earlier call to `draw_cursor`. |
no test coverage detected