AdjustSAutoLeftAlign keep going

This commit is contained in:
cuu
2018-06-12 21:49:54 +08:00
parent cd4c65ec8a
commit f8aaab26fa
6 changed files with 569 additions and 22 deletions

View File

@@ -5,6 +5,8 @@ import (
"github.com/veandco/go-sdl2/sdl"
"github.com/cuu/gogame/font"
)
type element struct {
@@ -45,6 +47,10 @@ func (stk *PageStack) Pop() interface{} {
return r
}
func (stk *PageStack) Length() int {
return stk.Size
}
func NewPageStack() *PageStack {
stk := new(PageStack)
stk.lock = &sync.Mutex{}
@@ -52,29 +58,67 @@ func NewPageStack() *PageStack {
}
type PageSelectorInterface interface {
Adjust(x,y,w,h,alpha int)
Draw()
}
type PageSelector struct {
PosX int
PosY int
Width int
Height int
Parent interface{} //
Parent PageInterface
Alpha int
OnShow bool
IconSurf *sdl.Surface
}
func (p *PageSelector) Adjust(x,y,w,h,alpha int) {
p.PosX = x
p.PosY = y
p.Width = w
p.Height = h
p.Alpha = alpha
func NewPageSelector() *PageSelector {
p := &PageSelector{}
return p
}
func (p *PageSelector) Draw() {
func (self *PageSelector) Init(x,y,w,h,alpha int) {
self.Adjust(x,y,w,h,alpha)
}
func (self *PageSelector) Adjust(x,y,w,h,alpha int) {
self.PosX = x
self.PosY = y
self.Width = w
self.Height = h
self.Alpha = alpha
}
func (self *PageSelector) Draw() {
canvas := self.Parent.GetCanvasHWND()
idx := self.Parent.GetPsIndex()
iconidx := self.Parent.GetIconIndex()
icons := self.Parent.GetIcons()
if idx < len(icons) {
icon_x ,_ := icons[idx].Coord()
_,icon_y := icons[iconidx].Coord()
parent_x,parent_y := self.Parent.Coord()
parent_w,parent_h := self.Parent.Size()
x := icon_x + parent_x
y := icon_y // only use current icon's PosY
rect_ = draw.MidRect(x,y, self.Width, self.Height, parent_w,parent_h)
if rect_.W <=0 || rect_.H <= 0 {
return
}
if self.IconSurf != nil {
surface.Blit(canvas,self.IconSurf, rect_,nil)
}
}
}
@@ -96,20 +140,21 @@ type PageInterface interface {
// GetIconIndex
// Coord
// Size
}
type Page struct {
PosX int
PosY int
Width int
Height int
Icons []interface{} // make first
Icons []IconItemInterface // slice ,use append
IconNumbers int
IconIndex int
PrevIconIndex int
Ps interface{}
Ps PageSelectorInterface
PsIndex int
Index int
@@ -120,7 +165,6 @@ type Page struct {
HWND *sdl.Surface
OnShow bool
Name string
Screen *MainScreen
@@ -136,14 +180,101 @@ func NewPage() *Page {
p.PageIconMargin = 20
p.SelectedIconTopOffset = 20
p.EasingDur = 30
p.Align = ALIGN["SLeft"]
p.FootMsg = [5]string{"Nav.","","","","Enter"}
return p
}
func (self *Page) AdjustHLeftAlign() {
self.PosX = self.Index*self.Screen.Width
self.Width = self.Screen.Width
self.Height = self.Screen.Height
cols := int(Width/IconWidth)
rows := int( self.IconNumbers * IconWidth) / self.Width + 1
cnt := 0
if rows < 1 {
rows = 1
}
for i := 0; i < rows; i++ {
for j := 0; j < cols; j++ {
start_x := IconWidth/2 + j*IconWidth
start_y := IconHeight/2 + i*IconHeight
icon := self.Icons[cnt]
icon.Adjust(start_x,start_y,IconWidth-4,IconHeight-4,0)
icon.SetIndex(cnt)
icon.SetParent(self)
if cnt >= self.IconNumbers -1 {
break
}
cnt += 1
}
}
ps := NewPageSelector()
ps.IconSurf = MyIconPool.GetImgSurf("blueselector")
ps.Parent = self
ps.Init(IconWidth/2,TitleBar_BarHeight+IconHeight/2, 92,92,128) //hard coded of the blueselector png size
self.Ps = ps
self.PsIndex = 0
self.OnShow = false
}
func (self *Page) AdjustSLeftAlign() { // ## adjust coordinator and append the PageSelector
self.PosX = self.Index * self.Screen.Width
self.Width = self.Screen.Width
self.Height = self.Screen.Height
start_x := (self.PageIconMargin + IconWidth + self.PageIconMargin ) / 2
start_y := self.Height/2
for i := 0; i < self.IconNumbers; i++ {
it := self.Icons[i]
it.SetParent(self)
it.SetIndex(i)
it.Adjust(start_x+i*self.PageIconMargin+i*IconWidth, start_y, IconWidth-6,IconHeight-6,0)
old_surf := it.GetImageSurf()
it_w,it_h := it.Size() //width height changed by Adjust above
it.SetImageSurf( transform.SmoothScale(old_surf,it_w,it_h) )
}
ps := NewPageSelector()
ps.IconSurf = MyIconPool.GetImageSurf("blueselector")
ps.Parent = self
ps.Init(start_x,start_y,92,92,128)
self.Ps = ps
self.PsIndex = 0
self.OnShow = false
if self.IconNumbers > 1 {
self.PsIndex = 1
self.IconIndex = self.PsIndex
self.PrevIconIndex = self.IconIndex
cur_icon_x,cur_icon_y := self.Icons[self.IconIndex].Coord()
self.Icons[self.IconIndex].NewCoord(cur_icon_x, cur_icon_y - self.SelectedIconTopOffset )
}
}
func (self *Page) AdjustSAutoLeftAlign() { // ## adjust coordinator and append the PageSelector
self.PosX = self.Index * self.Screen.Width
self.Width = self.Screen.Width
self.Height = self.Screen.Height
start_x := (self.PageIconMargin + IconWidth + self.PageIconMargin ) / 2
start_y := self.Height/2
}