mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2026-03-19 02:12:46 +01:00
add HookExitCb for OnExitCb
This commit is contained in:
@@ -32,7 +32,7 @@ type DownloadProcessPage struct {
|
||||
|
||||
URLColor *color.Color
|
||||
TextColor *color.Color
|
||||
TheTicker *gotime.Ticker
|
||||
//TheTicker *gotime.Ticker
|
||||
|
||||
Downloader *grab.Client
|
||||
resp *grab.Response
|
||||
@@ -95,9 +95,9 @@ func (self *DownloadProcessPage) Init() {
|
||||
func (self *DownloadProcessPage) OnExitCb() {
|
||||
|
||||
//Stop Ticker and the Grab
|
||||
if self.TheTicker != nil {
|
||||
self.TheTicker.Stop()
|
||||
}
|
||||
//if self.TheTicker != nil {
|
||||
// self.TheTicker.Stop()
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ type ScreenInterface interface {
|
||||
IsPluginPackage(dirname string) bool
|
||||
KeyDown(ev *event.Event)
|
||||
OnExitCb()
|
||||
HookExitCb()
|
||||
PushCurPage()
|
||||
PushPage(pg PageInterface)
|
||||
RunEXE(cmdpath string)
|
||||
@@ -160,10 +161,13 @@ func (self *MessageBox) Draw() {
|
||||
type MainScreen struct {
|
||||
Widget
|
||||
Pages []PageInterface
|
||||
Child []PageInterface
|
||||
|
||||
PageMax int
|
||||
PageIndex int
|
||||
|
||||
MyPageStack *PageStack
|
||||
|
||||
CurrentPage PageInterface
|
||||
CanvasHWND *sdl.Surface
|
||||
HWND *sdl.Surface
|
||||
@@ -181,6 +185,7 @@ type MainScreen struct {
|
||||
|
||||
LastKey string
|
||||
LastKeyDown gotime.Time
|
||||
|
||||
}
|
||||
|
||||
func NewMainScreen() *MainScreen {
|
||||
@@ -377,8 +382,16 @@ func (self *MainScreen) RunEXE(cmdpath string) {
|
||||
|
||||
}
|
||||
|
||||
func (self *MainScreen) HookExitCb( page PageInterface) {
|
||||
self.Child = append(self.Child,page)
|
||||
}
|
||||
|
||||
func (self *MainScreen) OnExitCb() {
|
||||
self.CurrentPage.OnExitCb()
|
||||
PageLen := len(self.Child)
|
||||
|
||||
for i := 0; i < PageLen; i++ {
|
||||
self.Child[i].OnExitCb()
|
||||
}
|
||||
}
|
||||
|
||||
func (self *MainScreen) KeyDown(ev *event.Event) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
// "math"
|
||||
//"reflect"
|
||||
"sync"
|
||||
// "sync"
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
|
||||
@@ -19,54 +19,6 @@ import (
|
||||
"github.com/cuu/gogame/transform"
|
||||
)
|
||||
|
||||
type element struct {
|
||||
data interface{}
|
||||
next *element
|
||||
}
|
||||
|
||||
type PageStack struct {
|
||||
lock *sync.Mutex
|
||||
head *element
|
||||
Size int
|
||||
}
|
||||
|
||||
func (stk *PageStack) Push(data interface{}) {
|
||||
stk.lock.Lock()
|
||||
|
||||
element := new(element)
|
||||
element.data = data
|
||||
temp := stk.head
|
||||
element.next = temp
|
||||
stk.head = element
|
||||
stk.Size++
|
||||
|
||||
stk.lock.Unlock()
|
||||
}
|
||||
|
||||
func (stk *PageStack) Pop() interface{} {
|
||||
if stk.head == nil {
|
||||
return nil
|
||||
}
|
||||
stk.lock.Lock()
|
||||
r := stk.head.data
|
||||
stk.head = stk.head.next
|
||||
stk.Size--
|
||||
|
||||
stk.lock.Unlock()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (stk *PageStack) Length() int {
|
||||
return stk.Size
|
||||
}
|
||||
|
||||
func NewPageStack() *PageStack {
|
||||
stk := new(PageStack)
|
||||
stk.lock = &sync.Mutex{}
|
||||
return stk
|
||||
}
|
||||
|
||||
type PageSelectorInterface interface {
|
||||
Init(x, y, w, h, alpha int)
|
||||
Adjust(x, y, w, h, alpha int)
|
||||
@@ -208,6 +160,7 @@ type PageInterface interface {
|
||||
OnReturnBackCb()
|
||||
OnKbdReturnBackCb()
|
||||
OnExitCb()
|
||||
OnPopUpCb()
|
||||
|
||||
// IconClick()
|
||||
ResetPageSelector()
|
||||
@@ -806,13 +759,15 @@ func (self *Page) IconClick() {
|
||||
}
|
||||
|
||||
func (self *Page) ReturnToUpLevelPage() {
|
||||
|
||||
self.Screen.CurrentPage.OnPopUpCb()
|
||||
|
||||
pop_page := self.Screen.MyPageStack.Pop()
|
||||
if pop_page != nil {
|
||||
page_ := pop_page.(PageInterface)
|
||||
page_.Draw()
|
||||
self.Screen.CurrentPage = page_
|
||||
self.Screen.CurrentPage.OnReturnBackCb()
|
||||
|
||||
} else {
|
||||
if self.Screen.MyPageStack.Length() == 0 {
|
||||
if len(self.Screen.Pages) > 0 {
|
||||
@@ -824,6 +779,7 @@ func (self *Page) ReturnToUpLevelPage() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (self *Page) ClearCanvas() {
|
||||
@@ -919,9 +875,12 @@ func (self *Page) OnReturnBackCb() {
|
||||
}
|
||||
|
||||
func (self *Page) OnExitCb() {
|
||||
|
||||
//MainScreen will call every page's OnExitCb when launchego ready to exit(0)
|
||||
}
|
||||
func (self *Page) OnPopUpCb(){
|
||||
//happend when page switching
|
||||
//use self.Screen.Current.OnPopUpCb to call the current custom Page's OnPopUpCb ,not this empty one
|
||||
}
|
||||
|
||||
func (self *Page) Draw() {
|
||||
self.ClearCanvas()
|
||||
self.DrawIcons()
|
||||
|
||||
62
sysgo/UI/page_stack.go
Normal file
62
sysgo/UI/page_stack.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type element struct {
|
||||
data interface{}
|
||||
next *element
|
||||
}
|
||||
|
||||
type PageStack struct {
|
||||
lock *sync.Mutex
|
||||
head *element
|
||||
Size int
|
||||
}
|
||||
|
||||
func (stk *PageStack) Push(data interface{}) {
|
||||
stk.lock.Lock()
|
||||
|
||||
element := new(element)
|
||||
element.data = data
|
||||
temp := stk.head
|
||||
element.next = temp
|
||||
stk.head = element
|
||||
stk.Size++
|
||||
|
||||
stk.lock.Unlock()
|
||||
}
|
||||
|
||||
func (stk *PageStack) Pop() interface{} {
|
||||
if stk.head == nil {
|
||||
return nil
|
||||
}
|
||||
stk.lock.Lock()
|
||||
r := stk.head.data
|
||||
stk.head = stk.head.next
|
||||
stk.Size--
|
||||
|
||||
stk.lock.Unlock()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (stk *PageStack) Length() int {
|
||||
return stk.Size
|
||||
}
|
||||
|
||||
func (stk *PageStack) Last() interface{} {
|
||||
idx := stk.Length() - 1
|
||||
if idx < 0 {
|
||||
return nil
|
||||
} else {
|
||||
return stk.head.data
|
||||
}
|
||||
}
|
||||
|
||||
func NewPageStack() *PageStack {
|
||||
stk := new(PageStack)
|
||||
stk.lock = &sync.Mutex{}
|
||||
return stk
|
||||
}
|
||||
Reference in New Issue
Block a user