commit 0486e6f

uint  ·  2026-06-23 23:07:57 +0000 UTC
parent d29cb31
Add README program example
1 files changed,  +78, -0
+78, -0
 1@@ -1,3 +1,81 @@
 2 ![logo](assets/logo_256x112.png)  
 3 is a small, cross-platform, software windowing library
 4 
 5+### Building
 6+Unix:
 7+```sh
 8+./configure --backend=[x11|wayland|mac]
 9+make # That's it!
10+```
11+
12+Windows:
13+```
14+.\build.bat [msvc|gcc|clang]
15+```
16+
17+After building, you have a library which you link _your_ sources with. It is
18+located in `build/`.
19+
20+### Usage
21+#### libmaus
22+Here is an annoted example for a basic window program which counts the number of
23+frames that have elapsed, draw the text and displays if you've pressed a key
24+(specifically 'A').
25+
26+For the full list of functions and what they do, look at
27+[the header](include/maus.h).
28+
29+```c
30+#include "maus.h"
31+#include "maus_font.h"
32+
33+int main(void)
34+{
35+	int x=50, y=50, width=640, height=480;
36+	Maus* ctx = maus_init("example!", x, y, width, height);
37+	maus_create_window(ctx);
38+	MausFont* font = maus_font_load("assets/fonts/font1.bdf");
39+
40+	int running = true;
41+	long long frames = 0;
42+	int a_pressed = false;
43+
44+	while (running) {
45+		MausEvent ev;
46+		while (maus_event_poll(ctx, &ev)) {
47+			// to see the full list of event types, look at
48+			// the enum `MausEventType` in `maus.h`
49+			if (ev.type == MAUS_EV_CLOSE)  {
50+				running = false;
51+				continue;
52+			}
53+
54+			if (ev.type == MAUS_EV_KEY && ev.key.pressed)  {
55+				if (ctx->key_syms[MAUS_KEY_A])
56+					a_pressed = 1;
57+			}
58+		}
59+
60+		// clear framebuffer with color white
61+		// colors are in format ARGB
62+		maus_clear(ctx, (MausColor){255, 255, 255, 255});
63+
64+		if (a_pressed) {
65+			const char* msg = "how dare you press a!!";
66+			maus_draw_text(ctx, font, 10, 50, msg, (MausColor){255, 255, 0, 0});
67+		}
68+
69+		char frames_text[256];
70+		snprintf(frames_text, sizeof(frames_text), "%lld", frames++);
71+		maus_draw_text(ctx, font, 10, 20, frames_text, (MausColor){255, 255, 0, 0});
72+
73+		maus_target_fps(ctx, 512);
74+		maus_present(ctx);
75+	}
76+
77+	// free resources
78+	maus_font_free(font);
79+	maus_close(ctx);
80+}
81+```
82+