Bladeren bron

Added Window_Flags enum with just Resizable in it for now

Karl Zylinski 6 maanden geleden
bovenliggende
commit
a8f323eee3
4 gewijzigde bestanden met toevoegingen van 53 en 6 verwijderingen
  1. 10 1
      karl2d.doc.odin
  2. 13 2
      karl2d.odin
  3. 5 1
      window_interface.odin
  4. 25 2
      window_win32.odin

+ 10 - 1
karl2d.doc.odin

@@ -10,7 +10,8 @@ package karl2d
 // all dynamically allocated memory. The return value can be ignored unless you need to later call
 // `set_internal_state`.
 init :: proc(window_width: int, window_height: int, window_title: string,
-             allocator := context.allocator, loc := #caller_location) -> ^State
+            window_creation_flags := Window_Flags {},
+            allocator := context.allocator, loc := #caller_location) -> ^State
 
 // Returns true if the program wants to shut down. This happens when for example pressing the close
 // button on the window. The application can decide if it wants to shut down or if it wants to show
@@ -41,6 +42,8 @@ set_window_position :: proc(x: int, y: int)
 
 set_window_size :: proc(width: int, height: int)
 
+set_window_flags :: proc(flags: Window_Flags)
+
 // Flushes the current batch. This sends off everything to the GPU that has been queued in the
 // current batch. Normally, you do not need to do this manually. It is done automatically when these
 // procedures run:
@@ -226,6 +229,12 @@ Camera :: struct {
 	zoom: f32,
 }
 
+Window_Flag :: enum {
+	Resizable,
+}
+
+Window_Flags :: bit_set[Window_Flag]
+
 Shader_Handle :: distinct Handle
 
 SHADER_NONE :: Shader_Handle {}

+ 13 - 2
karl2d.odin

@@ -24,7 +24,8 @@ import hm "handle_map"
 // all dynamically allocated memory. The return value can be ignored unless you need to later call
 // `set_internal_state`.
 init :: proc(window_width: int, window_height: int, window_title: string,
-             allocator := context.allocator, loc := #caller_location) -> ^State {
+            window_creation_flags := Window_Flags {},
+            allocator := context.allocator, loc := #caller_location) -> ^State {
 	assert(s == nil, "Don't call 'init' twice.")
 
 	s = new(State, allocator, loc)
@@ -41,7 +42,7 @@ init :: proc(window_width: int, window_height: int, window_title: string,
 	s.window_state, window_state_alloc_error = mem.alloc(win.state_size())
 	log.assertf(window_state_alloc_error == nil, "Failed allocating memory for window state: %v", window_state_alloc_error)
 
-	win.init(s.window_state, window_width, window_height, window_title, allocator)
+	win.init(s.window_state, window_width, window_height, window_title, window_creation_flags, allocator)
 	s.window = win.window_handle()
 
 	s.rb = RENDER_BACKEND_INTERFACE_D3D11
@@ -174,6 +175,10 @@ set_window_size :: proc(width: int, height: int) {
 	win.set_size(width, height)
 }
 
+set_window_flags :: proc(flags: Window_Flags) {
+	win.set_flags(flags)
+}
+
 // Flushes the current batch. This sends off everything to the GPU that has been queued in the
 // current batch. Normally, you do not need to do this manually. It is done automatically when these
 // procedures run:
@@ -843,6 +848,12 @@ Camera :: struct {
 	zoom: f32,
 }
 
+Window_Flag :: enum {
+	Resizable,
+}
+
+Window_Flags :: bit_set[Window_Flag]
+
 Shader_Handle :: distinct Handle
 
 SHADER_NONE :: Shader_Handle {}

+ 5 - 1
window_interface.odin

@@ -1,8 +1,11 @@
 package karl2d
 
+import "base:runtime"
+
 Window_Interface :: struct {
 	state_size: proc() -> int,
-	init: proc(window_state: rawptr, window_width: int, window_height: int, window_title: string, allocator := context.allocator),
+	init: proc(window_state: rawptr, window_width: int, window_height: int, window_title: string, 
+	           flags: Window_Flags, allocator: runtime.Allocator),
 	shutdown: proc(),
 	window_handle: proc() -> Window_Handle,
 	process_events: proc(),
@@ -10,6 +13,7 @@ Window_Interface :: struct {
 	clear_events: proc(),
 	set_position: proc(x: int, y: int),
 	set_size: proc(w, h: int),
+	set_flags: proc(flags: Window_Flags),
 
 	set_internal_state: proc(state: rawptr),
 }

+ 25 - 2
window_win32.odin

@@ -13,6 +13,7 @@ WINDOW_INTERFACE_WIN32 :: Window_Interface {
 	clear_events = win32_clear_events,
 	set_position = win32_set_position,
 	set_size = win32_set_size,
+	set_flags = win32_set_flags,
 	set_internal_state = win32_set_internal_state,
 }
 
@@ -23,7 +24,8 @@ win32_state_size :: proc() -> int {
 	return size_of(Win32_State)
 }
 
-win32_init :: proc(window_state: rawptr, window_width: int, window_height: int, window_title: string, allocator := context.allocator) {
+win32_init :: proc(window_state: rawptr, window_width: int, window_height: int, window_title: string,
+	               flags: Window_Flags, allocator: runtime.Allocator) {
 	assert(window_state != nil)
 	s = (^Win32_State)(window_state)
 	s.allocator = allocator
@@ -46,7 +48,10 @@ win32_init :: proc(window_state: rawptr, window_width: int, window_height: int,
 	r.right = i32(window_width)
 	r.bottom = i32(window_height)
 
-	style := win32.WS_OVERLAPPEDWINDOW | win32.WS_VISIBLE
+	s.flags = flags
+
+	style := style_from_flags(flags)
+
 	win32.AdjustWindowRect(&r, style, false)
 
 	hwnd := win32.CreateWindowW(CLASS_NAME,
@@ -113,6 +118,12 @@ win32_set_size :: proc(w, h: int) {
 	)
 }
 
+win32_set_flags :: proc(flags: Window_Flags) {
+	s.flags = flags
+	style := style_from_flags(flags)
+	win32.SetWindowLongW(s.hwnd, win32.GWL_STYLE, i32(style))
+}
+
 win32_set_internal_state :: proc(state: rawptr) {
 	assert(state != nil)
 	s = (^Win32_State)(state)
@@ -122,9 +133,21 @@ Win32_State :: struct {
 	allocator: runtime.Allocator,
 	custom_context: runtime.Context,
 	hwnd: win32.HWND,
+	flags: Window_Flags,
 	events: [dynamic]Window_Event,
 }
 
+style_from_flags :: proc(flags: Window_Flags) -> win32.DWORD {
+	style := win32.WS_OVERLAPPED | win32.WS_CAPTION | win32.WS_SYSMENU |
+	         win32.WS_MINIMIZEBOX | win32.WS_MAXIMIZEBOX | win32.WS_VISIBLE
+
+	if .Resizable in flags {
+		style |= win32.WS_THICKFRAME
+	}
+
+	return style
+}
+
 s: ^Win32_State
 
 window_proc :: proc "stdcall" (hwnd: win32.HWND, msg: win32.UINT, wparam: win32.WPARAM, lparam: win32.LPARAM) -> win32.LRESULT {