ded

Dramatic EDitor
Index Commits Files Refs README LICENSE
commit bcc9b8b5d9ded5823237c063015e52f298cb459f
parent df91d9ac064d646125f5c823f378bf5cdb377907
Author: nonvegan <pedromagalhaes_2000@hotmail.com>
Date:   Mon,  5 Jul 2021 11:07:03 +0100

Add basic mouse integration

Diffstat:
Msrc/main.c | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -436,6 +436,21 @@ int main(int argc, char **argv)
                 editor_insert_text_before_cursor(&editor, event.text.text);
             }
             break;
+
+            case SDL_MOUSEBUTTONDOWN: {
+                Vec2f mouse_click = vec2f((float) event.button.x, (float) event.button.y);
+                switch(event.button.button) { 
+                case SDL_BUTTON_LEFT: {
+                    Vec2f cursor_click = vec2f_add(mouse_click, vec2f_sub(camera_pos, vec2f_div(window_size(window), vec2fs(2.0f))));
+                    if(cursor_click.x > 0.0f && cursor_click.y > 0.0f) {
+                        editor.cursor_col = (size_t) floorf(cursor_click.x / ((float) FONT_CHAR_WIDTH * FONT_SCALE));
+                        editor.cursor_row = (size_t) floorf(cursor_click.y / ((float) FONT_CHAR_HEIGHT * FONT_SCALE));
+                    }
+                }
+                break;
+                }
+            }
+            break;
             }
         }