diff --git a/code/custom/4coder_default_hooks.cpp b/code/custom/4coder_default_hooks.cpp index 7e73098d..9e7d306d 100644 --- a/code/custom/4coder_default_hooks.cpp +++ b/code/custom/4coder_default_hooks.cpp @@ -9,7 +9,8 @@ CUSTOM_DOC("Default command for responding to a startup event") { ProfileScope(app, "default startup"); User_Input input = get_current_input(app); - if (match_core_code(&input, CoreCode_Startup)){ + if (match_core_code(&input, CoreCode_Startup)) + { String_Const_u8_Array file_names = input.event.core.file_names; load_themes_default_folder(app); default_4coder_initialize(app, file_names); @@ -308,11 +309,16 @@ recursive_nest_highlight(Application_Links *app, Text_Layout_ID layout_id, Range recursive_nest_highlight(app, layout_id, range, &file->nest_array, 0); } -function void -default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, - Buffer_ID buffer, Text_Layout_ID text_layout_id, - Rect_f32 rect){ +function void default_render_buffer( + Application_Links *app, + View_ID view_id, + Face_ID face_id, + Buffer_ID buffer, + Text_Layout_ID text_layout_id, + Rect_f32 rect +){ ProfileScope(app, "render buffer"); + Scratch_Block scratch(app); View_ID active_view = get_active_view(app, Access_Always); b32 is_active_view = (active_view == view_id); @@ -328,14 +334,41 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, // NOTE(allen): Token colorizing - ARGB_Color color_default = fcolor_resolve(fcolor_id(defcolor_text_default)); + ARGB_Color color_default = fcolor_resolve(fcolor_id(defcolor_text_default)); ARGB_Color color_function = fcolor_resolve(fcolor_id(defcolor_function)); ARGB_Color color_operator = fcolor_resolve(fcolor_id(defcolor_operator)); ARGB_Color color_type = fcolor_resolve(fcolor_id(defcolor_type)); ARGB_Color color_macro = fcolor_resolve(fcolor_id(defcolor_macro)); + ARGB_Color color_back = fcolor_resolve(fcolor_id(defcolor_back)); + + ARGB_Color color_cur_token = color_default; Token_Array token_array = get_token_array_from_buffer(app, buffer); - if (token_array.tokens != 0){ + if (token_array.tokens != 0) + { + Token* cursor_token = token_from_pos(&token_array, view_get_cursor_pos(app, active_view)); + String_Const_u8 cursor_token_string = push_token_lexeme(app, scratch, buffer, cursor_token); + if (cursor_token->kind == TokenBaseKind_Identifier) + { + Code_Index_Note* note = code_index_note_from_string(cursor_token_string); + + if (note != 0) + { + switch (note->note_kind) + { + case CodeIndexNote_Function: color_cur_token = color_function; break; + case CodeIndexNote_Type: color_cur_token = color_type; break; + case CodeIndexNote_Macro: color_cur_token = color_macro; break; + //case CodeIndexNote_Global: color_cur_token = color_global; break; + //case CodeIndexNote_Enum: color_cur_token = color_enum; break; + } + } + } + + Rect_f32 cursor_tok_rect = text_layout_character_on_screen(app, text_layout_id, cursor_token->pos); + Vec2_f32 tok_rect_dim = V2f32(cursor_token->size*rect_width(cursor_tok_rect), 2.f); + cursor_tok_rect = Rf32_xy_wh(V2f32(cursor_tok_rect.x0, cursor_tok_rect.y1 - 2.f), tok_rect_dim); + draw_cpp_token_colors(app, text_layout_id, &token_array); // NOTE(allen): Scan for TODOs and NOTEs @@ -349,10 +382,9 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, } // NOTE(allen): Color functions - Scratch_Block scratch(app); Token_Iterator_Array it = token_iterator_pos(0, &token_array, visible_range.first); - it.count = Min(it.count, visible_range.one_past_last - visible_range.first); + it.count = Min(it.count, visible_range.one_past_last); for (;;){ if (!token_it_inc_non_whitespace(&it)){ break; @@ -373,6 +405,15 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, { String_Const_u8 lexeme = push_token_lexeme(app, scratch, buffer, token); Code_Index_Note *note = code_index_note_from_string(lexeme); + + // Underline tokens that match the identifier the cursor is on + if (string_match(lexeme, cursor_token_string)) + { + Rect_f32 cur_tok_rect = text_layout_character_on_screen(app, text_layout_id, token->pos); + cur_tok_rect = Rf32_xy_wh(V2f32(cur_tok_rect.x0, cur_tok_rect.y1 - 2.f), tok_rect_dim); + draw_rectangle(app, cur_tok_rect, 5.f, argb_color_blend(color_cur_token, 0.7f, color_back)); + } + if (note != 0) { switch (note->note_kind) diff --git a/project.4coder b/project.4coder index 4e6a4469..98607544 100644 --- a/project.4coder +++ b/project.4coder @@ -8,6 +8,7 @@ patterns = { "*.bat", "*.sh", "*.4coder", + "*.mm", }; blacklist_patterns = { ".*",