From 2f22c4182849b1fb914b8f7c9124926de6d8d4cd Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Thu, 25 Oct 2018 10:15:54 +0100 Subject: [PATCH] fix osx framebuffer issues --- buffer/buffer.go | 8 ++++++-- glfont/font.go | 6 ++++-- glfont/truetype.go | 2 +- gui/gui.go | 19 ++++++++++++------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/buffer/buffer.go b/buffer/buffer.go index 3b221d4..079a770 100644 --- a/buffer/buffer.go +++ b/buffer/buffer.go @@ -616,8 +616,6 @@ func (buffer *Buffer) incrementCursorPosition() { buffer.cursorX++ - } else { - fmt.Println("cursor position invalid") } } @@ -780,7 +778,13 @@ func (buffer *Buffer) DeleteChars(n int) { defer buffer.emitDisplayChange() line := buffer.getCurrentLine() + if int(buffer.cursorX) >= len(line.cells) { + return + } 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:] line.cells = append(before, after...) } diff --git a/glfont/font.go b/glfont/font.go index d578b35..9f698fd 100644 --- a/glfont/font.go +++ b/glfont/font.go @@ -14,6 +14,8 @@ import ( "golang.org/x/image/math/fixed" ) +const DPI = 72 + // A Font allows rendering of text to an OpenGL context. type Font struct { characters map[rune]*character @@ -213,7 +215,7 @@ func (f *Font) GetRune(r rune) (*character, error) { //create new face to measure glyph diamensions ttfFace := truetype.NewFace(f.ttf, &truetype.Options{ Size: float64(f.scale), - DPI: 72, + DPI: DPI, Hinting: font.HintingFull, }) @@ -257,7 +259,7 @@ func (f *Font) GetRune(r rune) (*character, error) { //create a freetype context for drawing c := freetype.NewContext() - c.SetDPI(72) + c.SetDPI(DPI) c.SetFont(f.ttf) c.SetFontSize(float64(f.scale)) c.SetClip(rgba.Bounds()) diff --git a/glfont/truetype.go b/glfont/truetype.go index 7809e2c..cda6275 100644 --- a/glfont/truetype.go +++ b/glfont/truetype.go @@ -41,7 +41,7 @@ func LoadTrueTypeFont(program uint32, r io.Reader, scale float32) (*Font, error) ttfFace := truetype.NewFace(f.ttf, &truetype.Options{ Size: float64(f.scale), - DPI: 72, + DPI: DPI, Hinting: font.HintingFull, }) diff --git a/gui/gui.go b/gui/gui.go index dbe1511..487e5a1 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -37,8 +37,8 @@ func New(config *config.Config, terminal *terminal.Terminal, logger *zap.Sugared return &GUI{ config: config, logger: logger, - width: 600, - height: 300, + width: 800, + height: 600, terminal: terminal, fontScale: 14.0, } @@ -54,16 +54,21 @@ func (gui *GUI) resize(w *glfw.Window, width int, height int) { gui.width = width gui.height = height + ww, wh := w.GetSize() + + hScale := float32(ww) / float32(width) + vScale := float32(wh) / float32(height) + gui.logger.Debugf("Updating font resolution...") if gui.font != nil { - gui.font.UpdateResolution((width), (height)) + gui.font.UpdateResolution(int(float32(width)*hScale), int(float32(height)*vScale)) } 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.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...") cols, rows := gui.renderer.GetTermSize() @@ -106,7 +111,7 @@ func (gui *GUI) Render() error { gui.logger.Debugf("Creating window...") var err error - gui.window, err = gui.createWindow(500, 300) + gui.window, err = gui.createWindow(gui.width, gui.height) if err != nil { return fmt.Errorf("Failed to create window: %s", err) } @@ -144,7 +149,7 @@ func (gui *GUI) Render() error { gui.terminal.SetDirty() } }) - w, h := gui.window.GetSize() + w, h := gui.window.GetFramebufferSize() gui.resize(gui.window, w, h) gui.logger.Debugf("Starting pty read handling...")