mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Remove examples/common
This commit is contained in:
parent
3b50e1ea54
commit
f253bb3c0c
@ -1,134 +0,0 @@
|
||||
// Copyright 2015 Hajime Hoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build example
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/examples/common/internal/assets"
|
||||
)
|
||||
|
||||
var (
|
||||
ArcadeFont *Font
|
||||
)
|
||||
|
||||
type Font struct {
|
||||
image *ebiten.Image
|
||||
origImage image.Image
|
||||
offset int
|
||||
charNumPerLine int
|
||||
charWidth int
|
||||
charHeight int
|
||||
}
|
||||
|
||||
func (f *Font) TextWidth(str string) int {
|
||||
// TODO: Take care about '\n'
|
||||
return f.charWidth * len(str)
|
||||
}
|
||||
|
||||
func (f *Font) TextHeight(str string) int {
|
||||
// TODO: Take care about '\n'
|
||||
return f.charHeight
|
||||
}
|
||||
|
||||
func init() {
|
||||
img := assets.ArcadeFontImage()
|
||||
eimg, _ := ebiten.NewImageFromImage(img, ebiten.FilterNearest)
|
||||
ArcadeFont = &Font{eimg, img, 32, 16, 8, 8}
|
||||
}
|
||||
|
||||
type part struct {
|
||||
sx, sy, dx0, dy0, dx1, dy1 int
|
||||
}
|
||||
|
||||
func (f *Font) parts(str string) []part {
|
||||
ps := []part{}
|
||||
x := 0
|
||||
y := 0
|
||||
for _, c := range str {
|
||||
if c == '\n' {
|
||||
x = 0
|
||||
y += f.charHeight
|
||||
continue
|
||||
}
|
||||
sx := (int(c) % f.charNumPerLine) * f.charWidth
|
||||
sy := ((int(c) - f.offset) / f.charNumPerLine) * f.charHeight
|
||||
dx0 := x
|
||||
dy0 := y
|
||||
dx1 := dx0 + f.charWidth
|
||||
dy1 := dy0 + f.charHeight
|
||||
ps = append(ps, part{sx, sy, dx0, dy0, dx1, dy1})
|
||||
x += f.charWidth
|
||||
}
|
||||
return ps
|
||||
}
|
||||
|
||||
func (f *Font) DrawText(rt *ebiten.Image, str string, ox, oy, scale int, c color.Color) {
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
ur, ug, ub, ua := c.RGBA()
|
||||
const max = math.MaxUint16
|
||||
r := float64(ur) / max
|
||||
g := float64(ug) / max
|
||||
b := float64(ub) / max
|
||||
a := float64(ua) / max
|
||||
if 0 < a {
|
||||
r /= a
|
||||
g /= a
|
||||
b /= a
|
||||
}
|
||||
op.ColorM.Scale(r, g, b, a)
|
||||
|
||||
// TODO: There is same logic in parts. Refactor this.
|
||||
x := 0
|
||||
y := 0
|
||||
for _, c := range str {
|
||||
if c == '\n' {
|
||||
x = 0
|
||||
y += f.charHeight
|
||||
continue
|
||||
}
|
||||
sx := (int(c) % f.charNumPerLine) * f.charWidth
|
||||
sy := ((int(c) - f.offset) / f.charNumPerLine) * f.charHeight
|
||||
r := image.Rect(sx, sy, sx+f.charWidth, sy+f.charHeight)
|
||||
op.SourceRect = &r
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(float64(x), float64(y))
|
||||
op.GeoM.Scale(float64(scale), float64(scale))
|
||||
op.GeoM.Translate(float64(ox), float64(oy))
|
||||
rt.DrawImage(f.image, op)
|
||||
x += f.charWidth
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Font) DrawTextOnImage(rt draw.Image, str string, ox, oy int) {
|
||||
// TODO: This function is needed only by examples/keyboard/keyboard.
|
||||
// This is executed without Ebiten, so ebiten.Image can't be used.
|
||||
// When ebiten.Image can be used without ebiten.Run, this function can be removed.
|
||||
for _, p := range f.parts(str) {
|
||||
draw.Draw(rt, image.Rect(p.dx0+ox, p.dy0+oy, p.dx1+ox, p.dy1+oy),
|
||||
f.origImage, image.Pt(p.sx, p.sy), draw.Over)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Font) DrawTextWithShadow(rt *ebiten.Image, str string, x, y, scale int, clr color.Color) {
|
||||
f.DrawText(rt, str, x+1, y+1, scale, color.NRGBA{0, 0, 0, 0x80})
|
||||
f.DrawText(rt, str, x, y, scale, clr)
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 1008 B |
@ -1,36 +0,0 @@
|
||||
// Copyright 2016 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build example
|
||||
|
||||
//go:generate go-bindata -nocompress -pkg=assets -tags=example arcadefont.png
|
||||
//go:generate gofmt -s -w .
|
||||
|
||||
package assets
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
_ "image/png"
|
||||
)
|
||||
|
||||
func ArcadeFontImage() image.Image {
|
||||
b := MustAsset("arcadefont.png")
|
||||
img, _, err := image.Decode(bytes.NewBuffer(b))
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("assets: image.Decode error: %v", err))
|
||||
}
|
||||
return img
|
||||
}
|
@ -1,211 +0,0 @@
|
||||
// Code generated by go-bindata.
|
||||
// sources:
|
||||
// arcadefont.png
|
||||
// DO NOT EDIT!
|
||||
|
||||
// +build example
|
||||
|
||||
package assets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type asset struct {
|
||||
bytes []byte
|
||||
info os.FileInfo
|
||||
}
|
||||
|
||||
type bindataFileInfo struct {
|
||||
name string
|
||||
size int64
|
||||
mode os.FileMode
|
||||
modTime time.Time
|
||||
}
|
||||
|
||||
func (fi bindataFileInfo) Name() string {
|
||||
return fi.name
|
||||
}
|
||||
func (fi bindataFileInfo) Size() int64 {
|
||||
return fi.size
|
||||
}
|
||||
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||
return fi.mode
|
||||
}
|
||||
func (fi bindataFileInfo) ModTime() time.Time {
|
||||
return fi.modTime
|
||||
}
|
||||
func (fi bindataFileInfo) IsDir() bool {
|
||||
return false
|
||||
}
|
||||
func (fi bindataFileInfo) Sys() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _arcadefontPng = []byte("\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x80\x00\x00\x000\b\x03\x00\x00\x00\xee*\x82\x8c\x00\x00\x00\x06PLTE\x00\x00\x00\xff\xff\xff\xa5\u065f\xdd\x00\x00\x00\x01tRNS\x00@\xe6\xd8f\x00\x00\x03\x98IDATx\x9c\xc4X\x89\x96\xac(\f\xe5\xd6\xf3\xff\u007f9\xd3B\x96\x9b\x18\u0469\xe99/\u0765\x82\x81\xec\v~F\x00\xa0\xd7\xf5\x10\xf3t=\xdf#\xe1\xdbCY\xf4\x0e0>\xbb\x97F\xf9\xdc{\x8e\xe6\xbf\b*\xa2\xfc\\%X,\xf7\r\ti\x18\x90\xf9\xbf(bm#sNN|\xdeW\x98\xbes\x80W\xa4\x8d~B];\xc1\t\x89\x13\x14\u01e7\xa1\x8e\x9d\x01{P\x04\x10\x8f\xa3\x19\xfbz\x9a@\x1e\x99\xb5\xf5\x0e\xffG\xc2,>\x01\xb2]\xb7o\xe6(\x99@\x12G2\xff\xd6r\u04cc\x8b!\t\xd1\xe8\x89\tYE\xeb\x04\xbd\xc8\u007f\xef\xc7H\x174a\xf2\x10\x05\xd5i\xff\x85\x9b\xfc\nli\x81\x9d,9\xcfZ\xa63\x92\x87\x11s\xa2\xc3\xce\u0248\x884\x83\xb5\xf0\u03f4m(y\xbd\a*G\x8d\xaf\x8b\xe5\x05\xba[*\x1b\xe9^\x9c?6\xfcy<&\x1f8=B\xc02\x12}\x01q\x1cQOq\xbb\x85\x88N\xf5\xd0I\xcd\xe5Q\t$cJ\"\xc8\u0487)HA\xc1u\xe3\xda\xd79\x90\u034ff\xc1\xf0x\x82\xe5*\x962\xe6]A\xb0\x90\xbd\xec\xef\x02\x93\x8f\xa4\xf7\x87\xaa\x9f\xe9',SM#Hp\xd4\x1b\xdb^'\x95\x13\x96\xf1\x85\xa4\xc2\xe4\xdd\xccj\x8a\x8eb1\x9b/\xf4!\rc1\xd8\xc8\xf4;\xf0*\u05c0\x95~\t\u007fR\x84i\xc65\xa4o\u0709\xd9\t\x91\xe69l\v\xfe\xe9\x84\u04df\xf4\xa5\x19\vP\xf7_\xfe\x91\x8d\xd8\xe9u\x8c\xceM\xf2\x04,\x9c\x89!\xc8g\xe6!wd\xe4\u0152*\xfdf\xf3\x16*J\u06e8\x1c\xc1\x19\xe3u\x9b\xe7\xfc\xa03ro\xea{\x16\x91\x198\u0167\xfc\xe7q^\xa1\x98`P\xee\xbc+\xa3\xb9\xbe\xab\xa4Y\xde\xcf\xe9\x15K\xd3\"\x97*\x0f\xdc\xca\u0499e\xe2r\u01c6\a\t\u01a9\x01A\xed\x94\x16\x8e\x00T\f\u01e5\xdcI\xd3;\u03ce5R)\xa9\xb6\xe8\u0096\xff\u03c9\xe0\r\x1c\x1e\xbe*`\x1a\xa7\f\x99\u3e09k\x89b\x15\x1b \xf2^nn\x15>\xcb\xf63\fE\xbb\v\x1f\xeb\xb0v\x8b\x05\x90L-\xe4J\"\xe4r\"-\xfe\xe6`\xf2@7U\x81\xeaD\\<kG\x98\xfd\xb7e@\x95\x87\xbe\u03e4\x13\x93r\xa0? 9\xed\r\a?R\xb1`\a\x19\aI\x80\xb9\xd75\x1f\u0324\x99\xab\x9bZUz\xfa3\x01t\x82,\xf8\x90\xd5\xc4)c\xdcw\xd9Q\x16.%l\xb4\xf4\xafV(\f\u063e\x00\xa7\xb6i\x02\x0e{\x1f\x8b\xd3\xcf\xf7\xe0!\x8eT\xc4\xc1\xf6|\xf4\x17\x80*S)\x9aMv\xaa}un\xe1\xae\rNid\xb7\xf9\xee\xcf(\xca\xe9TRs\xae<\xe0\xe7\xf9\xbd\x92\u03ee\xd8k+\xbbU\u0244>\xc6(=\xe2(%\x83\x9e\x904\xb5\xf0y\xd9y\x8f<`\x89P3 \xf8>bl\x89\x11\x1e\xcd\"\xa5\xdc\\m\xa2\xb3\x9eZi\xffc\xa7\xa9\xbe\xa1y\v\xef\x9a\u0783\xd1+\x89\x8b\b<z\xf1Q\xea\xe9\xd0vB\xce\x03k\x19T]q\x1fMj\x16\xb9(\bc\u06d0d\x01\xfcT\xf8-<\xb5\x8e\xbf\a_}\x00\xe4\x95\xd8m\xb3-\xc7\xff\x11\xaa\v\xb5\x1c\x1c).s\x97\u3ae8\xe1I?\xc3\xcd?\xdb\xf0\x15[\xb3-\x8f\x83\x90\xa2p^\u065e\x8b\a\xf5\xae.\xe8\xe0\xc3X\u0194\xa1\x9f!#>:\x13\x88m\xf4`|\x17\xb6\x86\x83U\xc9.\x85\xcb\xf0/\x06\xc6@\x0e\xb7`\xa3\x8f\x11o|\xac#BtP\x89\xfe\x068\x80\x81Z\xd9\xea'\x9d\xd4s\xc8`\r'\u007f\x18\xe3\xe2\x03\x86\xd9Z\u4581o\xe1\xcb\xf8\xff'\x00\x00\xff\xff\"\xd9\xed\u04b0\xcb\xea\x95\x00\x00\x00\x00IEND\xaeB`\x82")
|
||||
|
||||
func arcadefontPngBytes() ([]byte, error) {
|
||||
return _arcadefontPng, nil
|
||||
}
|
||||
|
||||
func arcadefontPng() (*asset, error) {
|
||||
bytes, err := arcadefontPngBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "arcadefont.png", size: 1008, mode: os.FileMode(420), modTime: time.Unix(1463226773, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func Asset(name string) ([]byte, error) {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[cannonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.bytes, nil
|
||||
}
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
|
||||
// MustAsset is like Asset but panics when Asset would return an error.
|
||||
// It simplifies safe initialization of global variables.
|
||||
func MustAsset(name string) []byte {
|
||||
a, err := Asset(name)
|
||||
if err != nil {
|
||||
panic("asset: Asset(" + name + "): " + err.Error())
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// AssetInfo loads and returns the asset info for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func AssetInfo(name string) (os.FileInfo, error) {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[cannonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.info, nil
|
||||
}
|
||||
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||
}
|
||||
|
||||
// AssetNames returns the names of the assets.
|
||||
func AssetNames() []string {
|
||||
names := make([]string, 0, len(_bindata))
|
||||
for name := range _bindata {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() (*asset, error){
|
||||
"arcadefont.png": arcadefontPng,
|
||||
}
|
||||
|
||||
// AssetDir returns the file names below a certain
|
||||
// directory embedded in the file by go-bindata.
|
||||
// For example if you run go-bindata on data/... and data contains the
|
||||
// following hierarchy:
|
||||
// data/
|
||||
// foo.txt
|
||||
// img/
|
||||
// a.png
|
||||
// b.png
|
||||
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||
// AssetDir("") will return []string{"data"}.
|
||||
func AssetDir(name string) ([]string, error) {
|
||||
node := _bintree
|
||||
if len(name) != 0 {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
pathList := strings.Split(cannonicalName, "/")
|
||||
for _, p := range pathList {
|
||||
node = node.Children[p]
|
||||
if node == nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.Func != nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
rv := make([]string, 0, len(node.Children))
|
||||
for childName := range node.Children {
|
||||
rv = append(rv, childName)
|
||||
}
|
||||
return rv, nil
|
||||
}
|
||||
|
||||
type bintree struct {
|
||||
Func func() (*asset, error)
|
||||
Children map[string]*bintree
|
||||
}
|
||||
|
||||
var _bintree = &bintree{nil, map[string]*bintree{
|
||||
"arcadefont.png": {arcadefontPng, map[string]*bintree{}},
|
||||
}}
|
||||
|
||||
// RestoreAsset restores an asset under the given directory
|
||||
func RestoreAsset(dir, name string) error {
|
||||
data, err := Asset(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info, err := AssetInfo(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RestoreAssets restores an asset under the given directory recursively
|
||||
func RestoreAssets(dir, name string) error {
|
||||
children, err := AssetDir(name)
|
||||
// File
|
||||
if err != nil {
|
||||
return RestoreAsset(dir, name)
|
||||
}
|
||||
// Dir
|
||||
for _, child := range children {
|
||||
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _filePath(dir, name string) string {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
# License
|
||||
|
||||
## arcadefont.png
|
||||
|
||||
```
|
||||
9031 Font ReadMe
|
||||
|
||||
Terms of Use and Disclaimer
|
||||
|
||||
All 9031 fonts are free of charge to use for personal or commercial purposes, e.g. printed papers, t-shirts, logos, images for website, merchandise or anything featuring these fonts.
|
||||
|
||||
OpenType font files are licensed for your personal desktop use only. No part of these files may be re-distributed, sold, renamed, converted, or made available for download on any web site without permission of author.
|
||||
|
||||
Author give no warranty in relation to these fonts, and you use them at your own risk. By using or installing these fonts, you agree to be bound by the terms of this agreement. Author will not be liable for any damage to your system, any loss or corruption of any data or font, or any other loss or damage that you may suffer as a result of downloading or using these fonts, whether it results from Author's negligence or in any other way.
|
||||
|
||||
|
||||
Author
|
||||
|
||||
Yuji Adachi, 9031
|
||||
Website: http://9031.com/
|
||||
Email: info@9031.com
|
||||
©1997-2011 9031
|
||||
```
|
Loading…
Reference in New Issue
Block a user