mirror of
https://github.com/BigJk/crt.git
synced 2026-02-06 10:47:25 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7710fdc88d | ||
|
|
d976f61673 | ||
|
|
ea37c58ee8 | ||
|
|
a3526f42c5 |
@ -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
16
crt.go
@ -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()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user