Beispiel #1
0
func (b *Button) HandleEvent(event interface{}) bool {
	switch event.(type) {
	case sdl.MouseMotionEvent:
		m := event.(sdl.MouseMotionEvent)
		if ui.Overlaps(int16(m.X), int16(m.Y), b.X, b.Y, b.W, b.H) {
			b.hovered = true
			return true
		} else {
			b.hovered = false
		}
	case sdl.MouseButtonEvent:
		m := event.(sdl.MouseButtonEvent)
		overlap := ui.Overlaps(int16(m.X), int16(m.Y), b.X, b.Y, b.W, b.H)
		if ui.IsMouseDown(m, 1) && overlap && b.OnClick != nil {
			b.OnClick()
			return true
		}
	}
	return false
}
Beispiel #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
}