Browse Source

Shade buttons

master
Trevor Slocum 1 month ago
parent
commit
47a7751c7a
  1. 2
      doc.go
  2. 4
      go.mod
  3. 10
      go.sum
  4. 35
      keyboard.go

2
doc.go

@ -1,4 +1,4 @@
/*
Package kibodo provides an on-screen keyboard widget for ebiten
Package kibodo provides an on-screen keyboard widget for Ebiten.
*/
package kibodo

4
go.mod

@ -3,14 +3,14 @@ module code.rocketnine.space/tslocum/kibodo
go 1.17
require (
github.com/hajimehoshi/ebiten/v2 v2.2.0-alpha.14.0.20210915040438-ec2f82342091
github.com/hajimehoshi/ebiten/v2 v2.2.0-alpha.14.0.20210916141036-9c321d1fcf27
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
)
require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210727001814-0db043d8d5be // indirect
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 // indirect
golang.org/x/exp v0.0.0-20210915225539-aeb18aa42a84 // indirect
golang.org/x/exp v0.0.0-20210916165020-5cb4fee858ee // indirect
golang.org/x/mobile v0.0.0-20210902104108-5d9a33257ab5 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210915083310-ed5796bab164 // indirect

10
go.sum

@ -98,12 +98,12 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hajimehoshi/bitmapfont/v2 v2.1.3 h1:JefUkL0M4nrdVwVq7MMZxSTh6mSxOylm+C4Anoucbb0=
github.com/hajimehoshi/bitmapfont/v2 v2.1.3/go.mod h1:2BnYrkTQGThpr/CY6LorYtt/zEPNzvE/ND69CRTaHMs=
github.com/hajimehoshi/ebiten/v2 v2.2.0-alpha.14.0.20210915040438-ec2f82342091 h1:z3+aOqAqZhE0ppbhy89l5T3RDB7d+S9TiyGbtVJ3NvA=
github.com/hajimehoshi/ebiten/v2 v2.2.0-alpha.14.0.20210915040438-ec2f82342091/go.mod h1:fS7PLZeV3mclX0J6qubENa9ms3NWmZdNJkCOeEHmF74=
github.com/hajimehoshi/ebiten/v2 v2.2.0-alpha.14.0.20210916141036-9c321d1fcf27 h1:QkZ/7JEkaoLrqMaNjskMvCoOV979VsfHTaDJzTBwGFw=
github.com/hajimehoshi/ebiten/v2 v2.2.0-alpha.14.0.20210916141036-9c321d1fcf27/go.mod h1:2sY8DHIXNs0Lf/pyTZXltEQtqCKZ2HyXbeUWzrLTlg0=
github.com/hajimehoshi/file2byteslice v0.0.0-20200812174855-0e5e8a80490e/go.mod h1:CqqAHp7Dk/AqQiwuhV1yT2334qbA/tFWQW0MD2dGqUE=
github.com/hajimehoshi/go-mp3 v0.3.2/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.0.20210912073017-18657977e3dc/go.mod h1:rUKQmwMkqmRxe+IAof9+tuYA2ofm8cAWXFmSfzDN8vQ=
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.1/go.mod h1:rUKQmwMkqmRxe+IAof9+tuYA2ofm8cAWXFmSfzDN8vQ=
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
@ -285,8 +285,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/exp v0.0.0-20210915225539-aeb18aa42a84 h1:rZZoVfcp9bNtyV7GbMqs6qTtgn/htRKdyfzKQ4EiLFE=
golang.org/x/exp v0.0.0-20210915225539-aeb18aa42a84/go.mod h1:a3o/VtDNHN+dCVLEpzjjUHOzR+Ln3DHX056ZPzoZGGA=
golang.org/x/exp v0.0.0-20210916165020-5cb4fee858ee h1:qlrAyYdKz4o7rWVUjiKqQJMa4PEpd55fqBU8jpsl4Iw=
golang.org/x/exp v0.0.0-20210916165020-5cb4fee858ee/go.mod h1:a3o/VtDNHN+dCVLEpzjjUHOzR+Ln3DHX056ZPzoZGGA=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=

35
keyboard.go

@ -135,8 +135,8 @@ func (k *Keyboard) updateKeyRects() {
}
// TODO user configurable
cellPaddingW := 2
cellPaddingH := 2
cellPaddingW := 1
cellPaddingH := 1
cellH := (k.h - (cellPaddingH * (len(k.keys) - 1))) / len(k.keys)
@ -368,15 +368,16 @@ func (k *Keyboard) drawBackground() {
}
}
// Draw key background
// TODO configurable
img.Fill(color.RGBA{90, 90, 90, 255})
// Draw key label
label := key.LowerLabel
if shift {
label = key.UpperLabel
}
// Draw key background
img.Fill(color.RGBA{100, 100, 100, 255})
// Draw key label
bounds := text.BoundString(k.labelFont, label)
x := (key.w - bounds.Dx()) / 2
if x < 0 {
@ -385,6 +386,18 @@ func (k *Keyboard) drawBackground() {
y := key.h / 2
text.Draw(img, label, k.labelFont, x, y, color.White)
// Draw border
lightShade := color.RGBA{150, 150, 150, 255}
darkShade := color.RGBA{30, 30, 30, 255}
for j := 0; j < key.w; j++ {
img.Set(j, 0, lightShade)
img.Set(j, key.h-1, darkShade)
}
for j := 0; j < key.h; j++ {
img.Set(0, j, lightShade)
img.Set(key.w-1, j, darkShade)
}
// Draw key
k.op.GeoM.Reset()
k.op.GeoM.Translate(float64(key.x), float64(key.y))
@ -438,6 +451,16 @@ func (k *Keyboard) Draw(target *ebiten.Image) {
target.DrawImage(background.SubImage(image.Rect(key.x, key.y, key.x+key.w, key.y+key.h)).(*ebiten.Image), k.op)
k.op.ColorM.Reset()
// Draw border
darkShade := color.RGBA{60, 60, 60, 255}
ox, oy := k.x+key.x, k.y+key.y
for j := 0; j < key.w; j++ {
target.Set(ox+j, oy, darkShade)
}
for j := 0; j < key.h; j++ {
target.Set(ox, oy+j, darkShade)
}
}
}
}

Loading…
Cancel
Save