Example #1
0
func mouseButtonCallback(w *glfw.Window, button glfw.MouseButton,
	action glfw.Action, mod glfw.ModifierKey) {

	switch action {

	case glfw.Release:
		var bue wde.MouseUpEvent
		bue.Which = getMouseButton(button)
		x, y := w.GetCursorPosition()
		bue.Where.X = int(math.Floor(x))
		bue.Where.Y = int(math.Floor(y))
		if ws, ok := windowMap[w.C()]; ok {
			ws.events <- bue
		}

	case glfw.Press:
		var bde wde.MouseDownEvent
		bde.Which = getMouseButton(button)
		x, y := w.GetCursorPosition()
		bde.Where.X = int(math.Floor(x))
		bde.Where.Y = int(math.Floor(y))
		if ws, ok := windowMap[w.C()]; ok {
			ws.events <- bde
		}
	}
}
Example #2
0
func characterCallback(w *glfw.Window, char rune) {
	ws := windowMap[w.C()]
	if ws == nil {
		return
	}
	characterChan <- characterType{ws, char}
}
Example #3
0
func framebufferSizeCallback(w *glfw.Window, width int, height int) {
	event := wde.ResizeEvent{width, height}
	if ws, ok := windowMap[w.C()]; ok {
		ws.buffer.RGBA = image.NewRGBA(image.Rect(0, 0, width, height))
		ws.events <- event
	}
}
Example #4
0
func keyCallback(w *glfw.Window, key glfw.Key, scancode int,
	action glfw.Action, mods glfw.ModifierKey) {

	ws := windowMap[w.C()]
	if ws == nil {
		return
	}

	switch action {

	case glfw.Press:
		var letter string
		var ke wde.KeyEvent

		blankLetter := containsInt(blankLetterCodes, key)
		if !blankLetter {
			letter = string(key)
		}

		ke.Key = keyMapping[key]

		ws.events <- wde.KeyDownEvent(ke)

		kte := wde.KeyTypedEvent{
			KeyEvent: ke,
			Chord:    constructChord(key, mods),
			Glyph:    letter,
		}

		keyChan <- keyType{ws, kte}

	case glfw.Repeat:
		var letter string

		blankLetter := containsInt(blankLetterCodes, key)
		if !blankLetter {
			letter = string(key)
		}

		ke := wde.KeyEvent{keyMapping[key]}

		kte := wde.KeyTypedEvent{
			KeyEvent: ke,
			Chord:    constructChord(key, mods),
			Glyph:    letter,
		}

		keyChan <- keyType{ws, kte}

	case glfw.Release:
		var ke wde.KeyUpEvent
		ke.Key = keyMapping[key]
		ws.events <- ke
	}

}
Example #5
0
func cursorPositionCallback(w *glfw.Window, xpos float64, ypos float64) {
	cursorPosition := image.Point{int(xpos), int(ypos)}
	if ws, ok := windowMap[w.C()]; ok {
		var event wde.MouseMovedEvent
		event.From = lastCursorPosition
		event.Where = cursorPosition
		ws.events <- event
	}
	lastCursorPosition = cursorPosition
}
Example #6
0
func cursorEnterCallback(w *glfw.Window, entered bool) {
	var event interface{}

	if entered {
		var ene wde.MouseEnteredEvent
		x, y := w.GetCursorPosition()
		ene.Where.X = int(math.Floor(x))
		ene.Where.Y = int(math.Floor(y))
		event = ene
	} else {
		var exe wde.MouseExitedEvent
		x, y := w.GetCursorPosition()
		exe.Where.X = int(math.Floor(x))
		exe.Where.Y = int(math.Floor(y))
		event = exe
	}

	if ws, ok := windowMap[w.C()]; ok {
		ws.events <- event
	}
}