mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-12 16:08:52 +01:00
AdjustSAutoLeftAlign keep going
This commit is contained in:
parent
cd4c65ec8a
commit
f8aaab26fa
@ -9,6 +9,23 @@ import (
|
|||||||
"github.com/cuu/gogame/utils"
|
"github.com/cuu/gogame/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type IconItemInterface interface {
|
||||||
|
Init(x,y,w,h,at int)
|
||||||
|
SetIndex(i int)
|
||||||
|
SetParent( p interface{} )
|
||||||
|
SetLabelColor(col *color.Color)
|
||||||
|
Coord() (int,int)
|
||||||
|
NewCoord(x,y int)
|
||||||
|
Size() (int,int)
|
||||||
|
AddLabel(text string, fontobj *ttf.Font)
|
||||||
|
AdjustLinkPage()
|
||||||
|
GetImageSurf() *sdl.Surface
|
||||||
|
SetImageSurf(newsurf *sdl.Surface)
|
||||||
|
CreateImageSurf()
|
||||||
|
ChangeImgSurfColor(col *color.Color)
|
||||||
|
Draw()
|
||||||
|
}
|
||||||
|
|
||||||
type IconItem struct {
|
type IconItem struct {
|
||||||
PosX int
|
PosX int
|
||||||
PosY int
|
PosY int
|
||||||
@ -41,7 +58,7 @@ func NewIconItem() *IconItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (self *IconItem) Init(x,y,w,h,at) {
|
func (self *IconItem) Init(x,y,w,h,at int) {
|
||||||
self.PosX = x
|
self.PosX = x
|
||||||
self.PosY = y
|
self.PosY = y
|
||||||
self.Width = w
|
self.Width = w
|
||||||
@ -49,15 +66,31 @@ func (self *IconItem) Init(x,y,w,h,at) {
|
|||||||
self.AnimationTime = at
|
self.AnimationTime = at
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *IconItem) SetIndex(i int) {
|
||||||
|
self.Index = i
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *IconItem) SetParent(p interface{} ) {
|
||||||
|
self.Parent = p
|
||||||
|
}
|
||||||
|
|
||||||
func (self *IconItem) SetLabelColor(col *color.Color) {
|
func (self *IconItem) SetLabelColor(col *color.Color) {
|
||||||
self.Label.SetColor(col)
|
self.Label.SetColor(col)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *IconItem) Coord() (int,int) {
|
||||||
|
return self.PosX,self.PosY
|
||||||
|
}
|
||||||
|
|
||||||
func (self *IconItem) NewCoord(x,y int) {
|
func (self *IconItem) NewCoord(x,y int) {
|
||||||
self.PosX = x
|
self.PosX = x
|
||||||
self.PosY = y
|
self.PosY = y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *IconItem) NewCoord(x,y int) {
|
||||||
|
return self.Width,self.Height
|
||||||
|
}
|
||||||
|
|
||||||
func (self *IconItem) AddLabel(text string, fontobj *ttf.Font) {
|
func (self *IconItem) AddLabel(text string, fontobj *ttf.Font) {
|
||||||
if self.Label == nil {
|
if self.Label == nil {
|
||||||
l:= NewLabel()
|
l:= NewLabel()
|
||||||
@ -87,6 +120,16 @@ func (self *IconItem) AdjustLinkPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (self *IconItem) GetImageSurf() *sdl.Surface {
|
||||||
|
return self.ImgSurf
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *IconItem) SetImageSurf(newsurf *sdl.Surface) {
|
||||||
|
self.ImgSurf = newsurf
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (self *IconItem) CreateImageSurf() {
|
func (self *IconItem) CreateImageSurf() {
|
||||||
if self.ImgSurf == nil && self.ImageName != "" {
|
if self.ImgSurf == nil && self.ImageName != "" {
|
||||||
self.ImgSurf = image.Load(self.ImageName)
|
self.ImgSurf = image.Load(self.ImageName)
|
||||||
|
|||||||
@ -0,0 +1,57 @@
|
|||||||
|
package UI
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
|
|
||||||
|
"github.com/cuu/gogame/image"
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
type IconPool struct {
|
||||||
|
GameShellIconPath string
|
||||||
|
Icons map[string]*sdl.Surface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewIconPool() *IconPool {
|
||||||
|
i := &IconPool{}
|
||||||
|
i.GameShellIconPath = SkinMap("gameshell/icons/")
|
||||||
|
i.Icons = make( map[string]*sdl.Surface )
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (self *IconPool) Init() {
|
||||||
|
files,err := ioutil.ReadDir(self.GameShellIconPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _,f := range files {
|
||||||
|
if f.IsDir() {
|
||||||
|
//pass
|
||||||
|
}else {
|
||||||
|
if strings.HasSuffix(f.Name(),".png") == true {
|
||||||
|
keyname := strings.Split(f.Name(),".")
|
||||||
|
if len(keyname) > 1 {
|
||||||
|
self.Icons[ keyname[0] ] = image.Load( self.GameShellIconPath+ "/"+f.Name() )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *IconPool) GetImgSurf(keyname string) *sdl.Surface {
|
||||||
|
if val,ok := self.Icons[keyname]; ok {
|
||||||
|
return self.Icons[keyname]
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var MyIconPool = NewIconPool()
|
||||||
|
|
||||||
@ -18,18 +18,36 @@ func NewMultiIconItem() *MultiIconItem {
|
|||||||
m.IconIndex = 0
|
m.IconIndex = 0
|
||||||
m.IconWidth = 18
|
m.IconWidth = 18
|
||||||
m.IconHeight = 18
|
m.IconHeight = 18
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self * MultiIconItem) CreateImageSurf() {
|
||||||
|
if self.ImgSurf == nil && self.ImageName != "" {
|
||||||
func (m * MultiIconItem) CreateImageSurf() {
|
self.ImgSurf = image.Load(self.ImageName)
|
||||||
if m.ImgSurf == nil and m.ImageName != "" {
|
|
||||||
m.ImgSurf = image.Load(m.ImageName)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MultiIconItem) Draw() {
|
func (self *MultiIconItem) Draw() {
|
||||||
|
parent_x,parent_y := self.Parent.Coord()
|
||||||
|
|
||||||
|
if self.Label != nil {
|
||||||
|
// lab_x,lab_y := self.Label.Coord()
|
||||||
|
lab_w,lab_h:= self.Label.Size()
|
||||||
|
if self.Align == ALIGN["VCenter"] {
|
||||||
|
self.Label.NewCoord( self.PosX - lab_w/2 + parent_x, self.PosY + self.Height/2+6 + parent_y)
|
||||||
|
}else if self.Align == ALIGN["HLeft"] {
|
||||||
|
self.Label.NewCoord( self.PosX + self.Width/2+3 + parent_x, self.PosY - lab_h/2 + parent_y )
|
||||||
|
}
|
||||||
|
|
||||||
|
self.Label.Draw()
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.ImgSurf != nil {
|
||||||
|
|
||||||
|
portion := rect.Rect(0,self.IconIndex*self.IconHeight,self.IconWidth,self.IconHeight)
|
||||||
|
|
||||||
|
surface.Blit(self.Parent.GetCanvasHWND(),
|
||||||
|
self.ImgSurf,draw.MidRect(self.PosX + parent_x, self.PosY + parent_y,
|
||||||
|
self.Width,self.Height, Width, Height),&portion)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
159
sysgo/UI/page.go
159
sysgo/UI/page.go
@ -5,6 +5,8 @@ import (
|
|||||||
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
|
|
||||||
|
"github.com/cuu/gogame/font"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type element struct {
|
type element struct {
|
||||||
@ -45,6 +47,10 @@ func (stk *PageStack) Pop() interface{} {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (stk *PageStack) Length() int {
|
||||||
|
return stk.Size
|
||||||
|
}
|
||||||
|
|
||||||
func NewPageStack() *PageStack {
|
func NewPageStack() *PageStack {
|
||||||
stk := new(PageStack)
|
stk := new(PageStack)
|
||||||
stk.lock = &sync.Mutex{}
|
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 {
|
type PageSelector struct {
|
||||||
|
|
||||||
PosX int
|
PosX int
|
||||||
PosY int
|
PosY int
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
Parent interface{} //
|
Parent PageInterface
|
||||||
Alpha int
|
Alpha int
|
||||||
OnShow bool
|
OnShow bool
|
||||||
IconSurf *sdl.Surface
|
IconSurf *sdl.Surface
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PageSelector) Adjust(x,y,w,h,alpha int) {
|
func NewPageSelector() *PageSelector {
|
||||||
p.PosX = x
|
p := &PageSelector{}
|
||||||
p.PosY = y
|
return p
|
||||||
p.Width = w
|
|
||||||
p.Height = h
|
|
||||||
p.Alpha = alpha
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// GetIconIndex
|
||||||
// Coord
|
// Coord
|
||||||
// Size
|
// Size
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Page struct {
|
type Page struct {
|
||||||
|
|
||||||
PosX int
|
PosX int
|
||||||
PosY int
|
PosY int
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
Icons []interface{} // make first
|
Icons []IconItemInterface // slice ,use append
|
||||||
IconNumbers int
|
IconNumbers int
|
||||||
IconIndex int
|
IconIndex int
|
||||||
PrevIconIndex int
|
PrevIconIndex int
|
||||||
|
|
||||||
Ps interface{}
|
Ps PageSelectorInterface
|
||||||
PsIndex int
|
PsIndex int
|
||||||
|
|
||||||
Index int
|
Index int
|
||||||
@ -120,7 +165,6 @@ type Page struct {
|
|||||||
HWND *sdl.Surface
|
HWND *sdl.Surface
|
||||||
|
|
||||||
OnShow bool
|
OnShow bool
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
Screen *MainScreen
|
Screen *MainScreen
|
||||||
|
|
||||||
@ -136,14 +180,101 @@ func NewPage() *Page {
|
|||||||
p.PageIconMargin = 20
|
p.PageIconMargin = 20
|
||||||
p.SelectedIconTopOffset = 20
|
p.SelectedIconTopOffset = 20
|
||||||
p.EasingDur = 30
|
p.EasingDur = 30
|
||||||
|
|
||||||
|
p.Align = ALIGN["SLeft"]
|
||||||
|
|
||||||
p.FootMsg = [5]string{"Nav.","","","","Enter"}
|
p.FootMsg = [5]string{"Nav.","","","","Enter"}
|
||||||
|
|
||||||
return p
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
7
sysgo/easings/README.md
Normal file
7
sysgo/easings/README.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
## easings [](https://godoc.org/github.com/gen2brain/raylib-go/easings)
|
||||||
|
|
||||||
|
Useful easing functions for values animation.
|
||||||
|
|
||||||
|
A port of Robert Penner's [easing equations](http://robertpenner.com/easing/).
|
||||||
|
|
||||||
|

|
||||||
291
sysgo/easings/easings.go
Normal file
291
sysgo/easings/easings.go
Normal file
@ -0,0 +1,291 @@
|
|||||||
|
// Package easings - Useful easing functions for values animation
|
||||||
|
//
|
||||||
|
// A port of Robert Penner's easing equations (http://robertpenner.com/easing/)
|
||||||
|
package easings
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Linear Easing functions
|
||||||
|
|
||||||
|
// LinearNone easing
|
||||||
|
func LinearNone(t, b, c, d float32) float32 {
|
||||||
|
return c*t/d + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinearIn easing
|
||||||
|
func LinearIn(t, b, c, d float32) float32 {
|
||||||
|
return c*t/d + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinearOut easing
|
||||||
|
func LinearOut(t, b, c, d float32) float32 {
|
||||||
|
return c*t/d + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinearInOut easing
|
||||||
|
func LinearInOut(t, b, c, d float32) float32 {
|
||||||
|
return c*t/d + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sine Easing functions
|
||||||
|
|
||||||
|
// SineIn easing
|
||||||
|
func SineIn(t, b, c, d float32) float32 {
|
||||||
|
return -c*float32(math.Cos(float64(t/d)*(math.Pi/2))) + c + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// SineOut easing
|
||||||
|
func SineOut(t, b, c, d float32) float32 {
|
||||||
|
return c*float32(math.Sin(float64(t/d)*(math.Pi/2))) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// SineInOut easing
|
||||||
|
func SineInOut(t, b, c, d float32) float32 {
|
||||||
|
return -c/2*(float32(math.Cos(math.Pi*float64(t/d)))-1) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Circular Easing functions
|
||||||
|
|
||||||
|
// CircIn easing
|
||||||
|
func CircIn(t, b, c, d float32) float32 {
|
||||||
|
t = t / d
|
||||||
|
return -c*(float32(math.Sqrt(float64(1-t*t)))-1) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// CircOut easing
|
||||||
|
func CircOut(t, b, c, d float32) float32 {
|
||||||
|
return c*float32(math.Sqrt(1-float64((t/d-1)*t))) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// CircInOut easing
|
||||||
|
func CircInOut(t, b, c, d float32) float32 {
|
||||||
|
t = t / d * 2
|
||||||
|
|
||||||
|
if t < 1 {
|
||||||
|
return -c/2*(float32(math.Sqrt(float64(1-t*t)))-1) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
t = t - 2
|
||||||
|
return c/2*(float32(math.Sqrt(1-float64(t*t)))+1) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cubic Easing functions
|
||||||
|
|
||||||
|
// CubicIn easing
|
||||||
|
func CubicIn(t, b, c, d float32) float32 {
|
||||||
|
t = t / d
|
||||||
|
return c*t*t*t + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// CubicOut easing
|
||||||
|
func CubicOut(t, b, c, d float32) float32 {
|
||||||
|
t = t/d - 1
|
||||||
|
return c*(t*t*t+1) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// CubicInOut easing
|
||||||
|
func CubicInOut(t, b, c, d float32) float32 {
|
||||||
|
t = t / d * 2
|
||||||
|
if t < 1 {
|
||||||
|
return (c/2*t*t*t + b)
|
||||||
|
}
|
||||||
|
|
||||||
|
t = t - 2
|
||||||
|
return c/2*(t*t*t+2) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quadratic Easing functions
|
||||||
|
|
||||||
|
// QuadIn easing
|
||||||
|
func QuadIn(t, b, c, d float32) float32 {
|
||||||
|
t = t / d
|
||||||
|
return c*t*t + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// QuadOut easing
|
||||||
|
func QuadOut(t, b, c, d float32) float32 {
|
||||||
|
t = t / d
|
||||||
|
return (-c*t*(t-2) + b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QuadInOut easing
|
||||||
|
func QuadInOut(t, b, c, d float32) float32 {
|
||||||
|
t = t / d * 2
|
||||||
|
if t < 1 {
|
||||||
|
return ((c / 2) * (t * t)) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
return -c/2*((t-1)*(t-3)-1) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exponential Easing functions
|
||||||
|
|
||||||
|
// ExpoIn easing
|
||||||
|
func ExpoIn(t, b, c, d float32) float32 {
|
||||||
|
if t == 0 {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
return (c*float32(math.Pow(2, 10*float64(t/d-1))) + b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpoOut easing
|
||||||
|
func ExpoOut(t, b, c, d float32) float32 {
|
||||||
|
if t == d {
|
||||||
|
return (b + c)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c*(-float32(math.Pow(2, -10*float64(t/d)))+1) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpoInOut easing
|
||||||
|
func ExpoInOut(t, b, c, d float32) float32 {
|
||||||
|
if t == 0 {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
if t == d {
|
||||||
|
return (b + c)
|
||||||
|
}
|
||||||
|
|
||||||
|
t = t / d * 2
|
||||||
|
|
||||||
|
if t < 1 {
|
||||||
|
return (c/2*float32(math.Pow(2, 10*float64(t-1))) + b)
|
||||||
|
}
|
||||||
|
|
||||||
|
t = t - 1
|
||||||
|
return (c/2*(-float32(math.Pow(2, -10*float64(t)))+2) + b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Back Easing functions
|
||||||
|
|
||||||
|
// BackIn easing
|
||||||
|
func BackIn(t, b, c, d float32) float32 {
|
||||||
|
s := float32(1.70158)
|
||||||
|
t = t / d
|
||||||
|
return c*t*t*((s+1)*t-s) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// BackOut easing
|
||||||
|
func BackOut(t, b, c, d float32) float32 {
|
||||||
|
s := float32(1.70158)
|
||||||
|
t = t/d - 1
|
||||||
|
return c*(t*t*((s+1)*t+s)+1) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// BackInOut easing
|
||||||
|
func BackInOut(t, b, c, d float32) float32 {
|
||||||
|
s := float32(1.70158)
|
||||||
|
s = s * 1.525
|
||||||
|
t = t / d * 2
|
||||||
|
|
||||||
|
if t < 1 {
|
||||||
|
return c/2*(t*t*((s+1)*t-s)) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
t = t - 2
|
||||||
|
return c/2*(t*t*((s+1)*t+s)+2) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bounce Easing functions
|
||||||
|
|
||||||
|
// BounceIn easing
|
||||||
|
func BounceIn(t, b, c, d float32) float32 {
|
||||||
|
return (c - BounceOut(d-t, 0, c, d) + b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BounceOut easing
|
||||||
|
func BounceOut(t, b, c, d float32) float32 {
|
||||||
|
t = t / d
|
||||||
|
if t < (1 / 2.75) {
|
||||||
|
return (c*(7.5625*t*t) + b)
|
||||||
|
} else if t < (2 / 2.75) {
|
||||||
|
t = t - (1.5 / 2.75)
|
||||||
|
return c*(7.5625*t*t+0.75) + b
|
||||||
|
} else if t < (2.5 / 2.75) {
|
||||||
|
t = t - (2.25 / 2.75)
|
||||||
|
return c*(7.5625*t*t+0.9375) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
t = t - (2.625 / 2.75)
|
||||||
|
return c*(7.5625*t*t+0.984375) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// BounceInOut easing
|
||||||
|
func BounceInOut(t, b, c, d float32) float32 {
|
||||||
|
if t < d/2 {
|
||||||
|
return BounceIn(t*2, 0, c, d)*0.5 + b
|
||||||
|
}
|
||||||
|
|
||||||
|
return BounceOut(t*2-d, 0, c, d)*0.5 + c*0.5 + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Elastic Easing functions
|
||||||
|
|
||||||
|
// ElasticIn easing
|
||||||
|
func ElasticIn(t, b, c, d float32) float32 {
|
||||||
|
if t == 0 {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
t = t / d
|
||||||
|
|
||||||
|
if t == 1 {
|
||||||
|
return b + c
|
||||||
|
}
|
||||||
|
|
||||||
|
p := d * 0.3
|
||||||
|
a := c
|
||||||
|
s := p / 4
|
||||||
|
postFix := a * float32(math.Pow(2, 10*float64(t-1)))
|
||||||
|
|
||||||
|
return -(postFix * float32(math.Sin(float64(t*d-s)*(2*math.Pi)/float64(p)))) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// ElasticOut easing
|
||||||
|
func ElasticOut(t, b, c, d float32) float32 {
|
||||||
|
if t == 0 {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
t = t / d
|
||||||
|
|
||||||
|
if t == 1 {
|
||||||
|
return b + c
|
||||||
|
}
|
||||||
|
|
||||||
|
p := d * 0.3
|
||||||
|
a := c
|
||||||
|
s := p / 4
|
||||||
|
|
||||||
|
return a*float32(math.Pow(2, -10*float64(t)))*float32(math.Sin(float64(t*d-s)*(2*math.Pi)/float64(p))) + c + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// ElasticInOut easing
|
||||||
|
func ElasticInOut(t, b, c, d float32) float32 {
|
||||||
|
if t == 0 {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
t = t / d * 2
|
||||||
|
|
||||||
|
if t == 2 {
|
||||||
|
return b + c
|
||||||
|
}
|
||||||
|
|
||||||
|
p := d * (0.3 * 1.5)
|
||||||
|
a := c
|
||||||
|
s := p / 4
|
||||||
|
|
||||||
|
if t < 1 {
|
||||||
|
t = t - 1
|
||||||
|
postFix := a * float32(math.Pow(2, 10*float64(t)))
|
||||||
|
return -0.5*(postFix*float32(math.Sin(float64(t*d-s)*(2*math.Pi)/float64(p)))) + b
|
||||||
|
}
|
||||||
|
|
||||||
|
t = t - 1
|
||||||
|
postFix := a * float32(math.Pow(2, -10*(float64(t))))
|
||||||
|
return postFix*float32(math.Sin(float64(t*d-s)*(2*math.Pi)/float64(p)))*0.5 + c + b
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user