Cube  Check-in [4c092023dc]

Overview
Comment:Use SDL_TextInputEvent for input
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4c092023dc2a717a1cf2df148d04b1c35a0371f43fcfc8aa69e60093ee4a4be2
User & Date: js on 2025-03-09 10:25:55
Other Links: manifest | tags
Context
2025-03-09
11:24
Migrate projectile to a class check-in: d3b4b2d476 user: js tags: trunk
10:25
Use SDL_TextInputEvent for input check-in: 4c092023dc user: js tags: trunk
00:56
More string cleanups check-in: 3e5cb10d19 user: js tags: trunk
Changes

Modified src/Cube.mm from [97e527d1c0] to [909022edb6].

235
236
237
238
239
240
241
242
243






244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
235
236
237
238
239
240
241


242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
271







-
-
+
+
+
+
+
+
















-
+







			case SDL_QUIT:
				[self quit];
				break;
			case SDL_KEYDOWN:
			case SDL_KEYUP:
				if (_repeatsKeys || event.key.repeat == 0)
					keypress(event.key.keysym.sym,
					    event.key.state == SDL_PRESSED,
					    event.key.keysym.sym);
					    event.key.state == SDL_PRESSED);
				break;
			case SDL_TEXTINPUT:
				@autoreleasepool {
					input(@(event.text.text));
				}
				break;
			case SDL_MOUSEMOTION:
				if (ignore) {
					ignore--;
					break;
				}
				mousemove(event.motion.xrel, event.motion.yrel);
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				if (lasttype == event.type &&
				    lastbut == event.button.button)
					// why?? get event twice without it
					break;

				keypress(-event.button.button,
				    event.button.state != 0, 0);
				    event.button.state != 0);
				lasttype = event.type;
				lastbut = event.button.button;
				break;
			}
		}
	}

Modified src/console.mm from [73f6aa3e13] to [e0a1b6879f].

177
178
179
180
181
182
183
184

185

186

187
188

189
190
191
192
193
194
195
177
178
179
180
181
182
183

184
185
186

187


188
189
190
191
192
193
194
195







-
+

+
-
+
-
-
+







		execute(vhistory[vhistory.count - n - 1]);
		rec = false;
	}
}
COMMAND(history, ARG_1INT)

void
keypress(int code, bool isdown, int cooked)
keypress(int code, bool isDown)
{
	// keystrokes go to commandline
	if (saycommandon) // keystrokes go to commandline
	if (saycommandon) {
	{
		if (isdown) {
		if (isDown) {
			switch (code) {
			case SDLK_RETURN:
				break;

			case SDLK_BACKSPACE:
			case SDLK_LEFT:
				if (commandbuf.length > 0)
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
222
223
224
225
226
227
228


229
230
231
232
233
234
235







-
-







				    (KMOD_LCTRL | KMOD_RCTRL)) {
					pasteconsole();
					return;
				}

			default:
				resetcomplete();
				if (cooked)
					[commandbuf appendFormat:@"%c", cooked];
			}
		} else {
			if (code == SDLK_RETURN) {
				if (commandbuf.length > 0) {
					@autoreleasepool {
						if (vhistory == nil)
							vhistory =
255
256
257
258
259
260
261
262

263
264
265
266
267
268
269

270
271
272
273
274







275
276
277
278
279
280
281
253
254
255
256
257
258
259

260
261
262
263
264
265
266

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286







-
+






-
+





+
+
+
+
+
+
+







						toserver(commandbuf);
				}
				saycommand(NULL);
			} else if (code == SDLK_ESCAPE) {
				saycommand(NULL);
			}
		}
	} else if (!menukey(code, isdown)) {
	} else if (!menukey(code, isDown)) {
		// keystrokes go to menu

		for (KeyMapping *mapping in keyMappings) {
			if (mapping.code == code) {
				// keystrokes go to game, lookup in keymap and
				// execute
				execute(mapping.action, isdown);
				execute(mapping.action, isDown);
				return;
			}
		}
	}
}

void
input(OFString *text)
{
	if (saycommandon)
		[commandbuf appendString:text];
}

OFString *
getcurcommand()
{
	return saycommandon ? commandbuf : NULL;
}

Modified src/protos.h from [ad3320c1d0] to [8800716a44].

13
14
15
16
17
18
19
20


21
22
23
24
25
26
27
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28







-
+
+







extern void resetcomplete();
extern void complete(OFString *s);
extern void alias(OFString *name, OFString *action);
extern OFString *getalias(OFString *name);
extern void writecfg();

// console
extern void keypress(int code, bool isdown, int cooked);
extern void keypress(int code, bool isDown);
extern void input(OFString *text);
extern void renderconsole();
extern void conoutf(OFConstantString *format, ...);
extern OFString *getcurcommand();
extern void writebinds(OFStream *stream);

// init
extern void enqueueInit(void (^init)(void));