summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c18
-rw-r--r--node.c17
-rw-r--r--ted.h9
3 files changed, 32 insertions, 12 deletions
diff --git a/main.c b/main.c
index 02580f0..863c574 100644
--- a/main.c
+++ b/main.c
@@ -365,6 +365,8 @@ int main(int argc, char **argv) {
ted->cursor_arrow = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
ted->cursor_resize_h = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
ted->cursor_resize_v = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
+ ted->cursor_hand = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
+ ted->cursor_move = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
Uint32 time_at_last_frame = SDL_GetTicks();
@@ -724,6 +726,9 @@ int main(int argc, char **argv) {
}
#endif
+ if (ted->dragging_tab_node)
+ ted->cursor = ted->cursor_move;
+
SDL_SetWindowTitle(window, ted->window_title);
SDL_SetCursor(ted->cursor);
@@ -740,21 +745,20 @@ int main(int argc, char **argv) {
}
- build_stop(ted);
-
-
- if (ted->menu)
- menu_close(ted); // free any memory used by the current menu
-
- if (log) fclose(log);
SDL_FreeCursor(ted->cursor_arrow);
SDL_FreeCursor(ted->cursor_ibeam);
SDL_FreeCursor(ted->cursor_resize_h);
SDL_FreeCursor(ted->cursor_resize_v);
+ SDL_FreeCursor(ted->cursor_hand);
+ SDL_FreeCursor(ted->cursor_move);
SDL_GL_DeleteContext(glctx);
SDL_DestroyWindow(window);
SDL_Quit();
+ build_stop(ted);
+ if (ted->menu)
+ menu_close(ted); // free any memory used by the current menu
+ if (log) fclose(log);
find_close(ted);
tag_selector_close(ted);
for (u16 i = 0; i < TED_MAX_BUFFERS; ++i)
diff --git a/node.c b/node.c
index 0def1e4..b203529 100644
--- a/node.c
+++ b/node.c
@@ -96,6 +96,7 @@ static void node_join(Ted *ted, Node *node) {
}
static void node_close(Ted *ted, u16 node_idx) {
+ ted->dragging_tab_node = NULL;
ted->resizing_split = NULL;
assert(node_idx < TED_MAX_NODES);
@@ -146,6 +147,8 @@ static void node_close(Ted *ted, u16 node_idx) {
// close tab, WITHOUT checking for unsaved changes!
// returns true if the node is still open
static bool node_tab_close(Ted *ted, Node *node, u16 index) {
+ ted->dragging_tab_node = NULL;
+
u16 ntabs = (u16)arr_len(node->tabs);
assert(index < ntabs);
if (ntabs == 1) {
@@ -195,8 +198,13 @@ static void node_frame(Ted *ted, Node *node, Rect r) {
if (rect_contains_point(tab_bar_rect, click)) {
// click on tab to switch to it
u16 tab_index = (u16)((click.x - r.pos.x) / tab_width);
- ted->active_node = node;
- node_switch_to_tab(ted, node, tab_index);
+ if (tab_index >= 0 && tab_index < arr_len(node->tabs)) {
+ ted->active_node = node;
+ node_switch_to_tab(ted, node, tab_index);
+ ted->dragging_tab_node = node;
+ ted->dragging_tab_idx = tab_index;
+ ted->dragging_tab_origin = click;
+ }
}
}
for (u16 c = 0; c < ted->nmouse_clicks[SDL_BUTTON_MIDDLE]; ++c) {
@@ -229,6 +237,11 @@ static void node_frame(Ted *ted, Node *node, Rect r) {
char const *path = buffer_get_filename(buffer);
char const *filename = path_filename(path);
Rect tab_rect = rect(V2(r.pos.x + tab_width * i, r.pos.y), V2(tab_width, tab_bar_height));
+
+ if (node == ted->dragging_tab_node && i == ted->dragging_tab_idx) {
+ // make tab follow mouse
+ tab_rect.pos = v2_add(tab_rect.pos, v2_sub(ted->mouse_pos, ted->dragging_tab_origin));
+ }
// tab border
gl_geometry_rect_border(tab_rect, border_thickness, colors[COLOR_BORDER]);
diff --git a/ted.h b/ted.h
index f92425f..da79178 100644
--- a/ted.h
+++ b/ted.h
@@ -277,11 +277,14 @@ typedef struct Ted {
// used by menus to keep track of the scroll position so we can return to it.
v2d prev_active_buffer_scroll;
- SDL_Cursor *cursor_arrow, *cursor_ibeam, *cursor_resize_h, *cursor_resize_v;
+ SDL_Cursor *cursor_arrow, *cursor_ibeam, *cursor_resize_h, *cursor_resize_v, *cursor_hand, *cursor_move;
SDL_Cursor *cursor; // which cursor to use this frame
- // index of buffer whose tab user is dragging around, 0 for none.
- u16 dragging_tab;
+ // node containing tab user is dragging around, NULL if user is not dragging a tab
+ Node *dragging_tab_node;
+ // index in dragging_tab_node->tabs
+ u16 dragging_tab_idx;
+ v2 dragging_tab_origin; // where the tab is being dragged from (i.e. mouse pos at start of drag action)
// if not NULL, points to the node whose split the user is currently resizing.
Node *resizing_split;