commit d867cab

uint  ·  2026-08-04 15:44:56 +0000 UTC
parent 1b25d36
Conform basic-window example and maus_win to ANSI C
2 files changed,  +26, -20
+23, -19
  1@@ -1,4 +1,3 @@
  2-#include <stdbool.h>
  3 #include <stdint.h>
  4 #include <stdlib.h>
  5 
  6@@ -6,13 +5,13 @@
  7 #include "maus_font.h"
  8 
  9 int mx, my;
 10-bool cur_visible = true;
 11-bool cur_locked = false;
 12-bool cur_relative = false;
 13-bool mb1_pressed = false;
 14+int cur_visible = 1;
 15+int cur_locked = 0;
 16+int cur_relative = 0;
 17+int mb1_pressed = 0;
 18 char txtbuf[4096] = {'\0'};
 19 int current_char = 0;
 20-bool resize = false;
 21+int resize = 0;
 22 int rszw;
 23 int rszh;
 24 MausColor white = {255, 255, 255, 255};
 25@@ -25,9 +24,8 @@ void handle_ev(Maus* mw, MausEvent* ev)
 26 			exit(EXIT_SUCCESS);
 27 			break;
 28 		case MAUS_EV_KEY: {
 29-			(void)0;
 30-
 31 			int8_t* keys = mw->key_syms;
 32+
 33 			if (keys[MAUS_KEY_CONTROL_L] && keys[MAUS_KEY_Q]) {
 34 				maus_close(mw);
 35 				exit(EXIT_SUCCESS);
 36@@ -54,7 +52,7 @@ void handle_ev(Maus* mw, MausEvent* ev)
 37 				cur_relative = !cur_relative;
 38 			}
 39 
 40-			if (ev->key.pressed == false)
 41+			if (ev->key.pressed == 0)
 42 				break;
 43 
 44 			if (!((ev->key.key >= 32 && ev->key.key <= 126) || ev->key.key == '\n'))
 45@@ -80,7 +78,7 @@ void handle_ev(Maus* mw, MausEvent* ev)
 46 			}
 47 			mb1_pressed =
 48 			mw->mouse_buttons[MAUS_MOUSE_BUTTON_LEFT] ?
 49-			true : false;
 50+			1 : 0;
 51 			break;
 52 		}
 53 		case MAUS_EV_MOUSE_MOTION: {
 54@@ -89,7 +87,7 @@ void handle_ev(Maus* mw, MausEvent* ev)
 55 
 56 		} break;
 57 		case MAUS_EV_RESIZE: {
 58-			resize = true;
 59+			resize = 1;
 60 			rszw = ev->resize.width;
 61 			rszh = ev->resize.height;
 62 		} break;
 63@@ -102,16 +100,22 @@ void handle_ev(Maus* mw, MausEvent* ev)
 64 
 65 int main(void)
 66 {
 67-	Maus* mw = maus_init("basic window", 0, 0, 800, 600);
 68+	Maus* mw;
 69+	MausFont* font;
 70+	MausEvent ev;
 71+	MausColor red = { 255, 255, 0, 0 };
 72+	uint32_t red_unpacked;
 73+	uint32_t x;
 74+	uint32_t y;
 75+
 76+	mw = maus_init("basic window", 0, 0, 800, 600);
 77 	if (!mw)
 78 		return EXIT_FAILURE;
 79 	maus_create_window(mw);
 80-	MausFont* font = maus_font_load("assets/fonts/font1.bdf");
 81+	font = maus_font_load("assets/fonts/font1.bdf");
 82 	if (!font)
 83 		return EXIT_FAILURE;
 84 
 85-	MausEvent ev;
 86-	MausColor red = { 255, 255, 0, 0 };
 87 	/* unsigned long long ticks = 0; */
 88 	for (;;) {
 89 		while (maus_event_poll(mw, &ev))
 90@@ -120,20 +124,20 @@ int main(void)
 91 		/* only resize window once per fram */
 92 		if (resize) {
 93 			maus_resize(mw, rszw, rszh);
 94-			resize = false;
 95+			resize = 0;
 96 		}
 97 
 98 		maus_clear(mw, white);
 99 
100-		uint32_t red_unpacked = MAUS_UNPACK_COL(red);
101+		red_unpacked = MAUS_UNPACK_COL(red);
102 		if (mx >= 0 && my >= 0 &&
103 		    mx < (int32_t)mw->width &&
104 		    my < (int32_t)mw->height && mb1_pressed) {
105 			MAUS_PIXEL_AT(mw, mx, my) = red_unpacked;
106 		}
107 
108-		for (uint32_t y = 0; y < mw->height/2; y++) {
109-			for (uint32_t x = 0; x < mw->width/2; x++) {
110+		for (y = 0; y < mw->height/2; y++) {
111+			for (x = 0; x < mw->width/2; x++) {
112 				MAUS_PIXEL_AT(mw, x, y) = red_unpacked;
113 			}
114 		}
+3, -1
 1@@ -194,6 +194,8 @@ static int8_t handle_event(const MSG* msg, MausEvent* ev, Maus* mw)
 2 
 3 static MausKey vk_to_mauskey(UINT vk)
 4 {
 5+	size_t i;
 6+
 7 	if (vk >= 'A' && vk <= 'Z')
 8 		return (MausKey)(MAUS_KEY_A + (vk - 'A'));
 9 	if (vk >= '0' && vk <= '9')
10@@ -203,7 +205,7 @@ static MausKey vk_to_mauskey(UINT vk)
11 	if (vk >= VK_NUMPAD0 && vk <= VK_NUMPAD9)
12 		return (MausKey)(MAUS_KEY_KP_0 + (vk - VK_NUMPAD0));
13 
14-	for (size_t i = 0; i < sizeof(keymap) / sizeof(keymap[0]); i++) {
15+	for (i = 0; i < sizeof(keymap) / sizeof(keymap[0]); i++) {
16 		if (keymap[i].vk == vk)
17 			return keymap[i].maus;
18 	}