@@ -33,124 +33,6 @@ pub const Context = struct {
33
33
window_id : mach.ObjectID ,
34
34
};
35
35
36
- // --------------------------
37
- // Module state
38
- // --------------------------
39
- // allocator: std.mem.Allocator,
40
- // core: *Core,
41
-
42
- // Core platform interface
43
- // surface_descriptor: gpu.Surface.Descriptor,
44
- // display_mode: DisplayMode,
45
- // vsync_mode: VSyncMode,
46
- // cursor_mode: CursorMode,
47
- // cursor_shape: CursorShape,
48
- // border: bool,
49
- // headless: bool,
50
- // size: Size,
51
-
52
- // // Internals
53
- // window: w.HWND,
54
- // refresh_rate: u32,
55
- // surrogate: u16 = 0,
56
- // dinput: *w.IDirectInput8W,
57
- // saved_window_rect: w.RECT,
58
- // surface_descriptor_from_hwnd: gpu.Surface.DescriptorFromWindowsHWND,
59
-
60
- // ------------------------------
61
- // Platform interface
62
- // ------------------------------
63
- // pub fn init(
64
- // self: *Win32,
65
- // core: *Core,
66
- // //options: InitOptions,
67
- // ) !void {
68
- // // self.allocator = options.allocator;
69
- // // self.core = core;
70
- // // self.size = options.size;
71
- // // self.saved_window_rect = .{ .top = 0, .left = 0, .right = 0, .bottom = 0 };
72
-
73
- // var native: Native = .{};
74
-
75
- // const hInstance = w.GetModuleHandleW(null);
76
- // const class_name = w.L("mach");
77
- // const class = std.mem.zeroInit(w.WNDCLASSW, .{
78
- // .style = w.CS_OWNDC,
79
- // .lpfnWndProc = wndProc,
80
- // .hInstance = hInstance,
81
- // .hIcon = w.LoadIconW(null, @as([*:0]align(1) const u16, @ptrFromInt(@as(u32, w.IDI_APPLICATION)))),
82
- // .hCursor = w.LoadCursorW(null, @as([*:0]align(1) const u16, @ptrFromInt(@as(u32, w.IDC_ARROW)))),
83
- // .lpszClassName = class_name,
84
- // });
85
- // if (w.RegisterClassW(&class) == 0) return error.Unexpected;
86
-
87
- // const title = try std.unicode.utf8ToUtf16LeAllocZ(self.allocator, options.title);
88
- // defer self.allocator.free(title);
89
-
90
- // var request_window_width: i32 = @bitCast(self.size.width);
91
- // var request_window_height: i32 = @bitCast(self.size.height);
92
-
93
- // const window_ex_style: w.WINDOW_EX_STYLE = .{ .APPWINDOW = 1 };
94
- // const window_style: w.WINDOW_STYLE = if (options.border) w.WS_OVERLAPPEDWINDOW else w.WS_POPUPWINDOW; // w.WINDOW_STYLE{.POPUP = 1};
95
- // // TODO (win32): should border == false mean borderless display_mode?
96
-
97
- // var rect: w.RECT = .{ .left = 0, .top = 0, .right = request_window_width, .bottom = request_window_height };
98
-
99
- // if (w.TRUE == w.AdjustWindowRectEx(&rect, window_style, w.FALSE, window_ex_style)) {
100
- // request_window_width = rect.right - rect.left;
101
- // request_window_height = rect.bottom - rect.top;
102
- // }
103
-
104
- // const window = w.CreateWindowExW(
105
- // window_ex_style,
106
- // class_name,
107
- // title,
108
- // window_style,
109
- // w.CW_USEDEFAULT,
110
- // w.CW_USEDEFAULT,
111
- // request_window_width,
112
- // request_window_height,
113
- // null,
114
- // null,
115
- // hInstance,
116
- // null,
117
- // ) orelse return error.Unexpected;
118
-
119
- // native.window = window;
120
-
121
- // var dinput: ?*w.IDirectInput8W = undefined;
122
- // const ptr: ?*?*anyopaque = @ptrCast(&dinput);
123
- // if (w.DirectInput8Create(hInstance, w.DIRECTINPUT_VERSION, w.IID_IDirectInput8W, ptr, null) != w.DI_OK) {
124
- // return error.Unexpected;
125
- // }
126
- // native.dinput = dinput.?;
127
-
128
- // native.surface_descriptor_from_hwnd = .{
129
- // .hinstance = std.os.windows.kernel32.GetModuleHandleW(null).?,
130
- // .hwnd = window,
131
- // };
132
-
133
- // core_window.surface_descriptor = .{ .next_in_chain = .{
134
- // .from_windows_hwnd = &self.surface_descriptor_from_hwnd,
135
- // } };
136
- // self.border = options.border;
137
- // self.headless = options.headless;
138
- // self.refresh_rate = 60; // TODO (win32) get monitor refresh rate
139
- // self.vsync_mode = .triple;
140
-
141
- // _ = w.SetWindowLongPtrW(window, w.GWLP_USERDATA, @bitCast(@intFromPtr(self)));
142
- // if (!options.headless) {
143
- // setDisplayMode(self, options.display_mode);
144
- // }
145
-
146
- // self.size = getClientRect(self);
147
- // _ = w.GetWindowRect(self.window, &self.saved_window_rect);
148
- // }
149
-
150
- // pub fn deinit(self: *Win32) void {
151
- // _ = self.dinput.IUnknown_Release();
152
- // }
153
-
154
36
pub fn tick (core : * Core ) ! void {
155
37
var windows = core .windows .slice ();
156
38
while (windows .next ()) | window_id | {
@@ -159,6 +41,12 @@ pub fn tick(core: *Core) !void {
159
41
if (native_opt ) | native | {
160
42
_ = native ; // autofix
161
43
44
+ var msg : w.MSG = undefined ;
45
+ while (w .PeekMessageW (& msg , null , 0 , 0 , w .PM_REMOVE ) != 0 ) {
46
+ _ = w .TranslateMessage (& msg );
47
+ _ = w .DispatchMessageW (& msg );
48
+ }
49
+
162
50
// Handle resizing the window when the user changes width or height
163
51
if (core .windows .updated (window_id , .width ) or core .windows .updated (window_id , .height )) {}
164
52
} else {
@@ -253,126 +141,6 @@ fn initWindow(
253
141
_ = w .ShowWindow (native_window , w .SW_SHOW );
254
142
}
255
143
256
- // pub fn update(self: *Win32) !void {
257
- // _ = self;
258
- // var msg: w.MSG = undefined;
259
- // while (w.PeekMessageW(&msg, null, 0, 0, w.PM_REMOVE) != 0) {
260
- // _ = w.TranslateMessage(&msg);
261
- // _ = w.DispatchMessageW(&msg);
262
- // }
263
- // }
264
-
265
- // pub fn setTitle(self: *Win32, title: [:0]const u8) void {
266
- // const wtitle = std.unicode.utf8ToUtf16LeAllocZ(self.allocator, title) catch {
267
- // self.state.oom.set();
268
- // return;
269
- // };
270
- // defer self.allocator.free(wtitle);
271
- // _ = w.SetWindowTextW(self.window, wtitle);
272
- // }
273
-
274
- // pub fn setDisplayMode(self: *Win32, mode: DisplayMode) void {
275
- // self.display_mode = mode;
276
-
277
- // switch (mode) {
278
- // .windowed => {
279
- // const window_style: w.WINDOW_STYLE = if (self.border) w.WS_OVERLAPPEDWINDOW else w.WS_POPUPWINDOW;
280
- // const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };
281
-
282
- // _ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
283
- // _ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
284
-
285
- // restoreWindowPosition(self);
286
- // },
287
- // .fullscreen => {
288
- // // TODO (win32) - change to use exclusive fullscreen using ChangeDisplaySetting
289
-
290
- // _ = w.GetWindowRect(self.window, &self.saved_window_rect);
291
-
292
- // const window_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1 };
293
- // const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };
294
-
295
- // _ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
296
- // _ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
297
-
298
- // const monitor = w.MonitorFromWindow(self.window, w.MONITOR_DEFAULTTONEAREST);
299
- // var monitor_info: w.MONITORINFO = undefined;
300
- // monitor_info.cbSize = @sizeOf(w.MONITORINFO);
301
- // if (w.GetMonitorInfoW(monitor, &monitor_info) == w.TRUE) {
302
- // _ = w.SetWindowPos(self.window, null, monitor_info.rcMonitor.left, monitor_info.rcMonitor.top, monitor_info.rcMonitor.right - monitor_info.rcMonitor.left, monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top, w.SWP_NOZORDER);
303
- // }
304
- // },
305
- // .borderless => {
306
- // _ = w.GetWindowRect(self.window, &self.saved_window_rect);
307
-
308
- // const window_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1 };
309
- // const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };
310
-
311
- // _ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
312
- // _ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
313
-
314
- // const monitor = w.MonitorFromWindow(self.window, w.MONITOR_DEFAULTTONEAREST);
315
- // var monitor_info: w.MONITORINFO = undefined;
316
- // monitor_info.cbSize = @sizeOf(w.MONITORINFO);
317
- // if (w.GetMonitorInfoW(monitor, &monitor_info) == w.TRUE) {
318
- // _ = w.SetWindowPos(self.window, null, monitor_info.rcMonitor.left, monitor_info.rcMonitor.top, monitor_info.rcMonitor.right - monitor_info.rcMonitor.left, monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top, w.SWP_NOZORDER);
319
- // }
320
- // },
321
- // }
322
- // }
323
-
324
- // pub fn setBorder(self: *Win32, value: bool) void {
325
- // const overlappedwindow: i32 = @bitCast(w.WS_OVERLAPPEDWINDOW);
326
- // const popupwindow: i32 = @bitCast(w.WS_POPUPWINDOW);
327
- // _ = w.SetWindowLongW(self.window, w.GWL_STYLE, if (value) overlappedwindow else popupwindow);
328
- // self.border = value;
329
- // }
330
-
331
- // pub fn setHeadless(self: *Win32, value: bool) void {
332
- // _ = w.ShowWindow(self.window, if (value) w.SW_HIDE else w.SW_SHOW);
333
- // self.headless = value;
334
- // }
335
-
336
- // pub fn setVSync(self: *Win32, mode: VSyncMode) void {
337
- // self.vsync_mode = mode;
338
- // }
339
-
340
- // pub fn setSize(self: *Win32, value: Size) void {
341
- // // TODO (win32) - use AdjustClientRect to get correct client rect.
342
- // _ = w.SetWindowPos(self.window, null, 0, 0, @as(i32, @intCast(value.width)), @as(i32, @intCast(value.height)), w.SET_WINDOW_POS_FLAGS{ .NOMOVE = 1, .NOZORDER = 1, .NOACTIVATE = 1 });
343
- // self.size = value;
344
- // }
345
-
346
- // pub fn setCursorMode(self: *Win32, mode: CursorMode) void {
347
- // switch (mode) {
348
- // .normal => while (w.ShowCursor(w.TRUE) < 0) {},
349
- // .hidden => while (w.ShowCursor(w.FALSE) >= 0) {},
350
- // .disabled => {},
351
- // }
352
- // self.cursor_mode = mode;
353
- // }
354
-
355
- // pub fn setCursorShape(self: *Win32, shape: CursorShape) void {
356
- // const name: i32 = switch (shape) {
357
- // .arrow => w.IDC_ARROW,
358
- // .ibeam => w.IDC_IBEAM,
359
- // .crosshair => w.IDC_CROSS,
360
- // .pointing_hand => w.IDC_HAND,
361
- // .resize_ew => w.IDC_SIZEWE,
362
- // .resize_ns => w.IDC_SIZENS,
363
- // .resize_nwse => w.IDC_SIZENWSE,
364
- // .resize_nesw => w.IDC_SIZENESW,
365
- // .resize_all => w.IDC_SIZEALL,
366
- // .not_allowed => w.IDC_NO,
367
- // };
368
- // _ = w.SetCursor(w.LoadCursorW(null, @ptrFromInt(@as(usize, @intCast(name)))));
369
- // self.cursor_shape = shape;
370
- // }
371
-
372
- // pub fn nativeWindowWin32(self: *Win32) w.HWND {
373
- // return self.window;
374
- // }
375
-
376
144
// -----------------------------
377
145
// Internal functions
378
146
// -----------------------------
0 commit comments