mirror of
https://github.com/felixangell/phi.git
synced 2024-10-03 19:27:35 +03:00
really simple dpi scaling for mac
This commit is contained in:
parent
412d7dc45a
commit
55bd38f041
@ -151,6 +151,17 @@ func NewBuffer(conf *cfg.TomlConfig, buffOpts BufferConfig, parent *BufferView,
|
||||
config = cfg.NewDefaultConfig()
|
||||
}
|
||||
|
||||
// TODO we load the font in config, instead
|
||||
// we should load it when used, for example here.
|
||||
// DPI FIX.
|
||||
newSize := int(float64(config.Editor.Font_Size) * cfg.ScaleFactor)
|
||||
scaledFont, err := config.Editor.Loaded_Font.DeriveFont(newSize)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("loading new font thing")
|
||||
config.Editor.Loaded_Font = scaledFont
|
||||
|
||||
curs := sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_IBEAM)
|
||||
|
||||
// TODO do this only if we are hovering over the buffer
|
||||
@ -1331,7 +1342,9 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
||||
highlightLinePosY := b.ey + (ry + b.curs.ry*(lastCharH+pad)) - (b.cam.y * (lastCharH + pad))
|
||||
highlightLinePosX := b.ex + rx
|
||||
|
||||
ctx.Rect(highlightLinePosX, highlightLinePosY, w-b.ex, (lastCharH+pad)-b.ey, strife.Fill)
|
||||
width := w - b.ex
|
||||
height := (lastCharH + pad) - b.ey
|
||||
ctx.Rect(highlightLinePosX, highlightLinePosY, width, height, strife.Fill)
|
||||
}
|
||||
|
||||
var visibleLines, visibleChars int = 50, -1
|
||||
@ -1433,7 +1446,7 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
||||
continue
|
||||
}
|
||||
|
||||
x_col += 1
|
||||
x_col++
|
||||
|
||||
if info, ok := matches[idx]; ok {
|
||||
if colorStack == nil || len(colorStack) == 0 {
|
||||
|
@ -20,7 +20,8 @@ type BufferPane struct {
|
||||
|
||||
func NewBufferPane(buff *Buffer) *BufferPane {
|
||||
fontPath := filepath.Join(cfg.FONT_FOLDER, buff.cfg.Editor.Font_Face+".ttf")
|
||||
metaPanelFont, err := strife.LoadFont(fontPath, 14)
|
||||
// FIXME DPI
|
||||
metaPanelFont, err := strife.LoadFont(fontPath, int(14.0*cfg.ScaleFactor))
|
||||
if err != nil {
|
||||
log.Println("Note: failed to load meta panel font ", fontPath)
|
||||
metaPanelFont = buff.buffOpts.font
|
||||
|
@ -70,6 +70,8 @@ func (c *Cursor) Render(ctx *strife.Renderer, xOff, yOff int) {
|
||||
xPos := b.ex + (xOff + c.rx*lastCharW) - (b.cam.x * lastCharW)
|
||||
yPos := b.ey + (yOff + c.ry*c.height) - (b.cam.y * c.height)
|
||||
|
||||
// NOTE: we dont have to scale the curor here because
|
||||
// it's based off the font size which has already been scaled.
|
||||
ctx.SetColor(strife.HexRGB(b.buffOpts.cursor))
|
||||
ctx.Rect(xPos, yPos, c.width, c.height, strife.Fill)
|
||||
|
||||
|
@ -94,6 +94,12 @@ func NewCommandPalette(conf cfg.TomlConfig, view *BufferView) *CommandPalette {
|
||||
conf.Editor.Show_Line_Numbers = false
|
||||
conf.Editor.Highlight_Line = false
|
||||
|
||||
newSize := int(float64(conf.Editor.Font_Size) * cfg.ScaleFactor)
|
||||
paletteFont, err := conf.Editor.Loaded_Font.DeriveFont(newSize)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
palette := &CommandPalette{
|
||||
conf: &conf,
|
||||
parent: view,
|
||||
@ -110,7 +116,7 @@ func NewCommandPalette(conf cfg.TomlConfig, view *BufferView) *CommandPalette {
|
||||
// so these aren't necessary
|
||||
0x0, 0x0,
|
||||
|
||||
conf.Editor.Loaded_Font,
|
||||
paletteFont,
|
||||
}, nil, 0),
|
||||
parentBuff: nil,
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ import (
|
||||
)
|
||||
|
||||
type TomlConfig struct {
|
||||
Editor EditorConfig `toml:"editor"`
|
||||
Cursor CursorConfig `toml:"cursor"`
|
||||
Render RenderConfig `toml:"render"`
|
||||
Theme ThemeConfig `toml:"theme"`
|
||||
Editor *EditorConfig `toml:"editor"`
|
||||
Cursor *CursorConfig `toml:"cursor"`
|
||||
Render *RenderConfig `toml:"render"`
|
||||
Theme *ThemeConfig `toml:"theme"`
|
||||
Associations map[string]FileAssociations `toml:"file_associations"`
|
||||
Commands map[string]Command `toml:"commands"`
|
||||
|
||||
@ -128,8 +128,8 @@ type EditorConfig struct {
|
||||
func NewDefaultConfig() *TomlConfig {
|
||||
log.Println("Loading default configuration... this should never happen")
|
||||
return &TomlConfig{
|
||||
Editor: EditorConfig{},
|
||||
Theme: ThemeConfig{
|
||||
Editor: &EditorConfig{},
|
||||
Theme: &ThemeConfig{
|
||||
Background: 0x002649,
|
||||
Foreground: 0xf2f4f6,
|
||||
Cursor: 0xf2f4f6,
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cfg
|
||||
|
||||
var (
|
||||
DebugMode = false
|
||||
DebugMode = false
|
||||
ScaleFactor = 1.0
|
||||
)
|
||||
|
@ -12,9 +12,8 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/felixangell/strife"
|
||||
|
||||
// fork of BurntSushi with hexadecimal support.
|
||||
"github.com/felixangell/strife"
|
||||
"github.com/felixangell/toml"
|
||||
)
|
||||
|
||||
@ -111,6 +110,7 @@ func configureAndValidate(conf *TomlConfig) {
|
||||
panic(err)
|
||||
}
|
||||
conf.Editor.Loaded_Font = font
|
||||
|
||||
}
|
||||
|
||||
// config & validate the keyboard shortcuts
|
||||
|
8
info.plist
Normal file
8
info.plist
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
27
main.go
27
main.go
@ -32,8 +32,8 @@ func (n *PhiEditor) handleEvent(evt strife.StrifeEvent) {
|
||||
|
||||
}
|
||||
|
||||
func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
|
||||
mainView := buff.NewView(1280, 720, cfg)
|
||||
func (n *PhiEditor) init(conf *cfg.TomlConfig) {
|
||||
mainView := buff.NewView(int(1280.0*cfg.ScaleFactor), int(720.0*cfg.ScaleFactor), conf)
|
||||
|
||||
args := os.Args
|
||||
if len(args) > 1 {
|
||||
@ -54,7 +54,7 @@ func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
|
||||
}
|
||||
|
||||
n.mainView = mainView
|
||||
n.defaultFont = cfg.Editor.Loaded_Font
|
||||
n.defaultFont = conf.Editor.Loaded_Font
|
||||
}
|
||||
|
||||
func (n *PhiEditor) dispose() {
|
||||
@ -75,14 +75,22 @@ func main() {
|
||||
|
||||
config := cfg.Setup()
|
||||
|
||||
ww, wh := 1280, 720
|
||||
|
||||
windowConfig := strife.DefaultConfig()
|
||||
windowConfig.Accelerated = config.Render.Accelerated
|
||||
windowConfig.Alias = config.Render.Aliased
|
||||
windowConfig.VerticalSync = config.Render.Vertical_Sync
|
||||
|
||||
window := strife.SetupRenderWindow(ww, wh, windowConfig)
|
||||
ww, wh := float32(640.0), float32(360.0)
|
||||
|
||||
dpi, defDpi := strife.GetDisplayDPI(0)
|
||||
|
||||
cfg.ScaleFactor = float64(dpi / defDpi)
|
||||
|
||||
scaledWidth := int((ww * dpi) / defDpi)
|
||||
scaledHeight := int((wh * dpi) / defDpi)
|
||||
|
||||
window := strife.SetupRenderWindow(scaledWidth, scaledHeight, windowConfig)
|
||||
window.AllowHighDPI()
|
||||
window.SetTitle("Hello world!")
|
||||
window.SetResizable(true)
|
||||
|
||||
@ -92,6 +100,7 @@ func main() {
|
||||
case *strife.CloseEvent:
|
||||
window.Close()
|
||||
case *strife.WindowResizeEvent:
|
||||
// FIXME.
|
||||
editor.resize(event.Width, event.Height)
|
||||
default:
|
||||
editor.handleEvent(evt)
|
||||
@ -150,12 +159,12 @@ func main() {
|
||||
// this is only printed on each
|
||||
// render...
|
||||
ctx.SetColor(strife.White)
|
||||
ctx.Text(fmt.Sprintf("fps: %d, ups %d", fps, ups), ww-256, wh-128)
|
||||
ctx.Text(fmt.Sprintf("fps: %d, ups %d", fps, ups), int(scaledWidth-256), int(scaledHeight-128))
|
||||
|
||||
ctx.Display()
|
||||
frames += 1
|
||||
frames++
|
||||
}
|
||||
updates += 1
|
||||
updates++
|
||||
|
||||
if time.Now().Sub(lastDebugRender) >= time.Second {
|
||||
lastDebugRender = time.Now()
|
||||
|
Loading…
Reference in New Issue
Block a user