From 8c8fe02000057bcbb659e8a318d6ec35fcd6e574 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 21 Sep 2020 02:42:28 +0200 Subject: [PATCH] gg: mouse_move, mouse_down --- examples/tetris/tetris.v | 4 +++- vlib/gg/gg.v | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/tetris/tetris.v b/examples/tetris/tetris.v index 2ac6e07de3..06cc636b7e 100644 --- a/examples/tetris/tetris.v +++ b/examples/tetris/tetris.v @@ -143,7 +143,9 @@ fn (mut game Game) showfps() { ticks := f64(game.second_sw.elapsed().microseconds())/1000.0 if ticks > 999.0 { fps := f64(game.frame - game.frame_old)*ticks/1000.0 - eprintln('fps: ${fps:5.1f} | last frame took: ${last_frame_ms:6.3f}ms | frame: ${game.frame:6} ') + $if debug { + eprintln('fps: ${fps:5.1f} | last frame took: ${last_frame_ms:6.3f}ms | frame: ${game.frame:6} ') + } game.second_sw.restart() game.frame_old = game.frame } diff --git a/vlib/gg/gg.v b/vlib/gg/gg.v index 12859543de..ba2caac8de 100644 --- a/vlib/gg/gg.v +++ b/vlib/gg/gg.v @@ -17,6 +17,8 @@ pub type FNFail = fn (msg string, x voidptr) pub type FNKeyDown = fn (c sapp.KeyCode, m sapp.Modifier, x voidptr) +pub type FNMove = fn (x, y f32, z voidptr) + pub type FNChar = fn (c u32, x voidptr) pub struct Config { @@ -41,6 +43,8 @@ pub: event_fn FNEvent = voidptr(0) keydown_fn FNKeyDown = voidptr(0) // special case of event_fn char_fn FNChar = voidptr(0) // special case of event_fn + move_fn FNMove= voidptr(0) // special case of event_fn + click_fn FNMove= voidptr(0) // special case of event_fn wait_events bool // set this to true for UIs, to save power fullscreen bool scale f32 = 1.0 // vid needs this @@ -140,8 +144,8 @@ fn gg_frame_fn(user_data voidptr) { // where it thinks that &sapp.Event(x) is a function call, // instead of a cast, if v has not yet seen &sapp.Event used // as a parameter type. -fn todo_remove_this(e &sapp.Event) { -} +//fn todo_remove_this(e &sapp.Event) { +//} fn gg_event_fn(ce &C.sapp_event, user_data voidptr) { e := &sapp.Event(ce) @@ -162,6 +166,18 @@ fn gg_event_fn(ce &C.sapp_event, user_data voidptr) { cfn(e.char_code, g.config.user_data) } } + .mouse_move{ + if g.config.move_fn != voidptr(0) { + cfn := g.config.move_fn + cfn(e.mouse_x / g.scale, e.mouse_y / g.scale, g.config.user_data) + } + } + .mouse_down{ + if g.config.click_fn != voidptr(0) { + cfn := g.config.click_fn + cfn(e.mouse_x / g.scale, e.mouse_y / g.scale, g.config.user_data) + } + } else {} } }