Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Area Markers - Improve edit box handling #587

Merged
merged 2 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 27 additions & 46 deletions addons/area_markers/functions/fnc_configure.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ markerSize _marker params ["_sizeA", "_sizeB"];

private _ctrl = _ctrlConfigure controlsGroupCtrl _idc;
_ctrl ctrlSetText str _value;

_ctrl ctrlAddEventHandler ["KeyDown", {
params ["_ctrl"];

private _value = ctrlText _ctrl;
private _filter = toArray ".-0123456789";
_value = toString (toArray _value select {_x in _filter});

_ctrl ctrlSetText _value;
}];
} forEach [
[IDC_CONFIGURE_SIZE_A, _sizeA],
[IDC_CONFIGURE_SIZE_B, _sizeB]
Expand Down Expand Up @@ -123,51 +113,42 @@ _ctrlButtonOK ctrlAddEventHandler ["ButtonClick", {

// Special handling for keyboard input when edit boxes have focus
// Needed to prevent interaction with Zeus display but still allow keyboard use with edit boxes
{
private _ctrl = _ctrlConfigure controlsGroupCtrl _x;

_ctrl ctrlAddEventHandler ["SetFocus", {
params ["_ctrl"];

private _ctrlConfigure = ctrlParent _ctrl displayCtrl IDC_CONFIGURE_GROUP;
_ctrlConfigure setVariable [QGVAR(focus), _ctrl];
}];

_ctrl ctrlAddEventHandler ["SetFocus", {
params ["_ctrl"];

private _ctrlConfigure = ctrlParent _ctrl displayCtrl IDC_CONFIGURE_GROUP;
_ctrlConfigure setVariable [QGVAR(focus), nil];
}];
} forEach [
IDC_CONFIGURE_SIZE_A,
IDC_CONFIGURE_SIZE_B,
IDC_CONFIGURE_ROTATION_EDIT,
IDC_CONFIGURE_ALPHA_EDIT
];

private _keyDownEH = _display displayAddEventHandler ["KeyDown", {
call {
params ["_display", "_keyCode"];
params ["_display", "_keyCode", "", "_ctrl"];

if (_keyCode in [DIK_UP, DIK_DOWN, DIK_LEFT, DIK_RIGHT]) exitWith {false};

if (_keyCode in [DIK_BACKSPACE, DIK_DELETE]) then {
private _ctrlConfigure = _display displayCtrl IDC_CONFIGURE_GROUP;
private _ctrlEdit = _ctrlConfigure getVariable QGVAR(focus);
if (isNil "_ctrlEdit") exitWith {};

private _text = ctrlText _ctrlEdit;

if (_keyCode == DIK_BACKSPACE) then {
_text = _text select [0, count _text - 1];
private _ctrlEdit = focusedCtrl _display;

if (ctrlIDC _ctrlEdit in IDCS_CONFIGURE_EDIT_BOXES) then {
ctrlTextSelection _ctrlEdit params ["_start", "_length"];

// Update length based on key to delete individual characters without selecting them
if (_length == 0) then {
_length = [1, -1] select (_keyCode == DIK_BACKSPACE);
};

// Get the selection start position from the left-hand side when the selection is made from right to left
if (_length < 0) then {
_start = _start + _length;
};

// Delete the selected characters and update the edit box's text and selection
private _characters = toArray ctrlText _ctrlEdit;
_characters deleteRange [_start, abs _length];
_ctrlEdit ctrlSetText toString _characters;
_ctrlEdit ctrlSetTextSelection [_start, 0];
};
};

if (_keyCode == DIK_DELETE) then {
_text = _text select [1, count _text - 1];
};
if (_keyCode == DIK_A && {_ctrl}) then {
private _ctrlEdit = focusedCtrl _display;

_ctrlEdit ctrlSetText _text;
if (ctrlIDC _ctrlEdit in IDCS_CONFIGURE_EDIT_BOXES) then {
_ctrlEdit ctrlSetTextSelection [0, count toArray ctrlText _ctrlEdit];
};
};

if (_keyCode in [DIK_ESCAPE, DIK_RETURN]) then {
Expand Down
4 changes: 3 additions & 1 deletion addons/area_markers/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@
#define IDC_CONFIGURE_ALPHA_SLIDER 42878
#define IDC_CONFIGURE_ALPHA_EDIT 42879
#define IDC_CONFIGURE_OK 42880
#define IDC_CONFIGURE_CANCEL 428781
#define IDC_CONFIGURE_CANCEL 42881

#define IDCS_CONFIGURE_EDIT_BOXES [IDC_CONFIGURE_SIZE_A, IDC_CONFIGURE_SIZE_B, IDC_CONFIGURE_ROTATION_EDIT, IDC_CONFIGURE_ALPHA_EDIT]
2 changes: 1 addition & 1 deletion addons/main/script_mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define VERSION_AR MAJOR,MINOR,PATCHLVL,BUILD

// MINIMAL required version for the Mod. Components can specify others..
#define REQUIRED_VERSION 2.02
#define REQUIRED_VERSION 2.04
#define REQUIRED_CBA_VERSION {3,14,0}

#ifdef COMPONENT_BEAUTIFIED
Expand Down