Compare commits

...

4 Commits

Author SHA1 Message Date
Daniel Schmidt
7710fdc88d
Merge pull request #1 from obvionaoe/main
Add WindowOption and RunWithOptions method to allow for extra configuration
2024-05-09 19:54:27 +02:00
obvionaoe
d976f61673
Remove test functions for WindowOption 2024-05-09 16:15:19 +01:00
obvionaoe
ea37c58ee8
Add WindowOption and RunWithOptions function to allow for extra configuration 2024-05-09 16:01:48 +01:00
Daniel Schmidt
a3526f42c5 feat: update to new bubbletea mouse handling 2024-01-12 21:00:06 +01:00
2 changed files with 48 additions and 12 deletions

View File

@ -95,6 +95,16 @@ var ebitenToTeaMouse = map[ebiten.MouseButton]tea.MouseEventType{
ebiten.MouseButtonRight: tea.MouseRight,
}
var ebitenToTeaMouseNew = map[ebiten.MouseButton]tea.MouseButton{
ebiten.MouseButtonLeft: tea.MouseButtonLeft,
ebiten.MouseButtonMiddle: tea.MouseButtonMiddle,
ebiten.MouseButtonRight: tea.MouseButtonRight,
// TODO: is this right?
ebiten.MouseButton3: tea.MouseButtonBackward,
ebiten.MouseButton4: tea.MouseButtonForward,
}
// Options are used to configure the adapter.
type Options func(*Adapter)
@ -124,11 +134,12 @@ func NewAdapter(prog *tea.Program, options ...Options) *Adapter {
func (b *Adapter) HandleMouseMotion(motion crt.MouseMotion) {
b.prog.Send(tea.MouseMsg{
X: motion.X,
Y: motion.Y,
Alt: false,
Ctrl: false,
Type: tea.MouseMotion,
X: motion.X,
Y: motion.Y,
Alt: false,
Ctrl: false,
Type: tea.MouseMotion,
Action: tea.MouseActionMotion,
})
}
@ -138,13 +149,22 @@ func (b *Adapter) HandleMouseButton(button crt.MouseButton) {
return
}
b.prog.Send(tea.MouseMsg{
X: button.X,
Y: button.Y,
Alt: ebiten.IsKeyPressed(ebiten.KeyAlt),
Ctrl: ebiten.IsKeyPressed(ebiten.KeyControl),
Type: ebitenToTeaMouse[button.Button],
})
msg := tea.MouseMsg{
X: button.X,
Y: button.Y,
Alt: ebiten.IsKeyPressed(ebiten.KeyAlt),
Ctrl: ebiten.IsKeyPressed(ebiten.KeyControl),
Type: ebitenToTeaMouse[button.Button],
Button: ebitenToTeaMouseNew[button.Button],
}
if button.JustReleased {
msg.Action = tea.MouseActionRelease
} else if button.JustPressed {
msg.Action = tea.MouseActionPress
}
b.prog.Send(msg)
}
func (b *Adapter) HandleMouseWheel(wheel crt.MouseWheel) {

16
crt.go
View File

@ -66,6 +66,8 @@ type Window struct {
invalidateBuffer bool
}
type WindowOption func(window *Window)
// NewGame creates a new terminal game with the given dimensions and font faces.
func NewGame(width int, height int, fonts Fonts, tty io.Reader, adapter InputAdapter, defaultBg color.Color) (*Window, error) {
if defaultBg == nil {
@ -631,6 +633,20 @@ func (g *Window) Run(title string) error {
return nil
}
func (g *Window) RunWithOptions(options ...WindowOption) error {
ebiten.SetWindowSize(int(float64(g.cellsWidth*g.cellWidth)/DeviceScale()), int(float64(g.cellsHeight*g.cellHeight)/DeviceScale()))
for _, opt := range options {
opt(g)
}
if err := ebiten.RunGame(g); err != nil {
return err
}
return nil
}
func (g *Window) Kill() {
SysKill()
}