Describe event using macros
This commit is contained in:
@@ -39,7 +39,7 @@ void GlobalCommand(Event event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle wheel scrolling
|
// Handle wheel scrolling
|
||||||
if (event.wheel.x || event.wheel.y) {
|
if (event.xwheel || event.ywheel) {
|
||||||
Vec2I mouse = MouseVec2I();
|
Vec2I mouse = MouseVec2I();
|
||||||
|
|
||||||
For(order) {
|
For(order) {
|
||||||
@@ -49,8 +49,8 @@ void GlobalCommand(Event event) {
|
|||||||
bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect);
|
bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect);
|
||||||
if (mouse_in_window) {
|
if (mouse_in_window) {
|
||||||
View *view = GetView(window->active_view);
|
View *view = GetView(window->active_view);
|
||||||
view->scroll.y -= (Int)(event.wheel.y * 48);
|
view->scroll.y -= (Int)(event.ywheel * 48);
|
||||||
view->scroll.x += (Int)(event.wheel.x * 48);
|
view->scroll.x += (Int)(event.xwheel * 48);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,12 +119,12 @@ void GlobalCommand(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.ctrl && event.shift && Mouse(RIGHT)) {
|
if (Ctrl() && Shift() && Mouse(RIGHT)) {
|
||||||
GotoForward(GetActiveMainSet().window);
|
GotoForward(GetActiveMainSet().window);
|
||||||
} else if (event.alt && event.ctrl && Mouse(RIGHT)) {
|
} else if (Alt() && Ctrl() && Mouse(RIGHT)) {
|
||||||
} else if (event.ctrl && Mouse(RIGHT)) {
|
} else if (Ctrl() && Mouse(RIGHT)) {
|
||||||
GotoBackward(GetActiveMainSet().window);
|
GotoBackward(GetActiveMainSet().window);
|
||||||
} else if (event.alt && Mouse(RIGHT)) {
|
} else if (Alt() && Mouse(RIGHT)) {
|
||||||
} else if (Mouse(RIGHT)) {
|
} else if (Mouse(RIGHT)) {
|
||||||
Vec2I mouse = MouseVec2I();
|
Vec2I mouse = MouseVec2I();
|
||||||
BSet active = GetActiveSet();
|
BSet active = GetActiveSet();
|
||||||
@@ -158,9 +158,9 @@ void GlobalCommand(Event event) {
|
|||||||
// for now let's leave it because we are relaying on global state
|
// for now let's leave it because we are relaying on global state
|
||||||
// - maybe just do the check if active window is matching the DocumentSelected window
|
// - maybe just do the check if active window is matching the DocumentSelected window
|
||||||
// - if scrollbar selected then don't invoke window command
|
// - if scrollbar selected then don't invoke window command
|
||||||
if (event.ctrl && event.shift && Mouse(LEFT)) {
|
if (Ctrl() && Shift() && Mouse(LEFT)) {
|
||||||
MouseExecWord(event);
|
MouseExecWord(event);
|
||||||
} else if (event.ctrl && Mouse(LEFT)) {
|
} else if (Ctrl() && Mouse(LEFT)) {
|
||||||
MouseLoadWord(event);
|
MouseLoadWord(event);
|
||||||
} else if (Mouse(LEFT)) { // CTRL SHIFT
|
} else if (Mouse(LEFT)) { // CTRL SHIFT
|
||||||
Vec2I mouse = MouseVec2I();
|
Vec2I mouse = MouseVec2I();
|
||||||
@@ -175,11 +175,11 @@ void GlobalCommand(Event event) {
|
|||||||
DocumentSelected = active.window->id;
|
DocumentSelected = active.window->id;
|
||||||
|
|
||||||
Int p = ScreenSpaceToBufferPos(active.window, active.view, active.buffer, mouse);
|
Int p = ScreenSpaceToBufferPos(active.window, active.view, active.buffer, mouse);
|
||||||
if (event.alt) Insert(&active.view->carets, MakeCaret(p, p), 0);
|
if (Alt()) Insert(&active.view->carets, MakeCaret(p, p), 0);
|
||||||
if (!event.alt && !event.shift) active.view->carets.len = 1;
|
if (!Alt() && !Shift()) active.view->carets.len = 1;
|
||||||
|
|
||||||
Caret &caret = active.view->carets[0];
|
Caret &caret = active.view->carets[0];
|
||||||
if (event.shift) {
|
if (Shift()) {
|
||||||
if (p <= caret.range.min) {
|
if (p <= caret.range.min) {
|
||||||
caret.range.min = p;
|
caret.range.min = p;
|
||||||
caret.ifront = 0;
|
caret.ifront = 0;
|
||||||
@@ -226,17 +226,17 @@ void GlobalCommand(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_P)) {
|
if (CtrlPress(SDLK_P)) {
|
||||||
Command_ListBuffers();
|
Command_ListBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_BACKSLASH)) {
|
if (CtrlShiftPress(SDLK_BACKSLASH)) {
|
||||||
AddRowWindow();
|
AddRowWindow();
|
||||||
} else if (Ctrl(SDLK_BACKSLASH)) {
|
} else if (CtrlPress(SDLK_BACKSLASH)) {
|
||||||
AddColumnWindow();
|
AddColumnWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_0)) {
|
if (CtrlPress(SDLK_0)) {
|
||||||
ToggleVisibility(DebugWindowID);
|
ToggleVisibility(DebugWindowID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,15 +248,15 @@ void GlobalCommand(Event event) {
|
|||||||
ToggleFullscreen();
|
ToggleFullscreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_1)) {
|
if (CtrlPress(SDLK_1)) {
|
||||||
Window *window = GetLayoutWindow(0);
|
Window *window = GetLayoutWindow(0);
|
||||||
if (window) ActiveWindow = window->id;
|
if (window) ActiveWindow = window->id;
|
||||||
}
|
}
|
||||||
if (Ctrl(SDLK_2)) {
|
if (CtrlPress(SDLK_2)) {
|
||||||
Window *window = GetLayoutWindow(1);
|
Window *window = GetLayoutWindow(1);
|
||||||
if (window) ActiveWindow = window->id;
|
if (window) ActiveWindow = window->id;
|
||||||
}
|
}
|
||||||
if (Ctrl(SDLK_3)) {
|
if (CtrlPress(SDLK_3)) {
|
||||||
Window *window = GetLayoutWindow(2);
|
Window *window = GetLayoutWindow(2);
|
||||||
if (window) ActiveWindow = window->id;
|
if (window) ActiveWindow = window->id;
|
||||||
}
|
}
|
||||||
@@ -268,120 +268,120 @@ void GlobalCommand(Event event) {
|
|||||||
WindowOpenBufferView(active.window, event.text);
|
WindowOpenBufferView(active.window, event.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlAlt(SDLK_DOWN)) {
|
if (CtrlAltPress(SDLK_DOWN)) {
|
||||||
Command_DuplicateLine(active.view, DIR_DOWN);
|
Command_DuplicateLine(active.view, DIR_DOWN);
|
||||||
} else if (AltShift(SDLK_DOWN)) {
|
} else if (AltShiftPress(SDLK_DOWN)) {
|
||||||
Command_CreateCursorVertical(active.view, DIR_DOWN);
|
Command_CreateCursorVertical(active.view, DIR_DOWN);
|
||||||
} else if (CtrlShift(SDLK_DOWN)) {
|
} else if (CtrlShiftPress(SDLK_DOWN)) {
|
||||||
Command_Move(active.view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESSED);
|
||||||
} else if (Alt(SDLK_DOWN)) {
|
} else if (AltPress(SDLK_DOWN)) {
|
||||||
Command_MoveLine(active.view, DIR_DOWN);
|
Command_MoveLine(active.view, DIR_DOWN);
|
||||||
} else if (Ctrl(SDLK_DOWN)) {
|
} else if (CtrlPress(SDLK_DOWN)) {
|
||||||
Command_Move(active.view, DIR_DOWN, CTRL_PRESSED);
|
Command_Move(active.view, DIR_DOWN, CTRL_PRESSED);
|
||||||
} else if (Shift(SDLK_DOWN)) {
|
} else if (ShiftPress(SDLK_DOWN)) {
|
||||||
Command_Move(active.view, DIR_DOWN, false, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_DOWN, false, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_DOWN)) {
|
} else if (Press(SDLK_DOWN)) {
|
||||||
Command_Move(active.view, DIR_DOWN);
|
Command_Move(active.view, DIR_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlAlt(SDLK_UP)) {
|
if (CtrlAltPress(SDLK_UP)) {
|
||||||
Command_DuplicateLine(active.view, DIR_UP);
|
Command_DuplicateLine(active.view, DIR_UP);
|
||||||
} else if (AltShift(SDLK_UP)) {
|
} else if (AltShiftPress(SDLK_UP)) {
|
||||||
Command_CreateCursorVertical(active.view, DIR_UP);
|
Command_CreateCursorVertical(active.view, DIR_UP);
|
||||||
} else if (CtrlShift(SDLK_UP)) {
|
} else if (CtrlShiftPress(SDLK_UP)) {
|
||||||
Command_Move(active.view, DIR_UP, CTRL_PRESSED, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_UP, CTRL_PRESSED, SHIFT_PRESSED);
|
||||||
} else if (Alt(SDLK_UP)) {
|
} else if (AltPress(SDLK_UP)) {
|
||||||
Command_MoveLine(active.view, DIR_UP);
|
Command_MoveLine(active.view, DIR_UP);
|
||||||
} else if (Ctrl(SDLK_UP)) {
|
} else if (CtrlPress(SDLK_UP)) {
|
||||||
Command_Move(active.view, DIR_UP, CTRL_PRESSED);
|
Command_Move(active.view, DIR_UP, CTRL_PRESSED);
|
||||||
} else if (Shift(SDLK_UP)) {
|
} else if (ShiftPress(SDLK_UP)) {
|
||||||
Command_Move(active.view, DIR_UP, false, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_UP, false, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_UP)) {
|
} else if (Press(SDLK_UP)) {
|
||||||
Command_Move(active.view, DIR_UP);
|
Command_Move(active.view, DIR_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_LEFT)) {
|
if (CtrlShiftPress(SDLK_LEFT)) {
|
||||||
Command_Move(active.view, DIR_LEFT, CTRL_PRESSED, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_LEFT, CTRL_PRESSED, SHIFT_PRESSED);
|
||||||
} else if (Ctrl(SDLK_LEFT)) {
|
} else if (CtrlPress(SDLK_LEFT)) {
|
||||||
Command_Move(active.view, DIR_LEFT, CTRL_PRESSED);
|
Command_Move(active.view, DIR_LEFT, CTRL_PRESSED);
|
||||||
} else if (Shift(SDLK_LEFT)) {
|
} else if (ShiftPress(SDLK_LEFT)) {
|
||||||
Command_Move(active.view, DIR_LEFT, false, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_LEFT, false, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_LEFT)) {
|
} else if (Press(SDLK_LEFT)) {
|
||||||
Command_Move(active.view, DIR_LEFT);
|
Command_Move(active.view, DIR_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_RIGHT)) {
|
if (CtrlShiftPress(SDLK_RIGHT)) {
|
||||||
Command_Move(active.view, DIR_RIGHT, CTRL_PRESSED, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_RIGHT, CTRL_PRESSED, SHIFT_PRESSED);
|
||||||
} else if (Ctrl(SDLK_RIGHT)) {
|
} else if (CtrlPress(SDLK_RIGHT)) {
|
||||||
Command_Move(active.view, DIR_RIGHT, CTRL_PRESSED);
|
Command_Move(active.view, DIR_RIGHT, CTRL_PRESSED);
|
||||||
} else if (Shift(SDLK_RIGHT)) {
|
} else if (ShiftPress(SDLK_RIGHT)) {
|
||||||
Command_Move(active.view, DIR_RIGHT, false, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_RIGHT, false, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_RIGHT)) {
|
} else if (Press(SDLK_RIGHT)) {
|
||||||
Command_Move(active.view, DIR_RIGHT);
|
Command_Move(active.view, DIR_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_Z)) {
|
if (CtrlShiftPress(SDLK_Z)) {
|
||||||
RedoEdit(active.buffer, &active.view->carets);
|
RedoEdit(active.buffer, &active.view->carets);
|
||||||
} else if (Ctrl(SDLK_Z)) {
|
} else if (CtrlPress(SDLK_Z)) {
|
||||||
UndoEdit(active.buffer, &active.view->carets);
|
UndoEdit(active.buffer, &active.view->carets);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_C)) {
|
if (CtrlPress(SDLK_C)) {
|
||||||
Command_Copy(active.view);
|
Command_Copy(active.view);
|
||||||
} else if (Ctrl(SDLK_V)) {
|
} else if (CtrlPress(SDLK_V)) {
|
||||||
Command_Paste(active.view);
|
Command_Paste(active.view);
|
||||||
} else if (Ctrl(SDLK_X)) {
|
} else if (CtrlPress(SDLK_X)) {
|
||||||
PreBeginEdit_SaveCaretHistory(active.buffer, active.view->carets);
|
PreBeginEdit_SaveCaretHistory(active.buffer, active.view->carets);
|
||||||
Command_Copy(active.view);
|
Command_Copy(active.view);
|
||||||
Command_Replace(active.view, L"");
|
Command_Replace(active.view, L"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_A)) {
|
if (CtrlPress(SDLK_A)) {
|
||||||
Command_SelectEntireBuffer(active.view);
|
Command_SelectEntireBuffer(active.view);
|
||||||
active.view->update_scroll = false;
|
active.view->update_scroll = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_PAGEUP)) {
|
if (ShiftPress(SDLK_PAGEUP)) {
|
||||||
Command_MoveCursorsByPageSize(active.window, DIR_UP, SHIFT_PRESSED);
|
Command_MoveCursorsByPageSize(active.window, DIR_UP, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_PAGEUP)) {
|
} else if (Press(SDLK_PAGEUP)) {
|
||||||
Command_MoveCursorsByPageSize(active.window, DIR_UP);
|
Command_MoveCursorsByPageSize(active.window, DIR_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_PAGEDOWN)) {
|
if (ShiftPress(SDLK_PAGEDOWN)) {
|
||||||
Command_MoveCursorsByPageSize(active.window, DIR_DOWN, SHIFT_PRESSED);
|
Command_MoveCursorsByPageSize(active.window, DIR_DOWN, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_PAGEDOWN)) {
|
} else if (Press(SDLK_PAGEDOWN)) {
|
||||||
Command_MoveCursorsByPageSize(active.window, DIR_DOWN);
|
Command_MoveCursorsByPageSize(active.window, DIR_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_HOME)) {
|
if (ShiftPress(SDLK_HOME)) {
|
||||||
Command_MoveCursorsToSide(active.view, DIR_LEFT, SHIFT_PRESSED);
|
Command_MoveCursorsToSide(active.view, DIR_LEFT, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_HOME)) {
|
} else if (Press(SDLK_HOME)) {
|
||||||
Command_MoveCursorsToSide(active.view, DIR_LEFT);
|
Command_MoveCursorsToSide(active.view, DIR_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_END)) {
|
if (ShiftPress(SDLK_END)) {
|
||||||
Command_MoveCursorsToSide(active.view, DIR_RIGHT, SHIFT_PRESSED);
|
Command_MoveCursorsToSide(active.view, DIR_RIGHT, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_END)) {
|
} else if (Press(SDLK_END)) {
|
||||||
Command_MoveCursorsToSide(active.view, DIR_RIGHT);
|
Command_MoveCursorsToSide(active.view, DIR_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_TAB)) {
|
if (ShiftPress(SDLK_TAB)) {
|
||||||
Command_IndentSelectedLines(active.view, SHIFT_PRESSED);
|
Command_IndentSelectedLines(active.view, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_TAB)) {
|
} else if (Press(SDLK_TAB)) {
|
||||||
Command_IndentSelectedLines(active.view);
|
Command_IndentSelectedLines(active.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_K)) {
|
if (CtrlShiftPress(SDLK_K)) {
|
||||||
Command_KillSelectedLines(active.view);
|
Command_KillSelectedLines(active.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_BACKSPACE)) {
|
if (CtrlPress(SDLK_BACKSPACE)) {
|
||||||
Command_Delete(active.view, DIR_LEFT, CTRL_PRESSED);
|
Command_Delete(active.view, DIR_LEFT, CTRL_PRESSED);
|
||||||
} else if (Press(SDLK_BACKSPACE)) {
|
} else if (Press(SDLK_BACKSPACE)) {
|
||||||
Command_Delete(active.view, DIR_LEFT);
|
Command_Delete(active.view, DIR_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_DELETE)) {
|
if (CtrlPress(SDLK_DELETE)) {
|
||||||
Command_Delete(active.view, DIR_RIGHT, CTRL_PRESSED);
|
Command_Delete(active.view, DIR_RIGHT, CTRL_PRESSED);
|
||||||
} else if (Press(SDLK_DELETE)) {
|
} else if (Press(SDLK_DELETE)) {
|
||||||
Command_Delete(active.view, DIR_RIGHT);
|
Command_Delete(active.view, DIR_RIGHT);
|
||||||
@@ -394,14 +394,14 @@ void GlobalCommand(Event event) {
|
|||||||
Command_Replace(active.view, string16);
|
Command_Replace(active.view, string16);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_D)) {
|
if (CtrlPress(SDLK_D)) {
|
||||||
String16 string = GetString(active.buffer, active.view->carets[0].range);
|
String16 string = GetString(active.buffer, active.view->carets[0].range);
|
||||||
Caret caret = FindNext(active.buffer, string, active.view->carets[0]);
|
Caret caret = FindNext(active.buffer, string, active.view->carets[0]);
|
||||||
Insert(&active.view->carets, caret, 0);
|
Insert(&active.view->carets, caret, 0);
|
||||||
MergeCarets(active.view);
|
MergeCarets(active.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_F3)) {
|
if (ShiftPress(SDLK_F3)) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
BSet main = GetActiveMainSet();
|
BSet main = GetActiveMainSet();
|
||||||
String16 search_string = ToString16(scratch, main.window->search_string);
|
String16 search_string = ToString16(scratch, main.window->search_string);
|
||||||
@@ -415,57 +415,57 @@ void GlobalCommand(Event event) {
|
|||||||
Command_SelectRangeOneCursor(main.view, caret);
|
Command_SelectRangeOneCursor(main.view, caret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_F4)) {
|
if (ShiftPress(SDLK_F4)) {
|
||||||
Command_GotoNextInList(active.window, -1);
|
Command_GotoNextInList(active.window, -1);
|
||||||
} else if (Press(SDLK_F4)) {
|
} else if (Press(SDLK_F4)) {
|
||||||
Command_GotoNextInList(active.window, 1);
|
Command_GotoNextInList(active.window, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_RETURN)) {
|
if (CtrlShiftPress(SDLK_RETURN)) {
|
||||||
Command_MoveCursorsToSide(active.view, DIR_LEFT);
|
Command_MoveCursorsToSide(active.view, DIR_LEFT);
|
||||||
Command_IdentedNewLine(active.view);
|
Command_IdentedNewLine(active.view);
|
||||||
Command_Move(active.view, DIR_UP);
|
Command_Move(active.view, DIR_UP);
|
||||||
} else if (Ctrl(SDLK_RETURN)) {
|
} else if (CtrlPress(SDLK_RETURN)) {
|
||||||
Command_MoveCursorsToSide(active.view, DIR_RIGHT);
|
Command_MoveCursorsToSide(active.view, DIR_RIGHT);
|
||||||
Command_IdentedNewLine(active.view);
|
Command_IdentedNewLine(active.view);
|
||||||
} else if (Press(SDLK_RETURN)) {
|
} else if (Press(SDLK_RETURN)) {
|
||||||
Command_IdentedNewLine(active.view);
|
Command_IdentedNewLine(active.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_F)) {
|
if (CtrlPress(SDLK_F)) {
|
||||||
Command_SelectTitlebarCommand(active.window, L"#Search(\"");
|
Command_SelectTitlebarCommand(active.window, L"#Search(\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_S)) {
|
if (CtrlPress(SDLK_S)) {
|
||||||
SaveBuffer(active.view);
|
SaveBuffer(active.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_PERIOD)) {
|
if (CtrlPress(SDLK_PERIOD)) {
|
||||||
BSet main = GetActiveMainSet();
|
BSet main = GetActiveMainSet();
|
||||||
String name = ChopLastSlash(main.buffer->name);
|
String name = ChopLastSlash(main.buffer->name);
|
||||||
Open(name);
|
Open(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_G)) {
|
if (CtrlShiftPress(SDLK_G)) {
|
||||||
} else if (Ctrl(SDLK_G)) {
|
} else if (CtrlPress(SDLK_G)) {
|
||||||
Command_SelectTitlebarCommand(active.window, L"#FuzzySort(\"");
|
Command_SelectTitlebarCommand(active.window, L"#FuzzySort(\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_W)) {
|
if (CtrlShiftPress(SDLK_W)) {
|
||||||
GotoForward(GetActiveMainSet().window);
|
GotoForward(GetActiveMainSet().window);
|
||||||
} else if (Ctrl(SDLK_W)) {
|
} else if (CtrlPress(SDLK_W)) {
|
||||||
GotoBackward(GetActiveMainSet().window);
|
GotoBackward(GetActiveMainSet().window);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool should_enclose = active.window->auto_enclose && (active.buffer->change_id != buffer_change_id);
|
bool should_enclose = active.window->auto_enclose && (active.buffer->change_id != buffer_change_id);
|
||||||
if (should_enclose || CtrlShift(SDLK_Q)) {
|
if (should_enclose || CtrlShiftPress(SDLK_Q)) {
|
||||||
Caret caret = active.view->carets[0];
|
Caret caret = active.view->carets[0];
|
||||||
Range range = caret.range;
|
Range range = caret.range;
|
||||||
if (GetSize(caret.range) == 0) range = EncloseExecWord(active.buffer, GetFront(caret));
|
if (GetSize(caret.range) == 0) range = EncloseExecWord(active.buffer, GetFront(caret));
|
||||||
String16 string = GetString(active.buffer, range);
|
String16 string = GetString(active.buffer, range);
|
||||||
|
|
||||||
Command_EvalLua(active.view, string);
|
Command_EvalLua(active.view, string);
|
||||||
} else if (Ctrl(SDLK_Q)) {
|
} else if (CtrlPress(SDLK_Q)) {
|
||||||
Caret caret = active.view->carets[0];
|
Caret caret = active.view->carets[0];
|
||||||
Range range = caret.range;
|
Range range = caret.range;
|
||||||
if (GetSize(caret.range) == 0) range = EncloseLoadWord(active.buffer, GetFront(caret));
|
if (GetSize(caret.range) == 0) range = EncloseLoadWord(active.buffer, GetFront(caret));
|
||||||
|
|||||||
@@ -18,41 +18,36 @@ enum {
|
|||||||
EVENT_DROP_FILE,
|
EVENT_DROP_FILE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define EVENT_FIELDS \
|
||||||
|
X(EventKind, Int, kind) \
|
||||||
|
X(SDL_Keycode, Int, key) \
|
||||||
|
X(int16_t, Int, xmouse) \
|
||||||
|
X(int16_t, Int, ymouse) \
|
||||||
|
X(int16_t, Int, xwindow) \
|
||||||
|
X(int16_t, Int, ywindow) \
|
||||||
|
X(uint8_t, Int, clicks) \
|
||||||
|
X(uint8_t, Int, shift) \
|
||||||
|
X(uint8_t, Int, ctrl) \
|
||||||
|
X(uint8_t, Int, alt) \
|
||||||
|
X(uint8_t, Int, super) \
|
||||||
|
X(float, Float, xwheel) \
|
||||||
|
X(float, Float, ywheel) \
|
||||||
|
X(char *, String, text)
|
||||||
|
#define EVENT_FIELD_COUNT 14
|
||||||
|
|
||||||
struct Event {
|
struct Event {
|
||||||
EventKind kind;
|
#define X(TYPE, KIND, NAME) TYPE NAME;
|
||||||
SDL_Keycode key;
|
EVENT_FIELDS
|
||||||
int16_t xmouse;
|
#undef X
|
||||||
int16_t ymouse;
|
|
||||||
int16_t xwindow;
|
|
||||||
int16_t ywindow;
|
|
||||||
uint8_t clicks;
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
uint8_t shift : 1;
|
|
||||||
uint8_t ctrl : 1;
|
|
||||||
uint8_t alt : 1;
|
|
||||||
uint8_t super : 1;
|
|
||||||
};
|
|
||||||
uint8_t flags;
|
|
||||||
};
|
|
||||||
Vec2 wheel;
|
|
||||||
char *text;
|
|
||||||
};
|
};
|
||||||
Array<Event> EventPlayback;
|
Array<Event> EventPlayback;
|
||||||
|
|
||||||
// :Event
|
// :Event
|
||||||
void Serialize(Serializer *s, Event *e) {
|
void Serialize(Serializer *s, Event *e) {
|
||||||
SerializeBegin(s);
|
SerializeBegin(s);
|
||||||
Serialize(s, "kind", &e->kind);
|
#define X(TYPE, KIND, NAME) Serialize(s, #NAME, &e->NAME);
|
||||||
Serialize(s, "key", &e->key);
|
EVENT_FIELDS
|
||||||
Serialize(s, "xmouse", &e->xmouse);
|
#undef X
|
||||||
Serialize(s, "ymouse", &e->ymouse);
|
|
||||||
Serialize(s, "xwindow", &e->xwindow);
|
|
||||||
Serialize(s, "ywindow", &e->ywindow);
|
|
||||||
Serialize(s, "clicks", &e->clicks);
|
|
||||||
Serialize(s, "flags", &e->flags);
|
|
||||||
Serialize(s, "wheel", &e->wheel);
|
|
||||||
Serialize(s, "text", &e->text);
|
|
||||||
SerializeEnd(s);
|
SerializeEnd(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,13 +62,17 @@ bool SHIFT_PRESSED = true;
|
|||||||
bool AppIsRunning = true;
|
bool AppIsRunning = true;
|
||||||
bool WaitForEvents = true;
|
bool WaitForEvents = true;
|
||||||
|
|
||||||
|
#define Ctrl() event.ctrl
|
||||||
|
#define Alt() event.alt
|
||||||
|
#define Shift() event.shift
|
||||||
|
|
||||||
#define Press(KEY) (event.key == KEY)
|
#define Press(KEY) (event.key == KEY)
|
||||||
#define Ctrl(KEY) (event.key == KEY && event.ctrl)
|
#define CtrlPress(KEY) (event.key == KEY && event.ctrl)
|
||||||
#define Shift(KEY) (event.key == KEY && event.shift)
|
#define ShiftPress(KEY) (event.key == KEY && event.shift)
|
||||||
#define Alt(KEY) (event.key == KEY && event.alt)
|
#define AltPress(KEY) (event.key == KEY && event.alt)
|
||||||
#define CtrlShift(KEY) (event.key == KEY && event.ctrl && event.shift)
|
#define CtrlShiftPress(KEY) (event.key == KEY && event.ctrl && event.shift)
|
||||||
#define CtrlAlt(KEY) (event.key == KEY && event.ctrl && event.alt)
|
#define CtrlAltPress(KEY) (event.key == KEY && event.ctrl && event.alt)
|
||||||
#define AltShift(KEY) (event.key == KEY && event.shift && event.alt)
|
#define AltShiftPress(KEY) (event.key == KEY && event.shift && event.alt)
|
||||||
#define MouseVec2() \
|
#define MouseVec2() \
|
||||||
Vec2 { (float)event.xmouse, (float)event.ymouse }
|
Vec2 { (float)event.xmouse, (float)event.ymouse }
|
||||||
#define MouseVec2I() \
|
#define MouseVec2I() \
|
||||||
|
|||||||
@@ -299,6 +299,13 @@ Int GetInt(lua_State *L, const char *name) {
|
|||||||
return (Int)num;
|
return (Int)num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double GetFloat(lua_State *L, const char *name) {
|
||||||
|
lua_getfield(L, -1, name);
|
||||||
|
double num = lua_tonumber(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
const char *GetString(lua_State *L, const char *name) {
|
const char *GetString(lua_State *L, const char *name) {
|
||||||
lua_getfield(L, -1, name);
|
lua_getfield(L, -1, name);
|
||||||
const char *result = lua_tostring(L, -1);
|
const char *result = lua_tostring(L, -1);
|
||||||
@@ -306,25 +313,16 @@ const char *GetString(lua_State *L, const char *name) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2 GetVec2(lua_State *L, const char *name) {
|
void PushEvent(lua_State *L, Event *event) {
|
||||||
Vec2 result = {};
|
lua_createtable(L, 0, EVENT_FIELD_COUNT);
|
||||||
lua_getfield(L, -1, name);
|
#define lua_pushInt lua_pushinteger
|
||||||
defer { lua_pop(L, 1); };
|
#define lua_pushString lua_pushstring
|
||||||
if (!lua_istable(L, -1)) return result;
|
#define lua_pushFloat lua_pushnumber
|
||||||
|
#define X(TYPE, KIND, NAME) \
|
||||||
{
|
lua_push##KIND(L, event->NAME); \
|
||||||
lua_getfield(L, -1, "1");
|
lua_setfield(L, -2, #NAME);
|
||||||
defer { lua_pop(L, 1); };
|
EVENT_FIELDS
|
||||||
result.x = (float)lua_tonumber(L, -1);
|
#undef X
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
lua_getfield(L, -1, "2");
|
|
||||||
defer { lua_pop(L, 1); };
|
|
||||||
result.y = (float)lua_tonumber(L, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// :Event
|
// :Event
|
||||||
@@ -339,16 +337,9 @@ int Lua_Play(lua_State *L) {
|
|||||||
defer { lua_pop(L, 1); };
|
defer { lua_pop(L, 1); };
|
||||||
|
|
||||||
Event event = {};
|
Event event = {};
|
||||||
event.kind = (EventKind)GetInt(L, "kind");
|
#define X(TYPE, KIND, NAME) event.NAME = (TYPE)Get##KIND(L, #NAME);
|
||||||
event.key = (SDL_Keycode)GetInt(L, "key");
|
EVENT_FIELDS
|
||||||
event.xmouse = (int16_t)GetInt(L, "xmouse");
|
#undef X
|
||||||
event.ymouse = (int16_t)GetInt(L, "ymouse");
|
|
||||||
event.xwindow = (int16_t)GetInt(L, "xwindow");
|
|
||||||
event.ywindow = (int16_t)GetInt(L, "ywindow");
|
|
||||||
event.clicks = (uint8_t)GetInt(L, "clicks");
|
|
||||||
event.flags = (uint8_t)GetInt(L, "flags");
|
|
||||||
event.text = (char *)GetString(L, "text");
|
|
||||||
event.wheel = GetVec2(L, "wheel");
|
|
||||||
Add(&EventPlayback, event);
|
Add(&EventPlayback, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ void Serialize(Serializer *s, String name, int16_t *datum) {
|
|||||||
*datum = (int16_t)d;
|
*datum = (int16_t)d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Serialize(Serializer *s, String name, Vec2 *datum) {
|
void Serialize(Serializer *s, String name, float *datum) {
|
||||||
IKnowWhatImDoing_Appendf(s->buffer, "%.*s = {%lld, %lld}, ", FmtString(name), (long long)datum->x, (long long)datum->y);
|
IKnowWhatImDoing_Appendf(s->buffer, "%.*s = %f, ", FmtString(name), *datum);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Serialize(Serializer *s, String name, char **text) {
|
void Serialize(Serializer *s, String name, char **text) {
|
||||||
|
|||||||
@@ -128,7 +128,8 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
|
|||||||
SDL_MouseWheelEvent &b = input_event->wheel;
|
SDL_MouseWheelEvent &b = input_event->wheel;
|
||||||
event.xmouse = (int16_t)b.mouse_x;
|
event.xmouse = (int16_t)b.mouse_x;
|
||||||
event.ymouse = (int16_t)b.mouse_y;
|
event.ymouse = (int16_t)b.mouse_y;
|
||||||
event.wheel = {b.x, b.y};
|
event.xwheel = b.x;
|
||||||
|
event.ywheel = b.y;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case SDL_EVENT_MOUSE_MOTION: {
|
case SDL_EVENT_MOUSE_MOTION: {
|
||||||
@@ -316,8 +317,8 @@ int main(int argc, char **argv)
|
|||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
Array<Event> frame_events = GetEventsForFrame(scratch);
|
Array<Event> frame_events = GetEventsForFrame(scratch);
|
||||||
For(frame_events) {
|
For(frame_events) {
|
||||||
|
Serialize(&ser, &it);
|
||||||
if (it.kind == EVENT_QUIT) goto end_of_editor_loop;
|
if (it.kind == EVENT_QUIT) goto end_of_editor_loop;
|
||||||
if (it.kind != EVENT_UPDATE) Serialize(&ser, &it);
|
|
||||||
Update(it);
|
Update(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,8 +185,8 @@ void DrawWindow(Window *window, Event &event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Underline word under mouse cursor
|
// Underline word under mouse cursor
|
||||||
if (event.ctrl) {
|
if (Ctrl()) {
|
||||||
auto enclose_proc = event.shift ? EncloseExecWord : EncloseLoadWord;
|
auto enclose_proc = Shift() ? EncloseExecWord : EncloseLoadWord;
|
||||||
|
|
||||||
Caret caret = view->carets[0];
|
Caret caret = view->carets[0];
|
||||||
Vec2I mouse = MouseVec2I();
|
Vec2I mouse = MouseVec2I();
|
||||||
|
|||||||
Reference in New Issue
Block a user