This commit is contained in:
Ivan Izaguirre 2020-10-12 19:29:30 +02:00 committed by Iván Izaguirre
parent 9395c2ffb3
commit 91e6eb6f6d
10 changed files with 168 additions and 60 deletions

3
go.mod
View File

@ -11,6 +11,5 @@ require (
github.com/veandco/go-sdl2 v0.4.0
)
replace fyne.io/fyne => github.com/ivanizag/fyne v1.3.4-0.20201010160818-ed5402384cff
//replace fyne.io/fyne => github.com/ivanizag/fyne v1.3.4-0.20201010160818-ed5402384cff
// replace fyne.io/fyne => ../../fyne/fyne

View File

@ -28,13 +28,15 @@ type joystickInfo struct {
}
type joysticks struct {
s *state
info [2]*joystickInfo
}
const unplugged = uint8(255) // Max resistance when unplugged
func newJoysticks() *joysticks {
func newJoysticks(s *state) *joysticks {
var j joysticks
j.s = s
return &j
}
@ -48,6 +50,9 @@ func (j *joysticks) start() {
case <-pool.C:
j.info[0] = j.queryJoystick(glfw.Joystick1)
j.info[1] = j.queryJoystick(glfw.Joystick2)
j.s.devices.joystick.updateJoy1(j.info[0])
j.s.devices.joystick.updateJoy2(j.info[1])
}
}
}()

View File

@ -113,20 +113,17 @@ func (k *keyboard) putKey(keyEvent *fyne.KeyEvent) {
case fyne.KeyF11:
k.s.a.SendCommand(izapple2.CommandToggleCPUTrace)
case fyne.KeyF12:
case fyne.KeyPrintScreen:
//case fyne.KeyPrintScreen:
err := izapple2.SaveSnapshot(k.s.a, "snapshot.png")
if err != nil {
fmt.Printf("Error saving snapshoot: %v.\n.", err)
} else {
fmt.Println("Saving snapshot")
}
case fyne.KeyPause:
k.s.a.SendCommand(izapple2.CommandPauseUnpauseEmulator)
//case fyne.KeyPause:
// k.s.a.SendCommand(izapple2.CommandPauseUnpauseEmulator)
}
// Missing values 91 to 95. Usually control for [\]^_
// On the Base64A it's control for \]./
if result != 0 {
k.keyChannel.PutChar(result)
}

View File

@ -23,6 +23,8 @@ type state struct {
app fyne.App
win fyne.Window
devices *panelDevices
showPages bool
}
@ -42,11 +44,66 @@ func main() {
func fyneRun(s *state) {
s.app = app.New()
// app.SetIcon(xxx)
s.app.SetIcon(resourceApple2Png)
s.win = s.app.NewWindow("iz-" + s.a.Name)
// window.SetIcon(xxx)
s.win.SetIcon(resourceApple2Png)
bottom := widget.NewToolbar(
s.devices = newPanelDevices(s)
toolbar := buildToolbar(s)
screen := canvas.NewImageFromImage(nil)
//screen.SetMinSize(fyne.NewSize(380, 192))
screen.SetMinSize(fyne.NewSize(280*2, 192*2))
container := fyne.NewContainerWithLayout(
layout.NewBorderLayout(nil, toolbar, nil, s.devices.w),
screen, toolbar, s.devices.w,
)
s.win.SetContent(container)
s.win.SetPadded(false)
registerKeyboardEvents(s)
j := newJoysticks(s)
j.start()
s.a.SetJoysticksProvider(j)
go s.a.Run()
ticker := time.NewTicker(60 * time.Millisecond)
done := make(chan bool)
go func() {
for {
select {
case <-done:
return
case <-ticker.C:
if !s.a.IsPaused() {
var img *image.RGBA
if s.showPages {
img = s.a.SnapshotParts()
s.win.SetTitle(fmt.Sprintf("%v %v %vx%v", s.a.Name, s.a.VideoModeName(), img.Rect.Dx()/2, img.Rect.Dy()/2))
} else {
img = s.a.Snapshot()
}
screen.Image = img
canvas.Refresh(screen)
}
}
}
}()
s.win.SetOnClosed(func() {
done <- true
})
s.win.Show()
fmt.Printf("%v\n", s.win.Canvas().Scale())
s.app.Run()
}
func buildToolbar(s *state) *widget.Toolbar {
return widget.NewToolbar(
widget.NewToolbarAction(
theme.NewThemedResource(resourceRestartSvg, nil), func() {
s.a.SendCommand(izapple2.CommandReset)
@ -88,54 +145,16 @@ func fyneRun(s *state) {
widget.NewToolbarAction(theme.ViewFullScreenIcon(), func() {
s.win.SetFullScreen(!s.win.FullScreen())
}),
)
screen := canvas.NewImageFromImage(nil)
screen.SetMinSize(fyne.NewSize(380, 192))
container := fyne.NewContainerWithLayout(
layout.NewBorderLayout(nil, bottom, nil, nil),
screen, bottom,
)
s.win.SetContent(container)
s.win.SetPadded(false)
registerKeyboardEvents(s)
j := newJoysticks()
j.start()
s.a.SetJoysticksProvider(j)
go s.a.Run()
ticker := time.NewTicker(60 * time.Millisecond)
done := make(chan bool)
go func() {
for {
select {
case <-done:
return
case <-ticker.C:
if !s.a.IsPaused() {
var img *image.RGBA
if s.showPages {
img = s.a.SnapshotParts()
s.win.SetTitle(fmt.Sprintf("%v %v %vx%v", s.a.Name, s.a.VideoModeName(), img.Rect.Dx()/2, img.Rect.Dy()/2))
} else {
img = s.a.Snapshot()
}
screen.Image = img
canvas.Refresh(screen)
widget.NewToolbarAction(
theme.NewThemedResource(resourcePageLayoutSidebarRightSvg, nil), func() {
w := s.devices.w
if w.Visible() {
w.Hide()
} else {
w.Show()
}
}
}
}()
s.win.SetOnClosed(func() {
done <- true
})
s.win.Show()
s.app.Run()
}),
)
}
func registerKeyboardEvents(s *state) {

View File

@ -0,0 +1,23 @@
package main
import (
"fyne.io/fyne"
"fyne.io/fyne/widget"
)
type panelDevices struct {
s *state
w fyne.Widget
joystick *panelJoystick
}
func newPanelDevices(s *state) *panelDevices {
var pd panelDevices
pd.s = s
pd.joystick = newPanelJoystick()
pd.w = widget.NewVBox(pd.joystick.w)
return &pd
}

View File

@ -0,0 +1,51 @@
package main
import (
"fyne.io/fyne"
"fyne.io/fyne/widget"
)
type panelJoystick struct {
w fyne.Widget
labelJoy1 *widget.Label
labelJoy2 *widget.Label
}
const textJoystickNotAvailable = "unplugged"
func newPanelJoystick() *panelJoystick {
var pj panelJoystick
pj.labelJoy1 = widget.NewLabel("")
pj.labelJoy2 = widget.NewLabel("")
widget.NewForm()
pj.w = widget.NewGroup(
"Joysticks",
widget.NewForm(
widget.NewFormItem("Joystick 1", pj.labelJoy1),
widget.NewFormItem("Joystick 2", pj.labelJoy2),
),
)
return &pj
}
func (pj *panelJoystick) updateJoy1(info *joystickInfo) {
newName := textJoystickNotAvailable
if info != nil {
newName = info.name
}
if newName != pj.labelJoy1.Text {
pj.labelJoy1.SetText(newName)
}
}
func (pj *panelJoystick) updateJoy2(info *joystickInfo) {
newName := textJoystickNotAvailable
if info != nil {
newName = info.name
}
if newName != pj.labelJoy2.Text {
pj.labelJoy2.SetText(newName)
}
}

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M6,2H18A2,2 0 0,1 20,4V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2M14,8V16H18V8H14Z" /></svg>

After

Width:  |  Height:  |  Size: 386 B

View File

@ -10,6 +10,9 @@
- layers-triple
- format-font
- camera
- page-layout-sidebar-right
- https://www.iconfinder.com/icons/281710/rainbow_apple_icon
## Building resources.go