gg: support passing down the state of pressed mouse buttons in mouse moves events
parent
e662d61573
commit
ab6517c5fc
23
vlib/gg/gg.v
23
vlib/gg/gg.v
|
@ -31,6 +31,7 @@ pub:
|
||||||
char_code u32
|
char_code u32
|
||||||
key_repeat bool
|
key_repeat bool
|
||||||
modifiers u32
|
modifiers u32
|
||||||
|
pub mut:
|
||||||
mouse_button sapp.MouseButton
|
mouse_button sapp.MouseButton
|
||||||
mouse_x f32
|
mouse_x f32
|
||||||
mouse_y f32
|
mouse_y f32
|
||||||
|
@ -121,6 +122,7 @@ pub mut:
|
||||||
ft &FT
|
ft &FT
|
||||||
font_inited bool
|
font_inited bool
|
||||||
ui_mode bool // do not redraw everything 60 times/second, but only when the user requests
|
ui_mode bool // do not redraw everything 60 times/second, but only when the user requests
|
||||||
|
mbtn_mask byte
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Size {
|
pub struct Size {
|
||||||
|
@ -237,8 +239,27 @@ pub fn (mut ctx Context) refresh_ui() {
|
||||||
|
|
||||||
fn gg_event_fn(ce &C.sapp_event, user_data voidptr) {
|
fn gg_event_fn(ce &C.sapp_event, user_data voidptr) {
|
||||||
// e := unsafe { &sapp.Event(ce) }
|
// e := unsafe { &sapp.Event(ce) }
|
||||||
e := unsafe { &Event(ce) }
|
mut e := unsafe { &Event(ce) }
|
||||||
mut g := unsafe { &Context(user_data) }
|
mut g := unsafe { &Context(user_data) }
|
||||||
|
if e.typ == .mouse_down {
|
||||||
|
bitplace := int(e.mouse_button)
|
||||||
|
g.mbtn_mask |= byte(1 << bitplace)
|
||||||
|
}
|
||||||
|
if e.typ == .mouse_up {
|
||||||
|
bitplace := int(e.mouse_button)
|
||||||
|
g.mbtn_mask &= ~(byte(1 << bitplace))
|
||||||
|
}
|
||||||
|
if e.typ == .mouse_move && e.mouse_button == .invalid {
|
||||||
|
if g.mbtn_mask & 0x01 > 0 {
|
||||||
|
e.mouse_button = .left
|
||||||
|
}
|
||||||
|
if g.mbtn_mask & 0x02 > 0 {
|
||||||
|
e.mouse_button = .right
|
||||||
|
}
|
||||||
|
if g.mbtn_mask & 0x04 > 0 {
|
||||||
|
e.mouse_button = .middle
|
||||||
|
}
|
||||||
|
}
|
||||||
if g.config.event_fn != voidptr(0) {
|
if g.config.event_fn != voidptr(0) {
|
||||||
g.config.event_fn(e, g.config.user_data)
|
g.config.event_fn(e, g.config.user_data)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue