Karl Zylinski пре 6 месеци
родитељ
комит
02053e019e
4 измењених фајлова са 16 додато и 0 уклоњено
  1. 2 0
      examples/gamepad/gamepad.odin
  2. 5 0
      karl2d.odin
  3. 2 0
      window_interface.odin
  4. 7 0
      window_win32.odin

+ 2 - 0
examples/gamepad/gamepad.odin

@@ -18,6 +18,8 @@ main :: proc() {
 		k2.process_events()
 		k2.process_events()
 		k2.clear(k2.BLACK)
 		k2.clear(k2.BLACK)
 
 
+		log.info(k2.get_window_scale())
+
 		k2.draw_circle({120, 120}, 10, button_color(.Left_Face_Up))
 		k2.draw_circle({120, 120}, 10, button_color(.Left_Face_Up))
 		k2.draw_circle({120, 160}, 10, button_color(.Left_Face_Down))
 		k2.draw_circle({120, 160}, 10, button_color(.Left_Face_Down))
 		k2.draw_circle({100, 140}, 10, button_color(.Left_Face_Left))
 		k2.draw_circle({100, 140}, 10, button_color(.Left_Face_Left))

+ 5 - 0
karl2d.odin

@@ -187,6 +187,11 @@ set_window_size :: proc(width: int, height: int) {
 	win.set_size(width, height)
 	win.set_size(width, height)
 }
 }
 
 
+// Fetch the scale of the window. This usually comes from some DPI scaling setting in the OS.
+get_window_scale :: proc() -> f32 {
+	return win.get_window_scale()
+}
+
 set_window_flags :: proc(flags: Window_Flags) {
 set_window_flags :: proc(flags: Window_Flags) {
 	win.set_flags(flags)
 	win.set_flags(flags)
 }
 }

+ 2 - 0
window_interface.odin

@@ -13,7 +13,9 @@ Window_Interface :: struct {
 	clear_events: proc(),
 	clear_events: proc(),
 	set_position: proc(x: int, y: int),
 	set_position: proc(x: int, y: int),
 	set_size: proc(w, h: int),
 	set_size: proc(w, h: int),
+	get_window_scale: proc() -> f32,
 	set_flags: proc(flags: Window_Flags),
 	set_flags: proc(flags: Window_Flags),
+	
 	get_gamepad_axis: proc(gamepad: int, axis: Gamepad_Axis) -> f32,
 	get_gamepad_axis: proc(gamepad: int, axis: Gamepad_Axis) -> f32,
 	set_gamepad_vibration: proc(gamepad: int, left: f32, right: f32),
 	set_gamepad_vibration: proc(gamepad: int, left: f32, right: f32),
 
 

+ 7 - 0
window_win32.odin

@@ -13,6 +13,7 @@ WINDOW_INTERFACE_WIN32 :: Window_Interface {
 	clear_events = win32_clear_events,
 	clear_events = win32_clear_events,
 	set_position = win32_set_position,
 	set_position = win32_set_position,
 	set_size = win32_set_size,
 	set_size = win32_set_size,
+	get_window_scale = win32_get_window_scale,
 	set_flags = win32_set_flags,
 	set_flags = win32_set_flags,
 	get_gamepad_axis = win32_get_gamepad_axis,
 	get_gamepad_axis = win32_get_gamepad_axis,
 	set_gamepad_vibration = win32_set_gamepad_vibration,
 	set_gamepad_vibration = win32_set_gamepad_vibration,
@@ -34,6 +35,8 @@ win32_init :: proc(window_state: rawptr, window_width: int, window_height: int,
 	s.allocator = allocator
 	s.allocator = allocator
 	s.events = make([dynamic]Window_Event, allocator)
 	s.events = make([dynamic]Window_Event, allocator)
 	s.custom_context = context
 	s.custom_context = context
+	
+	win32.SetProcessDpiAwarenessContext(win32.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)
 	win32.SetProcessDPIAware()
 	win32.SetProcessDPIAware()
 	CLASS_NAME :: "karl2d"
 	CLASS_NAME :: "karl2d"
 	instance := win32.HINSTANCE(win32.GetModuleHandleW(nil))
 	instance := win32.HINSTANCE(win32.GetModuleHandleW(nil))
@@ -178,6 +181,10 @@ win32_set_size :: proc(w, h: int) {
 	)
 	)
 }
 }
 
 
+win32_get_window_scale :: proc() -> f32 {
+	return f32(win32.GetDpiForWindow(s.hwnd))/96.0
+}
+
 win32_set_flags :: proc(flags: Window_Flags) {
 win32_set_flags :: proc(flags: Window_Flags) {
 	s.flags = flags
 	s.flags = flags
 	style := style_from_flags(flags)
 	style := style_from_flags(flags)