Exemplo n.º 1
0
Arquivo: main.go Projeto: sycoso/glfw
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	if err = glfw.OpenWindow(640, 480, 8, 8, 8, 8, 0, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.CloseWindow()

	glfw.SetWindowTitle("Draw")
	glfw.SetSwapInterval(1)
	glfw.SetKeyCallback(onKey)
	glfw.SetMouseButtonCallback(onMouseBtn)
	glfw.SetWindowSizeCallback(onResize)

	running = true
	for running && glfw.WindowParam(glfw.Opened) == 1 {
		if mouse[0] != 0 {
			pen.lineTo(glfw.MousePos())
		} else {
			pen.moveTo(glfw.MousePos())
		}

		glfw.SwapBuffers()
	}
}
Exemplo n.º 2
0
func onMouseButton(button, state int) {
	globalState.Mouse[button] = state == glfw.KeyPress
	if globalState.Mouse[glfw.Mouse1] {
		x, y := glfw.MousePos()
		globalState.Drag.Start.X, globalState.Drag.Start.Y = float32(x), float32(y)
		globalState.Drag.IsDrag = true
	} else {
		if globalState.Drag.IsDrag {
			globalState.Drag.IsDrag = false
			x, y := glfw.MousePos()
			globalState.Drag.End.X, globalState.Drag.End.Y = float32(x), float32(y)
		}
	}
}
Exemplo n.º 3
0
Arquivo: input.go Projeto: vron/fm
func click(button, state int) {

	if button == glfw.Mouse1 {
		if state == 1 {
			isHeld = true
			ot, op, or = theta, phi, r
			ox, oy = glfw.MousePos()
		} else {
			isHeld = false
		}
	}
}
Exemplo n.º 4
0
func mouseButtonHandler(button int, state int) {

	prevX, prevY = glfw.MousePos()
	curButton = button
	curButtonState = state

	if button == glfw.MouseRight && state == 1 {
		stickyX = prevX
		stickyY = prevY
		drawAt(prevX, prevY)
	}
}
Exemplo n.º 5
0
func (w *window) MousePos() (int, int) {
	return glfw.MousePos()
}