mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
Update docs
This commit is contained in:
parent
f88f48f0ae
commit
106984e9c7
@ -81,6 +81,26 @@ pre {
|
||||
<li>v1.2.0-rc1 released.
|
||||
<ul>
|
||||
<li>Support for gamepads</li>
|
||||
<li>Added new functions for image rendering:
|
||||
<ul>
|
||||
<li>Image.DrawFilledRect</li>
|
||||
<li>Image.DrawFilledRects</li>
|
||||
<li>Image.DrawLine</li>
|
||||
<li>Image.DrawLines</li>
|
||||
<li>Image.DrawRect</li>
|
||||
<li>Image.DrawRects</li>
|
||||
<li>Image.ReplacePixels</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Some bug fix</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<h3>2015-??-??</h3>
|
||||
<ul>
|
||||
<li>v1.1.0 released.
|
||||
<ul>
|
||||
<li>Some bug fix</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB |
BIN
_docs/public/example/images/keyboard/keyboard.png
Normal file
BIN
_docs/public/example/images/keyboard/keyboard.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
@ -41,10 +41,9 @@ pre {
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/example/keyboard/keyboard"
|
||||
"log"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -52,13 +51,23 @@ const (
|
||||
screenHeight = 240
|
||||
)
|
||||
|
||||
var keyboardImage *ebiten.Image
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
keyboardImage, _, err = ebitenutil.NewImageFromFile("images/keyboard/keyboard.png", ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
var keyNames = map[ebiten.Key]string{
|
||||
ebiten.KeyBackspace: "Backspace",
|
||||
ebiten.KeyComma: "','",
|
||||
ebiten.KeyDelete: "Delete",
|
||||
ebiten.KeyBackspace: "BS",
|
||||
ebiten.KeyComma: ",",
|
||||
ebiten.KeyDelete: "Del",
|
||||
ebiten.KeyEnter: "Enter",
|
||||
ebiten.KeyEscape: "Esc",
|
||||
ebiten.KeyPeriod: "'.'",
|
||||
ebiten.KeyPeriod: ".",
|
||||
ebiten.KeySpace: "Space",
|
||||
ebiten.KeyTab: "Tab",
|
||||
|
||||
@ -74,7 +83,32 @@ var keyNames = map[ebiten.Key]string{
|
||||
ebiten.KeyAlt: "Alt",
|
||||
}
|
||||
|
||||
type pressedKeysParts []string
|
||||
|
||||
func (p pressedKeysParts) Len() int {
|
||||
return len(p)
|
||||
}
|
||||
|
||||
func (p pressedKeysParts) Dst(i int) (x0, y0, x1, y1 int) {
|
||||
k := p[i]
|
||||
r, ok := keyboard.KeyRect(k)
|
||||
if !ok {
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
return r.Min.X, r.Min.Y, r.Max.X, r.Max.Y
|
||||
}
|
||||
|
||||
func (p pressedKeysParts) Src(i int) (x0, y0, x1, y1 int) {
|
||||
return p.Dst(i)
|
||||
}
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
const offsetX, offsetY = 24, 40
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Translate(offsetX, offsetY)
|
||||
op.ColorM.Scale(0.5, 0.5, 0.5, 1)
|
||||
screen.DrawImage(keyboardImage, op)
|
||||
|
||||
pressed := []string{}
|
||||
for i := 0; i <= 9; i++ {
|
||||
if ebiten.IsKeyPressed(ebiten.Key(i) + ebiten.Key0) {
|
||||
@ -96,9 +130,13 @@ func update(screen *ebiten.Image) error {
|
||||
pressed = append(pressed, name)
|
||||
}
|
||||
}
|
||||
sort.Strings(pressed)
|
||||
str := "Pressed Keys: " + strings.Join(pressed, ", ")
|
||||
ebitenutil.DebugPrint(screen, str)
|
||||
|
||||
op = &ebiten.DrawImageOptions{
|
||||
ImageParts: pressedKeysParts(pressed),
|
||||
}
|
||||
op.GeoM.Translate(offsetX, offsetY)
|
||||
screen.DrawImage(keyboardImage, op)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -107,6 +107,26 @@ pre {
|
||||
<li>v1.2.0-rc1 released.
|
||||
<ul>
|
||||
<li>Support for gamepads</li>
|
||||
<li>Added new functions for image rendering:
|
||||
<ul>
|
||||
<li>Image.DrawFilledRect</li>
|
||||
<li>Image.DrawFilledRects</li>
|
||||
<li>Image.DrawLine</li>
|
||||
<li>Image.DrawLines</li>
|
||||
<li>Image.DrawRect</li>
|
||||
<li>Image.DrawRects</li>
|
||||
<li>Image.ReplacePixels</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Some bug fix</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<h3>2015-??-??</h3>
|
||||
<ul>
|
||||
<li>v1.1.0 released.
|
||||
<ul>
|
||||
<li>Some bug fix</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user