Esempio n. 1
0
func (w *Window) HandleEvent(event interface{}) bool {
	for _, child := range w.children {
		if child.HandleEvent(event) {
			return true
		}
	}

	switch event.(type) {
	case sdl.KeyboardEvent:
		if w.OnEscape != nil && ui.IsKeyDown(event, sdl.K_ESCAPE) {
			w.OnEscape()
			return true
		}
	case sdl.MouseButtonEvent:
		return true
	}
	return false
}
Esempio n. 2
0
func (m *MainMenu) HandleEvent(event interface{}) bool {
	switch event.(type) {
	case sdl.MouseMotionEvent:
		e := event.(sdl.MouseMotionEvent)
		m.mouseX = e.X
		m.mouseY = e.Y
		return true

	case sdl.MouseButtonEvent:
		if ui.IsMouseDown(event, 1) {
			m.click()
		}
		return true

	case sdl.KeyboardEvent:
		if ui.IsKeyDown(event, sdl.K_ESCAPE) {
			m.running = false
		}
		return true
	}
	return false
}