Fixed windows race-condition when peeking messages. Added Mouse events.
This commit is contained in:
@@ -107,6 +107,8 @@ update_windows :: proc(window: ^Window) -> Event {
|
||||
}
|
||||
}
|
||||
|
||||
win.CoInitializeEx(nil)
|
||||
|
||||
ok := win.PeekMessageW(
|
||||
lpMsg = &msg,
|
||||
hWnd = nil, // NOTE: SS - Don't like that this needs to be nil but apparently it does for this window to receive the WM_CLOSE and WM_QUIT messages.
|
||||
@@ -126,12 +128,63 @@ update_windows :: proc(window: ^Window) -> Event {
|
||||
// fmt.printfln("Message type: %x", msg.message)
|
||||
|
||||
switch msg.message {
|
||||
// Keyboard.
|
||||
case win.WM_KEYDOWN, win.WM_SYSKEYDOWN: {
|
||||
return Event_Key { virtual_key = get_virtual_key_windows(i32(msg.wParam)), state = .Down }
|
||||
input_event: Event_Input = Event_Keyboard {
|
||||
virtual_key = get_virtual_key_windows(i32(msg.wParam)),
|
||||
state = .Down
|
||||
}
|
||||
|
||||
return input_event
|
||||
}
|
||||
case win.WM_KEYUP, win.WM_SYSKEYUP: {
|
||||
return Event_Key { virtual_key = get_virtual_key_windows(i32(msg.wParam)), state = .Up }
|
||||
input_event: Event_Input = Event_Keyboard {
|
||||
virtual_key = get_virtual_key_windows(i32(msg.wParam)),
|
||||
state = .Up
|
||||
}
|
||||
|
||||
return input_event
|
||||
}
|
||||
// Mouse.
|
||||
case win.WM_MOUSEMOVE: {
|
||||
x := win.GET_X_LPARAM(msg.lParam)
|
||||
y := win.GET_Y_LPARAM(msg.lParam)
|
||||
|
||||
assert(x >= 0)
|
||||
assert(y >= 0)
|
||||
|
||||
mouse_event: Event_Mouse = Event_Mouse_Move{
|
||||
x = u16(x),
|
||||
y = u16(y),
|
||||
}
|
||||
|
||||
return Event_Input(mouse_event)
|
||||
}
|
||||
case win.WM_LBUTTONDOWN, win.WM_LBUTTONUP: {
|
||||
mouse_event: Event_Mouse = Event_Mouse_Button {
|
||||
button = .Left,
|
||||
state = msg.message == win.WM_LBUTTONDOWN ? .Down : .Up
|
||||
}
|
||||
|
||||
return Event_Input(mouse_event)
|
||||
}
|
||||
case win.WM_MBUTTONDOWN, win.WM_MBUTTONUP: {
|
||||
mouse_event: Event_Mouse = Event_Mouse_Button {
|
||||
button = .Middle,
|
||||
state = msg.message == win.WM_MBUTTONDOWN ? .Down : .Up
|
||||
}
|
||||
|
||||
return Event_Input(mouse_event)
|
||||
}
|
||||
case win.WM_RBUTTONDOWN, win.WM_RBUTTONUP: {
|
||||
mouse_event: Event_Mouse = Event_Mouse_Button {
|
||||
button = .Right,
|
||||
state = msg.message == win.WM_RBUTTONDOWN ? .Down : .Up
|
||||
}
|
||||
|
||||
return Event_Input(mouse_event)
|
||||
}
|
||||
|
||||
case win.WM_QUIT: {
|
||||
return Event_Quit {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user