MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetKeyboardLayout

Function GetKeyboardLayout

src/osk_gui.cpp:352–384  ·  view source on GitHub ↗

* Retrieve keyboard layout from language string or (if set) config file. * Also check for invalid characters. */

Source from the content-addressed store, hash-verified

350 * Also check for invalid characters.
351 */
352void GetKeyboardLayout()
353{
354 std::string keyboard[2];
355 std::string errormark[2]; // used for marking invalid chars
356 bool has_error = false; // true when an invalid char is detected
357
358 keyboard[0] = _keyboard_opt[0].empty() ? GetString(STR_OSK_KEYBOARD_LAYOUT) : _keyboard_opt[0];
359 keyboard[1] = _keyboard_opt[1].empty() ? GetString(STR_OSK_KEYBOARD_LAYOUT_CAPS) : _keyboard_opt[1];
360
361 for (uint j = 0; j < 2; j++) {
362 StringConsumer consumer(keyboard[j]);
363 for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
364 /* Be lenient when the last characters are missing (is quite normal) */
365 _keyboard[j][i] = consumer.AnyBytesLeft() ? consumer.ReadUtf8() : ' ';
366
367 if (IsPrintable(_keyboard[j][i])) {
368 errormark[j] += ' ';
369 } else {
370 has_error = true;
371 errormark[j] += '^';
372 _keyboard[j][i] = ' ';
373 }
374 }
375 }
376
377 if (has_error) {
378 ShowInfo("The keyboard layout you selected contains invalid chars. Please check those chars marked with ^.");
379 ShowInfo("Normal keyboard: {}", keyboard[0]);
380 ShowInfo(" {}", errormark[0]);
381 ShowInfo("Caps Lock: {}", keyboard[1]);
382 ShowInfo(" {}", errormark[1]);
383 }
384}
385
386/**
387 * Show the on-screen keyboard (osk) associated with a given textbox

Callers 2

ShowOnScreenKeyboardFunction · 0.85
WndProcGdiFunction · 0.85

Calls 5

IsPrintableFunction · 0.85
AnyBytesLeftMethod · 0.80
ReadUtf8Method · 0.80
GetStringFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected