commit c61162a

uint  ·  2026-06-22 20:52:39 +0000 UTC
parent 36fb585
Add maus_init, window creation win32
1 files changed,  +82, -0
+82, -0
 1@@ -0,0 +1,82 @@
 2+#include <windows.h>
 3+
 4+#include "maus.h"
 5+#include "maus_win.h"
 6+
 7+static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
 8+{
 9+	if (msg == WM_DESTROY) {
10+		PostQuitMessage(EXIT_SUCCESS);
11+		return 0;
12+	}
13+
14+	return DefWindowProc(hwnd, msg, wp, lp);
15+}
16+
17+void maus_clear(Maus* mw, MausColor col);
18+void maus_clipboard_set_text(Maus* mw, const char* text);
19+char* maus_clipboard_get_text(Maus* mw);
20+void maus_close(Maus* mw);
21+bool maus_close_window(Maus* mw);
22+
23+bool maus_create_window(Maus* mw)
24+{
25+	MausBackend* be = &mw->backend;
26+	be->hInst = GetModuleHandle(NULL);
27+
28+	WNDCLASS wc = {0};
29+	wc.lpfnWndProc = WndProc;
30+	wc.hInstance = be->hInst;
31+	wc.lpszClassName = "MausWindow";
32+	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
33+	if (!RegisterClass(&wc))
34+		return false;
35+
36+	RECT r = { 0, 0, mw->width, mw->height };
37+	AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);
38+
39+	be->hwnd = CreateWindowEx(
40+		0, "MausWindow", mw->title,
41+		WS_OVERLAPPEDWINDOW, mw->x, mw->y,
42+		r.right - r.left, r.bottom - r.top,
43+		NULL, NULL, be->hInst, NULL
44+	);
45+
46+	if (!be->hwnd)
47+		return false;
48+
49+	SetWindowLongPtr(be->hwnd, GWLP_USERDATA, (LONG_PTR)mw);
50+	ShowWindow(be->hwnd, SW_SHOW);
51+	UpdateWindow(be->hwnd);
52+	return true;
53+}
54+
55+Maus* maus_init(const char* title, int x, int y, int width, int height)
56+{
57+	Maus* mw = calloc(1, sizeof(Maus));
58+	mw->frame_time_last = maus_get_time_ns();
59+	mw->title = title;
60+	mw->width = width;
61+	mw->height = height;
62+	mw->x = x;
63+	mw->y = y;
64+	mw->fb = NULL;
65+
66+	mw->bfb = calloc(mw->stride * mw->height, sizeof(uint32_t));
67+	if (!mw->bfb) {
68+		maus_log(stderr, "failed to allocate back buffer");
69+		maus_close(mw);
70+		free(mw);
71+		return NULL;
72+	}
73+
74+	return mw;
75+}
76+
77+bool maus_event_poll(Maus* mw, MausEvent* ev);
78+void maus_event_wait(Maus* mw, MausEvent* ev);
79+void maus_present(Maus* mw);
80+bool maus_resize(Maus* mw, uint32_t width, uint32_t height);
81+void maus_target_fps(Maus* mw, uint32_t fps);
82+void maus_cur_set_mode(Maus* mw, MausCursorState state);
83+