Demo Running Level as Title Screen Wallpaper
* Load SDL2 fonts from go-bindata storage so we don't have to ship external font files on disk. * Dedupe names of doodads so we don't show double on the front-end (go-bindata bundled doodads + those on local filesystem) * Use go-bindata for accessing wallpaper images. * Better flashed messages walking you through the Link Tool. * Stylize the title screen (MainScene) by rendering a live example level as the background wallpaper, with mobile doodads in motion.
This commit is contained in:
parent
981b2b98e0
commit
e682bb27c0
|
@ -13,7 +13,7 @@ var (
|
|||
DebugWindowEvents = false
|
||||
DebugMouseEvents = false
|
||||
DebugClickEvents = false
|
||||
DebugKeyEvents = true
|
||||
DebugKeyEvents = false
|
||||
)
|
||||
|
||||
// Poll for events.
|
||||
|
|
51
sdl/text.go
51
sdl/text.go
|
@ -3,6 +3,7 @@ package sdl
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"git.kirsle.net/apps/doodle/lib/events"
|
||||
"git.kirsle.net/apps/doodle/lib/render"
|
||||
|
@ -11,9 +12,29 @@ import (
|
|||
)
|
||||
|
||||
// TODO: font filenames
|
||||
var defaultFontFilename = "./fonts/DejaVuSans.ttf"
|
||||
var defaultFontFilename = "DejaVuSans.ttf"
|
||||
|
||||
var fonts = map[string]*ttf.Font{}
|
||||
// Font holds cached SDL_TTF structures for loaded fonts. They are created
|
||||
// automatically when fonts are either preinstalled (InstallFont) or loaded for
|
||||
// the first time as demanded by the DrawText method.
|
||||
type Font struct {
|
||||
Filename string
|
||||
data []byte // raw binary data of font
|
||||
ttf *ttf.Font
|
||||
}
|
||||
|
||||
var (
|
||||
fonts = map[string]*ttf.Font{} // keys like "DejaVuSans@14" by font size
|
||||
installedFont = map[string][]byte{} // installed font files' binary handles
|
||||
fontsMu sync.RWMutex
|
||||
)
|
||||
|
||||
// InstallFont preloads the font cache using TTF binary data in memory.
|
||||
func InstallFont(filename string, binary []byte) {
|
||||
fontsMu.Lock()
|
||||
installedFont[filename] = binary
|
||||
fontsMu.Unlock()
|
||||
}
|
||||
|
||||
// LoadFont loads and caches the font at a given size.
|
||||
func LoadFont(filename string, size int) (*ttf.Font, error) {
|
||||
|
@ -27,10 +48,30 @@ func LoadFont(filename string, size int) (*ttf.Font, error) {
|
|||
return font, nil
|
||||
}
|
||||
|
||||
font, err := ttf.OpenFont(filename, size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// Do we have this font in memory?
|
||||
var (
|
||||
font *ttf.Font
|
||||
err error
|
||||
)
|
||||
|
||||
if binary, ok := installedFont[filename]; ok {
|
||||
var RWops *sdl.RWops
|
||||
RWops, err = sdl.RWFromMem(binary)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("LoadFont(%s): RWFromMem: %s", filename, err)
|
||||
}
|
||||
|
||||
font, err = ttf.OpenFontRW(RWops, 0, size)
|
||||
} else {
|
||||
font, err = ttf.OpenFont(filename, size)
|
||||
}
|
||||
|
||||
// Error opening the font?
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("LoadFont(%s): %s", filename, err)
|
||||
}
|
||||
|
||||
// Cache this font name and size.
|
||||
fonts[keyName] = font
|
||||
|
||||
return font, nil
|
||||
|
|
Loading…
Reference in New Issue
Block a user