From 886c70100d927258378ffa216a1a53e742d88e1d Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 1 May 2020 12:28:36 -0700 Subject: [PATCH] Simplify fade range code; make it update with buffer edits --- custom/4coder_clipboard.cpp | 2 +- custom/4coder_default_framework.cpp | 50 ++++++++----------------- custom/4coder_default_framework.h | 5 +-- custom/4coder_default_hooks.cpp | 4 +- ship_files/changes.txt | 2 + ship_files/themes/theme-sunlight.4coder | 2 +- 6 files changed, 24 insertions(+), 41 deletions(-) diff --git a/custom/4coder_clipboard.cpp b/custom/4coder_clipboard.cpp index efb9caf3..713f75a6 100644 --- a/custom/4coder_clipboard.cpp +++ b/custom/4coder_clipboard.cpp @@ -251,7 +251,7 @@ CUSTOM_DOC("Paste multiple entries from the clipboard at once") view_set_cursor_and_preferred_x(app, view, seek_pos(range.max + insert_string.size)); ARGB_Color argb = fcolor_resolve(fcolor_id(defcolor_paste)); - view_post_fade(app, buffer, 0.667f, Ii64(range.max + 1, range.max + insert_string.size), argb); + buffer_post_fade(app, buffer, 0.667f, Ii64(range.max + 1, range.max + insert_string.size), argb); } else{ paste(app); diff --git a/custom/4coder_default_framework.cpp b/custom/4coder_default_framework.cpp index 8bfd637d..bae36421 100644 --- a/custom/4coder_default_framework.cpp +++ b/custom/4coder_default_framework.cpp @@ -717,15 +717,20 @@ buffer_post_fade(Application_Links *app, Buffer_ID buffer_id, f32 seconds, Range } function void -view_post_fade(Application_Links *app, View_ID view_id, f32 seconds, Range_i64 range, ARGB_Color color){ - Fade_Range *fade_range = alloc_fade_range(); - sll_queue_push(view_fade_ranges.first, view_fade_ranges.last, fade_range); - view_fade_ranges.count += 1; - fade_range->view_id = view_id; - fade_range->t = seconds; - fade_range->full_t = seconds; - fade_range->range = range; - fade_range->color= color; +buffer_shift_fade_ranges(Buffer_ID buffer_id, i64 shift_after_p, i64 shift_amount){ + for (Fade_Range *node = buffer_fade_ranges.first; + node != 0; + node = node->next){ + if (node->buffer_id == buffer_id){ + if (node->range.min >= shift_after_p){ + node->range.min += shift_amount; + node->range.max += shift_amount; + } + else if (node->range.max >= shift_after_p){ + node->range.max += shift_amount; + } + } + } } function b32 @@ -742,29 +747,14 @@ tick_all_fade_ranges(f32 t){ } else{ prev_next = &node->next; + buffer_fade_ranges.last = node; } } - - prev_next = &view_fade_ranges.first; - for (Fade_Range *node = view_fade_ranges.first, *next = 0; - node != 0; - node = next){ - next = node->next; - node->t -= t; - if (node->t <= 0.f){ - *prev_next = next; - view_fade_ranges.count -= 1; - } - else{ - prev_next = &node->next; - } - } - return(buffer_fade_ranges.count > 0 || view_fade_ranges.count > 0); } function void -paint_fade_ranges(Application_Links *app, Text_Layout_ID layout, Buffer_ID buffer, View_ID view){ +paint_fade_ranges(Application_Links *app, Text_Layout_ID layout, Buffer_ID buffer){ for (Fade_Range *node = buffer_fade_ranges.first; node != 0; node = node->next){ @@ -772,14 +762,6 @@ paint_fade_ranges(Application_Links *app, Text_Layout_ID layout, Buffer_ID buffe paint_text_color_blend(app, layout, node->range, node->color, node->t/node->full_t); } } - - for (Fade_Range *node = view_fade_ranges.first; - node != 0; - node = node->next){ - if (node->view_id == view){ - paint_text_color_blend(app, layout, node->range, node->color, node->t/node->full_t); - } - } } //////////////////////////////// diff --git a/custom/4coder_default_framework.h b/custom/4coder_default_framework.h index b1daa3e2..555139da 100644 --- a/custom/4coder_default_framework.h +++ b/custom/4coder_default_framework.h @@ -98,10 +98,7 @@ struct Buffer_Modified_Set{ struct Fade_Range{ Fade_Range *next; - union{ - Buffer_ID buffer_id; - View_ID view_id; - }; + Buffer_ID buffer_id; f32 t; f32 full_t; Range_i64 range; diff --git a/custom/4coder_default_hooks.cpp b/custom/4coder_default_hooks.cpp index 7ef1d4b6..2de10dc6 100644 --- a/custom/4coder_default_hooks.cpp +++ b/custom/4coder_default_hooks.cpp @@ -378,7 +378,7 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, } // NOTE(allen): Fade ranges - paint_fade_ranges(app, text_layout_id, buffer, view_id); + paint_fade_ranges(app, text_layout_id, buffer); // NOTE(allen): put the actual text on the actual screen draw_text_layout_default(app, text_layout_id); @@ -919,6 +919,8 @@ BUFFER_EDIT_RANGE_SIG(default_buffer_edit_range){ Range_i64 old_range = Ii64(new_range.first, new_range.first + original_size); + buffer_shift_fade_ranges(buffer_id, old_range.max, (new_range.max - old_range.max)); + { code_index_lock(); Code_Index_File *file = code_index_get_file(buffer_id); diff --git a/ship_files/changes.txt b/ship_files/changes.txt index ede62bd8..912bdb54 100644 --- a/ship_files/changes.txt +++ b/ship_files/changes.txt @@ -12,6 +12,8 @@ + Fix: no crash when a project file .cmd is not the right type + Fix: windows layer now generates layout independent key stroke events + Fix: notepad like mode scrolling does not snap mark to cursor + + Fix: special case colors from the theme override general case colors + + Fix: Paste fade range is updated with buffer edits 4.1.4 + MAJOR: The clipboard history is now a fully custom layer implemented system. Users maintaining a customization layer should try to update their call sites to the old clipboard API. #define FCODER_TRANSITION_TO 4001004 to disable the transitional function wrappers when you are ready to make the transition. diff --git a/ship_files/themes/theme-sunlight.4coder b/ship_files/themes/theme-sunlight.4coder index e6cf3a2e..780ac19b 100644 --- a/ship_files/themes/theme-sunlight.4coder +++ b/ship_files/themes/theme-sunlight.4coder @@ -18,7 +18,7 @@ defcolor_comment_pop = {0xFF00C030, 0xFFF00000}; defcolor_keyword = 0xFF002255; defcolor_str_constant = 0xFFE820E0; defcolor_char_constant = defcolor_str_constant; -defcolor_int_constant = 0xFF20E8E0; +defcolor_int_constant = 0xFF109810; defcolor_float_constant = defcolor_int_constant; defcolor_bool_constant = defcolor_int_constant; defcolor_include = 0xFFF010F0;