WIP on cleanup of arrow handling code
This commit is contained in:
parent
cf2edb5145
commit
20aab75c7b
@ -593,153 +593,7 @@ static void endEditing()
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
bool Editor_keyDown(int key, int keyCode, int modifiers)
|
||||
{
|
||||
bool handled_key = true;
|
||||
TrackData* trackData = &s_editorData.trackData;
|
||||
TrackViewInfo* viewInfo = &s_editorData.trackViewInfo;
|
||||
bool paused = RemoteConnection_isPaused();
|
||||
struct sync_track** tracks = getTracks();
|
||||
int active_track = getActiveTrack();
|
||||
int row_pos = viewInfo->rowPos;
|
||||
|
||||
const int selectLeft = mini(viewInfo->selectStartTrack, viewInfo->selectStopTrack);
|
||||
const int selectRight = maxi(viewInfo->selectStartTrack, viewInfo->selectStopTrack);
|
||||
const int selectTop = mini(viewInfo->selectStartRow, viewInfo->selectStopRow);
|
||||
const int selectBottom = maxi(viewInfo->selectStartRow, viewInfo->selectStopRow);
|
||||
|
||||
// If some emgui control has focus let it do its thing until its done
|
||||
|
||||
if (Emgui_hasKeyboardFocus())
|
||||
{
|
||||
Editor_update();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == EMGUI_KEY_TAB)
|
||||
{
|
||||
Emgui_setFirstControlFocus();
|
||||
Editor_update();
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case EMGUI_KEY_BACKSPACE:
|
||||
{
|
||||
endEditing();
|
||||
deleteArea(row_pos, active_track, 1, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
case EMGUI_ARROW_DOWN:
|
||||
{
|
||||
const int active_track = getActiveTrack();
|
||||
int row = row_pos;
|
||||
|
||||
endEditing();
|
||||
|
||||
if (modifiers & EMGUI_KEY_CTRL)
|
||||
{
|
||||
struct sync_track* t = getTracks()[active_track];
|
||||
|
||||
if (t->keys)
|
||||
{
|
||||
int idx = key_idx_floor(t, row_pos);
|
||||
|
||||
if (idx < 0)
|
||||
row = t->keys[0].row;
|
||||
else if (idx > (int)t->num_keys - 2)
|
||||
row = t->keys[t->num_keys - 1].row;
|
||||
else
|
||||
row = t->keys[idx + 1].row;
|
||||
|
||||
viewInfo->rowPos = row;
|
||||
|
||||
if (modifiers & EMGUI_KEY_SHIFT)
|
||||
viewInfo->selectStopRow = row;
|
||||
else
|
||||
viewInfo->selectStartRow = viewInfo->selectStopRow = row;
|
||||
|
||||
RemoteConnection_sendSetRowCommand(row);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
row += modifiers & EMGUI_KEY_ALT ? 8 : 1;
|
||||
|
||||
if ((modifiers & EMGUI_KEY_COMMAND) || row > trackData->endRow)
|
||||
row = TrackData_getNextBookmark(trackData, row);
|
||||
|
||||
viewInfo->rowPos = row;
|
||||
|
||||
if (modifiers & EMGUI_KEY_SHIFT)
|
||||
{
|
||||
viewInfo->selectStopRow = row;
|
||||
break;
|
||||
}
|
||||
|
||||
viewInfo->selectStartRow = viewInfo->selectStopRow = row;
|
||||
viewInfo->selectStartTrack = viewInfo->selectStopTrack = active_track;
|
||||
|
||||
RemoteConnection_sendSetRowCommand(row);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case EMGUI_ARROW_UP:
|
||||
{
|
||||
int row = row_pos;
|
||||
endEditing();
|
||||
|
||||
if (modifiers & EMGUI_KEY_CTRL)
|
||||
{
|
||||
struct sync_track* t = getTracks()[active_track];
|
||||
|
||||
if (t->keys)
|
||||
{
|
||||
int idx = sync_find_key(t, row);
|
||||
if (idx < 0)
|
||||
idx = -idx - 1;
|
||||
|
||||
viewInfo->rowPos = row = t->keys[emaxi(idx - 1, 0)].row;
|
||||
|
||||
if (modifiers & EMGUI_KEY_SHIFT)
|
||||
viewInfo->selectStartRow = row;
|
||||
else
|
||||
viewInfo->selectStartRow = viewInfo->selectStopRow = row;
|
||||
|
||||
RemoteConnection_sendSetRowCommand(row);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
row -= modifiers & EMGUI_KEY_ALT ? 8 : 1;
|
||||
|
||||
if ((modifiers & EMGUI_KEY_COMMAND) || row < trackData->startRow)
|
||||
row = TrackData_getPrevBookmark(trackData, row);
|
||||
|
||||
viewInfo->rowPos = row;
|
||||
|
||||
if (modifiers & EMGUI_KEY_SHIFT)
|
||||
{
|
||||
viewInfo->selectStopRow = row;
|
||||
break;
|
||||
}
|
||||
|
||||
viewInfo->selectStartRow = viewInfo->selectStopRow = row;
|
||||
viewInfo->selectStartTrack = viewInfo->selectStopTrack = active_track;
|
||||
|
||||
RemoteConnection_sendSetRowCommand(row);
|
||||
handled_key = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case EMGUI_ARROW_LEFT:
|
||||
static void onArrowLeft(int modifiers)
|
||||
{
|
||||
const int current_track = getActiveTrack();
|
||||
int track = getPrevTrack();
|
||||
@ -794,19 +648,15 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
|
||||
|
||||
handled_key = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case EMGUI_ARROW_RIGHT:
|
||||
{
|
||||
const int current_track = getActiveTrack();
|
||||
int track = getNextTrack();
|
||||
int track_count = getTrackCount();
|
||||
endEditing();
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void onArrowRight(int row, sync_track* track, int activeTrack, int modifiers)
|
||||
{
|
||||
if (modifiers & EMGUI_KEY_ALT)
|
||||
{
|
||||
Track* t = &trackData->tracks[current_track];
|
||||
Track* t = getTrackData()[activeTrack];
|
||||
|
||||
if (modifiers & EMGUI_KEY_CTRL)
|
||||
{
|
||||
@ -818,6 +668,7 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
|
||||
|
||||
Editor_updateTrackScroll();
|
||||
Editor_update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -849,7 +700,178 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
|
||||
viewInfo->selectStartTrack = viewInfo->selectStopTrack = track;
|
||||
|
||||
handled_key = true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void onArrowUp(int row, sync_track* track, int activeTrack, int modifiers)
|
||||
{
|
||||
if (modifiers & EMGUI_KEY_CTRL)
|
||||
{
|
||||
if (track->keys)
|
||||
{
|
||||
int idx = sync_find_key(track, row);
|
||||
if (idx < 0)
|
||||
idx = -idx - 1;
|
||||
|
||||
viewInfo->rowPos = row = track->keys[emaxi(idx - 1, 0)].row;
|
||||
|
||||
if (modifiers & EMGUI_KEY_SHIFT)
|
||||
viewInfo->selectStartRow = row;
|
||||
else
|
||||
viewInfo->selectStartRow = viewInfo->selectStopRow = row;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
row -= modifiers & EMGUI_KEY_ALT ? 8 : 1;
|
||||
|
||||
if ((modifiers & EMGUI_KEY_COMMAND) || row < trackData->startRow)
|
||||
row = TrackData_getPrevBookmark(trackData, row);
|
||||
|
||||
viewInfo->rowPos = row;
|
||||
|
||||
if (modifiers & EMGUI_KEY_SHIFT)
|
||||
{
|
||||
viewInfo->selectStopRow = row;
|
||||
break;
|
||||
}
|
||||
|
||||
viewInfo->selectStartRow = viewInfo->selectStopRow = row;
|
||||
viewInfo->selectStartTrack = viewInfo->selectStopTrack = active_track;
|
||||
}
|
||||
|
||||
RemoteConnection_sendSetRowCommand(row);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void onArrowDown(int rowPos, sync_track* track, int activeTrack, int modifiers)
|
||||
{
|
||||
const int active_track = getActiveTrack();
|
||||
int row = getRowPos();
|
||||
|
||||
if (modifiers & EMGUI_KEY_CTRL)
|
||||
{
|
||||
struct sync_track* t = getTracks()[active_track];
|
||||
|
||||
if (t->keys)
|
||||
{
|
||||
int idx = key_idx_floor(t, row_pos);
|
||||
|
||||
if (idx < 0)
|
||||
row = t->keys[0].row;
|
||||
else if (idx > (int)t->num_keys - 2)
|
||||
row = t->keys[t->num_keys - 1].row;
|
||||
else
|
||||
row = t->keys[idx + 1].row;
|
||||
|
||||
viewInfo->rowPos = row;
|
||||
|
||||
if (modifiers & EMGUI_KEY_SHIFT)
|
||||
viewInfo->selectStopRow = row;
|
||||
else
|
||||
viewInfo->selectStartRow = viewInfo->selectStopRow = row;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
row += modifiers & EMGUI_KEY_ALT ? 8 : 1;
|
||||
|
||||
if ((modifiers & EMGUI_KEY_COMMAND) || row > trackData->endRow)
|
||||
row = TrackData_getNextBookmark(getTrackData(), row);
|
||||
|
||||
viewInfo->rowPos = row;
|
||||
|
||||
if (modifiers & EMGUI_KEY_SHIFT)
|
||||
{
|
||||
viewInfo->selectStopRow = row;
|
||||
return;
|
||||
}
|
||||
|
||||
viewInfo->selectStartRow = viewInfo->selectStopRow = row;
|
||||
viewInfo->selectStartTrack = viewInfo->selectStopTrack = active_track;
|
||||
}
|
||||
|
||||
RemoteConnection_sendSetRowCommand(row);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void onArrow(int key, int modifiers, int rowPos, sync_track* track, int activeTrack)
|
||||
{
|
||||
endEditing();
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case EMGUI_ARROW_DOWN: onArrowDown(rowPos, track, activetrack, modifiers); break;
|
||||
case EMGUI_ARROW_UP: onArrowUp(rowPos, track, activetrack, modifiers); break;
|
||||
case EMGUI_ARROW_RIGHT: onArrowRight(rowPos, track, activetrack, modifiers); break;
|
||||
case EMGUI_ARROW_LEFT: onArrowLeft(rowPos, track, activetrack, modifiers); break;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Editor_keyDown(int key, int keyCode, int modifiers)
|
||||
{
|
||||
bool handled_key = true;
|
||||
TrackData* trackData = &s_editorData.trackData;
|
||||
TrackViewInfo* viewInfo = &s_editorData.trackViewInfo;
|
||||
bool paused = RemoteConnection_isPaused();
|
||||
struct sync_track** tracks = getTracks();
|
||||
int active_track = getActiveTrack();
|
||||
int row_pos = viewInfo->rowPos;
|
||||
|
||||
const int selectLeft = mini(viewInfo->selectStartTrack, viewInfo->selectStopTrack);
|
||||
const int selectRight = maxi(viewInfo->selectStartTrack, viewInfo->selectStopTrack);
|
||||
const int selectTop = mini(viewInfo->selectStartRow, viewInfo->selectStopRow);
|
||||
const int selectBottom = maxi(viewInfo->selectStartRow, viewInfo->selectStopRow);
|
||||
|
||||
// If some emgui control has focus let it do its thing until its done
|
||||
|
||||
if (Emgui_hasKeyboardFocus())
|
||||
{
|
||||
Editor_update();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == EMGUI_KEY_TAB)
|
||||
{
|
||||
Emgui_setFirstControlFocus();
|
||||
Editor_update();
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case EMGUI_KEY_BACKSPACE:
|
||||
{
|
||||
endEditing();
|
||||
deleteArea(row_pos, active_track, 1, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
case EMGUI_ARROW_DOWN:
|
||||
case EMGUI_ARROW_UP:
|
||||
case EMGUI_ARROW_RIGHT:
|
||||
case EMGUI_ARROW_LEFT: onArrow(key, modifiers);
|
||||
{
|
||||
}
|
||||
|
||||
case EMGUI_ARROW_UP:
|
||||
{
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case EMGUI_ARROW_LEFT:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case EMGUI_ARROW_RIGHT:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user