|
|
|
@ -27,6 +27,8 @@ type Keyboard struct {
@@ -27,6 +27,8 @@ type Keyboard struct {
|
|
|
|
|
background *ebiten.Image |
|
|
|
|
|
|
|
|
|
op *ebiten.DrawImageOptions |
|
|
|
|
|
|
|
|
|
backgroundColor color.Color |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewKeyboard returns a new Keyboard.
|
|
|
|
@ -36,7 +38,8 @@ func NewKeyboard() *Keyboard {
@@ -36,7 +38,8 @@ func NewKeyboard() *Keyboard {
|
|
|
|
|
op: &ebiten.DrawImageOptions{ |
|
|
|
|
Filter: ebiten.FilterNearest, |
|
|
|
|
}, |
|
|
|
|
background: ebiten.NewImage(1, 1), |
|
|
|
|
background: ebiten.NewImage(1, 1), |
|
|
|
|
backgroundColor: color.Black, |
|
|
|
|
} |
|
|
|
|
return k |
|
|
|
|
} |
|
|
|
@ -64,12 +67,26 @@ func (k *Keyboard) SetKeys(keys [][]*Key) {
@@ -64,12 +67,26 @@ func (k *Keyboard) SetKeys(keys [][]*Key) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (k *Keyboard) updateKeyRects() { |
|
|
|
|
maxCells := 0 |
|
|
|
|
for _, rowKeys := range k.keys { |
|
|
|
|
if len(rowKeys) > maxCells { |
|
|
|
|
maxCells = len(rowKeys) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cellPaddingW := 10 |
|
|
|
|
cellPaddingH := 10 |
|
|
|
|
|
|
|
|
|
cellH := (k.h - (cellPaddingH * (len(k.keys) - 1))) / len(k.keys) |
|
|
|
|
|
|
|
|
|
for row, rowKeys := range k.keys { |
|
|
|
|
cellW := (k.w - (cellPaddingW * (len(rowKeys) - 1))) / len(rowKeys) |
|
|
|
|
|
|
|
|
|
for i, key := range rowKeys { |
|
|
|
|
key.x = 50 * i |
|
|
|
|
key.y = 50 * row |
|
|
|
|
key.w = 40 |
|
|
|
|
key.h = 40 |
|
|
|
|
key.x = (cellW + cellPaddingW) * i |
|
|
|
|
key.y = (cellH + cellPaddingH) * row |
|
|
|
|
key.w = cellW |
|
|
|
|
key.h = cellH |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -141,7 +158,7 @@ func (k *Keyboard) drawBackground() {
@@ -141,7 +158,7 @@ func (k *Keyboard) drawBackground() {
|
|
|
|
|
|
|
|
|
|
debugBox := image.NewRGBA(image.Rect(0, 0, k.w, k.h)) |
|
|
|
|
buffer := ebiten.NewImageFromImage(debugBox) |
|
|
|
|
buffer.Fill(color.White) |
|
|
|
|
buffer.Fill(k.backgroundColor) |
|
|
|
|
|
|
|
|
|
for _, rowKeys := range k.keys { |
|
|
|
|
for _, key := range rowKeys { |
|
|
|
@ -150,9 +167,10 @@ func (k *Keyboard) drawBackground() {
@@ -150,9 +167,10 @@ func (k *Keyboard) drawBackground() {
|
|
|
|
|
img := ebiten.NewImageFromImage(image.NewRGBA(image.Rect(0, 0, key.w, key.h))) |
|
|
|
|
img.Fill(color.RGBA{150, 150, 150, 255}) |
|
|
|
|
k.op.GeoM.Reset() |
|
|
|
|
k.op.GeoM.Scale(2, 2) |
|
|
|
|
k.op.GeoM.Scale(3, 3) |
|
|
|
|
k.op.GeoM.Translate(float64(0), float64(key.h)/4) |
|
|
|
|
if len(key.LowerLabel) <= 1 { |
|
|
|
|
k.op.GeoM.Translate(float64(12), 0) |
|
|
|
|
k.op.GeoM.Translate(float64(key.w/4), 0) |
|
|
|
|
} |
|
|
|
|
img.DrawImage(labelImg, k.op) |
|
|
|
|
|
|
|
|
|