gg: mouse_move, mouse_down

pull/6439/head
Alexander Medvednikov 2020-09-21 02:42:28 +02:00
parent 21c5ff681b
commit 8c8fe02000
2 changed files with 21 additions and 3 deletions

View File

@ -143,7 +143,9 @@ fn (mut game Game) showfps() {
ticks := f64(game.second_sw.elapsed().microseconds())/1000.0 ticks := f64(game.second_sw.elapsed().microseconds())/1000.0
if ticks > 999.0 { if ticks > 999.0 {
fps := f64(game.frame - game.frame_old)*ticks/1000.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.second_sw.restart()
game.frame_old = game.frame game.frame_old = game.frame
} }

View File

@ -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 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 type FNChar = fn (c u32, x voidptr)
pub struct Config { pub struct Config {
@ -41,6 +43,8 @@ pub:
event_fn FNEvent = voidptr(0) event_fn FNEvent = voidptr(0)
keydown_fn FNKeyDown = voidptr(0) // special case of event_fn keydown_fn FNKeyDown = voidptr(0) // special case of event_fn
char_fn FNChar = 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 wait_events bool // set this to true for UIs, to save power
fullscreen bool fullscreen bool
scale f32 = 1.0 // vid needs this 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, // where it thinks that &sapp.Event(x) is a function call,
// instead of a cast, if v has not yet seen &sapp.Event used // instead of a cast, if v has not yet seen &sapp.Event used
// as a parameter type. // 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) { fn gg_event_fn(ce &C.sapp_event, user_data voidptr) {
e := &sapp.Event(ce) 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) 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 {} else {}
} }
} }