当前位置: 首页>>代码示例>>Golang>>正文


Golang tcell.Event类代码示例

本文整理汇总了Golang中github.com/gdamore/tcell.Event的典型用法代码示例。如果您正苦于以下问题:Golang Event类的具体用法?Golang Event怎么用?Golang Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: HandleEvent

func (a *mainWindow) HandleEvent(ev tcell.Event) bool {

	switch ev := ev.(type) {
	case *tcell.EventKey:
		switch ev.Key() {
		case tcell.KeyCtrlL:
			app.Refresh()
			return true
		case tcell.KeyRune:
			switch ev.Rune() {
			case 'Q', 'q':
				app.Quit()
				return true
			case 'S', 's':
				a.model.hide = false
				a.updateKeys()
				return true
			case 'H', 'h':
				a.model.hide = true
				a.updateKeys()
				return true
			case 'E', 'e':
				a.model.enab = true
				a.updateKeys()
				return true
			case 'D', 'd':
				a.model.enab = false
				a.updateKeys()
				return true
			}
		}
	}
	return a.Panel.HandleEvent(ev)
}
开发者ID:jmptrader,项目名称:tcell,代码行数:34,代码来源:cellview.go

示例2: HandleEvent

func (o *gantry) HandleEvent(ev tcell.Event) bool {
	s := o.sprite
	switch ev := ev.(type) {
	case *EventSpriteMove:
		x, _ := o.sprite.Position()
		if o.startx != 0 && o.startx-5 >= x {
			o.sprite.SetVelocity(0, 0)
		}
	case *EventCollision:
		switch ev.Collider().Layer() {
		case LayerShot, LayerPlayer:
			o.sprite.Hide()
			x, y, _, _ := s.Bounds()
			props := GameObjectProps{}
			props.PropSetInt("x", x)
			props.PropSetInt("y", y)
			props.PropSetInt("count", 2)
			MakeGameObject(o.level, "explosion", props)
		}
	case *EventLevelStart:
		o.sprite.SetVelocity(-3.0, 0)
		o.sprite.SetFrame("RETRACT")
		o.startx, _ = o.sprite.Position()
	}
	return false
}
开发者ID:gdamore,项目名称:proxima5,代码行数:26,代码来源:f-gantry.go

示例3: HandleEvent

// HandleEvent handles events.  In particular, it handles certain key events
// to move the cursor or pan the view.
func (a *CellView) HandleEvent(e tcell.Event) bool {
	if a.model == nil {
		return false
	}
	switch e := e.(type) {
	case *tcell.EventKey:
		switch e.Key() {
		case tcell.KeyUp, tcell.KeyCtrlP:
			a.keyUp()
			return true
		case tcell.KeyDown, tcell.KeyCtrlN:
			a.keyDown()
			return true
		case tcell.KeyRight, tcell.KeyCtrlF:
			a.keyRight()
			return true
		case tcell.KeyLeft, tcell.KeyCtrlB:
			a.keyLeft()
			return true
		case tcell.KeyPgDn:
			a.keyPgDn()
			return true
		case tcell.KeyPgUp:
			a.keyPgUp()
			return true
		case tcell.KeyEnd:
			a.keyEnd()
			return true
		case tcell.KeyHome:
			a.keyHome()
			return true
		}
	}
	return false
}
开发者ID:jmptrader,项目名称:tcell,代码行数:37,代码来源:cellarea.go

示例4: HandleEvent

func (o *explosion) HandleEvent(ev tcell.Event) bool {
	switch ev := ev.(type) {
	case *EventSpriteFrame:
		if ev.Frame() == "" {
			o.level.RemoveSprite(ev.Sprite())
		}
	}
	return false
}
开发者ID:gdamore,项目名称:proxima5,代码行数:9,代码来源:f-explosion.go

示例5: HandleEvent

func (m *boxL) HandleEvent(ev tcell.Event) bool {
	switch ev := ev.(type) {
	case *tcell.EventKey:
		if ev.Key() == tcell.KeyEscape {
			app.Quit()
			return true
		}
	}
	return m.BoxLayout.HandleEvent(ev)
}
开发者ID:jmptrader,项目名称:tcell,代码行数:10,代码来源:hbox.go

示例6: HandleEvent

func (a *AuthPanel) HandleEvent(ev tcell.Event) bool {
	switch ev := ev.(type) {
	case *tcell.EventKey:
		switch ev.Key() {
		case tcell.KeyEsc:
			a.App().Quit()
			return true
		case tcell.KeyTab, tcell.KeyEnter:
			if a.passactive {
				a.App().SetUserPassword(string(a.username),
					string(a.password))
				a.App().ShowMain()
			} else {
				a.passactive = true
			}
		case tcell.KeyBacktab:
			if a.passactive {
				a.passactive = false
			}
		case tcell.KeyCtrlU, tcell.KeyCtrlW:
			if a.passactive {
				a.password = a.password[:0]
			} else {
				a.username = a.username[:0]
			}
		case tcell.KeyBackspace, tcell.KeyBackspace2:
			if a.passactive {
				if len(a.password) > 0 {
					a.password =
						a.password[:len(a.password)-1]
				}
			} else {
				if len(a.username) > 0 {
					a.username =
						a.username[:len(a.username)-1]
				}
			}
		case tcell.KeyRune:
			r := ev.Rune()
			if a.passactive {
				if len(a.password) < 256 {
					a.password = append(a.password, r)
				}
			} else {
				if len(a.username) < 256 {
					a.username = append(a.username, r)
				}
			}
		default:
			return false
		}
		return true
	}
	return a.Panel.HandleEvent(ev)
}
开发者ID:jmptrader,项目名称:govisor,代码行数:55,代码来源:apanel.go

示例7: makeEvent

func makeEvent(tev tcell.Event) Event {
	switch tev := tev.(type) {
	case *tcell.EventInterrupt:
		return Event{Type: EventInterrupt}
	case *tcell.EventResize:
		w, h := tev.Size()
		return Event{Type: EventResize, Width: w, Height: h}
	case *tcell.EventKey:
		k := tev.Key()
		ch := rune(0)
		if k == tcell.KeyRune {
			ch = tev.Rune()
			if ch == ' ' {
				k = tcell.Key(' ')
			}
		}
		mod := tev.Modifiers()
		return Event{
			Type: EventKey,
			Key:  Key(k),
			Ch:   ch,
			Mod:  Modifier(mod),
		}
	default:
		return Event{Type: EventNone}
	}
}
开发者ID:jmptrader,项目名称:tcell,代码行数:27,代码来源:compat.go

示例8: HandleEvent

func (p *LogPanel) HandleEvent(ev tcell.Event) bool {
	info := p.info
	app := p.app
	switch ev := ev.(type) {
	case *tcell.EventKey:
		switch ev.Key() {
		case tcell.KeyEsc:
			app.ShowMain()
			return true
		case tcell.KeyF1:
			app.ShowHelp()
			return true
		case tcell.KeyRune:
			switch ev.Rune() {
			case 'Q', 'q':
				app.ShowMain()
				return true
			case 'H', 'h':
				app.ShowHelp()
				return true
			case 'I', 'i':
				if info != nil {
					app.ShowInfo(info.Name)
					return true
				}
			case 'R', 'r':
				if info != nil {
					app.RestartService(info.Name)
					return true
				}
			case 'E', 'e':
				if info != nil && !info.Enabled {
					app.EnableService(info.Name)
					return true
				}
			case 'D', 'd':
				if info != nil && info.Enabled {
					app.DisableService(info.Name)
					return true
				}
			case 'C', 'c':
				if info != nil && info.Failed {
					app.ClearService(info.Name)
					return true
				}
			}
		}
	}
	return p.Panel.HandleEvent(ev)
}
开发者ID:jmptrader,项目名称:govisor,代码行数:50,代码来源:lpanel.go

示例9: HandleEvent

func (o *hfence) HandleEvent(ev tcell.Event) bool {
	if o.dead {
		return false
	}
	switch ev := ev.(type) {
	case *EventCollision:
		switch ev.Collider().Layer() {
		case LayerPlayer:
			switch ev.Target() {
			case o.lemit:
				o.destroy(o.lemit, o.remit)
			case o.remit:
				o.destroy(o.remit, o.lemit)
			}
		case LayerShot:
			switch ev.Target() {
			case o.lemit:
				o.destroy(o.lemit, o.remit)
			case o.remit:
				o.destroy(o.remit, o.lemit)
			case o.beam:
				x, y, _, _ := ev.Collider().Bounds()
				props := GameObjectProps{}
				props.PropSetInt("x", x)
				props.PropSetInt("y", y)
				props.PropSetInt("count", 1)
				props.PropSetString("sprite", "TinyExplosion")
				MakeGameObject(o.level, "explosion", props)
			}
		}
	}
	return false
}
开发者ID:gdamore,项目名称:proxima5,代码行数:33,代码来源:f-hfence.go

示例10: HandleEvent

func (i *InfoPanel) HandleEvent(ev tcell.Event) bool {
	info := i.info
	switch ev := ev.(type) {
	case *tcell.EventKey:
		switch ev.Key() {
		case tcell.KeyEsc:
			i.App().ShowMain()
			return true
		case tcell.KeyF1:
			i.App().ShowHelp()
			return true
		case tcell.KeyRune:
			switch ev.Rune() {
			case 'Q', 'q':
				i.App().ShowMain()
				return true
			case 'H', 'h':
				i.App().ShowHelp()
				return true
			case 'L', 'l':
				if info != nil {
					i.App().ShowLog(info.Name)
					return true
				}
			case 'R', 'r':
				if info != nil {
					i.App().RestartService(info.Name)
					return true
				}
			case 'E', 'e':
				if info != nil && !info.Enabled {
					i.App().EnableService(info.Name)
					return true
				}
			case 'D', 'd':
				if info != nil && info.Enabled {
					i.App().DisableService(info.Name)
					return true
				}
			case 'C', 'c':
				if info != nil && info.Failed {
					i.App().ClearService(info.Name)
					return true
				}
			}
		}
	}
	return i.Panel.HandleEvent(ev)
}
开发者ID:jmptrader,项目名称:govisor,代码行数:49,代码来源:ipanel.go

示例11: HandleEvent

func (h *HelpPanel) HandleEvent(ev tcell.Event) bool {
	switch ev := ev.(type) {
	case *tcell.EventKey:
		switch ev.Key() {
		case tcell.KeyEsc:
			h.App().ShowMain()
			return true
		case tcell.KeyRune:
			switch ev.Rune() {
			case 'Q', 'q':
				h.app.ShowMain()
				return true
			}
		}
	}
	return h.Panel.HandleEvent(ev)
}
开发者ID:jmptrader,项目名称:govisor,代码行数:17,代码来源:hpanel.go

示例12: HandleEvent

func (o *alien1) HandleEvent(ev tcell.Event) bool {
	s := o.sprite
	switch ev := ev.(type) {
	case *EventSpriteAccelerate:
		if ev.s != s {
			return false
		}
		vx, _ := s.Velocity()
		if vx > 0 {
			s.SetFrame("F1")
		} else {
			s.SetFrame("R1")
		}
	case *EventCollision:
		switch ev.Collider().Layer() {
		case LayerTerrain, LayerHazard:
			x, y, _, _ := s.Bounds()
			vx, vy := s.Velocity()
			vx = -vx
			vy = -vy
			s.SetVelocity(vx, vy)
			if vx < 0 {
				x--
			} else if vx > 0 {
				x++
			}
			if vy < 0 {
				y--
			} else if vy > 0 {
				y++
			}
			s.SetPosition(x, y)
		case LayerShot, LayerPlayer:
			s.Hide()
			x, y, _, _ := s.Bounds()
			props := GameObjectProps{}
			props.PropSetInt("x", x)
			props.PropSetInt("y", y)
			props.PropSetInt("count", 1)
			MakeGameObject(o.level, "smexplosion", props)
			o.level.RemoveSprite(o.sprite)
		}
	}
	return false
}
开发者ID:gdamore,项目名称:proxima5,代码行数:45,代码来源:f-alien1.go

示例13: HandleEvent

func (g *Game) HandleEvent(ev tcell.Event) bool {
	switch ev := ev.(type) {
	case *tcell.EventResize:
		g.lview.Resize(0, 1, -1, -1)
		g.sview.Resize(0, 0, -1, 1)
		g.level.HandleEvent(ev)
	case *tcell.EventKey:
		if ev.Key() == tcell.KeyEscape {
			g.Quit()
			return true
		}
		if !g.started {
			if ev.Key() == tcell.KeyEnter {
				if g.gameover {
					g.lives = 5
				}
				g.level.Reset()
				g.level.Start()
				g.started = true
				g.gameover = false
			}
			// eat all keys until level starts
			return true
		}
	case *EventPlayerDeath:
		g.lives--
		g.started = false
		if g.lives == 0 {
			g.gameover = true
			g.level.HandleEvent(&EventGameOver{})
		}
		return true

	case *EventLevelComplete:
		g.lives++ // bonus life (for now)
		g.started = false
		return true
	}
	if !g.level.HandleEvent(ev) {
		return true
	}
	return true
}
开发者ID:gdamore,项目名称:proxima5,代码行数:43,代码来源:game.go

示例14: HandleEvent

func (o *bullet) HandleEvent(ev tcell.Event) bool {
	switch ev := ev.(type) {
	case *EventSpriteAccelerate:
		if ev.s != o.sprite {
			return false
		}

		vx, _ := o.sprite.Velocity()
		if vx > 0 {
			o.sprite.SetFrame("H")
		} else {
			o.sprite.SetFrame("V")
		}
	case *EventSpriteMove:
		if ev.s != o.sprite {
			return false
		}

		x, y, _, _ := o.sprite.Bounds()
		w, h := o.level.Size()
		if x < 0 || y < 0 || x >= w || y >= h {
			o.destroy()
		}
	case *EventCollision:
		switch ev.Collider().Layer() {

		case LayerTerrain, LayerHazard, LayerPlayer, LayerExplosion:
			// Impact with most solid objects removes the shot.
			// The impacted object is responsible for painting
			// any explosive effect.
			o.destroy()
		}
	case *EventAlarm:
		o.destroy()
	}
	return false
}
开发者ID:gdamore,项目名称:proxima5,代码行数:37,代码来源:f-bullet.go

示例15: HandleEvent

func (o *ship) HandleEvent(ev tcell.Event) bool {
	if o.dead {
		return false
	}
	switch ev := ev.(type) {
	case *EventSpriteAccelerate:
		if ev.s != o.ship {
			return false
		}
		vx, _ := o.ship.Velocity()
		if vx >= 1.0 {
			o.ship.SetFrame("RIGHT")
		} else if vx <= -1.0 {
			o.ship.SetFrame("LEFT")
		} else {
			o.ship.SetFrame("FWD")
		}
	case *EventSpriteMove:
		// We don't let ship leave the map
		x, y := o.ship.Position()
		ox, oy := x, y
		vx, vy := o.ship.Velocity()
		w, h := o.level.Size()
		if x < 0 {
			x = 0
			if vx < 0 {
				vx = 0
			}
		} else if x >= w {
			x = w - 1
			if vx > 0 {
				vx = 0
			}
		}
		if y < 0 {
			y = 0
			if vy < 0 {
				vy = 0
			}
		} else if y >= h {
			y = h - 1
			if vy > 0 {
				vy = 0
			}
		}
		if ox != x || oy != y {
			o.ship.SetPosition(x, y)
			o.ship.SetVelocity(vx, vy)
		}

		if y == 0 {
			o.dead = true
			o.level.HandleEvent(&EventLevelComplete{})
		}
		o.adjustView()
	case *EventGravity:
		now := ev.When()
		if !o.lastgrav.IsZero() {
			vx, vy := o.ship.Velocity()
			frac := float64(now.Sub(o.lastgrav))
			frac /= float64(time.Second)
			vy += ev.Accel() * frac
			o.ship.SetVelocity(vx, vy)
		}
		o.lastgrav = now

	case *EventCollision:
		switch ev.Collider().Layer() {
		case LayerTerrain, LayerHazard, LayerShot:
			o.destroy()
		case LayerPad:
			// if we're on the pad, and not too
			// fast, then stay on the pad.
			// TODO: probably the max velocity (4.0)
			// should be tunable.
			vx, vy := o.ship.Velocity()
			x, y := o.ship.Position()
			if vx == 0 && vy > 0 && vy < 4.0 {
				y--
				vy = 0
				o.ship.SetPosition(x, y)
				o.ship.SetVelocity(vx, vy)
				o.launched = false
			} else {
				o.destroy()
			}
		}

	case *EventTimesUp:
		o.destroy()

	case *tcell.EventKey:
		switch ev.Key() {

		case tcell.KeyLeft:
			o.thrustLeft()
			return true

		case tcell.KeyRight:
			o.thrustRight()
//.........这里部分代码省略.........
开发者ID:gdamore,项目名称:proxima5,代码行数:101,代码来源:f-ship.go


注:本文中的github.com/gdamore/tcell.Event类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。