Merge pull request #41 from liamg/fix-osx-framebuffer-issues

fix osx framebuffer issues
This commit is contained in:
Liam Galvin 2018-10-25 10:18:48 +01:00 committed by GitHub
commit 700bbb9af9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 12 deletions

View File

@ -616,8 +616,6 @@ func (buffer *Buffer) incrementCursorPosition() {
buffer.cursorX++ buffer.cursorX++
} else {
fmt.Println("cursor position invalid")
} }
} }
@ -780,7 +778,13 @@ func (buffer *Buffer) DeleteChars(n int) {
defer buffer.emitDisplayChange() defer buffer.emitDisplayChange()
line := buffer.getCurrentLine() line := buffer.getCurrentLine()
if int(buffer.cursorX) >= len(line.cells) {
return
}
before := line.cells[:buffer.cursorX] before := line.cells[:buffer.cursorX]
if int(buffer.cursorX)+n >= len(line.cells) {
n = len(line.cells) - int(buffer.cursorX)
}
after := line.cells[int(buffer.cursorX)+n:] after := line.cells[int(buffer.cursorX)+n:]
line.cells = append(before, after...) line.cells = append(before, after...)
} }

View File

@ -14,6 +14,8 @@ import (
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
) )
const DPI = 72
// A Font allows rendering of text to an OpenGL context. // A Font allows rendering of text to an OpenGL context.
type Font struct { type Font struct {
characters map[rune]*character characters map[rune]*character
@ -213,7 +215,7 @@ func (f *Font) GetRune(r rune) (*character, error) {
//create new face to measure glyph diamensions //create new face to measure glyph diamensions
ttfFace := truetype.NewFace(f.ttf, &truetype.Options{ ttfFace := truetype.NewFace(f.ttf, &truetype.Options{
Size: float64(f.scale), Size: float64(f.scale),
DPI: 72, DPI: DPI,
Hinting: font.HintingFull, Hinting: font.HintingFull,
}) })
@ -257,7 +259,7 @@ func (f *Font) GetRune(r rune) (*character, error) {
//create a freetype context for drawing //create a freetype context for drawing
c := freetype.NewContext() c := freetype.NewContext()
c.SetDPI(72) c.SetDPI(DPI)
c.SetFont(f.ttf) c.SetFont(f.ttf)
c.SetFontSize(float64(f.scale)) c.SetFontSize(float64(f.scale))
c.SetClip(rgba.Bounds()) c.SetClip(rgba.Bounds())

View File

@ -41,7 +41,7 @@ func LoadTrueTypeFont(program uint32, r io.Reader, scale float32) (*Font, error)
ttfFace := truetype.NewFace(f.ttf, &truetype.Options{ ttfFace := truetype.NewFace(f.ttf, &truetype.Options{
Size: float64(f.scale), Size: float64(f.scale),
DPI: 72, DPI: DPI,
Hinting: font.HintingFull, Hinting: font.HintingFull,
}) })

View File

@ -37,8 +37,8 @@ func New(config *config.Config, terminal *terminal.Terminal, logger *zap.Sugared
return &GUI{ return &GUI{
config: config, config: config,
logger: logger, logger: logger,
width: 600, width: 800,
height: 300, height: 600,
terminal: terminal, terminal: terminal,
fontScale: 14.0, fontScale: 14.0,
} }
@ -54,16 +54,21 @@ func (gui *GUI) resize(w *glfw.Window, width int, height int) {
gui.width = width gui.width = width
gui.height = height gui.height = height
ww, wh := w.GetSize()
hScale := float32(ww) / float32(width)
vScale := float32(wh) / float32(height)
gui.logger.Debugf("Updating font resolution...") gui.logger.Debugf("Updating font resolution...")
if gui.font != nil { if gui.font != nil {
gui.font.UpdateResolution((width), (height)) gui.font.UpdateResolution(int(float32(width)*hScale), int(float32(height)*vScale))
} }
if gui.boldFont != nil { if gui.boldFont != nil {
gui.boldFont.UpdateResolution((width), (height)) gui.boldFont.UpdateResolution(int(float32(width)*hScale), int(float32(height)*vScale))
} }
gui.logger.Debugf("Setting renderer area...") gui.logger.Debugf("Setting renderer area...")
gui.renderer.SetArea(0, 0, gui.width, gui.height) gui.renderer.SetArea(0, 0, int(float32(width)*hScale), int(float32(height)*vScale))
gui.logger.Debugf("Calculating size in cols/rows...") gui.logger.Debugf("Calculating size in cols/rows...")
cols, rows := gui.renderer.GetTermSize() cols, rows := gui.renderer.GetTermSize()
@ -106,7 +111,7 @@ func (gui *GUI) Render() error {
gui.logger.Debugf("Creating window...") gui.logger.Debugf("Creating window...")
var err error var err error
gui.window, err = gui.createWindow(500, 300) gui.window, err = gui.createWindow(gui.width, gui.height)
if err != nil { if err != nil {
return fmt.Errorf("Failed to create window: %s", err) return fmt.Errorf("Failed to create window: %s", err)
} }
@ -144,7 +149,7 @@ func (gui *GUI) Render() error {
gui.terminal.SetDirty() gui.terminal.SetDirty()
} }
}) })
w, h := gui.window.GetSize() w, h := gui.window.GetFramebufferSize()
gui.resize(gui.window, w, h) gui.resize(gui.window, w, h)
gui.logger.Debugf("Starting pty read handling...") gui.logger.Debugf("Starting pty read handling...")