mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-02 22:14:29 +01:00
keyboard: Bug fix: Image.DrawLine no longer exists
This commit is contained in:
parent
278948a770
commit
7ab04167d7
@ -53,7 +53,7 @@ func text_png() (*asset, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info := bindata_file_info{name: "text.png", size: 2058, mode: os.FileMode(420), modTime: time.Unix(1420820510, 0)}
|
info := bindata_file_info{name: "text.png", size: 2058, mode: os.FileMode(420), modTime: time.Unix(1455503506, 0)}
|
||||||
a := &asset{bytes: bytes, info: info}
|
a := &asset{bytes: bytes, info: info}
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ import (
|
|||||||
|
|
||||||
func licenseComment() (string, error) {
|
func licenseComment() (string, error) {
|
||||||
_, path, _, _ := runtime.Caller(0)
|
_, path, _, _ := runtime.Caller(0)
|
||||||
licensePath := filepath.Join(filepath.Dir(path), "..", "..", "..", "license.txt")
|
licensePath := filepath.Join(filepath.Dir(path), "..", "..", "..", "LICENSE")
|
||||||
l, err := ioutil.ReadFile(licensePath)
|
l, err := ioutil.ReadFile(licensePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -55,21 +55,61 @@ var keyboardKeys = [][]string{
|
|||||||
{"Left", "Down", "Right"},
|
{"Left", "Down", "Right"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawKey(t *ebiten.Image, name string, x, y, width int) {
|
func drawKey(t *ebiten.Image, name string, x, y, width int) error {
|
||||||
const height = 16
|
const height = 16
|
||||||
width--
|
width--
|
||||||
c := color.White
|
shape, err := ebiten.NewImage(width, height, ebiten.FilterNearest)
|
||||||
t.DrawLine(x, y+3, x, y+height-3, c)
|
if err != nil {
|
||||||
t.DrawLine(x+width-1, y+3, x+width-1, y+height-3, c)
|
return err
|
||||||
t.DrawLine(x+3, y, x+width-3, y, c)
|
}
|
||||||
t.DrawLine(x+3, y+height-1, x+width-3, y+height-1, c)
|
p := make([]uint8, width*height*4)
|
||||||
|
for j := 0; j < height; j++ {
|
||||||
t.DrawLine(x, y+3, x+3, y, c)
|
for i := 0; i < width; i++ {
|
||||||
t.DrawLine(x+width-4, y, x+width-1, y+3, c)
|
x := (i + j*width) * 4
|
||||||
t.DrawLine(x, y+height-4, x+3, y+height-1, c)
|
switch j {
|
||||||
t.DrawLine(x+width-1, y+height-4, x+width-4, y+height-1, c)
|
case 0, height - 1:
|
||||||
|
if 3 <= i && i <= width-4 {
|
||||||
common.ArcadeFont.DrawText(t, name, x+4, y+5, 1, color.White)
|
p[x] = 0xff
|
||||||
|
p[x+1] = 0xff
|
||||||
|
p[x+2] = 0xff
|
||||||
|
p[x+3] = 0xff
|
||||||
|
}
|
||||||
|
case 1, height - 2:
|
||||||
|
if i == 2 || i == width-3 {
|
||||||
|
p[x] = 0xff
|
||||||
|
p[x+1] = 0xff
|
||||||
|
p[x+2] = 0xff
|
||||||
|
p[x+3] = 0xff
|
||||||
|
}
|
||||||
|
case 2, height - 3:
|
||||||
|
if i == 1 || i == width-2 {
|
||||||
|
p[x] = 0xff
|
||||||
|
p[x+1] = 0xff
|
||||||
|
p[x+2] = 0xff
|
||||||
|
p[x+3] = 0xff
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if i == 0 || i == width-1 {
|
||||||
|
p[x] = 0xff
|
||||||
|
p[x+1] = 0xff
|
||||||
|
p[x+2] = 0xff
|
||||||
|
p[x+3] = 0xff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := shape.ReplacePixels(p); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
op := &ebiten.DrawImageOptions{}
|
||||||
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
|
if err := t.DrawImage(shape, op); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := common.ArcadeFont.DrawText(t, name, x+4, y+5, 1, color.White); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func outputKeyboardImage() (map[string]image.Rectangle, error) {
|
func outputKeyboardImage() (map[string]image.Rectangle, error) {
|
||||||
@ -109,7 +149,9 @@ func outputKeyboardImage() (map[string]image.Rectangle, error) {
|
|||||||
width = 16 * 3
|
width = 16 * 3
|
||||||
}
|
}
|
||||||
if key != "" {
|
if key != "" {
|
||||||
drawKey(img, key, x, y, width)
|
if err := drawKey(img, key, x, y, width); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if key != " " {
|
if key != " " {
|
||||||
keyMap[key] = image.Rect(x, y, x+width, y+height)
|
keyMap[key] = image.Rect(x, y, x+width, y+height)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2015 Hajime Hoshi
|
// Copyright 2014 Hajime Hoshi
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
Loading…
Reference in New Issue
Block a user