Online backgammon client (FIBS)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
1.8 KiB

package game
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
const (
windowMinimized = iota
windowNormal
WindowMaximized
)
const windowStartingAlpha = 0.8
type tabbedBuffers struct {
buffers []*textBuffer
labels [][]byte
x, y int
w, h int
unfocusedAlpha float64
buffer *ebiten.Image
bufferDirty bool
op *ebiten.DrawImageOptions
state int
focused bool
touchIDs []ebiten.TouchID
}
func newTabbedBuffers() *tabbedBuffers {
return &tabbedBuffers{
state: windowNormal,
unfocusedAlpha: windowStartingAlpha,
buffer: ebiten.NewImage(1, 1),
op: &ebiten.DrawImageOptions{},
}
}
func (t *tabbedBuffers) setRect(x, y, w, h int) {
if t.x == x && t.y == y && t.w == w && t.h == h {
return
}
if t.w != w || t.h != h {
t.buffer = ebiten.NewImage(w, h)
t.bufferDirty = true
}
t.x, t.y, t.w, t.h = x, y, w, h
}
func (t *tabbedBuffers) drawBuffer() {
t.buffer.Fill(frameColor)
}
func (t *tabbedBuffers) draw(target *ebiten.Image) {
if t.buffer == nil {
return
}
return // This feature is not yet finished.
if t.bufferDirty {
t.drawBuffer()
t.bufferDirty = false
}
alpha := t.unfocusedAlpha
if t.focused {
alpha = 1.0
}
t.op.GeoM.Reset()
t.op.GeoM.Translate(float64(t.x), float64(t.y))
t.op.ColorM.Reset()
t.op.ColorM.Scale(1, 1, 1, alpha)
target.DrawImage(t.buffer, t.op)
}
func (t *tabbedBuffers) click(x, y int) {
}
func (t *tabbedBuffers) update() {
// TODO accept keyboard input
// TODO switch tabs
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
x, y := ebiten.CursorPosition()
t.click(x, y)
}
t.touchIDs = inpututil.AppendJustPressedTouchIDs(t.touchIDs[:0])
for _, id := range t.touchIDs {
x, y := ebiten.TouchPosition(id)
t.click(x, y)
}
// TODO add show virtual keyboard button
}