From 975286302c19f330547716df79bc201b7ea40a90 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 21 Jul 2019 11:56:03 +0200 Subject: [PATCH] fix Tetris onkeydown --- examples/tetris/tetris.v | 5 +++-- vlib/glfw/glfw.v | 18 ++---------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/examples/tetris/tetris.v b/examples/tetris/tetris.v index 2a502f0d3d..353c50bf25 100644 --- a/examples/tetris/tetris.v +++ b/examples/tetris/tetris.v @@ -1,10 +1,10 @@ // Copyright (c) 2019 Alexander Medvednikov. All rights reserved. // Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. +// that can be found in the LICENSE file. import rand import time -import gx +import gx import gl import gg import glfw @@ -114,6 +114,7 @@ fn main() { window_user_ptr: game }) } + game.gg.window.set_user_ptr(game) // TODO remove this when `window_user_ptr:` works game.init_game() game.gg.window.onkeydown(key_down) go game.run() // Run the game loop in a new thread diff --git a/vlib/glfw/glfw.v b/vlib/glfw/glfw.v index cc46e3bb4d..4e9750b43e 100644 --- a/vlib/glfw/glfw.v +++ b/vlib/glfw/glfw.v @@ -150,27 +150,20 @@ pub fn mouse_move(w voidptr, x, y f64) { // #printf("%f : %f => %d \n", x,y); } -// pub fn create_window(title string, w, h int) * Window { pub fn window_hint(key, val int) { C.glfwWindowHint(key, val) } pub fn create_window(c WinCfg) *Window { - // TODO why i need this in stdlib? extern? - // # if (!gconst_init) { init_consts(); gconst_init = 1; } - // ChatsRepo if c.borderless { window_hint(GLFW_RESIZABLE, 0) window_hint(GLFW_DECORATED, 0) } if c.always_on_top { window_hint(GLFW_FLOATING, 1) - -} + } cwindow := C.glfwCreateWindow(c.width, c.height, c.title.str, 0, 0) - # if (!cwindow) - // if cwindow == 0 - { + if isnil(cwindow) { println('failed to credate glfw window') C.glfwTerminate() } @@ -184,13 +177,6 @@ pub fn create_window(c WinCfg) *Window { data: cwindow, title: c.title, } - // user_ptr: ptr, - // repo: repo, - // for !C.glfwWindowShouldClose(cwindow) { - // C.glfwPollEvents() - // wait_events() - // } - // C.glfwTerminate() return window }