Skip to content

Commit

Permalink
make things build on non-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
felixangell committed May 24, 2018
1 parent a40626e commit 20ca1c9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
25 changes: 25 additions & 0 deletions dpi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package strife

import (
"runtime"

"github.com/veandco/go-sdl2/sdl"
)

func defaultDpi() float32 {
if runtime.GOOS == "windows" {
return 96.0
} else if runtime.GOOS == "darwin" {
return 72.0
}
panic("no dpi for this os")
}

// returns the dpi, and the default dpi
func GetDisplayDPI(displayIndex int) (float32, float32) {
_, hdpi, _, err := sdl.GetDisplayDPI(displayIndex)
if err != nil {
return 0, defaultDpi()
}
return hdpi, defaultDpi()
}
24 changes: 3 additions & 21 deletions dpi_any.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
package strife

import (
"runtime"
// +build !windows

"github.com/veandco/go-sdl2/sdl"
)
package strife

func defaultDpi() float32 {
if runtime.GOOS == "windows" {
return 96.0
} else if runtime.GOOS == "darwin" {
return 72.0
}
panic("no dpi for this os")
}
func EnableDPI() {

// returns the dpi, and the default dpi
func GetDisplayDPI(displayIndex int) (float32, float32) {
_, hdpi, _, err := sdl.GetDisplayDPI(displayIndex)
if err != nil {
return 0, defaultDpi()
}
return hdpi, defaultDpi()
}
11 changes: 9 additions & 2 deletions renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,20 @@ func CreateRenderer(parent *RenderWindow, config *RenderConfig) (*Renderer, erro

fontChoices := map[string]bool{}
filepath.Walk(fontFolder, func(path string, r os.FileInfo, err error) error {
fontChoices[filepath.Base(path)] = true
fontName := filepath.Base(path)
log.Println("- ", fontName)
fontChoices[fontName] = true
return nil
})

chosenFont := func() string {
defaultFontChoices := []string{
"calibri.ttf", "verdana.ttf", // todo add more fonts.
// todo add more fonts.
// maybe depending on the platform
// we can sort them manually
// e.g. georgia first on mac, calibiri first on windows
// for faster lookup?
"Verdana.ttf", "calibri.ttf", "verdana.ttf",
}
for _, font := range defaultFontChoices {
if _, exists := fontChoices[font]; exists {
Expand Down

0 comments on commit 20ca1c9

Please sign in to comment.