mirror of https://github.com/liamg/aminal.git
Merge pull request #73 from liamg/retina-display-support
Retina display support
This commit is contained in:
commit
1538fb291d
|
@ -39,6 +39,7 @@ Ensure you have your latest graphics card drivers installed before use.
|
||||||
- Sixel support
|
- Sixel support
|
||||||
- Hints/overlays
|
- Hints/overlays
|
||||||
- Built-in patched fonts for powerline
|
- Built-in patched fonts for powerline
|
||||||
|
- Retina display support
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
|
|
|
@ -2,16 +2,14 @@ package glfont
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
|
||||||
"image/draw"
|
|
||||||
"io"
|
|
||||||
"math"
|
|
||||||
|
|
||||||
"github.com/go-gl/gl/all-core/gl"
|
"github.com/go-gl/gl/all-core/gl"
|
||||||
"github.com/golang/freetype"
|
"github.com/golang/freetype"
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"golang.org/x/image/font"
|
"golang.org/x/image/font"
|
||||||
"golang.org/x/image/math/fixed"
|
"golang.org/x/image/math/fixed"
|
||||||
|
"image"
|
||||||
|
"image/draw"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DPI = 72
|
const DPI = 72
|
||||||
|
@ -83,9 +81,6 @@ func (f *Font) LinePadding() float32 {
|
||||||
//Printf draws a string to the screen, takes a list of arguments like printf
|
//Printf draws a string to the screen, takes a list of arguments like printf
|
||||||
func (f *Font) Print(x, y float32, text string) error {
|
func (f *Font) Print(x, y float32, text string) error {
|
||||||
|
|
||||||
x = float32(math.Round(float64(x)))
|
|
||||||
y = float32(math.Round(float64(y)))
|
|
||||||
|
|
||||||
indices := []rune(text)
|
indices := []rune(text)
|
||||||
|
|
||||||
if len(indices) == 0 {
|
if len(indices) == 0 {
|
||||||
|
|
10
gui/fonts.go
10
gui/fonts.go
|
@ -10,12 +10,12 @@ import (
|
||||||
|
|
||||||
func (gui *GUI) getPackedFont(name string) (*glfont.Font, error) {
|
func (gui *GUI) getPackedFont(name string) (*glfont.Font, error) {
|
||||||
box := packr.NewBox("./packed-fonts")
|
box := packr.NewBox("./packed-fonts")
|
||||||
fontBytes, err := box.MustBytes(name)
|
fontBytes, err := box.Find(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("packaged font '%s' could not be read: %s", name, err)
|
return nil, fmt.Errorf("packaged font '%s' could not be read: %s", name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
font, err := glfont.LoadFont(bytes.NewReader(fontBytes), gui.fontScale, gui.width, gui.height)
|
font, err := glfont.LoadFont(bytes.NewReader(fontBytes), gui.fontScale/gui.scale(), gui.width, gui.height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("font '%s' failed to load: %v", name, err)
|
return nil, fmt.Errorf("font '%s' failed to load: %v", name, err)
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,13 @@ func (gui *GUI) loadFonts() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if gui.fontMap == nil {
|
||||||
gui.fontMap = NewFontMap(defaultFont, boldFont)
|
gui.fontMap = NewFontMap(defaultFont, boldFont)
|
||||||
|
}else{
|
||||||
|
gui.fontMap.defaultFont = defaultFont
|
||||||
|
gui.fontMap.defaultBoldFont = boldFont
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// add special non-ascii fonts here
|
// add special non-ascii fonts here
|
||||||
|
|
||||||
|
|
21
gui/gui.go
21
gui/gui.go
|
@ -55,6 +55,12 @@ func New(config *config.Config, terminal *terminal.Terminal, logger *zap.Sugared
|
||||||
|
|
||||||
// inspired by https://kylewbanks.com/blog/tutorial-opengl-with-golang-part-1-hello-opengl
|
// inspired by https://kylewbanks.com/blog/tutorial-opengl-with-golang-part-1-hello-opengl
|
||||||
|
|
||||||
|
func (gui *GUI) scale() float32{
|
||||||
|
pw, _ := gui.window.GetFramebufferSize()
|
||||||
|
ww, _ := gui.window.GetSize()
|
||||||
|
return float32(ww) / float32(pw)
|
||||||
|
}
|
||||||
|
|
||||||
// can only be called on OS thread
|
// can only be called on OS thread
|
||||||
func (gui *GUI) resize(w *glfw.Window, width int, height int) {
|
func (gui *GUI) resize(w *glfw.Window, width int, height int) {
|
||||||
|
|
||||||
|
@ -63,16 +69,11 @@ 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 resolutions...")
|
gui.logger.Debugf("Updating font resolutions...")
|
||||||
gui.fontMap.UpdateResolution(int(float32(width)*hScale), int(float32(height)*vScale))
|
gui.loadFonts()
|
||||||
|
|
||||||
gui.logger.Debugf("Setting renderer area...")
|
gui.logger.Debugf("Setting renderer area...")
|
||||||
gui.renderer.SetArea(0, 0, int(float32(width)*hScale), int(float32(height)*vScale))
|
gui.renderer.SetArea(0, 0, width, height)
|
||||||
|
|
||||||
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()
|
||||||
|
@ -245,9 +246,11 @@ func (gui *GUI) Render() error {
|
||||||
if gui.terminal.ActiveBuffer().InSelection(uint16(x), uint16(y)) {
|
if gui.terminal.ActiveBuffer().InSelection(uint16(x), uint16(y)) {
|
||||||
colour = &gui.config.ColourScheme.Selection
|
colour = &gui.config.ColourScheme.Selection
|
||||||
}
|
}
|
||||||
|
if cell.Image() != nil {
|
||||||
gui.renderer.DrawCellBg(cell, uint(x), uint(y), cursor, colour, false)
|
|
||||||
gui.renderer.DrawCellImage(cell, uint(x), uint(y))
|
gui.renderer.DrawCellImage(cell, uint(x), uint(y))
|
||||||
|
}else{
|
||||||
|
gui.renderer.DrawCellBg(cell, uint(x), uint(y), cursor, colour, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for y := 0; y < lineCount; y++ {
|
for y := 0; y < lineCount; y++ {
|
||||||
|
|
Loading…
Reference in New Issue