Merge pull request #102 from vkravets/redraw_fix

redraw correctly during resize
This commit is contained in:
Liam Galvin 2018-12-02 19:15:29 +00:00 committed by GitHub
commit c4389a87e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 90 additions and 88 deletions

View File

@ -91,6 +91,8 @@ func (gui *GUI) resize(w *glfw.Window, width int, height int) {
gui.logger.Debugf("Resize complete!") gui.logger.Debugf("Resize complete!")
gui.redraw(buffer.NewBackgroundCell(gui.config.ColourScheme.Background))
gui.window.SwapBuffers()
} }
func (gui *GUI) getTermSize() (uint, uint) { func (gui *GUI) getTermSize() (uint, uint) {
@ -219,94 +221,7 @@ func (gui *GUI) Render() error {
if gui.terminal.CheckDirty() { if gui.terminal.CheckDirty() {
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT) gui.redraw(defaultCell)
lines := gui.terminal.GetVisibleLines()
lineCount := int(gui.terminal.ActiveBuffer().ViewHeight())
colCount := int(gui.terminal.ActiveBuffer().ViewWidth())
cx := uint(gui.terminal.GetLogicalCursorX())
cy := uint(gui.terminal.GetLogicalCursorY()) + uint(gui.terminal.GetScrollOffset())
var colour *config.Colour
for y := 0; y < lineCount; y++ {
if y < len(lines) {
cells := lines[y].Cells()
for x := 0; x < colCount; x++ {
cursor := false
if gui.terminal.Modes().ShowCursor {
cursor = cx == uint(x) && cy == uint(y)
}
if gui.terminal.ActiveBuffer().InSelection(uint16(x), uint16(y)) {
colour = &gui.config.ColourScheme.Selection
} else {
colour = nil
}
cell := defaultCell
if colour != nil || cursor || x < len(cells) {
if x < len(cells) {
cell = cells[x]
if cell.Image() != nil {
gui.renderer.DrawCellImage(cell, uint(x), uint(y))
continue
}
}
gui.renderer.DrawCellBg(cell, uint(x), uint(y), cursor, colour, false)
}
}
}
}
for y := 0; y < lineCount; y++ {
if y < len(lines) {
bufStr := ""
bold := false
dim := false
col := 0
colour := [3]float32{0, 0, 0}
cells := lines[y].Cells()
for x := 0; x < colCount; x++ {
if x < len(cells) {
cell := cells[x]
if bufStr != "" && (cell.Attr().Dim != dim || cell.Attr().Bold != bold || colour != cell.Fg()) {
var alpha float32 = 1.0
if dim {
alpha = 0.5
}
gui.renderer.DrawCellText(bufStr, uint(col), uint(y), alpha, colour, bold)
col = x
bufStr = ""
}
dim = cell.Attr().Dim
colour = cell.Fg()
bold = cell.Attr().Bold
r := cell.Rune()
if r == 0 {
r = ' '
}
bufStr += string(r)
}
}
if bufStr != "" {
var alpha float32 = 1.0
if dim {
alpha = 0.5
}
gui.renderer.DrawCellText(bufStr, uint(col), uint(y), alpha, colour, bold)
}
}
}
gui.renderOverlay()
if gui.showDebugInfo { if gui.showDebugInfo {
gui.textbox(2, 2, fmt.Sprintf(`Cursor: %d,%d gui.textbox(2, 2, fmt.Sprintf(`Cursor: %d,%d
@ -357,6 +272,93 @@ Buffer Size: %d lines
} }
func (gui *GUI) redraw(defaultCell buffer.Cell) {
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)
lines := gui.terminal.GetVisibleLines()
lineCount := int(gui.terminal.ActiveBuffer().ViewHeight())
colCount := int(gui.terminal.ActiveBuffer().ViewWidth())
cx := uint(gui.terminal.GetLogicalCursorX())
cy := uint(gui.terminal.GetLogicalCursorY()) + uint(gui.terminal.GetScrollOffset())
var colour *config.Colour
for y := 0; y < lineCount; y++ {
if y < len(lines) {
cells := lines[y].Cells()
for x := 0; x < colCount; x++ {
cursor := false
if gui.terminal.Modes().ShowCursor {
cursor = cx == uint(x) && cy == uint(y)
}
if gui.terminal.ActiveBuffer().InSelection(uint16(x), uint16(y)) {
colour = &gui.config.ColourScheme.Selection
} else {
colour = nil
}
cell := defaultCell
if colour != nil || cursor || x < len(cells) {
if x < len(cells) {
cell = cells[x]
if cell.Image() != nil {
gui.renderer.DrawCellImage(cell, uint(x), uint(y))
continue
}
}
gui.renderer.DrawCellBg(cell, uint(x), uint(y), cursor, colour, false)
}
}
}
}
for y := 0; y < lineCount; y++ {
if y < len(lines) {
bufStr := ""
bold := false
dim := false
col := 0
colour := [3]float32{0, 0, 0}
cells := lines[y].Cells()
for x := 0; x < colCount; x++ {
if x < len(cells) {
cell := cells[x]
if bufStr != "" && (cell.Attr().Dim != dim || cell.Attr().Bold != bold || colour != cell.Fg()) {
var alpha float32 = 1.0
if dim {
alpha = 0.5
}
gui.renderer.DrawCellText(bufStr, uint(col), uint(y), alpha, colour, bold)
col = x
bufStr = ""
}
dim = cell.Attr().Dim
colour = cell.Fg()
bold = cell.Attr().Bold
r := cell.Rune()
if r == 0 {
r = ' '
}
bufStr += string(r)
}
}
if bufStr != "" {
var alpha float32 = 1.0
if dim {
alpha = 0.5
}
gui.renderer.DrawCellText(bufStr, uint(col), uint(y), alpha, colour, bold)
}
}
}
gui.renderOverlay()
}
func (gui *GUI) createWindow() (*glfw.Window, error) { func (gui *GUI) createWindow() (*glfw.Window, error) {
if err := glfw.Init(); err != nil { if err := glfw.Init(); err != nil {
return nil, fmt.Errorf("Failed to initialise GLFW: %s", err) return nil, fmt.Errorf("Failed to initialise GLFW: %s", err)