big update, add goroutine sdl render

replace a lot of self.Screen.Draw() to self.Screen.Refresh()
This commit is contained in:
cuu
2023-01-23 14:04:11 +00:00
parent 057bcc86f1
commit 7814f9ca6f
40 changed files with 358 additions and 403 deletions

View File

@@ -45,6 +45,7 @@ type ScreenInterface interface {
SetCurPage(pg PageInterface)
SwapAndShow()
IsWifiConnectedNow()
Refresh()
}
type PluginConfig struct {
@@ -185,7 +186,8 @@ type MainScreen struct {
LastKey string
LastKeyDown gotime.Time
updateScreen chan bool
}
func NewMainScreen() *MainScreen {
@@ -199,6 +201,9 @@ func NewMainScreen() *MainScreen {
m.MsgBoxFont = Fonts["veramono20"]
m.IconFont = Fonts["varela15"]
m.Closed = false
m.updateScreen = make(chan bool,1)
return m
}
@@ -217,7 +222,11 @@ func (self *MainScreen) Init() {
self.CounterScreen.Init()
//self.GenList() // load predefined plugin list,ready to be injected ,or ,as a .so for dynamic loading
go func() {
sdl.Do(func() {
self.RefreshLoop()
})
}()
}
func (self *MainScreen) FartherPages() { // right after ReadTheDirIntoPages
@@ -272,6 +281,7 @@ func (self *MainScreen) SwapAndShow() {
surface.Blit(self.HWND, self.CanvasHWND, &rect_, nil)
}
display.Flip()
}
@@ -443,3 +453,23 @@ func (self *MainScreen) Draw() {
self.FootBar.Draw()
}
}
func (self *MainScreen) Refresh() {
self.updateScreen <- true
}
func (self *MainScreen) RefreshLoop() {
L:
for {
select {
case v:= <- self.updateScreen:
if v == true {
self.Draw()
self.SwapAndShow()
}
if v== false {
break L
}
}
}
}