mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
Update docs
This commit is contained in:
parent
f88f48f0ae
commit
106984e9c7
@ -81,6 +81,26 @@ pre {
|
|||||||
<li>v1.2.0-rc1 released.
|
<li>v1.2.0-rc1 released.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Support for gamepads</li>
|
<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>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</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 (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||||
|
"github.com/hajimehoshi/ebiten/example/keyboard/keyboard"
|
||||||
"log"
|
"log"
|
||||||
"sort"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -52,13 +51,23 @@ const (
|
|||||||
screenHeight = 240
|
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{
|
var keyNames = map[ebiten.Key]string{
|
||||||
ebiten.KeyBackspace: "Backspace",
|
ebiten.KeyBackspace: "BS",
|
||||||
ebiten.KeyComma: "','",
|
ebiten.KeyComma: ",",
|
||||||
ebiten.KeyDelete: "Delete",
|
ebiten.KeyDelete: "Del",
|
||||||
ebiten.KeyEnter: "Enter",
|
ebiten.KeyEnter: "Enter",
|
||||||
ebiten.KeyEscape: "Esc",
|
ebiten.KeyEscape: "Esc",
|
||||||
ebiten.KeyPeriod: "'.'",
|
ebiten.KeyPeriod: ".",
|
||||||
ebiten.KeySpace: "Space",
|
ebiten.KeySpace: "Space",
|
||||||
ebiten.KeyTab: "Tab",
|
ebiten.KeyTab: "Tab",
|
||||||
|
|
||||||
@ -74,7 +83,32 @@ var keyNames = map[ebiten.Key]string{
|
|||||||
ebiten.KeyAlt: "Alt",
|
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 {
|
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{}
|
pressed := []string{}
|
||||||
for i := 0; i <= 9; i++ {
|
for i := 0; i <= 9; i++ {
|
||||||
if ebiten.IsKeyPressed(ebiten.Key(i) + ebiten.Key0) {
|
if ebiten.IsKeyPressed(ebiten.Key(i) + ebiten.Key0) {
|
||||||
@ -96,9 +130,13 @@ func update(screen *ebiten.Image) error {
|
|||||||
pressed = append(pressed, name)
|
pressed = append(pressed, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Strings(pressed)
|
|
||||||
str := "Pressed Keys: " + strings.Join(pressed, ", ")
|
op = &ebiten.DrawImageOptions{
|
||||||
ebitenutil.DebugPrint(screen, str)
|
ImageParts: pressedKeysParts(pressed),
|
||||||
|
}
|
||||||
|
op.GeoM.Translate(offsetX, offsetY)
|
||||||
|
screen.DrawImage(keyboardImage, op)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +107,26 @@ pre {
|
|||||||
<li>v1.2.0-rc1 released.
|
<li>v1.2.0-rc1 released.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Support for gamepads</li>
|
<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>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user