예제 #1
0
파일: console.go 프로젝트: genbattle/haunts
func (c *Console) Respond(ui *gui.Gui, group gui.EventGroup) bool {
	if found, event := group.FindEvent(GetDefaultKeyMap()["console"].Id()); found && event.Type == gin.Press {
		if group.Focus {
			ui.DropFocus()
		} else {
			ui.TakeFocus(c)
		}
		return true
	}
	if found, event := group.FindEvent(gin.Left); found && event.Type == gin.Press {
		c.xscroll += 250
	}
	if found, event := group.FindEvent(gin.Right); found && event.Type == gin.Press {
		c.xscroll -= 250
	}
	if c.xscroll > 0 {
		c.xscroll = 0
	}
	if found, event := group.FindEvent(gin.Space); found && event.Type == gin.Press {
		c.xscroll = 0
	}

	if group.Events[0].Type == gin.Press {
		r := rune(group.Events[0].Key.Id())
		if r < 256 {
			if gin.In().GetKey(gin.EitherShift).IsDown() {
				r = unicode.ToUpper(r)
			}
			c.cmd = append(c.cmd, byte(r))
		}
	}

	return group.Focus
}
예제 #2
0
func (sm *SystemMenu) Respond(g *gui.Gui, group gui.EventGroup) bool {
	cursor := group.Events[0].Key.Cursor()
	if cursor != nil {
		sm.mx, sm.my = cursor.Point()
	}
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		if sm.layout.Main.handleClick(sm.mx, sm.my, g) {
			if sm.focus {
				g.DropFocus()
			} else {
				g.TakeFocus(sm)
			}
			sm.focus = true
			base.Log().Printf("focus: %v %v", sm, g.FocusWidget())
			return true
		}
		if sm.focus {
			hit := false
			for _, button := range sm.buttons {
				if button.handleClick(sm.mx, sm.my, g) {
					hit = true
				}
			}
			if hit {
				return true
			}
		}
	} else {
		hit := false
		for _, button := range sm.buttons {
			if button.Respond(group, nil) {
				hit = true
			}
		}
		if hit {
			return true
		}
	}
	return (g.FocusWidget() == sm)
}