Focus event
This commit is contained in:
48
window.odin
48
window.odin
@@ -6,6 +6,7 @@ import "core:fmt"
|
||||
Window :: struct {
|
||||
title: string,
|
||||
width, height: u16,
|
||||
focused: bool,
|
||||
|
||||
backend: Backend_Info,
|
||||
|
||||
@@ -16,12 +17,17 @@ Event_Queue :: queue.Queue(Event)
|
||||
|
||||
Event :: union {
|
||||
Event_Quit,
|
||||
Event_Focus,
|
||||
Event_Input,
|
||||
Event_Resize,
|
||||
}
|
||||
|
||||
Event_Quit :: struct {}
|
||||
|
||||
Event_Focus :: struct {
|
||||
is_focused: bool,
|
||||
}
|
||||
|
||||
Event_Input_State :: enum {
|
||||
Up,
|
||||
Down,
|
||||
@@ -82,6 +88,7 @@ create :: proc(width, height: u16) -> (^Window, bool) {
|
||||
}
|
||||
|
||||
set_title(w, "Window")
|
||||
// show_cursor(w, true)
|
||||
|
||||
return w, true
|
||||
}
|
||||
@@ -99,6 +106,33 @@ set_title :: proc(window: ^Window, title: string) {
|
||||
}
|
||||
}
|
||||
|
||||
show_cursor :: proc(window: ^Window, show: bool) {
|
||||
when ODIN_OS == .Windows {
|
||||
show_cursor_window(window, show)
|
||||
}
|
||||
else {
|
||||
#assert(false, "Missing implementation for 'show_cursor'.")
|
||||
}
|
||||
}
|
||||
|
||||
cursor_visible :: proc(window: ^Window) -> bool {
|
||||
when ODIN_OS == .Windows {
|
||||
return cursor_visible_windows(window)
|
||||
}
|
||||
else {
|
||||
#assert(false, "Missing implementation for 'cursor_visible'.")
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
set_cursor_position :: proc(window: ^Window, pos: [2]u32) {
|
||||
// fmt.printfln("Set cursor pos: %v:%v", pos.x, pos.y)
|
||||
when ODIN_OS == .Windows {
|
||||
set_cursor_position_windows(window, pos)
|
||||
}
|
||||
}
|
||||
|
||||
get_pointer_to_surface :: proc(window: ^Window) -> rawptr {
|
||||
when ODIN_OS == .Windows {
|
||||
return window.backend.hwnd
|
||||
@@ -116,7 +150,7 @@ update :: proc(window: ^Window, out_event: ^Event) -> bool {
|
||||
update_windows(window)
|
||||
}
|
||||
else {
|
||||
#assert(false, "Missing implementation for 'set_title'.")
|
||||
#assert(false, "Missing implementation for 'update'.")
|
||||
}
|
||||
|
||||
out_event^ = nil
|
||||
@@ -126,6 +160,18 @@ update :: proc(window: ^Window, out_event: ^Event) -> bool {
|
||||
return false
|
||||
}
|
||||
|
||||
switch e in event {
|
||||
case Event_Quit: {}
|
||||
case Event_Focus: {
|
||||
window.focused = e.is_focused
|
||||
}
|
||||
case Event_Resize: {
|
||||
window.width = e.new_width
|
||||
window.height = e.new_height
|
||||
}
|
||||
case Event_Input: {}
|
||||
}
|
||||
|
||||
assert(event != nil)
|
||||
out_event^ = event
|
||||
|
||||
|
||||
Reference in New Issue
Block a user