mirror of
https://github.com/Cesarus85/ringfall-mjolnir-vr.git
synced 2026-10-17 21:00:26 +02:00
- input.h: struct key_stroke ascii_code is a char (January stores NONE as -1; XINPUT_DEBUG_KEYSTROKE.Ascii is CHAR); edit_text.c drops its (byte) cast on the NONE test and stays 5/5. Measured board-wide over all 24 includers: 0 regressions. - input_xbox (27/27): _input_get_device_states with indexed gamepad and button loops and a MIN tick clamp (park reopen); _input_update_keyboard_devices with a short key-code loop and uncast ascii ternary (park reopen) - _structure_test_pill2d (624 B, previously unwritten): left/right offset line tests via point_from_line2d and the nearer collision - _find_turning_point: normalize2d/point_from_line2d/set_real_vector2d replace hand-expanded helper math - _structure_visibility_build_surfaces_traverse_leaf: the static bounding_rectangles_intersect returns short through one result (park reopen) Rejected: _first_person_weapon_update (removed NULL guards, UB hold). Follow-up: _path_test_pill_endpoint_near_wall_ok_bit is file-local in both path_smoothing.c and path_structure_bsp.c; its owner is path_structure_bsp.h. Stable diff: 0 regressions; parks 226 -> 223. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
250 lines
5.9 KiB
C
250 lines
5.9 KiB
C
/*
|
|
EDIT_TEXT.C
|
|
|
|
symbols in this file:
|
|
00085920 0080:
|
|
_code_00085920 (0000)
|
|
000859A0 0070:
|
|
_edit_text_selection_reset (0000)
|
|
00085A10 00a0:
|
|
_edit_text_get_selection_indices (0000)
|
|
00085AB0 0060:
|
|
_edit_text_new (0000)
|
|
00085B10 0340:
|
|
_edit_text_handle_key (0000)
|
|
00259730 0016:
|
|
??_C@_0BG@FJHACPE@valid_edit_text?$CIedit?$CJ?$AA@ (0000)
|
|
00259748 0023:
|
|
??_C@_0CD@CHJIFMCD@c?3?2halo?2SOURCE?2dialogs?2edit_text@ (0000)
|
|
*/
|
|
|
|
/* ---------- headers */
|
|
|
|
#include "cseries.h"
|
|
#include "edit_text.h"
|
|
|
|
#include "input/input.h"
|
|
#include "text/international_strings.h"
|
|
|
|
/* ---------- constants */
|
|
|
|
/* ---------- macros */
|
|
|
|
/* ---------- structures */
|
|
|
|
/* ---------- prototypes */
|
|
|
|
static void edit_text_fix_selection(struct edit_text *edit);
|
|
|
|
/* ---------- globals */
|
|
|
|
/* ---------- public code */
|
|
|
|
void edit_text_new(
|
|
struct edit_text *edit)
|
|
{
|
|
match_assert("c:\\halo\\SOURCE\\dialogs\\edit_text.c", 25, valid_edit_text(edit));
|
|
edit_text_selection_reset(edit);
|
|
|
|
return;
|
|
}
|
|
|
|
void edit_text_handle_key(
|
|
struct edit_text *edit,
|
|
struct key_stroke const *key)
|
|
{
|
|
boolean backspace;
|
|
|
|
match_assert("c:\\halo\\SOURCE\\dialogs\\edit_text.c", 35, valid_edit_text(edit));
|
|
edit_text_fix_selection(edit);
|
|
|
|
if (key->key_code==_key_backspace)
|
|
{
|
|
backspace = TRUE;
|
|
}
|
|
|
|
if (key->key_code==_key_backspace ||
|
|
key->key_code==_key_delete)
|
|
{
|
|
short selection_end;
|
|
short selection_start;
|
|
|
|
if (edit_text_get_selection_indices(
|
|
edit,
|
|
&selection_start,
|
|
&selection_end))
|
|
{
|
|
memmove(
|
|
&edit->buffer[selection_start],
|
|
&edit->buffer[selection_end],
|
|
strlen(&edit->buffer[selection_end])+1);
|
|
edit->insertion_point_index = selection_start;
|
|
edit->selection_start_index = NONE;
|
|
}
|
|
else if (key->key_code==_key_backspace &&
|
|
edit->insertion_point_index > 0)
|
|
{
|
|
short src_index = edit->insertion_point_index;
|
|
get_previous_character(
|
|
(unsigned char *)edit->buffer,
|
|
&edit->insertion_point_index);
|
|
memmove(
|
|
&edit->buffer[edit->insertion_point_index],
|
|
&edit->buffer[src_index],
|
|
strlen(&edit->buffer[src_index])+1);
|
|
}
|
|
else if (key->key_code == _key_delete)
|
|
{
|
|
if (edit->insertion_point_index < strlen(edit->buffer))
|
|
{
|
|
short next_index = edit->insertion_point_index;
|
|
get_next_character(
|
|
(unsigned char *)edit->buffer,
|
|
&next_index
|
|
);
|
|
memmove(
|
|
&edit->buffer[edit->insertion_point_index],
|
|
&edit->buffer[next_index],
|
|
strlen(&edit->buffer[next_index])+1);
|
|
}
|
|
}
|
|
}
|
|
else if (
|
|
key->key_code==_key_left_arrow ||
|
|
key->key_code==_key_right_arrow)
|
|
{
|
|
short selection_end;
|
|
short selection_start;
|
|
|
|
if (TEST_FLAG(key->modifier_flags, 0) ||
|
|
!edit_text_get_selection_indices(
|
|
edit,
|
|
&selection_start,
|
|
&selection_end))
|
|
{
|
|
if (TEST_FLAG(key->modifier_flags, 0) && edit->selection_start_index==NONE)
|
|
{
|
|
edit->selection_start_index = edit->insertion_point_index;
|
|
}
|
|
|
|
if (key->key_code==_key_left_arrow && edit->insertion_point_index>0)
|
|
{
|
|
get_previous_character(
|
|
(unsigned char *)edit->buffer,
|
|
&edit->insertion_point_index);
|
|
}
|
|
else if (key->key_code==_key_right_arrow)
|
|
{
|
|
if (edit->insertion_point_index<strlen(edit->buffer))
|
|
{
|
|
get_next_character(
|
|
(unsigned char *)edit->buffer,
|
|
&edit->insertion_point_index);
|
|
}
|
|
}
|
|
|
|
if (edit->selection_start_index==edit->insertion_point_index)
|
|
{
|
|
edit->selection_start_index = NONE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (key->key_code==_key_left_arrow)
|
|
{
|
|
edit->insertion_point_index = selection_start;
|
|
edit->selection_start_index = NONE;
|
|
}
|
|
else
|
|
{
|
|
edit->insertion_point_index = selection_end;
|
|
edit->selection_start_index = NONE;
|
|
}
|
|
}
|
|
}
|
|
else if (key->ascii_code && key->ascii_code!=NONE)
|
|
{
|
|
short selection_end;
|
|
short selection_start;
|
|
|
|
if (edit_text_get_selection_indices(
|
|
edit,
|
|
&selection_start,
|
|
&selection_end))
|
|
{
|
|
memmove(
|
|
&edit->buffer[selection_start+1],
|
|
&edit->buffer[selection_end],
|
|
strlen(&edit->buffer[selection_end])+1);
|
|
|
|
edit->insertion_point_index = selection_start;
|
|
edit->selection_start_index = NONE;
|
|
edit->buffer[edit->insertion_point_index++] = key->ascii_code;
|
|
}
|
|
else if (strlen(edit->buffer)<edit->maximum_length)
|
|
{
|
|
memmove(
|
|
&edit->buffer[edit->insertion_point_index+1],
|
|
&edit->buffer[edit->insertion_point_index],
|
|
strlen(&edit->buffer[edit->insertion_point_index])+1);
|
|
edit->buffer[edit->insertion_point_index++] = key->ascii_code;
|
|
}
|
|
}
|
|
|
|
align_to_character(
|
|
(unsigned char *)edit->buffer,
|
|
&edit->insertion_point_index);
|
|
|
|
return;
|
|
}
|
|
|
|
boolean edit_text_get_selection_indices(struct edit_text *edit, short *start_index, short *end_index)
|
|
{
|
|
boolean result = FALSE;
|
|
match_assert("c:\\halo\\SOURCE\\dialogs\\edit_text.c", 174, valid_edit_text(edit));
|
|
edit_text_fix_selection(edit);
|
|
|
|
if (edit->selection_start_index != NONE)
|
|
{
|
|
*start_index = edit->selection_start_index > edit->insertion_point_index ? edit->insertion_point_index : edit->selection_start_index;
|
|
*end_index = edit->selection_start_index > edit->insertion_point_index ? edit->selection_start_index : edit->insertion_point_index;
|
|
result = TRUE;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void edit_text_selection_reset(
|
|
struct edit_text *edit)
|
|
{
|
|
match_assert("c:\\halo\\SOURCE\\dialogs\\edit_text.c", 159, valid_edit_text(edit));
|
|
edit_text_fix_selection(edit);
|
|
edit->insertion_point_index = (short)strlen(edit->buffer);
|
|
edit->selection_start_index = NONE;
|
|
|
|
return;
|
|
}
|
|
|
|
/* ---------- private code */
|
|
|
|
static void edit_text_fix_selection(
|
|
struct edit_text *edit)
|
|
{
|
|
short length = (short)strlen(edit->buffer);
|
|
edit->insertion_point_index = PIN(edit->insertion_point_index, 0, length);
|
|
edit->selection_start_index = PIN(edit->selection_start_index, NONE, length);
|
|
|
|
if (edit->insertion_point_index == edit->selection_start_index)
|
|
{
|
|
edit->selection_start_index = NONE;
|
|
}
|
|
|
|
align_to_character((unsigned char *)edit->buffer, &edit->insertion_point_index);
|
|
if (edit->selection_start_index != NONE)
|
|
{
|
|
align_to_character((unsigned char*)edit->buffer, &edit->selection_start_index);
|
|
}
|
|
|
|
return;
|
|
}
|