()
| 8 | ) |
| 9 | |
| 10 | func (r *Render) drawCursor() { |
| 11 | //draw cursor |
| 12 | if !r.buffer.IsCursorVisible() { |
| 13 | return |
| 14 | } |
| 15 | |
| 16 | pixelX := float64(int(r.buffer.CursorColumn()) * r.font.CellSize.X) |
| 17 | pixelY := float64(int(r.buffer.CursorLine()) * r.font.CellSize.Y) |
| 18 | cell := r.buffer.GetCell(r.buffer.CursorColumn(), r.buffer.CursorLine()) |
| 19 | |
| 20 | useFace := r.font.Regular |
| 21 | if cell != nil { |
| 22 | if cell.Bold() && cell.Italic() { |
| 23 | useFace = r.font.BoldItalic |
| 24 | } else if cell.Bold() { |
| 25 | useFace = r.font.Bold |
| 26 | } else if cell.Italic() { |
| 27 | useFace = r.font.Italic |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | pixelW, pixelH := float64(r.font.CellSize.X), float64(r.font.CellSize.Y) |
| 32 | |
| 33 | // empty rect without focus |
| 34 | if !ebiten.IsFocused() { |
| 35 | ebitenutil.DrawRect(r.frame, pixelX, pixelY, pixelW, pixelH, r.theme.CursorBackground()) |
| 36 | ebitenutil.DrawRect(r.frame, pixelX+1, pixelY+1, pixelW-2, pixelH-2, r.theme.CursorForeground()) |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | // draw the cursor shape |
| 41 | switch r.buffer.GetCursorShape() { |
| 42 | case termutil.CursorShapeBlinkingBar, termutil.CursorShapeSteadyBar: |
| 43 | ebitenutil.DrawRect(r.frame, pixelX, pixelY, 2, pixelH, r.theme.CursorBackground()) |
| 44 | case termutil.CursorShapeBlinkingUnderline, termutil.CursorShapeSteadyUnderline: |
| 45 | ebitenutil.DrawRect(r.frame, pixelX, pixelY+pixelH-2, pixelW, 2, r.theme.CursorBackground()) |
| 46 | default: |
| 47 | // draw a custom cursor if we have one and there are no characters in the way |
| 48 | if r.cursorImage != nil && (cell == nil || cell.Rune().Rune == 0) { |
| 49 | opt := &ebiten.DrawImageOptions{} |
| 50 | _, h := r.cursorImage.Size() |
| 51 | ratio := 1 / (float64(h) / float64(r.font.CellSize.Y)) |
| 52 | actualHeight := float64(h) * ratio |
| 53 | offsetY := (float64(r.font.CellSize.Y) - actualHeight) / 2 |
| 54 | opt.GeoM.Scale(ratio, ratio) |
| 55 | opt.GeoM.Translate(pixelX, pixelY+offsetY) |
| 56 | r.frame.DrawImage(r.cursorImage, opt) |
| 57 | return |
| 58 | } |
| 59 | |
| 60 | ebitenutil.DrawRect(r.frame, pixelX, pixelY, pixelW, pixelH, r.theme.CursorBackground()) |
| 61 | |
| 62 | // we've drawn over the cell contents, so we need to draw it again in the cursor colours |
| 63 | if cell != nil && cell.Rune().Rune > 0 { |
| 64 | text.Draw(r.frame, string(cell.Rune().Rune), useFace, int(pixelX), int(pixelY)+r.font.DotDepth, r.theme.CursorForeground()) |
| 65 | } |
| 66 | } |
| 67 | } |
no test coverage detected