From 1f059510123fb932ae658ac042015af83abed93f Mon Sep 17 00:00:00 2001 From: rrrooommmaaa Date: Tue, 5 Feb 2019 16:16:38 +0300 Subject: [PATCH] bug fix: character under cursor rendering (#194) --- gui/gui.go | 38 +++++++++++++++++++++++++++++++++++--- gui/renderer.go | 13 ++----------- gui/textbox.go | 2 +- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/gui/gui.go b/gui/gui.go index fa91273..ad24163 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -207,6 +207,20 @@ func (gui *GUI) generateDefaultCell(reverse bool) { ) } +func (gui *GUI) getCursorBg(cell *buffer.Cell) (bg [3]float32) { + if gui.config.ColourScheme.Cursor != cell.Bg() { + bg = gui.config.ColourScheme.Cursor + } else { + bg = cell.Fg() + } + return bg +} + +func (gui *GUI) getCursorFg(cell *buffer.Cell) (fg [3]float32) { + fg = cell.Bg() + return fg +} + // can only be called on OS thread func (gui *GUI) resize(w *glfw.Window, width int, height int) { @@ -481,7 +495,12 @@ func (gui *GUI) redraw() { } } - gui.renderer.DrawCellBg(*cell, uint(x), uint(y), cursor, colour, false) + if cursor { + var bgColour config.Colour = gui.getCursorBg(cell) + colour = &bgColour + } + + gui.renderer.DrawCellBg(*cell, uint(x), uint(y), colour, false) } } @@ -501,7 +520,20 @@ func (gui *GUI) redraw() { for x := 0; x < colCount; x++ { if x < len(cells) { cell := cells[x] - if builder.Len() > 0 && (cell.Attr().Dim != dim || cell.Attr().Bold != bold || colour != cell.Fg()) { + + cursor := false + if gui.terminal.Modes().ShowCursor { + cursor = cx == uint(x) && cy == uint(y) + } + + var newFg [3]float32 + if cursor { + newFg = gui.getCursorFg(&cell) + } else { + newFg = cell.Fg() + } + + if builder.Len() > 0 && (cell.Attr().Dim != dim || cell.Attr().Bold != bold || colour != newFg) { var alpha float32 = 1.0 if dim { alpha = 0.5 @@ -511,7 +543,7 @@ func (gui *GUI) redraw() { builder.Reset() } dim = cell.Attr().Dim - colour = cell.Fg() + colour = newFg bold = cell.Attr().Bold r := cell.Rune() if r == 0 { diff --git a/gui/renderer.go b/gui/renderer.go index 39a191b..b5aee10 100644 --- a/gui/renderer.go +++ b/gui/renderer.go @@ -203,23 +203,14 @@ func (r *OpenGLRenderer) DrawCursor(col uint, row uint, colour config.Colour) { rect.Free() } -func (r *OpenGLRenderer) DrawCellBg(cell buffer.Cell, col uint, row uint, cursor bool, colour *config.Colour, force bool) { +func (r *OpenGLRenderer) DrawCellBg(cell buffer.Cell, col uint, row uint, colour *config.Colour, force bool) { var bg [3]float32 if colour != nil { bg = *colour } else { - - if cursor { - if r.config.ColourScheme.Cursor != r.backgroundColour { - bg = r.config.ColourScheme.Cursor - } else { - bg = cell.Fg() - } - } else { - bg = cell.Bg() - } + bg = cell.Bg() } if bg != r.backgroundColour || force { diff --git a/gui/textbox.go b/gui/textbox.go index efc2cdc..0eaf528 100644 --- a/gui/textbox.go +++ b/gui/textbox.go @@ -81,7 +81,7 @@ DONE: for hx := col; hx < col+uint16(longestLine)+1; hx++ { for hy := row - 1; hy < row+uint16(len(lines))+1; hy++ { - gui.renderer.DrawCellBg(buffer.NewBackgroundCell(bg), uint(hx), uint(hy), false, nil, true) + gui.renderer.DrawCellBg(buffer.NewBackgroundCell(bg), uint(hx), uint(hy), nil, true) } }