From 6ffcff960064697c933d368c8b97fbdd97bfddd3 Mon Sep 17 00:00:00 2001 From: Felix Angell Date: Sat, 9 Jan 2021 12:57:32 +0000 Subject: [PATCH] change default font to Arial Unicode for mac; small cleanups --- buff/buffer_pane.go | 2 +- cfg/config_mac.go | 2 +- cfg/loader.go | 34 +++++++++++------------ gui/debug_pane.go | 67 --------------------------------------------- main.go | 6 ++-- 5 files changed, 23 insertions(+), 88 deletions(-) delete mode 100644 gui/debug_pane.go diff --git a/buff/buffer_pane.go b/buff/buffer_pane.go index e02532e..f04feb5 100644 --- a/buff/buffer_pane.go +++ b/buff/buffer_pane.go @@ -19,7 +19,7 @@ type BufferPane struct { } func NewBufferPane(buff *Buffer) *BufferPane { - fontPath := filepath.Join(cfg.FONT_FOLDER, buff.cfg.Editor.Font_Face+".ttf") + fontPath := filepath.Join(cfg.FontFolder, buff.cfg.Editor.Font_Face+".ttf") // FIXME DPI metaPanelFont, err := strife.LoadFont(fontPath, int(14.0*cfg.ScaleFactor)) if err != nil { diff --git a/cfg/config_mac.go b/cfg/config_mac.go index 893f52c..a348098 100644 --- a/cfg/config_mac.go +++ b/cfg/config_mac.go @@ -9,7 +9,7 @@ tabs_are_spaces = true match_braces = false maintain_indentation = true highlight_line = true -font_face = "Courier New" +font_face = "Arial Unicode" font_size = 20 show_line_numbers = true diff --git a/cfg/loader.go b/cfg/loader.go index fd1d1cb..2fbab48 100644 --- a/cfg/loader.go +++ b/cfg/loader.go @@ -23,21 +23,21 @@ import ( // const ( - CONFIG_DIR_PATH = "/.phi-editor/" - CONFIG_TOML_FILE = "config.toml" + ConfigDirPath = "/.phi-editor/" + ConfigTomlFile = "config.toml" ) -var FONT_FOLDER string = "" +var FontFolder = "" // this is the absolute path to the // config.toml file. todo rename/refactor -var CONFIG_FULL_PATH string = "" +var ConfigFullPath = "" // the absolute path to the config directory // rename/refactor due here too! -var configDirAbsPath string = "" +var configDirAbsPath = "" -var ICON_DIR_PATH string = "" +var IconDirPath = "" // TODO we only had double key combos // e.g. cmd+s. we want to handle things @@ -85,14 +85,14 @@ func configureAndValidate(conf *TomlConfig) { if len(conf.Editor.Font_Path) == 0 { switch runtime.GOOS { case "windows": - FONT_FOLDER = filepath.Join(os.Getenv("WINDIR"), "fonts") + FontFolder = filepath.Join(os.Getenv("WINDIR"), "fonts") case "darwin": - FONT_FOLDER = "/Library/Fonts/" + FontFolder = "/Library/Fonts/" case "linux": - FONT_FOLDER = findFontFolder() + FontFolder = findFontFolder() } // and set it accordingly. - conf.Editor.Font_Path = FONT_FOLDER + conf.Editor.Font_Path = FontFolder } // we only support ttf at the moment. @@ -190,15 +190,15 @@ func Setup() TomlConfig { home = os.Getenv("USERPROFILE") } - CONFIG_DIR := filepath.Join(home, CONFIG_DIR_PATH) + CONFIG_DIR := filepath.Join(home, ConfigDirPath) configDirAbsPath = CONFIG_DIR - CONFIG_PATH := filepath.Join(CONFIG_DIR, CONFIG_TOML_FILE) + CONFIG_PATH := filepath.Join(CONFIG_DIR, ConfigTomlFile) // this folder is where we store all of the language syntax SYNTAX_CONFIG_DIR := filepath.Join(CONFIG_DIR, "syntax") - CONFIG_FULL_PATH = CONFIG_PATH + ConfigFullPath = CONFIG_PATH // if the user doesn't have a /.phi-editor // directory we create it for them. @@ -211,9 +211,9 @@ func Setup() TomlConfig { // ---- // downloads the icon from github // and puts it into the phi-editor config folder. - ICON_DIR_PATH = filepath.Join(CONFIG_DIR, "icons") - if _, err := os.Stat(ICON_DIR_PATH); os.IsNotExist(err) { - if err := os.Mkdir(ICON_DIR_PATH, 0775); err != nil { + IconDirPath = filepath.Join(CONFIG_DIR, "icons") + if _, err := os.Stat(IconDirPath); os.IsNotExist(err) { + if err := os.Mkdir(IconDirPath, 0775); err != nil { panic(err) } @@ -223,7 +223,7 @@ func Setup() TomlConfig { downloadIcon := func(iconSize int) { log.Println("downloading the phi icon ", iconSize, "x", iconSize, " png image.") - file, err := os.Create(filepath.Join(ICON_DIR_PATH, fmt.Sprintf("icon%d.png", iconSize))) + file, err := os.Create(filepath.Join(IconDirPath, fmt.Sprintf("icon%d.png", iconSize))) defer file.Close() if err != nil { log.Println(err.Error()) diff --git a/gui/debug_pane.go b/gui/debug_pane.go deleted file mode 100644 index 6d56e67..0000000 --- a/gui/debug_pane.go +++ /dev/null @@ -1,67 +0,0 @@ -package gui - -import ( - "github.com/felixangell/strife" -) - -type debugPane struct { - fpsGraph *lineGraph -} - -type lineGraph struct { - yAxisLabel string - xAxisLabel string - - xValues []float64 - yValues []float64 -} - -func newLineGraph(xAxis, yAxis string) *lineGraph { - return &lineGraph{ - xAxis, - yAxis, - []float64{}, - []float64{1, 2, 3, 4, 5, 6, 7}, - } -} - -func (l *lineGraph) plot(x, y float64) { - l.xValues = append(l.xValues, x) - l.yValues = append(l.yValues, y) -} - -func max(a, b int) int { - if a > b { - return a - } - return b -} - -func (l *lineGraph) render(ctx *strife.Renderer, x, y int) { - graphWidth, graphHeight := 256, 256 - - ctx.SetColor(strife.RGBA(0, 0, 0, 255)) - ctx.Rect(x, y, graphWidth, graphHeight, strife.Fill) - - // render last ten values - // xSnip := l.xValues[len(l.xValues)-10:] - ySnip := l.yValues[max(len(l.yValues)-256, 0):] - - size := graphHeight / len(ySnip) - - for idx, yItem := range ySnip { - ctx.SetColor(strife.RGB(255, 0, 255)) - ctx.Rect(x+(idx*size), y+(graphHeight-(int(yItem)*size)), 5, 5, strife.Fill) - } -} - -var pane = &debugPane{ - newLineGraph("time", "framerate"), -} - -func renderDebugPane(ctx *strife.Renderer, x, y int) { - ctx.SetColor(strife.HexRGB(0xff00ff)) - { - pane.fpsGraph.render(ctx, x, y) - } -} diff --git a/main.go b/main.go index 04916ec..97fd5e5 100644 --- a/main.go +++ b/main.go @@ -106,7 +106,9 @@ func main() { } }) - window.Create() + if err := window.Create(); err != nil { + panic(err) + } { size := 16 @@ -122,7 +124,7 @@ func main() { } iconFile := fmt.Sprintf("icon%d.png", size) - icon, err := strife.LoadImage(filepath.Join(cfg.ICON_DIR_PATH, iconFile)) + icon, err := strife.LoadImage(filepath.Join(cfg.IconDirPath, iconFile)) if err != nil { log.Println("Failed to load icon ", err.Error()) } else {