Skip to content

Commit

Permalink
D3/Q4/Prey: add ctrl key
Browse files Browse the repository at this point in the history
  • Loading branch information
glKarin committed Dec 16, 2024
1 parent a64f78f commit dd30ec4
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android.changelog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gzdoom launcher add extra file chooser button
ctrl
45 changes: 40 additions & 5 deletions Q3E/src/main/java/com/n0n3m4/q3e/karin/KKeyToolBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,53 @@ public boolean onTouch(View v, MotionEvent event) {
if(null == obj)
return false;
Key key = (Key)obj;
boolean down = false;
boolean down;
boolean send;
switch (event.getActionMasked())
{
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
key.state = Key.STATE_PRESSED;
down = true;
if(key.type == Key.TYPE_BUTTON)
{
key.state = Key.STATE_PRESSED;
down = true;
send = true;
}
else
{
down = false;
send = false;
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_CANCEL:
key.state = Key.STATE_RELEASED;
send = true;
if(key.type == Key.TYPE_BUTTON)
{
key.state = Key.STATE_RELEASED;
down = false;
}
else
{
if(key.state == Key.STATE_RELEASED)
{
key.state = Key.STATE_PRESSED;
down = true;
}
else
{
key.state = Key.STATE_RELEASED;
down = false;
}
}
break;
default:
return false;
}
post(m_updateToolBar);
Q3EUtils.q3ei.callbackObj.sendKeyEvent(down, key.keyCode, 0);
if(send)
Q3EUtils.q3ei.callbackObj.sendKeyEvent(down, key.keyCode, 0);
return true;
}
};
Expand All @@ -89,6 +118,7 @@ void Setup()

setBackgroundColor(resources.getColor(R.color.toolbar_background));
int[] keys = getResources().getIntArray(R.array.key_toolbar_codes);
int[] types = getResources().getIntArray(R.array.key_toolbar_types);
String[] values = getResources().getStringArray(R.array.key_toolbar_names);
List<Key> list = new ArrayList<>();
Key key;
Expand All @@ -97,6 +127,7 @@ void Setup()
key = new Key();
key.name = values[i];
key.keyCode = Q3EKeyCodes.GetRealKeyCode(keys[i]);
key.type = types[i];
list.add(key);
}

Expand Down Expand Up @@ -152,7 +183,11 @@ private static class Key
public static final int STATE_PRESSED = 1;
public static final int STATE_TOGGLED = 2;

public static final int TYPE_BUTTON = 1;
public static final int TYPE_TOGGLE = 2;

public String name;
public int type;
public int keyCode;
public int state = STATE_RELEASED;
}
Expand Down
52 changes: 52 additions & 0 deletions Q3E/src/main/jni/doom3/neo/framework/EditField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,58 @@ void idEditField::KeyDownEvent(int key)
if (key != K_CAPSLOCK && key != K_ALT && key != K_CTRL && key != K_SHIFT) {
ClearAutoComplete();
}

// ctrl-v = paste
if (tolower(key) == 'v' && idKeyInput::IsDown(K_CTRL)) {
ClearAutoComplete();
Paste();
return;
}

// ctrl-c = copy
if (tolower(key) == 'c' && idKeyInput::IsDown(K_CTRL)) {
if(buffer[0])
Sys_SetClipboardData(buffer);
return;
}

// ctrl-u = clear line
if (tolower(key) == 'u' && idKeyInput::IsDown(K_CTRL)) {
ClearAutoComplete();
Clear();
return;
}

// ctrl-w = clear a word
if (tolower(key) == 'w' && idKeyInput::IsDown(K_CTRL)) {
if(cursor > 0)
{
int lastCursor = cursor;
// skip to previous word
while ((cursor > 0) && (buffer[ cursor - 1 ] == ' ')) {
cursor--;
}

while ((cursor > 0) && (buffer[ cursor - 1 ] != ' ')) {
cursor--;
}

if (cursor < 0) {
cursor = 0;
}

if (cursor < scroll) {
scroll = cursor;
}

if (autoComplete.length) {
autoComplete.length = cursor;
}
buffer[cursor] = '\0';
strcat(buffer, buffer + lastCursor);
}
return;
}
}

/*
Expand Down
5 changes: 5 additions & 0 deletions Q3E/src/main/jni/doom3/neo/sys/android/sys_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,16 @@ void Sys_SyncState(void)
}
}

static bool ctrl_state = false;
void Q3E_KeyEvent(int state,int key,int character)
{
if(key == K_CTRL)
ctrl_state = bool(state);

Posix_QueEvent(SE_KEY, key, state, 0, NULL);
if ((character != 0) && (state == 1))
{
if(!ctrl_state || character == '\b')
Posix_QueEvent(SE_CHAR, character, 0, 0, NULL);
}
Posix_AddKeyboardPollEvent(key, state);
Expand Down
15 changes: 15 additions & 0 deletions Q3E/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<item>PageDown</item>
<item>PageUp</item>
<item>End</item>
<item>Ctrl</item>
</string-array>

<integer-array name="key_toolbar_codes">
Expand All @@ -23,5 +24,19 @@
<item>145</item>
<item>146</item>
<item>148</item>
<item>141</item>
</integer-array>

<integer-array name="key_toolbar_types">
<item>1</item>
<item>1</item>
<item>1</item>
<item>1</item>
<item>1</item>
<item>1</item>
<item>1</item>
<item>1</item>
<item>1</item>
<item>2</item>
</integer-array>
</resources>

0 comments on commit dd30ec4

Please sign in to comment.