gg: mouse_move, mouse_down
parent
21c5ff681b
commit
8c8fe02000
|
@ -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
|
||||
}
|
||||
|
|
20
vlib/gg/gg.v
20
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 {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue