Ported mouse movement and conditional update
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
Int MoveOnWhitespaceBoundaryForward(Buffer &buffer, Int pos) {
|
Int MoveOnWhitespaceBoundaryForward(Buffer &buffer, Int pos) {
|
||||||
pos = Clamp(pos, (Int)0, buffer.len);
|
pos = Clamp(pos, (Int)0, buffer.len);
|
||||||
bool standing_on_whitespace = IsWhitespace(buffer.str[pos]);
|
bool standing_on_whitespace = IsWhitespace(buffer.str[pos]);
|
||||||
|
|||||||
@@ -224,275 +224,6 @@ void MergeCarets(View *view, Range *mouse_selection_anchor) {
|
|||||||
Swap(&view->carets[first_caret_index], &view->carets[0]);
|
Swap(&view->carets[first_caret_index], &view->carets[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleActiveWindowBindings(Window *window, bool *update_scroll) {
|
|
||||||
View &view = *GetActiveView(window);
|
|
||||||
Buffer *buffer = GetBuffer(view.active_buffer);
|
|
||||||
// if (CtrlPress(KEY_F2)) {
|
|
||||||
// LoadBigLine(buffer);
|
|
||||||
// } else if (Press(KEY_F2)) {
|
|
||||||
// LoadBigText(buffer);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (Press(KEY_ESCAPE)) {
|
|
||||||
// if (window->deactivate_on_escape) {
|
|
||||||
// SetActiveWindow(GetLastActiveWindow());
|
|
||||||
// } else {
|
|
||||||
// view.carets.len = 1;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (CtrlAltPress(KEY_DOWN)) {
|
|
||||||
// Command_DuplicateLine(&view, DIR_DOWN);
|
|
||||||
// } else if (AltShiftPress(KEY_DOWN)) {
|
|
||||||
// Command_CreateCursorVertical(&view, DIR_DOWN);
|
|
||||||
// } else if (CtrlShiftPress(KEY_DOWN)) {
|
|
||||||
// For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, true));
|
|
||||||
// } else if (CtrlPress(KEY_DOWN)) {
|
|
||||||
// For(view.carets) it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, true));
|
|
||||||
// } else if (ShiftPress(KEY_DOWN)) {
|
|
||||||
// For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, false));
|
|
||||||
// } else if (Press(KEY_DOWN)) {
|
|
||||||
// For(view.carets) {
|
|
||||||
// if (GetSize(it.range) == 0) {
|
|
||||||
// it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, false));
|
|
||||||
// } else {
|
|
||||||
// it = MakeCaret(it.range.max);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (CtrlAltPress(KEY_UP)) {
|
|
||||||
// Command_DuplicateLine(&view, DIR_UP);
|
|
||||||
// } else if (AltShiftPress(KEY_UP)) {
|
|
||||||
// Command_CreateCursorVertical(&view, DIR_UP);
|
|
||||||
// } else if (CtrlShiftPress(KEY_UP)) {
|
|
||||||
// For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_UP, CTRL_PRESSED));
|
|
||||||
// } else if (CtrlPress(KEY_UP)) {
|
|
||||||
// For(view.carets) it = MakeCaret(MovePos(*buffer, it.range.min, DIR_UP, CTRL_PRESSED));
|
|
||||||
// } else if (ShiftPress(KEY_UP)) {
|
|
||||||
// For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_UP));
|
|
||||||
// } else if (Press(KEY_UP)) {
|
|
||||||
// For(view.carets) {
|
|
||||||
// if (GetSize(it.range) == 0) {
|
|
||||||
// it = MakeCaret(MovePos(*buffer, it.range.min, DIR_UP));
|
|
||||||
// } else {
|
|
||||||
// it = MakeCaret(it.range.min);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (CtrlShiftPress(KEY_LEFT)) {
|
|
||||||
// For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_LEFT, true));
|
|
||||||
// } else if (CtrlPress(KEY_LEFT)) {
|
|
||||||
// For(view.carets) {
|
|
||||||
// if (GetSize(it.range) != 0 && GetFront(it) != it.range.min) {
|
|
||||||
// it = MakeCaret(it.range.min);
|
|
||||||
// } else {
|
|
||||||
// it = MakeCaret(MovePos(*buffer, it.range.min, DIR_LEFT, true));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else if (ShiftPress(KEY_LEFT)) {
|
|
||||||
// For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_LEFT, false));
|
|
||||||
// } else if (Press(KEY_LEFT)) {
|
|
||||||
// For(view.carets) {
|
|
||||||
// if (GetSize(it.range) == 0) {
|
|
||||||
// it = MakeCaret(MovePos(*buffer, it.range.min, DIR_LEFT, false));
|
|
||||||
// } else {
|
|
||||||
// it = MakeCaret(it.range.min);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (CtrlShiftPress(KEY_RIGHT)) {
|
|
||||||
// For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_RIGHT, true));
|
|
||||||
// } else if (CtrlPress(KEY_RIGHT)) {
|
|
||||||
// For(view.carets) {
|
|
||||||
// if (GetSize(it.range) != 0 && GetFront(it) != it.range.max) {
|
|
||||||
// it = MakeCaret(it.range.max);
|
|
||||||
// } else {
|
|
||||||
// it = MakeCaret(MovePos(*buffer, it.range.max, DIR_RIGHT, true));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else if (ShiftPress(KEY_RIGHT)) {
|
|
||||||
// For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_RIGHT, false));
|
|
||||||
// } else if (Press(KEY_RIGHT)) {
|
|
||||||
// For(view.carets) {
|
|
||||||
// if (GetSize(it.range) == 0) {
|
|
||||||
// it = MakeCaret(MovePos(*buffer, it.range.max, DIR_RIGHT, false));
|
|
||||||
// } else {
|
|
||||||
// it = MakeCaret(it.range.max);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (CtrlShiftPress(KEY_Z)) {
|
|
||||||
// RedoEdit(buffer, &view.carets);
|
|
||||||
// } else if (CtrlPress(KEY_Z)) {
|
|
||||||
// UndoEdit(buffer, &view.carets);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (CtrlPress(KEY_C)) {
|
|
||||||
// Command_Copy(&view);
|
|
||||||
// } else if (CtrlPress(KEY_V)) {
|
|
||||||
// Command_Paste(&view);
|
|
||||||
// } else if (CtrlPress(KEY_X)) {
|
|
||||||
// Command_Copy(&view);
|
|
||||||
// Command_Replace(&view, L"");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (CtrlPress(KEY_A)) {
|
|
||||||
// Command_SelectEntireBuffer(&view);
|
|
||||||
// *update_scroll = false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (ShiftPress(KEY_PAGE_UP)) {
|
|
||||||
// Command_MoveCursorsByPageSize(window, DIR_UP, SHIFT_PRESSED);
|
|
||||||
// } else if (Press(KEY_PAGE_UP)) {
|
|
||||||
// Command_MoveCursorsByPageSize(window, DIR_UP);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (ShiftPress(KEY_PAGE_DOWN)) {
|
|
||||||
// Command_MoveCursorsByPageSize(window, DIR_DOWN, SHIFT_PRESSED);
|
|
||||||
// } else if (Press(KEY_PAGE_DOWN)) {
|
|
||||||
// Command_MoveCursorsByPageSize(window, DIR_DOWN);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (ShiftPress(KEY_HOME)) {
|
|
||||||
// Command_MoveCursorsToSide(window, DIR_LEFT, SHIFT_PRESSED);
|
|
||||||
// } else if (Press(KEY_HOME)) {
|
|
||||||
// Command_MoveCursorsToSide(window, DIR_LEFT);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (ShiftPress(KEY_END)) {
|
|
||||||
// Command_MoveCursorsToSide(window, DIR_RIGHT, SHIFT_PRESSED);
|
|
||||||
// } else if (Press(KEY_END)) {
|
|
||||||
// Command_MoveCursorsToSide(window, DIR_RIGHT);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// bool search = false;
|
|
||||||
// if (Press(KEY_TAB)) {
|
|
||||||
// Command_Replace(&view, L" ");
|
|
||||||
// search = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (CtrlPress(KEY_BACKSPACE)) {
|
|
||||||
// Command_Delete(&view, DIR_LEFT, CTRL_PRESSED);
|
|
||||||
// search = true;
|
|
||||||
// } else if (Press(KEY_BACKSPACE)) {
|
|
||||||
// Command_Delete(&view, DIR_LEFT);
|
|
||||||
// search = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (CtrlPress(KEY_DELETE)) {
|
|
||||||
// Command_Delete(&view, DIR_RIGHT, CTRL_PRESSED);
|
|
||||||
// search = true;
|
|
||||||
// } else if (Press(KEY_DELETE)) {
|
|
||||||
// Command_Delete(&view, DIR_RIGHT);
|
|
||||||
// search = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// for (int c = GetCharPressed(); c; c = GetCharPressed()) {
|
|
||||||
// // we interpret 2 byte sequences as 1 byte when rendering but we still
|
|
||||||
// // want to read them properly.
|
|
||||||
// String16 string = L"?";
|
|
||||||
// UTF16Result result = UTF32ToUTF16((uint32_t)c);
|
|
||||||
// if (!result.error) string = {(wchar_t *)result.out_str, result.len};
|
|
||||||
// Command_Replace(&view, string);
|
|
||||||
// search = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (CtrlPress(KEY_D)) {
|
|
||||||
// String16 string = GetString(*buffer, view.carets[0].range);
|
|
||||||
// Caret caret = FindInBuffer(buffer, string, view.carets[0], true);
|
|
||||||
// Insert(&view.carets, caret, 0);
|
|
||||||
// MergeCarets(&view);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (Press(KEY_F3)) {
|
|
||||||
// Buffer *search_buffer = GetBuffer("*search*");
|
|
||||||
// String16 search_string = GetString(*search_buffer);
|
|
||||||
// Caret caret = FindInBuffer(buffer, search_string, view.carets[0], true);
|
|
||||||
// if (Ctrl()) {
|
|
||||||
// Insert(&view.carets, caret, 0);
|
|
||||||
// MergeCarets(&view);
|
|
||||||
// } else {
|
|
||||||
// view.carets.len = 1;
|
|
||||||
// view.carets[0] = caret;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (window->id.id == SearchWindowID.id) {
|
|
||||||
// Window *seek_window = GetWindow(GetLastActiveWindow());
|
|
||||||
// View *seek_view = GetView(seek_window->active_view);
|
|
||||||
// Buffer *seek_buffer = GetBuffer(seek_view->active_buffer);
|
|
||||||
// String16 needle = GetString(*buffer);
|
|
||||||
// if (search) {
|
|
||||||
// seek_view->carets[0] = FindInBuffer(seek_buffer, needle, seek_view->carets[0]);
|
|
||||||
// seek_view->carets.len = 1;
|
|
||||||
// }
|
|
||||||
// if (AltPress(KEY_ENTER)) {
|
|
||||||
// Command_SelectAll(seek_view, needle);
|
|
||||||
// // SetActiveWindow(seek_window->id);
|
|
||||||
// } else if (Press(KEY_ENTER)) {
|
|
||||||
// Caret caret = FindInBuffer(seek_buffer, needle, seek_view->carets[0], true);
|
|
||||||
// if (Ctrl()) {
|
|
||||||
// Insert(&seek_view->carets, caret, 0);
|
|
||||||
// MergeCarets(seek_view);
|
|
||||||
// } else {
|
|
||||||
// seek_view->carets.len = 1;
|
|
||||||
// seek_view->carets[0] = caret;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (window->fuzzy_search && search) {
|
|
||||||
// Scratch scratch;
|
|
||||||
// String16 first_line_string = GetLineStringWithoutNL(*buffer, 0);
|
|
||||||
// Array<FuzzyPair> ratings = FuzzySearchLines(scratch, buffer, 1, buffer->line_starts.len, first_line_string);
|
|
||||||
|
|
||||||
// Buffer *temp_buffer = CreateTempBuffer(scratch, buffer->cap);
|
|
||||||
// ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), first_line_string);
|
|
||||||
// ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n");
|
|
||||||
// For(ratings) {
|
|
||||||
// String16 s = GetLineStringWithoutNL(*buffer, it.index);
|
|
||||||
// if (s.len == 0) continue;
|
|
||||||
// ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), s);
|
|
||||||
// ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Caret caret = view.carets[0];
|
|
||||||
// Command_SelectEntireBuffer(&view);
|
|
||||||
// Command_Replace(&view, GetString(*temp_buffer));
|
|
||||||
// view.carets[0] = caret;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (CtrlPress(KEY_Q) || IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE)) {
|
|
||||||
// // @todo: Consider applying this to all cursors
|
|
||||||
// if (GetSize(view.carets[0].range) == 0) {
|
|
||||||
// Command_EvalLuaLine(&view);
|
|
||||||
// } else {
|
|
||||||
// String16 string = GetString(*buffer, view.carets[0].range);
|
|
||||||
// Command_EvalLua(&view, string);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (window->execute_line) {
|
|
||||||
// if (Press(KEY_ENTER)) {
|
|
||||||
// Command_EvalLuaLine(&view);
|
|
||||||
// }
|
|
||||||
// } else if (window->id.id == SearchWindowID.id) {
|
|
||||||
// } else {
|
|
||||||
// if (CtrlPress(KEY_ENTER)) {
|
|
||||||
// Command_MoveCursorsToSide(window, DIR_RIGHT);
|
|
||||||
// Command_Replace(&view, L"\n");
|
|
||||||
// } else if (Press(KEY_ENTER)) {
|
|
||||||
// Command_Replace(&view, L"\n");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
MergeCarets(&view);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReplaceInfobarData() {
|
void ReplaceInfobarData() {
|
||||||
Window *window = GetWindow(InfoBarWindowID);
|
Window *window = GetWindow(InfoBarWindowID);
|
||||||
if (IsActive(window)) return;
|
if (IsActive(window)) return;
|
||||||
@@ -514,7 +245,15 @@ void ReplaceInfobarData() {
|
|||||||
ReplaceText(buffer, GetEndAsRange(*buffer), L"|");
|
ReplaceText(buffer, GetEndAsRange(*buffer), L"|");
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = Format(scratch, "line: %5lld col: %5lld name: %.*s wid: %d vid: %d bid: %d", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name), (int)last_window->id.id, (int)last_view->id.id, (int)last_buffer->id.id);
|
// {
|
||||||
|
// Scratch scratch;
|
||||||
|
// uint64_t ms = SDL_GetTicks();
|
||||||
|
// double time = (double)ms / 1000.0;
|
||||||
|
// String string = Format(scratch, "%d %f %f", (int)FrameID, time, (time / (double)FrameID));
|
||||||
|
// DrawString(&MainFont, ToString16(scratch, string), {0, 0}, {255, 0, 0, 255});
|
||||||
|
// }
|
||||||
|
|
||||||
|
String s = Format(scratch, "line: %5lld col: %5lld name: %.*s wid: %d vid: %d bid: %d frame%lld", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name), (int)last_window->id.id, (int)last_view->id.id, (int)last_buffer->id.id, (long long)FrameID);
|
||||||
String16 string = ToString16(scratch, s);
|
String16 string = ToString16(scratch, s);
|
||||||
ReplaceText(buffer, replace_range, string);
|
ReplaceText(buffer, replace_range, string);
|
||||||
Command_SelectRangeOneCursor(view, {});
|
Command_SelectRangeOneCursor(view, {});
|
||||||
|
|||||||
@@ -40,6 +40,19 @@ bool AppIsRunning = true;
|
|||||||
bool WaitForEvents = true;
|
bool WaitForEvents = true;
|
||||||
SDL_Cursor *SDL_MouseCursor = NULL;
|
SDL_Cursor *SDL_MouseCursor = NULL;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MOUSE_NONE,
|
||||||
|
|
||||||
|
MOUSE_MOVE,
|
||||||
|
MOUSE_LEFT,
|
||||||
|
MOUSE_RIGHT,
|
||||||
|
MOUSE_MIDDLE,
|
||||||
|
|
||||||
|
MOUSE_LEFT_UP,
|
||||||
|
MOUSE_RIGHT_UP,
|
||||||
|
MOUSE_MIDDLE_UP,
|
||||||
|
};
|
||||||
|
|
||||||
struct Event {
|
struct Event {
|
||||||
SDL_Keycode key;
|
SDL_Keycode key;
|
||||||
int16_t xmouse;
|
int16_t xmouse;
|
||||||
@@ -49,13 +62,9 @@ struct Event {
|
|||||||
uint8_t ctrl : 1;
|
uint8_t ctrl : 1;
|
||||||
uint8_t alt : 1;
|
uint8_t alt : 1;
|
||||||
uint8_t super : 1;
|
uint8_t super : 1;
|
||||||
|
|
||||||
uint8_t mouse_move : 1;
|
|
||||||
uint8_t mouse_left : 1;
|
|
||||||
uint8_t mouse_right : 1;
|
|
||||||
uint8_t mouse_middle : 1;
|
|
||||||
uint8_t mouse_double_click : 1;
|
|
||||||
};
|
};
|
||||||
|
uint8_t mouse;
|
||||||
|
uint8_t mouse_double_click;
|
||||||
float wheel;
|
float wheel;
|
||||||
const char *text;
|
const char *text;
|
||||||
};
|
};
|
||||||
@@ -67,15 +76,16 @@ struct Event {
|
|||||||
#define CtrlShift(KEY) (event.key == KEY && event.ctrl && event.shift)
|
#define CtrlShift(KEY) (event.key == KEY && event.ctrl && event.shift)
|
||||||
#define CtrlAlt(KEY) (event.key == KEY && event.ctrl && event.alt)
|
#define CtrlAlt(KEY) (event.key == KEY && event.ctrl && event.alt)
|
||||||
#define AltShift(KEY) (event.key == KEY && event.shift && event.alt)
|
#define AltShift(KEY) (event.key == KEY && event.shift && event.alt)
|
||||||
#define MousePress() (event.mouse_left == 1 || event.mouse_right == 1 || event.mouse_middle == 1 || event.mouse_double_click == 1)
|
|
||||||
#define MouseVec2() \
|
#define MouseVec2() \
|
||||||
Vec2 { (float)event.xmouse, (float)event.ymouse }
|
Vec2 { (float)event.xmouse, (float)event.ymouse }
|
||||||
#define MouseVec2I() \
|
#define MouseVec2I() \
|
||||||
Vec2I { (Int) event.xmouse, (Int)event.ymouse }
|
Vec2I { (Int) event.xmouse, (Int)event.ymouse }
|
||||||
|
#define Mouse(x) (event.mouse == MOUSE_##x)
|
||||||
|
#define MousePress() (Mouse(LEFT) || Mouse(RIGHT) || Mouse(MIDDLE))
|
||||||
|
|
||||||
bool GlobalCommand(Event event) {
|
bool GlobalCommand(Event event) {
|
||||||
bool run_window_command = true;
|
bool run_window_command = true;
|
||||||
if (event.mouse_move) {
|
if (Mouse(MOVE)) {
|
||||||
Vec2I mouse = MouseVec2I();
|
Vec2I mouse = MouseVec2I();
|
||||||
Window *window = GetActiveWindow();
|
Window *window = GetActiveWindow();
|
||||||
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
|
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
|
||||||
@@ -352,16 +362,6 @@ void WindowCommand(Event event, Window *window, View *view) {
|
|||||||
search = true;
|
search = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (int c = GetCharPressed(); c; c = GetCharPressed()) {
|
|
||||||
// // we interpret 2 byte sequences as 1 byte when rendering but we still
|
|
||||||
// // want to read them properly.
|
|
||||||
// String16 string = L"?";
|
|
||||||
// UTF16Result result = UTF32ToUTF16((uint32_t)c);
|
|
||||||
// if (!result.error) string = {(wchar_t *)result.out_str, result.len};
|
|
||||||
// Command_Replace(view, string);
|
|
||||||
// search = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (Ctrl(SDLK_D)) {
|
if (Ctrl(SDLK_D)) {
|
||||||
String16 string = GetString(*buffer, view->carets[0].range);
|
String16 string = GetString(*buffer, view->carets[0].range);
|
||||||
Caret caret = FindInBuffer(buffer, string, view->carets[0], true);
|
Caret caret = FindInBuffer(buffer, string, view->carets[0], true);
|
||||||
@@ -451,93 +451,113 @@ void WindowCommand(Event event, Window *window, View *view) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// {
|
if (!Mouse(NONE)) {
|
||||||
// ProfileScope(mouse);
|
ProfileScope(mouse);
|
||||||
|
|
||||||
// Vec2 _mouse = GetMousePosition();
|
Vec2 mouse_vec2 = MouseVec2();
|
||||||
// bool mouse_in_view = CheckCollisionPointRec(_mouse, ToRectangle(window->document_rect));
|
Vec2I mouse = MouseVec2I();
|
||||||
// bool mouse_in_scrollbar = CheckCollisionPointRec(_mouse, ToRectangle(window->scrollbar_rect));
|
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
|
||||||
// Vec2I mouse = ToVec2I(_mouse);
|
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
|
||||||
|
|
||||||
// if (!(mouse_in_scrollbar || window->mouse_selecting_scrollbar) && (mouse_in_view || window->mouse_selecting)) {
|
bool scrollbar_action = mouse_in_scrollbar || window->mouse_selecting_scrollbar;
|
||||||
// Vec2I mworld = mouse - window->document_rect.min + view.scroll;
|
bool document_action = mouse_in_document || window->mouse_selecting;
|
||||||
// Vec2I pos = mworld / Vec2I{FontCharSpacing, FontLineSpacing};
|
if (!scrollbar_action && document_action) {
|
||||||
// XY xy = {(Int)(pos.x), (Int)(pos.y)};
|
Vec2I mworld = mouse - window->document_rect.min + view->scroll;
|
||||||
// Int p = XYToPosWithoutNL(*buffer, xy);
|
Vec2I pos = mworld / Vec2I{FontCharSpacing, FontLineSpacing};
|
||||||
|
XY xy = {(Int)(pos.x), (Int)(pos.y)};
|
||||||
|
Int p = XYToPosWithoutNL(*buffer, xy);
|
||||||
|
|
||||||
// if (mouse_in_view && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
if (mouse_in_document && Mouse(LEFT) && event.mouse_double_click) {
|
||||||
// if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
Caret *c = &view->carets[0];
|
||||||
// if (IsDoubleClick()) {
|
if (InBounds({c->range.min - 1, c->range.max + 1}, p)) {
|
||||||
// Caret *c = &view.carets[0];
|
c->range = EncloseWord(*buffer, p);
|
||||||
// if (InBounds({c->range.min - 1, c->range.max + 1}, p)) {
|
view->selection_anchor = c->range;
|
||||||
// c->range = EncloseWord(*buffer, p);
|
}
|
||||||
// view.selection_anchor = c->range;
|
} else if (mouse_in_document && Mouse(LEFT) && event.ctrl) {
|
||||||
// }
|
Insert(&view->carets, MakeCaret(p, p), 0);
|
||||||
// } else {
|
view->selection_anchor = view->carets[0].range;
|
||||||
// if (!IsKeyDown(KEY_LEFT_CONTROL)) {
|
} else if (mouse_in_document && Mouse(LEFT)) {
|
||||||
// view.carets.len = 0;
|
view->carets.len = 0;
|
||||||
// }
|
Insert(&view->carets, MakeCaret(p, p), 0);
|
||||||
// Insert(&view.carets, MakeCaret(p, p), 0);
|
view->selection_anchor = view->carets[0].range;
|
||||||
// view.selection_anchor = view.carets[0].range;
|
}
|
||||||
// }
|
|
||||||
// } else if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
|
||||||
// window->mouse_selecting = true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (window->mouse_selecting) {
|
if (mouse_in_document && Mouse(LEFT)) {
|
||||||
// if (!IsMouseButtonDown(MOUSE_BUTTON_LEFT)) window->mouse_selecting = false;
|
window->mouse_selecting = true;
|
||||||
// MergeCarets(&view, &view.selection_anchor);
|
}
|
||||||
// Caret &caret = view.carets[0];
|
|
||||||
// if (view.selection_anchor.min > p) {
|
|
||||||
// caret = MakeCaret(p, view.selection_anchor.max);
|
|
||||||
// } else if (view.selection_anchor.max < p) {
|
|
||||||
// caret = MakeCaret(p, view.selection_anchor.min);
|
|
||||||
// } else {
|
|
||||||
// caret = MakeCaret(view.selection_anchor.max, view.selection_anchor.min);
|
|
||||||
// }
|
|
||||||
// MergeCarets(&view, &view.selection_anchor);
|
|
||||||
// }
|
|
||||||
// } else if (!(mouse_in_view || window->mouse_selecting) && mouse_in_scrollbar || window->mouse_selecting_scrollbar) {
|
|
||||||
// Scroller s = ComputeScrollerRect(*window);
|
|
||||||
// double size_y = (double)GetSize(window->scrollbar_rect).y;
|
|
||||||
// double p = _mouse.y - window->scrollbar_rect.min.y;
|
|
||||||
|
|
||||||
// if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
if (window->mouse_selecting) {
|
||||||
// window->mouse_selecting_scrollbar = true;
|
if (Mouse(LEFT_UP)) {
|
||||||
// } else if (!IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
window->mouse_selecting = false;
|
||||||
// window->mouse_selecting_scrollbar = false;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
MergeCarets(view, &view->selection_anchor);
|
||||||
// if (_mouse.y < s.rect.min.y || _mouse.y > s.rect.max.y) {
|
Caret &caret = view->carets[0];
|
||||||
// view.scroll.y = (Int)(p / size_y * (double)s.line_count * (double)FontLineSpacing);
|
if (view->selection_anchor.min > p) {
|
||||||
// window->mouse_scroller_offset = -(double)GetSize(s.rect).y / 2.0 / size_y;
|
caret = MakeCaret(p, view->selection_anchor.max);
|
||||||
// } else {
|
} else if (view->selection_anchor.max < p) {
|
||||||
// window->mouse_scroller_offset = (s.rect.min.y - p) / size_y;
|
caret = MakeCaret(p, view->selection_anchor.min);
|
||||||
// }
|
} else {
|
||||||
// }
|
caret = MakeCaret(view->selection_anchor.max, view->selection_anchor.min);
|
||||||
|
}
|
||||||
|
MergeCarets(view, &view->selection_anchor);
|
||||||
|
}
|
||||||
|
} else if (!(mouse_in_document || window->mouse_selecting) && mouse_in_scrollbar || window->mouse_selecting_scrollbar) {
|
||||||
|
Scroller s = ComputeScrollerRect(*window);
|
||||||
|
double size_y = (double)GetSize(window->scrollbar_rect).y;
|
||||||
|
double p = mouse_vec2.y - window->scrollbar_rect.min.y;
|
||||||
|
|
||||||
// if (window->mouse_selecting_scrollbar) {
|
if (Mouse(LEFT)) {
|
||||||
// double v = p / size_y;
|
window->mouse_selecting_scrollbar = true;
|
||||||
// v = v + (window->mouse_scroller_offset);
|
} else if (Mouse(LEFT_UP)) {
|
||||||
// view.scroll.y = (Int)(v * (double)s.line_count * (double)FontLineSpacing);
|
window->mouse_selecting_scrollbar = false;
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
// }
|
if (Mouse(LEFT)) {
|
||||||
|
if (mouse_vec2.y < s.rect.min.y || mouse_vec2.y > s.rect.max.y) {
|
||||||
|
view->scroll.y = (Int)(p / size_y * (double)s.line_count * (double)FontLineSpacing);
|
||||||
|
window->mouse_scroller_offset = -(double)GetSize(s.rect).y / 2.0 / size_y;
|
||||||
|
} else {
|
||||||
|
window->mouse_scroller_offset = (s.rect.min.y - p) / size_y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window->mouse_selecting_scrollbar) {
|
||||||
|
double v = p / size_y;
|
||||||
|
v = v + (window->mouse_scroller_offset);
|
||||||
|
view->scroll.y = (Int)(v * (double)s.line_count * (double)FontLineSpacing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window->mouse_selecting || window->mouse_selecting_scrollbar) {
|
||||||
|
WaitForEvents = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Command(Event event) {
|
||||||
|
bool run_window_command = GlobalCommand(event);
|
||||||
|
if (run_window_command) {
|
||||||
|
Window *window = GetActiveWindow();
|
||||||
|
View *view = GetActiveView(window);
|
||||||
|
WindowCommand(event, window, view);
|
||||||
|
MergeCarets(view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessSDLEvent(SDL_Event *input_event) {
|
void ProcessSDLEvent(SDL_Event *input_event) {
|
||||||
Event event = {};
|
Event event = {};
|
||||||
|
SDL_Keymod mod = SDL_GetModState();
|
||||||
|
event.shift = (mod & SDL_KMOD_SHIFT) != 0;
|
||||||
|
event.ctrl = (mod & SDL_KMOD_CTRL) != 0;
|
||||||
|
event.alt = (mod & SDL_KMOD_ALT) != 0;
|
||||||
|
event.super = (mod & SDL_KMOD_GUI) != 0;
|
||||||
|
|
||||||
switch (input_event->type) {
|
switch (input_event->type) {
|
||||||
case SDL_EVENT_QUIT: AppIsRunning = false; return;
|
case SDL_EVENT_QUIT: AppIsRunning = false; return;
|
||||||
case SDL_EVENT_KEY_DOWN: {
|
case SDL_EVENT_KEY_DOWN: {
|
||||||
SDL_KeyboardEvent &key = input_event->key;
|
SDL_KeyboardEvent &key = input_event->key;
|
||||||
event.key = key.key;
|
event.key = key.key;
|
||||||
event.shift = (key.mod & SDL_KMOD_SHIFT) != 0;
|
|
||||||
event.ctrl = (key.mod & SDL_KMOD_CTRL) != 0;
|
|
||||||
event.alt = (key.mod & SDL_KMOD_ALT) != 0;
|
|
||||||
event.super = (key.mod & SDL_KMOD_GUI) != 0;
|
|
||||||
} break;
|
} break;
|
||||||
case SDL_EVENT_KEY_UP: {
|
case SDL_EVENT_KEY_UP: {
|
||||||
return;
|
return;
|
||||||
@@ -547,27 +567,38 @@ void ProcessSDLEvent(SDL_Event *input_event) {
|
|||||||
event.text = b.text;
|
event.text = b.text;
|
||||||
} break;
|
} break;
|
||||||
case SDL_EVENT_MOUSE_MOTION: {
|
case SDL_EVENT_MOUSE_MOTION: {
|
||||||
SDL_MouseMotionEvent &b = input_event->motion;
|
// SDL_MouseMotionEvent &b = input_event->motion;
|
||||||
event.xmouse = (int16_t)b.x;
|
// event.xmouse = (int16_t)b.x;
|
||||||
event.ymouse = (int16_t)b.y;
|
// event.ymouse = (int16_t)b.y;
|
||||||
event.mouse_move = 1;
|
// event.mouse = MOUSE_MOVE;
|
||||||
|
return;
|
||||||
} break;
|
} break;
|
||||||
case SDL_EVENT_MOUSE_BUTTON_DOWN: {
|
case SDL_EVENT_MOUSE_BUTTON_DOWN: {
|
||||||
SDL_MouseButtonEvent &b = input_event->button;
|
SDL_MouseButtonEvent &b = input_event->button;
|
||||||
event.xmouse = (int16_t)b.x;
|
event.xmouse = (int16_t)b.x;
|
||||||
event.ymouse = (int16_t)b.y;
|
event.ymouse = (int16_t)b.y;
|
||||||
if (b.button == SDL_BUTTON_LEFT) {
|
if (b.button == SDL_BUTTON_LEFT) {
|
||||||
event.mouse_left = 1;
|
event.mouse = MOUSE_LEFT;
|
||||||
if (b.clicks == 2) event.mouse_double_click = 1;
|
if (b.clicks == 2) {
|
||||||
|
event.mouse_double_click = 1;
|
||||||
|
}
|
||||||
} else if (b.button == SDL_BUTTON_RIGHT) {
|
} else if (b.button == SDL_BUTTON_RIGHT) {
|
||||||
event.mouse_right = 1;
|
event.mouse = MOUSE_RIGHT;
|
||||||
} else if (b.button == SDL_BUTTON_MIDDLE) {
|
} else if (b.button == SDL_BUTTON_MIDDLE) {
|
||||||
event.mouse_middle = 1;
|
event.mouse = MOUSE_MIDDLE;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case SDL_EVENT_MOUSE_BUTTON_UP: {
|
case SDL_EVENT_MOUSE_BUTTON_UP: {
|
||||||
SDL_MouseButtonEvent &b = input_event->button;
|
SDL_MouseButtonEvent &b = input_event->button;
|
||||||
return;
|
event.xmouse = (int16_t)b.x;
|
||||||
|
event.ymouse = (int16_t)b.y;
|
||||||
|
if (b.button == SDL_BUTTON_LEFT) {
|
||||||
|
event.mouse = MOUSE_LEFT_UP;
|
||||||
|
} else if (b.button == SDL_BUTTON_RIGHT) {
|
||||||
|
event.mouse = MOUSE_RIGHT_UP;
|
||||||
|
} else if (b.button == SDL_BUTTON_MIDDLE) {
|
||||||
|
event.mouse = MOUSE_MIDDLE_UP;
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case SDL_EVENT_MOUSE_WHEEL: {
|
case SDL_EVENT_MOUSE_WHEEL: {
|
||||||
SDL_MouseWheelEvent &b = input_event->wheel;
|
SDL_MouseWheelEvent &b = input_event->wheel;
|
||||||
@@ -578,13 +609,7 @@ void ProcessSDLEvent(SDL_Event *input_event) {
|
|||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool run_window_command = GlobalCommand(event);
|
Command(event);
|
||||||
if (run_window_command) {
|
|
||||||
Window *window = GetActiveWindow();
|
|
||||||
View *view = GetActiveView(window);
|
|
||||||
WindowCommand(event, window, view);
|
|
||||||
MergeCarets(view);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
@@ -682,9 +707,21 @@ int main()
|
|||||||
SDL_WaitEvent(&event);
|
SDL_WaitEvent(&event);
|
||||||
ProcessSDLEvent(&event);
|
ProcessSDLEvent(&event);
|
||||||
}
|
}
|
||||||
|
WaitForEvents = true;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
ProcessSDLEvent(&event);
|
ProcessSDLEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Event event = {};
|
||||||
|
float xmouse, ymouse;
|
||||||
|
SDL_GetMouseState(&xmouse, &ymouse);
|
||||||
|
event.xmouse = (int16_t)xmouse;
|
||||||
|
event.ymouse = (int16_t)ymouse;
|
||||||
|
event.mouse = MOUSE_MOVE;
|
||||||
|
Command(event);
|
||||||
|
}
|
||||||
|
|
||||||
ReplaceInfobarData();
|
ReplaceInfobarData();
|
||||||
|
|
||||||
For(order) {
|
For(order) {
|
||||||
@@ -744,13 +781,6 @@ int main()
|
|||||||
// HandleWindowBindings(&window);
|
// HandleWindowBindings(&window);
|
||||||
DrawWindow(window);
|
DrawWindow(window);
|
||||||
}
|
}
|
||||||
// {
|
|
||||||
// Scratch scratch;
|
|
||||||
// uint64_t ms = SDL_GetTicks();
|
|
||||||
// double time = (double)ms / 1000.0;
|
|
||||||
// String string = Format(scratch, "%d %f %f", (int)FrameID, time, (time / (double)FrameID));
|
|
||||||
// DrawString(&MainFont, ToString16(scratch, string), {0, 0}, {255, 0, 0, 255});
|
|
||||||
// }
|
|
||||||
EndFrameRender(ColorBackground);
|
EndFrameRender(ColorBackground);
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user