summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-25 14:30:27 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-25 14:30:27 -0500
commit6d77e94b652ab4b8070b5acf1c6febfe77fc41c3 (patch)
tree371459fb5c1eb323959c365f8b39fe5a53631681
parent047764ebab345a2bcb3a856c1f1956e849f52354 (diff)
change cursor
-rw-r--r--buffer.c7
-rw-r--r--main.c13
-rw-r--r--ted.h5
3 files changed, 23 insertions, 2 deletions
diff --git a/buffer.c b/buffer.c
index 0c226ea..c14389b 100644
--- a/buffer.c
+++ b/buffer.c
@@ -2072,7 +2072,7 @@ void buffer_render(TextBuffer *buffer, Rect r) {
rect_coords(r, &x1, &y1, &x2, &y2);
// Correct the scroll, because the window size might have changed
buffer_correct_scroll(buffer);
-
+
Font *font = buffer_font(buffer);
u32 nlines = buffer->nlines;
Line *lines = buffer->lines;
@@ -2123,6 +2123,11 @@ void buffer_render(TextBuffer *buffer, Rect r) {
buffer->x1 = x1; buffer->y1 = y1; buffer->x2 = x2; buffer->y2 = y2;
+ // change cursor to ibeam when it's hovering over the buffer
+ if ((!ted->menu || buffer == &ted->line_buffer) && rect_contains_point(rect4(x1, y1, x2, y2), ted->mouse_pos)) {
+ ted->cursor = ted->cursor_ibeam;
+ }
+
if (buffer->center_cursor_next_frame) {
buffer_center_cursor(buffer);
diff --git a/main.c b/main.c
index a370a45..70200f2 100644
--- a/main.c
+++ b/main.c
@@ -360,6 +360,11 @@ int main(int argc, char **argv) {
u32 *colors = settings->colors; (void)colors;
+ ted->cursor_ibeam = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
+ 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);
+
Uint32 time_at_last_frame = SDL_GetTicks();
while (!ted->quit) {
@@ -521,6 +526,9 @@ int main(int argc, char **argv) {
}
}
+ // default to arrow cursor
+ ted->cursor = ted->cursor_arrow;
+
if (!(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_LMASK)) {
// originally this was done on SDL_MOUSEBUTTONUP events but for some reason
// I was getting a bunch of those even when I was holding down the mouse.
@@ -713,6 +721,7 @@ int main(int argc, char **argv) {
#endif
SDL_SetWindowTitle(window, ted->window_title);
+ SDL_SetCursor(ted->cursor);
SDL_GL_SwapWindow(window);
PROFILE_TIME(frame_end);
@@ -735,6 +744,10 @@ int main(int argc, char **argv) {
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_GL_DeleteContext(glctx);
SDL_DestroyWindow(window);
SDL_Quit();
diff --git a/ted.h b/ted.h
index 3c31ab0..cdfa433 100644
--- a/ted.h
+++ b/ted.h
@@ -274,7 +274,10 @@ 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; // which cursor to use this frame
+
char **tag_selector_entries; // an array of all tags (see tag_selector_open)
// points to a selector if any is open, otherwise NULL.