2017-01-29 00:03:23 +00:00
|
|
|
/*
|
|
|
|
4coder_default_hooks.cpp - Sets up the hooks for the default framework.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2017-06-12 17:40:54 +00:00
|
|
|
#include "languages/4coder_language_cpp.h"
|
2017-05-21 01:22:20 +00:00
|
|
|
#include "languages/4coder_language_rust.h"
|
|
|
|
#include "languages/4coder_language_cs.h"
|
|
|
|
#include "languages/4coder_language_java.h"
|
|
|
|
|
2017-11-08 18:24:30 +00:00
|
|
|
CUSTOM_COMMAND_SIG(set_bindings_choose);
|
|
|
|
CUSTOM_COMMAND_SIG(set_bindings_default);
|
|
|
|
CUSTOM_COMMAND_SIG(set_bindings_mac_default);
|
|
|
|
|
|
|
|
static Named_Mapping named_maps_values[] = {
|
2019-06-01 23:58:28 +00:00
|
|
|
{string_u8_litexpr("mac-default") , set_bindings_mac_default },
|
|
|
|
{string_u8_litexpr("choose") , set_bindings_choose },
|
|
|
|
{string_u8_litexpr("default") , set_bindings_default },
|
2017-11-08 18:24:30 +00:00
|
|
|
};
|
|
|
|
|
2017-06-23 23:07:18 +00:00
|
|
|
START_HOOK_SIG(default_start){
|
2017-11-08 18:24:30 +00:00
|
|
|
named_maps = named_maps_values;
|
|
|
|
named_map_count = ArrayCount(named_maps_values);
|
|
|
|
|
2019-02-27 05:49:35 +00:00
|
|
|
default_4coder_initialize(app, files, file_count);
|
2017-06-23 23:07:18 +00:00
|
|
|
default_4coder_side_by_side_panels(app, files, file_count);
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2019-02-24 07:22:16 +00:00
|
|
|
#if 0
|
|
|
|
default_4coder_one_panel(app, files, file_count);
|
|
|
|
|
|
|
|
View_ID left_view = 0;
|
|
|
|
|
|
|
|
Panel_ID left = 0;
|
|
|
|
Panel_ID right = 0;
|
|
|
|
Panel_ID bottom = 0;
|
|
|
|
Panel_ID header = 0;
|
|
|
|
|
|
|
|
get_active_view(app, AccessAll, &left_view);
|
|
|
|
|
|
|
|
view_get_panel(app, left_view, &left);
|
|
|
|
|
|
|
|
Panel_ID h_split_main = 0;
|
|
|
|
Panel_ID h_split_minor = 0;
|
|
|
|
|
|
|
|
panel_create_split(app, left , ViewSplit_Bottom, &bottom, &h_split_main);
|
|
|
|
panel_create_split(app, bottom, ViewSplit_Top , &header, &h_split_minor);
|
|
|
|
panel_create_split(app, left , ViewSplit_Right , &right, 0);
|
|
|
|
|
|
|
|
i32_Rect header_margin = {};
|
|
|
|
i32_Rect bottom_margin = {};
|
|
|
|
panel_get_margin(app, header, &header_margin);
|
|
|
|
panel_get_margin(app, header, &bottom_margin);
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 header_vertical_pixels = header_margin.y0 + header_margin.y1;
|
|
|
|
i32 margin_vertical_pixels = header_vertical_pixels + bottom_margin.y0 + bottom_margin.y1;
|
2019-02-24 07:22:16 +00:00
|
|
|
|
2019-04-06 21:13:49 +00:00
|
|
|
|
|
|
|
Face_ID face_id = 0;
|
|
|
|
get_face_id(app, 0, &face_id);
|
|
|
|
Face_Metrics metrics = {};
|
|
|
|
get_face_metrics(app, face_id, &metrics);
|
|
|
|
f32 line_height = metrics.line_height;
|
|
|
|
panel_set_split(app, h_split_main , PanelSplitKind_FixedPixels_BR, line_height*6.f + margin_vertical_pixels);
|
|
|
|
panel_set_split(app, h_split_minor, PanelSplitKind_FixedPixels_TL, line_height + header_vertical_pixels);
|
2019-02-24 07:22:16 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-12 00:53:02 +00:00
|
|
|
if (global_config.automatically_load_project){
|
2017-03-27 22:36:42 +00:00
|
|
|
load_project(app);
|
|
|
|
}
|
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
// no meaning for return
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen|a4.0.9): All command calls can now go through this hook
|
|
|
|
// If this hook is not implemented a default behavior of calling the
|
|
|
|
// command is used. It is important to note that paste_next does not
|
|
|
|
// work without this hook.
|
|
|
|
// NOTE(allen|a4.0.10): As of this version the word_complete command
|
|
|
|
// also relies on this particular command caller hook.
|
|
|
|
COMMAND_CALLER_HOOK(default_command_caller){
|
2019-04-06 21:13:49 +00:00
|
|
|
View_ID view = 0;
|
|
|
|
get_active_view(app, AccessAll, &view);
|
2019-06-01 23:58:28 +00:00
|
|
|
Managed_Scope scope = 0;
|
|
|
|
view_get_managed_scope(app, view, &scope);
|
2018-09-07 22:39:33 +00:00
|
|
|
managed_variable_set(app, scope, view_next_rewrite_loc, 0);
|
2018-09-30 12:14:47 +00:00
|
|
|
if (fcoder_mode == FCoderMode_NotepadLike){
|
2019-04-06 21:13:49 +00:00
|
|
|
View_ID view_it = 0;
|
|
|
|
for (get_view_next(app, 0, AccessAll, &view_it);
|
|
|
|
view_it != 0;
|
|
|
|
get_view_next(app, view_it, AccessAll, &view_it)){
|
2019-06-01 23:58:28 +00:00
|
|
|
Managed_Scope scope_it = 0;
|
|
|
|
view_get_managed_scope(app, view_it, &scope_it);
|
2018-10-06 01:42:56 +00:00
|
|
|
managed_variable_set(app, scope_it, view_snap_mark_to_cursor, true);
|
|
|
|
}
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
2018-10-06 01:42:56 +00:00
|
|
|
|
2019-02-27 05:49:35 +00:00
|
|
|
cmd.command(app);
|
2018-10-06 01:42:56 +00:00
|
|
|
|
2019-02-27 05:49:35 +00:00
|
|
|
u64 next_rewrite = 0;
|
2018-09-07 22:39:33 +00:00
|
|
|
managed_variable_get(app, scope, view_next_rewrite_loc, &next_rewrite);
|
|
|
|
managed_variable_set(app, scope, view_rewrite_loc, next_rewrite);
|
2018-09-30 12:14:47 +00:00
|
|
|
if (fcoder_mode == FCoderMode_NotepadLike){
|
2019-04-06 21:13:49 +00:00
|
|
|
View_ID view_it = 0;
|
|
|
|
for (get_view_next(app, 0, AccessAll, &view_it);
|
|
|
|
view_it != 0;
|
|
|
|
get_view_next(app, view_it, AccessAll, &view_it)){
|
2019-06-01 23:58:28 +00:00
|
|
|
Managed_Scope scope_it = 0;
|
|
|
|
view_get_managed_scope(app, view_it, &scope_it);
|
2019-02-27 05:49:35 +00:00
|
|
|
u64 val = 0;
|
2018-10-06 01:42:56 +00:00
|
|
|
if (managed_variable_get(app, scope_it, view_snap_mark_to_cursor, &val)){
|
|
|
|
if (val != 0){
|
2019-04-06 21:13:49 +00:00
|
|
|
i32 pos = 0;
|
|
|
|
view_get_cursor_pos(app, view_it, &pos);
|
|
|
|
view_set_mark(app, view_it, seek_pos(pos));
|
2018-10-06 01:42:56 +00:00
|
|
|
}
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-06 01:42:56 +00:00
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2018-09-30 12:14:47 +00:00
|
|
|
struct Highlight_Record{
|
2019-06-01 23:58:28 +00:00
|
|
|
Highlight_Record *next;
|
|
|
|
Range range;
|
2018-09-30 12:14:47 +00:00
|
|
|
int_color color;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2019-02-26 23:08:42 +00:00
|
|
|
sort_highlight_record(Highlight_Record *records, i32 first, i32 one_past_last){
|
2018-09-30 12:14:47 +00:00
|
|
|
if (first + 1 < one_past_last){
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 pivot_index = one_past_last - 1;
|
2018-09-30 12:14:47 +00:00
|
|
|
int_color pivot_color = records[pivot_index].color;
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 j = first;
|
|
|
|
for (i32 i = first; i < pivot_index; i += 1){
|
2018-09-30 12:14:47 +00:00
|
|
|
int_color color = records[i].color;
|
|
|
|
if (color < pivot_color){
|
|
|
|
Swap(Highlight_Record, records[i], records[j]);
|
|
|
|
j += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Swap(Highlight_Record, records[pivot_index], records[j]);
|
|
|
|
pivot_index = j;
|
|
|
|
|
|
|
|
sort_highlight_record(records, first, pivot_index);
|
|
|
|
sort_highlight_record(records, pivot_index + 1, one_past_last);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Range_Array
|
2019-06-01 23:58:28 +00:00
|
|
|
get_enclosure_ranges(Application_Links *app, Arena *arena, Buffer_ID buffer, i32 pos, u32 flags){
|
2018-11-20 08:18:54 +00:00
|
|
|
Range_Array array = {};
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 max = 100;
|
|
|
|
array.ranges = push_array(arena, Range, max);
|
2018-09-30 12:14:47 +00:00
|
|
|
for (;;){
|
2018-11-20 08:18:54 +00:00
|
|
|
Range range = {};
|
2018-09-30 12:14:47 +00:00
|
|
|
if (find_scope_range(app, buffer, pos, &range, flags)){
|
2019-06-01 23:58:28 +00:00
|
|
|
array.ranges[array.count] = range;
|
|
|
|
array.count += 1;
|
2018-09-30 12:14:47 +00:00
|
|
|
pos = range.first;
|
2019-06-01 23:58:28 +00:00
|
|
|
if (array.count >= max){
|
|
|
|
break;
|
|
|
|
}
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(array);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-01 23:58:28 +00:00
|
|
|
mark_enclosures(Application_Links *app, Managed_Scope render_scope, Buffer_ID buffer, i32 pos, u32 flags,
|
2019-04-04 08:25:16 +00:00
|
|
|
Marker_Visual_Type type, int_color *back_colors, int_color *fore_colors, i32 color_count){
|
2019-06-01 23:58:28 +00:00
|
|
|
Arena *scratch = context_get_arena(app);
|
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
2019-02-25 23:42:13 +00:00
|
|
|
Range_Array ranges = get_enclosure_ranges(app, scratch, buffer, pos, flags);
|
2018-09-30 12:14:47 +00:00
|
|
|
|
|
|
|
if (ranges.count > 0){
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 marker_count = ranges.count*2;
|
2018-09-30 12:14:47 +00:00
|
|
|
Marker *markers = push_array(scratch, Marker, marker_count);
|
|
|
|
Marker *marker = markers;
|
|
|
|
Range *range = ranges.ranges;
|
2019-02-26 23:08:42 +00:00
|
|
|
for (i32 i = 0;
|
2018-09-30 12:14:47 +00:00
|
|
|
i < ranges.count;
|
|
|
|
i += 1, range += 1, marker += 2){
|
|
|
|
marker[0].pos = range->first;
|
|
|
|
marker[1].pos = range->one_past_last - 1;
|
|
|
|
}
|
2019-04-04 08:25:16 +00:00
|
|
|
Managed_Object o = alloc_buffer_markers_on_buffer(app, buffer, marker_count, &render_scope);
|
2018-09-30 12:14:47 +00:00
|
|
|
managed_object_store_data(app, o, 0, marker_count, markers);
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Marker_Visual_Take_Rule take_rule = {};
|
2018-09-30 12:14:47 +00:00
|
|
|
take_rule.take_count_per_step = 2;
|
|
|
|
take_rule.step_stride_in_marker_count = 8;
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 first_color_index = (ranges.count - 1)%color_count;
|
|
|
|
for (i32 i = 0, color_index = first_color_index;
|
2018-09-30 12:14:47 +00:00
|
|
|
i < color_count;
|
|
|
|
i += 1){
|
2018-10-01 19:32:28 +00:00
|
|
|
Marker_Visual visual = create_marker_visual(app, o);
|
2019-02-25 23:42:13 +00:00
|
|
|
int_color back = 0;
|
|
|
|
int_color fore = 0;
|
2018-09-30 12:14:47 +00:00
|
|
|
if (back_colors != 0){
|
|
|
|
back = back_colors[color_index];
|
|
|
|
}
|
|
|
|
if (fore_colors != 0){
|
|
|
|
fore = fore_colors[color_index];
|
|
|
|
}
|
2018-10-01 19:32:28 +00:00
|
|
|
marker_visual_set_effect(app, visual, type, back, fore, 0);
|
2018-09-30 12:14:47 +00:00
|
|
|
take_rule.first_index = i*2;
|
2018-10-01 19:32:28 +00:00
|
|
|
marker_visual_set_take_rule(app, visual, take_rule);
|
2018-09-30 12:14:47 +00:00
|
|
|
color_index = color_index - 1;
|
|
|
|
if (color_index < 0){
|
|
|
|
color_index += color_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
end_temp(temp);
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
static argb_color default_colors[Stag_COUNT] = {};
|
|
|
|
|
|
|
|
MODIFY_COLOR_TABLE_SIG(default_modify_color_table){
|
|
|
|
if (default_colors[Stag_NOOP] == 0){
|
|
|
|
default_colors[Stag_NOOP] = 0xFFFF00FF;
|
|
|
|
|
|
|
|
default_colors[Stag_Back] = 0xFF0C0C0C;
|
|
|
|
default_colors[Stag_Margin] = 0xFF181818;
|
|
|
|
default_colors[Stag_Margin_Hover] = 0xFF252525;
|
|
|
|
default_colors[Stag_Margin_Active] = 0xFF323232;
|
|
|
|
default_colors[Stag_List_Item] = default_colors[Stag_Margin];
|
|
|
|
default_colors[Stag_List_Item_Hover] = default_colors[Stag_Margin_Hover];
|
|
|
|
default_colors[Stag_List_Item_Active] = default_colors[Stag_Margin_Active];
|
|
|
|
default_colors[Stag_Cursor] = 0xFF00EE00;
|
|
|
|
default_colors[Stag_Highlight] = 0xFFDDEE00;
|
|
|
|
default_colors[Stag_Mark] = 0xFF494949;
|
|
|
|
default_colors[Stag_Default] = 0xFF90B080;
|
|
|
|
default_colors[Stag_At_Cursor] = default_colors[Stag_Back];
|
|
|
|
default_colors[Stag_Highlight_Cursor_Line] = 0xFF1E1E1E;
|
|
|
|
default_colors[Stag_At_Highlight] = 0xFFFF44DD;
|
|
|
|
default_colors[Stag_Comment] = 0xFF2090F0;
|
|
|
|
default_colors[Stag_Keyword] = 0xFFD08F20;
|
|
|
|
default_colors[Stag_Str_Constant] = 0xFF50FF30;
|
|
|
|
default_colors[Stag_Char_Constant] = default_colors[Stag_Str_Constant];
|
|
|
|
default_colors[Stag_Int_Constant] = default_colors[Stag_Str_Constant];
|
|
|
|
default_colors[Stag_Float_Constant] = default_colors[Stag_Str_Constant];
|
|
|
|
default_colors[Stag_Bool_Constant] = default_colors[Stag_Str_Constant];
|
|
|
|
default_colors[Stag_Include] = default_colors[Stag_Str_Constant];
|
|
|
|
default_colors[Stag_Preproc] = default_colors[Stag_Default];
|
|
|
|
default_colors[Stag_Special_Character] = 0xFFFF0000;
|
|
|
|
default_colors[Stag_Ghost_Character] = 0xFF4E5E46;
|
|
|
|
|
|
|
|
default_colors[Stag_Paste] = 0xFFDDEE00;
|
|
|
|
default_colors[Stag_Undo] = 0xFF00DDEE;
|
|
|
|
|
|
|
|
default_colors[Stag_Highlight_Junk] = 0xFF3A0000;
|
|
|
|
default_colors[Stag_Highlight_White] = 0xFF003A3A;
|
|
|
|
|
|
|
|
default_colors[Stag_Bar] = 0xFF888888;
|
|
|
|
default_colors[Stag_Base] = 0xFF000000;
|
|
|
|
default_colors[Stag_Pop1] = 0xFF3C57DC;
|
|
|
|
default_colors[Stag_Pop2] = 0xFFFF0000;
|
|
|
|
|
|
|
|
default_colors[Stag_Back_Cycle_1] = 0x10A00000;
|
|
|
|
default_colors[Stag_Back_Cycle_2] = 0x0C00A000;
|
|
|
|
default_colors[Stag_Back_Cycle_3] = 0x0C0000A0;
|
|
|
|
default_colors[Stag_Back_Cycle_4] = 0x0CA0A000;
|
|
|
|
default_colors[Stag_Text_Cycle_1] = 0xFFA00000;
|
|
|
|
default_colors[Stag_Text_Cycle_2] = 0xFF00A000;
|
|
|
|
default_colors[Stag_Text_Cycle_3] = 0xFF0030B0;
|
|
|
|
default_colors[Stag_Text_Cycle_4] = 0xFFA0A000;
|
2019-02-27 21:14:25 +00:00
|
|
|
|
|
|
|
default_colors[Stag_Line_Numbers_Back] = 0xFF101010;
|
|
|
|
default_colors[Stag_Line_Numbers_Text] = 0xFF404040;
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Color_Table color_table = {};
|
|
|
|
color_table.vals = default_colors;
|
|
|
|
color_table.count = ArrayCount(default_colors);
|
|
|
|
return(color_table);
|
|
|
|
}
|
|
|
|
|
2019-02-27 05:49:35 +00:00
|
|
|
GET_VIEW_BUFFER_REGION_SIG(default_view_buffer_region){
|
2019-04-06 21:13:49 +00:00
|
|
|
Buffer_ID buffer = 0;
|
|
|
|
view_get_buffer(app, view_id, AccessAll, &buffer);
|
|
|
|
Face_ID face_id = 0;
|
|
|
|
get_face_id(app, buffer, &face_id);
|
|
|
|
Face_Metrics metrics = {};
|
|
|
|
get_face_metrics(app, face_id, &metrics);
|
|
|
|
i32 line_height = ceil32(metrics.line_height);
|
2019-02-27 05:49:35 +00:00
|
|
|
|
|
|
|
// file bar
|
|
|
|
{
|
|
|
|
b32 showing_file_bar = false;
|
|
|
|
if (view_get_setting(app, view_id, ViewSetting_ShowFileBar, &showing_file_bar)){
|
|
|
|
if (showing_file_bar){
|
|
|
|
sub_region.y0 += line_height + 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// query bar
|
|
|
|
{
|
|
|
|
Query_Bar *space[32];
|
|
|
|
Query_Bar_Ptr_Array query_bars = {};
|
|
|
|
query_bars.ptrs = space;
|
|
|
|
if (get_active_query_bars(app, view_id, ArrayCount(space), &query_bars)){
|
|
|
|
i32 widget_height = (line_height + 2)*query_bars.count;
|
|
|
|
sub_region.y0 += widget_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 21:14:25 +00:00
|
|
|
// line number margins
|
|
|
|
if (global_config.show_line_number_margins){
|
2019-04-04 08:25:16 +00:00
|
|
|
i32 line_count = 0;
|
|
|
|
buffer_get_line_count(app, buffer, &line_count);
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 line_count_digit_count = (i32)digit_count_from_integer(line_count, 10);
|
2019-04-04 08:25:16 +00:00
|
|
|
i32 margin_width = ceil32((f32)line_count_digit_count*metrics.typical_character_width);
|
2019-02-27 21:14:25 +00:00
|
|
|
sub_region.x0 += margin_width + 2;
|
|
|
|
}
|
|
|
|
|
2019-02-27 05:49:35 +00:00
|
|
|
return(sub_region);
|
|
|
|
}
|
|
|
|
|
2019-04-01 00:36:09 +00:00
|
|
|
static Buffer_Point
|
2019-03-31 20:56:00 +00:00
|
|
|
buffer_position_from_scroll_position(Application_Links *app, View_ID view_id, Vec2 scroll){
|
2019-04-01 04:24:13 +00:00
|
|
|
Full_Cursor cursor = {};
|
|
|
|
view_compute_cursor(app, view_id, seek_wrapped_xy(0.f, scroll.y, false), &cursor);
|
|
|
|
view_compute_cursor(app, view_id, seek_line_char(cursor.line, 1), &cursor);
|
2019-04-01 00:36:09 +00:00
|
|
|
Buffer_Point result = {};
|
2019-04-01 04:24:13 +00:00
|
|
|
result.line_number = cursor.line;
|
2019-03-31 20:56:00 +00:00
|
|
|
result.pixel_shift.x = scroll.x;
|
2019-04-01 04:24:13 +00:00
|
|
|
result.pixel_shift.y = scroll.y - cursor.wrapped_y;
|
2019-03-31 20:56:00 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-04-01 06:40:24 +00:00
|
|
|
static i32
|
|
|
|
abs_position_from_buffer_point(Application_Links *app, View_ID view_id, Buffer_Point buffer_point){
|
|
|
|
Full_Cursor cursor = {};
|
|
|
|
view_compute_cursor(app, view_id, seek_line_char(buffer_point.line_number, 0), &cursor);
|
|
|
|
view_compute_cursor(app, view_id, seek_wrapped_xy(buffer_point.pixel_shift.x,
|
|
|
|
buffer_point.pixel_shift.y + cursor.wrapped_y, false),
|
|
|
|
&cursor);
|
|
|
|
return(cursor.pos);
|
|
|
|
}
|
|
|
|
|
2019-02-26 19:59:57 +00:00
|
|
|
static void
|
2019-03-31 18:55:26 +00:00
|
|
|
default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View_ID view_id, Rect_i32 view_inner_rect){
|
|
|
|
Buffer_ID buffer_id = 0;
|
|
|
|
view_get_buffer(app, view_id, AccessAll, &buffer_id);
|
|
|
|
|
2019-04-06 21:13:49 +00:00
|
|
|
Face_ID face_id = 0;
|
|
|
|
get_face_id(app, buffer_id, &face_id);
|
|
|
|
Face_Metrics face_metrics = {};
|
|
|
|
get_face_metrics(app, face_id, &face_metrics);
|
|
|
|
|
|
|
|
f32 line_height = face_metrics.line_height;
|
|
|
|
|
2019-03-31 18:55:26 +00:00
|
|
|
Rect_i32 sub_region = i32R(0, 0, rect_width(view_inner_rect), rect_height(view_inner_rect));
|
|
|
|
sub_region = default_view_buffer_region(app, view_id, sub_region);
|
2019-04-01 06:40:24 +00:00
|
|
|
Rect_f32 buffer_rect = {};
|
|
|
|
buffer_rect.p0 = V2(view_inner_rect.p0 + sub_region.p0);
|
|
|
|
buffer_rect.p1 = V2(view_inner_rect.p0 + sub_region.p1);
|
|
|
|
buffer_rect = intersection_of(buffer_rect, f32R(view_inner_rect));
|
2019-03-31 18:55:26 +00:00
|
|
|
|
2019-03-31 20:56:00 +00:00
|
|
|
GUI_Scroll_Vars scroll = {};
|
|
|
|
view_get_scroll_vars(app, view_id, &scroll);
|
|
|
|
|
2019-04-01 00:36:09 +00:00
|
|
|
Buffer_Point buffer_point = buffer_position_from_scroll_position(app, view_id, scroll.scroll_p);
|
|
|
|
Text_Layout_ID text_layout_id = 0;
|
2019-04-01 06:40:24 +00:00
|
|
|
|
|
|
|
compute_render_layout(app, view_id, buffer_id, buffer_rect.p0, rect_dim(buffer_rect), buffer_point,
|
|
|
|
max_i32, &text_layout_id);
|
|
|
|
Range on_screen_range = {};
|
2019-04-02 16:23:07 +00:00
|
|
|
text_layout_get_on_screen_range(app, text_layout_id, &on_screen_range);
|
|
|
|
text_layout_free(app, text_layout_id);
|
2019-03-31 18:55:26 +00:00
|
|
|
|
2019-04-06 21:13:49 +00:00
|
|
|
View_ID active_view = 0;
|
|
|
|
get_active_view(app, AccessAll, &active_view);
|
|
|
|
b32 is_active_view = (active_view == view_id);
|
2019-02-27 05:49:35 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Arena *scratch = context_get_arena(app);
|
|
|
|
Temp_Memory major_temp = begin_temp(scratch);
|
2019-03-30 21:51:56 +00:00
|
|
|
|
2018-09-27 05:01:01 +00:00
|
|
|
static Managed_Scope render_scope = 0;
|
|
|
|
if (render_scope == 0){
|
|
|
|
render_scope = create_user_managed_scope(app);
|
|
|
|
}
|
2018-09-22 23:45:24 +00:00
|
|
|
|
2019-02-27 05:49:35 +00:00
|
|
|
{
|
2019-04-06 21:13:49 +00:00
|
|
|
Rect_f32 r_cursor = {};
|
|
|
|
view_get_screen_rect(app, view_id, &r_cursor);
|
|
|
|
r_cursor.p1 -= r_cursor.p0;
|
|
|
|
r_cursor.p0 = V2(0.f,0.f);
|
2019-02-27 05:49:35 +00:00
|
|
|
|
|
|
|
// NOTE(allen): Filebar
|
|
|
|
{
|
|
|
|
b32 showing_file_bar = false;
|
2019-03-31 18:55:26 +00:00
|
|
|
if (view_get_setting(app, view_id, ViewSetting_ShowFileBar, &showing_file_bar)){
|
2019-02-27 05:49:35 +00:00
|
|
|
if (showing_file_bar){
|
2019-02-27 21:14:25 +00:00
|
|
|
Rect_f32 bar = r_cursor;
|
2019-02-27 05:49:35 +00:00
|
|
|
bar.y1 = bar.y0 + line_height + 2.f;
|
2019-02-27 21:14:25 +00:00
|
|
|
r_cursor.y0 = bar.y1;
|
2019-02-27 05:49:35 +00:00
|
|
|
|
|
|
|
draw_rectangle(app, bar, Stag_Bar);
|
|
|
|
|
|
|
|
Fancy_Color base_color = fancy_id(Stag_Base);
|
|
|
|
Fancy_Color pop2_color = fancy_id(Stag_Pop2);
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
2019-03-30 20:17:10 +00:00
|
|
|
|
2019-04-06 21:13:49 +00:00
|
|
|
i32 cursor_position = 0;
|
|
|
|
view_get_cursor_pos(app, view_id, &cursor_position);
|
|
|
|
Full_Cursor cursor = {};
|
|
|
|
view_compute_cursor(app, view_id, seek_pos(cursor_position), &cursor);
|
2019-02-27 05:49:35 +00:00
|
|
|
|
2019-04-06 21:13:49 +00:00
|
|
|
Fancy_String_List list = {};
|
2019-06-02 03:07:57 +00:00
|
|
|
String_Const_u8 unique_name = push_buffer_unique_name(app, scratch, buffer_id);
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_string(scratch, &list, base_color, unique_name);
|
|
|
|
push_fancy_stringf(scratch, &list, base_color, " - Row: %3.d Col: %3.d -", cursor.line, cursor.character);
|
2019-03-31 21:30:06 +00:00
|
|
|
|
2019-02-27 05:49:35 +00:00
|
|
|
b32 is_dos_mode = false;
|
2019-04-06 21:13:49 +00:00
|
|
|
if (buffer_get_setting(app, buffer_id, BufferSetting_Eol, &is_dos_mode)){
|
2019-02-27 05:49:35 +00:00
|
|
|
if (is_dos_mode){
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" dos"));
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" nix"));
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" ???"));
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-04-04 08:25:16 +00:00
|
|
|
Dirty_State dirty = 0;
|
2019-04-06 21:13:49 +00:00
|
|
|
buffer_get_dirty_state(app, buffer_id, &dirty);
|
2019-06-01 23:58:28 +00:00
|
|
|
u8 space[3];
|
|
|
|
String_u8 str = Su8(space, 0, 3);
|
2019-02-27 05:49:35 +00:00
|
|
|
if (dirty != 0){
|
2019-06-01 23:58:28 +00:00
|
|
|
string_append(&str, string_u8_litexpr(" "));
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
if (HasFlag(dirty, DirtyState_UnsavedChanges)){
|
2019-06-01 23:58:28 +00:00
|
|
|
string_append(&str, string_u8_litexpr("*"));
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
if (HasFlag(dirty, DirtyState_UnloadedChanges)){
|
2019-06-01 23:58:28 +00:00
|
|
|
string_append(&str, string_u8_litexpr("!"));
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_string(scratch, &list, pop2_color, str.string);
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Vec2 p = bar.p0 + V2(0.f, 2.f);
|
2019-03-31 21:30:06 +00:00
|
|
|
draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0);
|
2019-02-27 05:49:35 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
end_temp(temp);
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Query Bars
|
|
|
|
{
|
|
|
|
Query_Bar *space[32];
|
|
|
|
Query_Bar_Ptr_Array query_bars = {};
|
|
|
|
query_bars.ptrs = space;
|
2019-03-31 18:55:26 +00:00
|
|
|
if (get_active_query_bars(app, view_id, ArrayCount(space), &query_bars)){
|
2019-02-27 05:49:35 +00:00
|
|
|
for (i32 i = 0; i < query_bars.count; i += 1){
|
|
|
|
Query_Bar *query_bar = query_bars.ptrs[i];
|
|
|
|
|
2019-02-27 21:14:25 +00:00
|
|
|
Rect_f32 bar = r_cursor;
|
2019-02-27 05:49:35 +00:00
|
|
|
bar.y1 = bar.y0 + line_height + 2.f;
|
2019-02-27 21:14:25 +00:00
|
|
|
r_cursor.y0 = bar.y1;
|
2019-02-27 05:49:35 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
2019-02-27 05:49:35 +00:00
|
|
|
Fancy_String_List list = {};
|
|
|
|
|
|
|
|
Fancy_Color default_color = fancy_id(Stag_Default);
|
|
|
|
Fancy_Color pop1_color = fancy_id(Stag_Pop1);
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_string(scratch, &list, pop1_color , query_bar->prompt);
|
|
|
|
push_fancy_string(scratch, &list, default_color, query_bar->string);
|
2019-02-27 05:49:35 +00:00
|
|
|
|
|
|
|
Vec2 p = bar.p0 + V2(0.f, 2.f);
|
2019-04-06 21:13:49 +00:00
|
|
|
draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0);
|
2019-02-27 05:49:35 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
end_temp(temp);
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-27 21:14:25 +00:00
|
|
|
|
|
|
|
// NOTE(allen): Line Numbers
|
|
|
|
if (global_config.show_line_number_margins){
|
2019-04-04 08:25:16 +00:00
|
|
|
i32 line_count = 0;
|
2019-04-06 21:13:49 +00:00
|
|
|
buffer_get_line_count(app, buffer_id, &line_count);
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 line_count_digit_count = (i32)digit_count_from_integer(line_count, 10);
|
2019-02-27 21:14:25 +00:00
|
|
|
// TODO(allen): I need a "digit width"
|
2019-06-01 23:58:28 +00:00
|
|
|
f32 zero = get_string_advance(app, face_id, string_u8_litexpr("0"));
|
2019-02-27 21:14:25 +00:00
|
|
|
f32 margin_width = (f32)line_count_digit_count*zero;
|
|
|
|
|
|
|
|
Rect_f32 left_margin = r_cursor;
|
|
|
|
left_margin.x1 = left_margin.x0 + margin_width + 2;
|
|
|
|
r_cursor.x0 = left_margin.x1;
|
|
|
|
|
|
|
|
draw_rectangle(app, left_margin, Stag_Line_Numbers_Back);
|
2019-03-17 21:30:48 +00:00
|
|
|
draw_clip_push(app, left_margin);
|
2019-02-27 21:14:25 +00:00
|
|
|
|
|
|
|
Fancy_Color line_color = fancy_id(Stag_Line_Numbers_Text);
|
|
|
|
|
|
|
|
Full_Cursor cursor = {};
|
2019-03-31 18:55:26 +00:00
|
|
|
view_compute_cursor(app, view_id, seek_pos(on_screen_range.first), &cursor);
|
2019-04-06 21:13:49 +00:00
|
|
|
GUI_Scroll_Vars scroll_vars = {};
|
|
|
|
view_get_scroll_vars(app, view_id, &scroll_vars);
|
2019-03-31 18:55:26 +00:00
|
|
|
for (;cursor.pos <= on_screen_range.one_past_last;){
|
2019-04-06 21:13:49 +00:00
|
|
|
Vec2 p = panel_space_from_view_space(cursor.wrapped_p, scroll_vars.scroll_p);
|
2019-03-31 18:55:26 +00:00
|
|
|
p += V2(buffer_rect.p0);
|
2019-03-17 21:30:48 +00:00
|
|
|
p.x = left_margin.x0;
|
2019-06-01 23:58:28 +00:00
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
|
|
|
Fancy_String *line_string = push_fancy_stringf(scratch, line_color, "%*d", line_count_digit_count, cursor.line);
|
2019-04-06 21:13:49 +00:00
|
|
|
draw_fancy_string(app, face_id, line_string, p, Stag_Margin_Active, 0);
|
2019-06-01 23:58:28 +00:00
|
|
|
end_temp(temp);
|
2019-02-27 21:14:25 +00:00
|
|
|
i32 next_line = cursor.line + 1;
|
2019-03-31 18:55:26 +00:00
|
|
|
view_compute_cursor(app, view_id, seek_line_char(next_line, 1), &cursor);
|
2019-02-27 21:14:25 +00:00
|
|
|
if (cursor.line < next_line){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-17 21:30:48 +00:00
|
|
|
|
|
|
|
draw_clip_pop(app);
|
2019-02-27 21:14:25 +00:00
|
|
|
}
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 12:14:47 +00:00
|
|
|
// NOTE(allen): Scan for TODOs and NOTEs
|
|
|
|
{
|
2019-06-01 23:58:28 +00:00
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
2019-06-02 03:07:57 +00:00
|
|
|
String_Const_u8 tail = push_buffer_range(app, scratch, buffer_id, on_screen_range);
|
2018-09-30 12:14:47 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Highlight_Record *record_first = 0;
|
|
|
|
Highlight_Record *record_last = 0;
|
|
|
|
i32 record_count = 0;
|
|
|
|
i32 index = 0;
|
|
|
|
|
|
|
|
for (;tail.size > 0; tail = string_skip(tail, 1), index += 1){
|
|
|
|
if (string_match(string_prefix(tail, 4), string_u8_litexpr("NOTE"))){
|
2018-09-30 12:14:47 +00:00
|
|
|
Highlight_Record *record = push_array(scratch, Highlight_Record, 1);
|
2019-06-01 23:58:28 +00:00
|
|
|
sll_queue_push(record_first, record_last, record);
|
|
|
|
record_count += 1;
|
|
|
|
record->range.first = on_screen_range.first + index;
|
|
|
|
record->range.one_past_last = record->range.first + 4;
|
2019-02-26 21:05:02 +00:00
|
|
|
record->color = Stag_Text_Cycle_2;
|
2019-06-01 23:58:28 +00:00
|
|
|
tail = string_skip(tail, 3);
|
|
|
|
index += 3;
|
2018-09-27 20:15:32 +00:00
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
else if (string_match(string_prefix(tail, 4), string_u8_litexpr("TODO"))){
|
2018-09-30 12:14:47 +00:00
|
|
|
Highlight_Record *record = push_array(scratch, Highlight_Record, 1);
|
2019-06-01 23:58:28 +00:00
|
|
|
sll_queue_push(record_first, record_last, record);
|
|
|
|
record_count += 1;
|
|
|
|
record->range.first = on_screen_range.first + index;
|
|
|
|
record->range.one_past_last = record->range.first + 4;
|
2019-02-26 21:05:02 +00:00
|
|
|
record->color = Stag_Text_Cycle_1;
|
2019-06-01 23:58:28 +00:00
|
|
|
tail = string_skip(tail, 3);
|
|
|
|
index += 3;
|
2018-09-27 20:15:32 +00:00
|
|
|
}
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
|
|
|
|
Highlight_Record *records = push_array(scratch, Highlight_Record, record_count);
|
|
|
|
i32 record_index = 0;
|
|
|
|
for (Highlight_Record *node = record_first;
|
|
|
|
node != 0;
|
|
|
|
node = node->next){
|
|
|
|
records[record_index] = *node;
|
|
|
|
record_index += 1;
|
|
|
|
}
|
2018-09-27 20:15:32 +00:00
|
|
|
|
2018-09-30 12:14:47 +00:00
|
|
|
if (record_count > 0){
|
|
|
|
sort_highlight_record(records, 0, record_count);
|
2019-06-01 23:58:28 +00:00
|
|
|
Marker *markers = push_array_zero(scratch, Marker, 2*record_count);
|
|
|
|
i32 marker_index_first = 0;
|
|
|
|
i32 marker_index = 0;
|
2018-09-30 12:14:47 +00:00
|
|
|
int_color current_color = records[0].color;
|
2018-09-27 20:15:32 +00:00
|
|
|
{
|
2019-06-01 23:58:28 +00:00
|
|
|
Marker *marker = &markers[marker_index];
|
|
|
|
marker[0].pos = records[0].range.first;
|
|
|
|
marker[1].pos = records[0].range.one_past_last;
|
|
|
|
marker_index += 2;
|
2018-09-27 20:15:32 +00:00
|
|
|
}
|
2019-02-26 23:08:42 +00:00
|
|
|
for (i32 i = 1; i <= record_count; i += 1){
|
2019-06-01 23:58:28 +00:00
|
|
|
b32 do_emit = (i == record_count || records[i].color != current_color);
|
2018-09-30 12:14:47 +00:00
|
|
|
if (do_emit){
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 marker_count = marker_index - marker_index_first;
|
2019-04-06 21:13:49 +00:00
|
|
|
Managed_Object o = alloc_buffer_markers_on_buffer(app, buffer_id, marker_count, &render_scope);
|
2019-06-01 23:58:28 +00:00
|
|
|
managed_object_store_data(app, o, 0, marker_count, markers + marker_index_first);
|
2018-10-01 19:32:28 +00:00
|
|
|
Marker_Visual v = create_marker_visual(app, o);
|
2019-02-25 23:42:13 +00:00
|
|
|
marker_visual_set_effect(app, v, VisualType_CharacterHighlightRanges, SymbolicColor_Default, current_color, 0);
|
2018-10-01 19:32:28 +00:00
|
|
|
marker_visual_set_priority(app, v, VisualPriority_Lowest);
|
2018-09-30 12:14:47 +00:00
|
|
|
current_color = records[i].color;
|
2019-06-01 23:58:28 +00:00
|
|
|
marker_index_first = marker_index;
|
|
|
|
}
|
|
|
|
if (i < record_count){
|
|
|
|
Marker *marker = &markers[marker_index];
|
|
|
|
marker[0].pos = records[i].range.first;
|
|
|
|
marker[1].pos = records[i].range.one_past_last;
|
|
|
|
marker_index += 2;
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
2018-09-27 20:15:32 +00:00
|
|
|
}
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
end_temp(temp);
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Cursor and mark
|
2019-04-06 21:13:49 +00:00
|
|
|
i32 cursor_pos = 0;
|
|
|
|
i32 mark_pos = 0;
|
|
|
|
view_get_cursor_pos(app, view_id, &cursor_pos);
|
|
|
|
view_get_mark_pos(app, view_id, &mark_pos);
|
|
|
|
|
|
|
|
Managed_Object cursor_and_mark = alloc_buffer_markers_on_buffer(app, buffer_id, 2, &render_scope);
|
2018-11-20 08:18:54 +00:00
|
|
|
Marker cm_markers[2] = {};
|
2019-04-06 21:13:49 +00:00
|
|
|
cm_markers[0].pos = cursor_pos;
|
|
|
|
cm_markers[1].pos = mark_pos;
|
2018-09-30 12:14:47 +00:00
|
|
|
managed_object_store_data(app, cursor_and_mark, 0, 2, cm_markers);
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 cursor_is_hidden_in_this_view = (cursor_is_hidden && is_active_view);
|
2018-12-02 04:22:37 +00:00
|
|
|
if (!cursor_is_hidden_in_this_view){
|
2018-09-30 12:14:47 +00:00
|
|
|
switch (fcoder_mode){
|
|
|
|
case FCoderMode_Original:
|
|
|
|
{
|
2018-11-20 08:18:54 +00:00
|
|
|
Marker_Visual_Take_Rule take_rule = {};
|
2018-09-30 12:14:47 +00:00
|
|
|
take_rule.first_index = 0;
|
|
|
|
take_rule.take_count_per_step = 1;
|
|
|
|
take_rule.step_stride_in_marker_count = 1;
|
|
|
|
take_rule.maximum_number_of_markers = 1;
|
|
|
|
|
2018-10-01 19:32:28 +00:00
|
|
|
Marker_Visual visual = create_marker_visual(app, cursor_and_mark);
|
|
|
|
Marker_Visual_Type type = is_active_view?VisualType_CharacterBlocks:VisualType_CharacterWireFrames;
|
2019-03-30 21:51:56 +00:00
|
|
|
int_color cursor_color = Stag_Cursor;
|
2019-02-25 23:42:13 +00:00
|
|
|
int_color text_color = is_active_view?Stag_At_Cursor:Stag_Default;
|
2019-03-30 21:51:56 +00:00
|
|
|
marker_visual_set_effect(app, visual, type, cursor_color, text_color, 0);
|
2018-10-01 19:32:28 +00:00
|
|
|
marker_visual_set_take_rule(app, visual, take_rule);
|
|
|
|
marker_visual_set_priority(app, visual, VisualPriority_Highest);
|
2018-09-30 12:14:47 +00:00
|
|
|
|
2018-10-01 19:32:28 +00:00
|
|
|
visual = create_marker_visual(app, cursor_and_mark);
|
2019-02-25 23:42:13 +00:00
|
|
|
marker_visual_set_effect(app, visual, VisualType_CharacterWireFrames, Stag_Mark, 0, 0);
|
2018-09-30 12:14:47 +00:00
|
|
|
take_rule.first_index = 1;
|
2018-10-01 19:32:28 +00:00
|
|
|
marker_visual_set_take_rule(app, visual, take_rule);
|
|
|
|
marker_visual_set_priority(app, visual, VisualPriority_Highest);
|
2018-09-30 12:14:47 +00:00
|
|
|
}break;
|
|
|
|
|
|
|
|
case FCoderMode_NotepadLike:
|
|
|
|
{
|
2019-02-25 23:42:13 +00:00
|
|
|
int_color cursor_color = Stag_Cursor;
|
|
|
|
int_color highlight_color = Stag_Highlight;
|
2018-09-30 12:14:47 +00:00
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Marker_Visual_Take_Rule take_rule = {};
|
2018-09-30 12:14:47 +00:00
|
|
|
take_rule.first_index = 0;
|
|
|
|
take_rule.take_count_per_step = 1;
|
|
|
|
take_rule.step_stride_in_marker_count = 1;
|
|
|
|
take_rule.maximum_number_of_markers = 1;
|
|
|
|
|
2018-10-01 19:32:28 +00:00
|
|
|
Marker_Visual visual = create_marker_visual(app, cursor_and_mark);
|
|
|
|
marker_visual_set_effect(app, visual, VisualType_CharacterIBars, cursor_color, 0, 0);
|
|
|
|
marker_visual_set_take_rule(app, visual, take_rule);
|
|
|
|
marker_visual_set_priority(app, visual, VisualPriority_Highest);
|
2018-09-30 12:14:47 +00:00
|
|
|
|
2019-04-06 21:13:49 +00:00
|
|
|
if (cursor_pos != mark_pos){
|
2018-10-01 19:32:28 +00:00
|
|
|
visual = create_marker_visual(app, cursor_and_mark);
|
2019-02-25 23:42:13 +00:00
|
|
|
marker_visual_set_effect(app, visual, VisualType_CharacterHighlightRanges, highlight_color, Stag_At_Highlight, 0);
|
2018-09-30 12:14:47 +00:00
|
|
|
take_rule.maximum_number_of_markers = 2;
|
2018-10-01 19:32:28 +00:00
|
|
|
marker_visual_set_take_rule(app, visual, take_rule);
|
|
|
|
marker_visual_set_priority(app, visual, VisualPriority_Highest);
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
}break;
|
|
|
|
}
|
2018-09-27 05:27:25 +00:00
|
|
|
}
|
|
|
|
|
2018-09-26 18:06:57 +00:00
|
|
|
// NOTE(allen): Line highlight setup
|
2018-10-06 01:42:56 +00:00
|
|
|
if (highlight_line_at_cursor && is_active_view){
|
2019-02-26 23:08:42 +00:00
|
|
|
u32 line_color = Stag_Highlight_Cursor_Line;
|
2018-10-01 19:32:28 +00:00
|
|
|
Marker_Visual visual = create_marker_visual(app, cursor_and_mark);
|
2019-02-25 23:42:13 +00:00
|
|
|
marker_visual_set_effect(app, visual, VisualType_LineHighlights, line_color, 0, 0);
|
2018-11-20 08:18:54 +00:00
|
|
|
Marker_Visual_Take_Rule take_rule = {};
|
2018-09-30 12:14:47 +00:00
|
|
|
take_rule.first_index = 0;
|
|
|
|
take_rule.take_count_per_step = 1;
|
|
|
|
take_rule.step_stride_in_marker_count = 1;
|
|
|
|
take_rule.maximum_number_of_markers = 1;
|
2018-10-01 19:32:28 +00:00
|
|
|
marker_visual_set_take_rule(app, visual, take_rule);
|
|
|
|
marker_visual_set_priority(app, visual, VisualPriority_Highest);
|
2018-09-22 23:45:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Token highlight setup
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 do_token_highlight = false;
|
2018-09-25 08:41:49 +00:00
|
|
|
if (do_token_highlight){
|
2019-02-25 23:42:13 +00:00
|
|
|
int_color token_color = 0x5000EE00;
|
2018-09-25 08:41:49 +00:00
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
u32 token_flags = BoundaryToken|BoundaryWhitespace;
|
2019-04-06 21:13:49 +00:00
|
|
|
i32 pos0 = cursor_pos;
|
|
|
|
i32 pos1 = buffer_boundary_seek(app, buffer_id, pos0, DirLeft , token_flags);
|
2019-02-21 06:58:34 +00:00
|
|
|
if (pos1 >= 0){
|
2019-04-06 21:13:49 +00:00
|
|
|
i32 pos2 = buffer_boundary_seek(app, buffer_id, pos1, DirRight, token_flags);
|
2019-04-04 08:25:16 +00:00
|
|
|
i32 buffer_size = 0;
|
2019-04-06 21:13:49 +00:00
|
|
|
buffer_get_size(app, buffer_id, &buffer_size);
|
2019-04-04 08:25:16 +00:00
|
|
|
if (pos2 <= buffer_size){
|
2019-04-06 21:13:49 +00:00
|
|
|
Managed_Object token_highlight = alloc_buffer_markers_on_buffer(app, buffer_id, 2, &render_scope);
|
2019-02-21 06:58:34 +00:00
|
|
|
Marker range_markers[2] = {};
|
|
|
|
range_markers[0].pos = pos1;
|
|
|
|
range_markers[1].pos = pos2;
|
|
|
|
managed_object_store_data(app, token_highlight, 0, 2, range_markers);
|
|
|
|
Marker_Visual visual = create_marker_visual(app, token_highlight);
|
2019-02-25 23:42:13 +00:00
|
|
|
marker_visual_set_effect(app, visual, VisualType_CharacterHighlightRanges, token_color, Stag_At_Highlight, 0);
|
2019-02-21 06:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-25 08:41:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Matching enclosure highlight setup
|
2019-02-26 23:08:42 +00:00
|
|
|
static const i32 color_count = 4;
|
2018-09-25 08:41:49 +00:00
|
|
|
if (do_matching_enclosure_highlight){
|
2018-09-30 12:14:47 +00:00
|
|
|
int_color colors[color_count];
|
2019-02-25 23:42:13 +00:00
|
|
|
for (u16 i = 0; i < color_count; i += 1){
|
|
|
|
colors[i] = Stag_Back_Cycle_1 + i;
|
2018-09-22 23:45:24 +00:00
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
mark_enclosures(app, render_scope, buffer_id, cursor_pos, FindScope_Brace, VisualType_LineHighlightRanges, colors, 0, color_count);
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
if (do_matching_paren_highlight){
|
2019-04-06 21:13:49 +00:00
|
|
|
i32 pos = cursor_pos;
|
|
|
|
if (buffer_get_char(app, buffer_id, pos) == '('){
|
2018-11-09 00:15:39 +00:00
|
|
|
pos += 1;
|
|
|
|
}
|
|
|
|
else if (pos > 0){
|
2019-04-06 21:13:49 +00:00
|
|
|
if (buffer_get_char(app, buffer_id, pos - 1) == ')'){
|
2018-11-09 00:15:39 +00:00
|
|
|
pos -= 1;
|
|
|
|
}
|
|
|
|
}
|
2019-02-25 23:42:13 +00:00
|
|
|
int_color colors[color_count];
|
|
|
|
for (u16 i = 0; i < color_count; i += 1){
|
|
|
|
colors[i] = Stag_Text_Cycle_1 + i;
|
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
mark_enclosures(app, render_scope, buffer_id, pos, FindScope_Paren, VisualType_CharacterBlocks, 0, colors, color_count);
|
2018-09-22 23:45:24 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 16:23:07 +00:00
|
|
|
draw_clip_push(app, buffer_rect);
|
2019-03-31 18:55:26 +00:00
|
|
|
draw_render_layout(app, view_id);
|
2019-04-02 16:23:07 +00:00
|
|
|
draw_clip_pop(app);
|
2018-09-22 23:45:24 +00:00
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
// NOTE(allen): FPS HUD
|
|
|
|
if (show_fps_hud){
|
|
|
|
static const i32 history_depth = 10;
|
|
|
|
static f32 history_literal_dt[history_depth] = {};
|
|
|
|
static f32 history_animation_dt[history_depth] = {};
|
|
|
|
static i32 history_frame_index[history_depth] = {};
|
|
|
|
|
2019-03-31 18:55:26 +00:00
|
|
|
i32 wrapped_index = frame_info.index%history_depth;
|
|
|
|
history_literal_dt[wrapped_index] = frame_info.literal_dt;
|
|
|
|
history_animation_dt[wrapped_index] = frame_info.animation_dt;
|
|
|
|
history_frame_index[wrapped_index] = frame_info.index;
|
2019-02-25 23:42:13 +00:00
|
|
|
|
2019-04-06 21:13:49 +00:00
|
|
|
Rect_f32 hud_rect = {};
|
|
|
|
view_get_screen_rect(app, view_id, &hud_rect);
|
|
|
|
hud_rect.p1 -= hud_rect.p0;
|
|
|
|
hud_rect.p0 = V2(0.f, 0.f);
|
|
|
|
hud_rect.y0 = hud_rect.y1 - line_height*(f32)(history_depth);
|
2019-02-25 23:42:13 +00:00
|
|
|
draw_rectangle(app, hud_rect, 0xFF000000);
|
|
|
|
draw_rectangle_outline(app, hud_rect, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
Vec2 p = hud_rect.p0;
|
|
|
|
|
|
|
|
Range ranges[2];
|
|
|
|
ranges[0].first = wrapped_index;
|
|
|
|
ranges[0].one_past_last = -1;
|
|
|
|
ranges[1].first = history_depth - 1;
|
|
|
|
ranges[1].one_past_last = wrapped_index;
|
|
|
|
for (i32 i = 0; i < 2; i += 1){
|
|
|
|
Range r = ranges[i];
|
2019-04-06 21:13:49 +00:00
|
|
|
for (i32 j = r.first; j > r.one_past_last; j -= 1, p.y += line_height){
|
2019-02-25 23:42:13 +00:00
|
|
|
f32 dts[2];
|
|
|
|
dts[0] = history_literal_dt[j];
|
|
|
|
dts[1] = history_animation_dt[j];
|
|
|
|
i32 frame_index = history_frame_index[j];
|
|
|
|
|
2019-02-26 19:59:57 +00:00
|
|
|
Fancy_Color white = fancy_rgba(1.f, 1.f, 1.f, 1.f);
|
|
|
|
Fancy_Color pink = fancy_rgba(1.f, 0.f, 1.f, 1.f);
|
|
|
|
Fancy_Color green = fancy_rgba(0.f, 1.f, 0.f, 1.f);
|
2019-02-25 23:42:13 +00:00
|
|
|
Fancy_String_List list = {};
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_stringf(scratch, &list, pink , "FPS: ");
|
|
|
|
push_fancy_stringf(scratch, &list, green, "[");
|
|
|
|
push_fancy_stringf(scratch, &list, white, "%5d", frame_index);
|
|
|
|
push_fancy_stringf(scratch, &list, green, "]: ");
|
2019-02-25 23:42:13 +00:00
|
|
|
|
|
|
|
for (i32 k = 0; k < 2; k += 1){
|
|
|
|
f32 dt = dts[k];
|
|
|
|
if (dt == 0.f){
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_stringf(scratch, &list, white, "----------");
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_stringf(scratch, &list, white, "%10.6f", dt);
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_stringf(scratch, &list, green, " | ");
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 21:13:49 +00:00
|
|
|
draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0, 0, V2(1.f, 0.f));
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-01 06:14:31 +00:00
|
|
|
|
|
|
|
animate_in_n_milliseconds(app, 1000);
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
end_temp(major_temp);
|
2018-10-01 19:32:28 +00:00
|
|
|
managed_scope_clear_self_all_dependent_scopes(app, render_scope);
|
2018-09-22 23:45:24 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 19:59:57 +00:00
|
|
|
static int_color
|
|
|
|
get_margin_color(i32 level){
|
|
|
|
int_color margin = 0;
|
|
|
|
switch (level){
|
|
|
|
default:
|
|
|
|
case UIActivation_None:
|
|
|
|
{
|
|
|
|
margin = Stag_List_Item;
|
|
|
|
}break;
|
|
|
|
case UIActivation_Hover:
|
|
|
|
{
|
|
|
|
margin = Stag_List_Item_Hover;
|
|
|
|
}break;
|
|
|
|
case UIActivation_Active:
|
|
|
|
{
|
|
|
|
margin = Stag_List_Item_Active;
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
return(margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-31 22:07:10 +00:00
|
|
|
default_ui_render_caller(Application_Links *app, View_ID view_id, Rect_f32 rect_f32, Face_ID face_id){
|
2019-02-26 19:59:57 +00:00
|
|
|
UI_Data *ui_data = 0;
|
|
|
|
Arena *ui_arena = 0;
|
2019-03-31 18:55:26 +00:00
|
|
|
if (view_get_ui_data(app, view_id, ViewGetUIFlag_KeepDataAsIs, &ui_data, &ui_arena)){
|
2019-03-31 22:07:10 +00:00
|
|
|
GUI_Scroll_Vars ui_scroll = {};
|
|
|
|
view_get_scroll_vars(app, view_id, &ui_scroll);
|
|
|
|
|
|
|
|
for (UI_Item *item = ui_data->list.first;
|
|
|
|
item != 0;
|
|
|
|
item = item->next){
|
|
|
|
Rect_i32 item_rect_i32 = item->rect_outer;
|
|
|
|
Rect_f32 item_rect = f32R(item_rect_i32);
|
|
|
|
|
|
|
|
switch (item->coordinates){
|
|
|
|
case UICoordinates_ViewSpace:
|
|
|
|
{
|
|
|
|
item_rect.p0 -= ui_scroll.scroll_p;
|
|
|
|
item_rect.p1 -= ui_scroll.scroll_p;
|
|
|
|
}break;
|
|
|
|
case UICoordinates_PanelSpace:
|
|
|
|
{}break;
|
|
|
|
}
|
2019-02-26 19:59:57 +00:00
|
|
|
|
2019-03-31 22:07:10 +00:00
|
|
|
if (rect_overlap(item_rect, rect_f32)){
|
|
|
|
Rect_f32 inner_rect = get_inner_rect(item_rect, (f32)item->inner_margin);
|
2019-02-26 19:59:57 +00:00
|
|
|
|
2019-03-31 22:07:10 +00:00
|
|
|
Face_Metrics metrics = {};
|
|
|
|
get_face_metrics(app, face_id, &metrics);
|
|
|
|
f32 line_height = metrics.line_height;
|
|
|
|
f32 info_height = (f32)item->line_count*line_height;
|
2019-02-26 19:59:57 +00:00
|
|
|
|
2019-03-31 22:07:10 +00:00
|
|
|
draw_rectangle(app, inner_rect, Stag_Back);
|
|
|
|
Vec2 p = V2(inner_rect.x0 + 3.f, (f32)(round32((inner_rect.y0 + inner_rect.y1 - info_height)*0.5f)));
|
|
|
|
for (i32 i = 0; i < item->line_count; i += 1){
|
|
|
|
draw_fancy_string(app, face_id, item->lines[i].first, p, Stag_Default, 0, 0, V2(1.f, 0));
|
|
|
|
p.y += line_height;
|
|
|
|
}
|
|
|
|
if (item->inner_margin > 0){
|
|
|
|
draw_margin(app, item_rect, inner_rect, get_margin_color(item->activation_level));
|
2019-02-26 19:59:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-31 22:07:10 +00:00
|
|
|
static void
|
|
|
|
default_ui_render_caller(Application_Links *app, View_ID view_id, Rect_f32 rect_f32){
|
|
|
|
Buffer_ID buffer_id = 0;
|
|
|
|
view_get_buffer(app, view_id, AccessAll, &buffer_id);
|
|
|
|
Face_ID face_id = 0;
|
|
|
|
get_face_id(app, buffer_id, &face_id);
|
|
|
|
default_ui_render_caller(app, view_id, rect_f32, face_id);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
default_ui_render_caller(Application_Links *app, View_ID view_id, Face_ID face_id){
|
2019-04-06 21:13:49 +00:00
|
|
|
Rect_f32 rect = {};
|
|
|
|
view_get_screen_rect(app, view_id, &rect);
|
|
|
|
rect.p1 -= rect.p0;
|
|
|
|
rect.p0 = V2(0.f,0.f);
|
|
|
|
default_ui_render_caller(app, view_id, rect, face_id);
|
2019-03-31 22:07:10 +00:00
|
|
|
}
|
|
|
|
static void
|
|
|
|
default_ui_render_caller(Application_Links *app, View_ID view_id){
|
2019-04-06 21:13:49 +00:00
|
|
|
Rect_f32 rect = {};
|
|
|
|
view_get_screen_rect(app, view_id, &rect);
|
|
|
|
rect.p1 -= rect.p0;
|
|
|
|
rect.p0 = V2(0.f,0.f);
|
|
|
|
Buffer_ID buffer_id = 0;
|
|
|
|
view_get_buffer(app, view_id, AccessAll, &buffer_id);
|
|
|
|
Face_ID face_id = 0;
|
|
|
|
get_face_id(app, buffer_id, &face_id);
|
|
|
|
default_ui_render_caller(app, view_id, rect, face_id);
|
2019-03-31 22:07:10 +00:00
|
|
|
}
|
2019-02-26 19:59:57 +00:00
|
|
|
|
2019-03-31 18:55:26 +00:00
|
|
|
static void
|
|
|
|
default_render_view(Application_Links *app, Frame_Info frame_info, View_ID view_id, b32 is_active){
|
|
|
|
Rect_i32 view_rect = {};
|
|
|
|
view_get_region(app, view_id, &view_rect);
|
|
|
|
Rect_i32 inner = get_inner_rect(view_rect, 3);
|
|
|
|
draw_rectangle(app, f32R(view_rect), get_margin_color(is_active?UIActivation_Active:UIActivation_None));
|
|
|
|
draw_rectangle(app, f32R(inner), Stag_Back);
|
|
|
|
draw_clip_push(app, f32R(inner));
|
|
|
|
draw_coordinate_center_push(app, V2(inner.p0));
|
|
|
|
if (view_is_in_ui_mode(app, view_id)){
|
|
|
|
default_ui_render_caller(app, view_id);
|
2019-02-26 19:59:57 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-03-31 18:55:26 +00:00
|
|
|
default_buffer_render_caller(app, frame_info, view_id, inner);
|
|
|
|
}
|
|
|
|
draw_clip_pop(app);
|
|
|
|
draw_coordinate_center_pop(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
RENDER_CALLER_SIG(default_render_caller){
|
|
|
|
View_ID active_view_id = 0;
|
|
|
|
get_active_view(app, AccessAll, &active_view_id);
|
|
|
|
View_ID view_id = 0;
|
|
|
|
for (get_view_next(app, 0, AccessAll, &view_id);
|
|
|
|
view_id != 0;
|
|
|
|
get_view_next(app, view_id, AccessAll, &view_id)){
|
|
|
|
default_render_view(app, frame_info, view_id, (active_view_id == view_id));
|
2019-02-26 19:59:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
HOOK_SIG(default_exit){
|
2019-04-04 08:25:16 +00:00
|
|
|
i32 result = 1;
|
2018-08-05 07:09:18 +00:00
|
|
|
|
2019-04-04 08:25:16 +00:00
|
|
|
// If this returns zero it cancels the exit.
|
|
|
|
if (!allow_immediate_close_without_checking_for_changes){
|
|
|
|
b32 has_unsaved_changes = false;
|
|
|
|
Buffer_ID buffer = 0;
|
|
|
|
for (get_buffer_next(app, 0, AccessAll, &buffer);
|
|
|
|
buffer != 0;
|
|
|
|
get_buffer_next(app, buffer, AccessAll, &buffer)){
|
|
|
|
Dirty_State dirty = 0;
|
|
|
|
buffer_get_dirty_state(app, buffer, &dirty);
|
|
|
|
if (HasFlag(dirty, DirtyState_UnsavedChanges)){
|
|
|
|
has_unsaved_changes = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (has_unsaved_changes){
|
2019-04-06 19:40:36 +00:00
|
|
|
View_ID view = 0;
|
|
|
|
get_active_view(app, AccessAll, &view);
|
|
|
|
do_gui_sure_to_close_4coder(app, view);
|
2019-04-04 08:25:16 +00:00
|
|
|
result = 0;
|
2018-08-05 07:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 08:25:16 +00:00
|
|
|
return(result);
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 07:22:16 +00:00
|
|
|
// TODO(allen): how to deal with multiple sizes on a single view
|
|
|
|
// TODO(allen): expected character advance.
|
2017-01-29 00:03:23 +00:00
|
|
|
HOOK_SIG(default_view_adjust){
|
2019-04-06 21:13:49 +00:00
|
|
|
View_ID view = 0;
|
|
|
|
for (get_view_next(app, 0, AccessAll, &view);
|
|
|
|
view != 0;
|
|
|
|
get_view_next(app, view, AccessAll, &view)){
|
2019-04-04 08:25:16 +00:00
|
|
|
Buffer_ID buffer = 0;
|
2019-04-06 21:13:49 +00:00
|
|
|
view_get_buffer(app, view, AccessAll, &buffer);
|
|
|
|
|
|
|
|
Rect_f32 screen_rect = {};
|
|
|
|
view_get_screen_rect(app, view, &screen_rect);
|
|
|
|
f32 view_width = rect_width(screen_rect);
|
|
|
|
|
|
|
|
Face_ID face_id = 0;
|
|
|
|
get_face_id(app, buffer, &face_id);
|
2019-06-01 23:58:28 +00:00
|
|
|
f32 em = get_string_advance(app, face_id, string_u8_litexpr("m"));
|
2019-02-24 07:22:16 +00:00
|
|
|
|
2019-02-27 21:14:25 +00:00
|
|
|
f32 wrap_width = view_width - 2.0f*em;
|
|
|
|
f32 min_width = 40.0f*em;
|
2019-02-24 07:22:16 +00:00
|
|
|
if (wrap_width < min_width){
|
|
|
|
wrap_width = min_width;
|
|
|
|
}
|
|
|
|
|
2019-02-27 21:14:25 +00:00
|
|
|
f32 min_base_width = 20.0f*em;
|
2019-04-04 08:25:16 +00:00
|
|
|
buffer_set_setting(app, buffer, BufferSetting_WrapPosition, (i32)(wrap_width));
|
|
|
|
buffer_set_setting(app, buffer, BufferSetting_MinimumBaseWrapPosition, (i32)(min_base_width));
|
2019-02-24 07:22:16 +00:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2017-11-30 23:25:49 +00:00
|
|
|
BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){
|
2017-12-01 18:04:07 +00:00
|
|
|
if (conflict_count > 1){
|
|
|
|
// List of unresolved conflicts
|
2019-06-01 23:58:28 +00:00
|
|
|
Scratch_Block scratch(app);
|
2017-11-30 23:25:49 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 *unresolved = push_array(scratch, i32, conflict_count);
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 unresolved_count = conflict_count;
|
|
|
|
for (i32 i = 0; i < conflict_count; ++i){
|
2017-12-01 18:04:07 +00:00
|
|
|
unresolved[i] = i;
|
|
|
|
}
|
2017-11-30 23:25:49 +00:00
|
|
|
|
2017-12-01 18:04:07 +00:00
|
|
|
// Resolution Loop
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 x = 0;
|
2017-12-01 18:04:07 +00:00
|
|
|
for (;;){
|
|
|
|
// Resolution Pass
|
|
|
|
++x;
|
2019-02-26 23:08:42 +00:00
|
|
|
for (i32 i = 0; i < unresolved_count; ++i){
|
|
|
|
i32 conflict_index = unresolved[i];
|
2017-12-01 18:04:07 +00:00
|
|
|
Buffer_Name_Conflict_Entry *conflict = &conflicts[conflict_index];
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
umem size = conflict->base_name.size;
|
|
|
|
size = clamp_top(size, conflict->unique_name_capacity);
|
|
|
|
conflict->unique_name_len_in_out = size;
|
|
|
|
memcpy(conflict->unique_name_in_out, conflict->base_name.str, size);
|
2017-12-01 18:04:07 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (conflict->file_name.str != 0){
|
|
|
|
Scratch_Block per_file_closer(scratch);
|
|
|
|
String_Const_u8 uniqueifier = {};
|
2018-10-10 04:40:30 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 file_name = string_remove_last_folder(conflict->file_name);
|
|
|
|
if (file_name.size > 0){
|
|
|
|
file_name = string_chop(file_name, 1);
|
|
|
|
u8 *end = file_name.str + file_name.size;
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 past_the_end = false;
|
|
|
|
for (i32 j = 0; j < x; ++j){
|
2019-06-01 23:58:28 +00:00
|
|
|
file_name = string_remove_last_folder(file_name);
|
2018-10-10 04:40:30 +00:00
|
|
|
if (j + 1 < x){
|
2019-06-01 23:58:28 +00:00
|
|
|
file_name = string_chop(file_name, 1);
|
2018-10-10 04:40:30 +00:00
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
if (file_name.size == 0){
|
2018-10-10 04:40:30 +00:00
|
|
|
if (j + 1 < x){
|
|
|
|
past_the_end = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-12-01 18:04:07 +00:00
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
u8 *start = file_name.str + file_name.size;
|
2018-10-10 04:40:30 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
uniqueifier = SCu8(start, end);
|
2018-10-10 04:40:30 +00:00
|
|
|
if (past_the_end){
|
2019-06-01 23:58:28 +00:00
|
|
|
uniqueifier = string_u8_pushf(scratch, "%.*s~%d",
|
|
|
|
string_expand(uniqueifier), i);
|
2017-12-01 18:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-10 04:40:30 +00:00
|
|
|
else{
|
2019-06-01 23:58:28 +00:00
|
|
|
uniqueifier = string_u8_pushf(scratch, "%d", i);
|
2018-10-10 04:40:30 +00:00
|
|
|
}
|
2017-12-01 18:04:07 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_u8 builder = Su8(conflict->unique_name_in_out,
|
|
|
|
conflict->unique_name_len_in_out,
|
|
|
|
conflict->unique_name_capacity);
|
|
|
|
string_append(&builder, string_u8_litexpr(" <"));
|
|
|
|
string_append(&builder, uniqueifier);
|
|
|
|
string_append(&builder, string_u8_litexpr(">"));
|
2017-12-01 19:13:36 +00:00
|
|
|
conflict->unique_name_len_in_out = builder.size;
|
2017-12-01 18:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conflict Check Pass
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 has_conflicts = false;
|
|
|
|
for (i32 i = 0; i < unresolved_count; ++i){
|
|
|
|
i32 conflict_index = unresolved[i];
|
2017-12-01 18:04:07 +00:00
|
|
|
Buffer_Name_Conflict_Entry *conflict = &conflicts[conflict_index];
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 conflict_name = SCu8(conflict->unique_name_in_out,
|
|
|
|
conflict->unique_name_len_in_out);
|
2017-12-01 18:04:07 +00:00
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 hit_conflict = false;
|
2019-06-01 23:58:28 +00:00
|
|
|
if (conflict->file_name.str != 0){
|
2019-02-26 23:08:42 +00:00
|
|
|
for (i32 j = 0; j < unresolved_count; ++j){
|
2017-12-01 18:04:07 +00:00
|
|
|
if (i == j) continue;
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 conflict_j_index = unresolved[j];
|
2017-12-01 18:04:07 +00:00
|
|
|
Buffer_Name_Conflict_Entry *conflict_j = &conflicts[conflict_j_index];
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 conflict_name_j = SCu8(conflict_j->unique_name_in_out,
|
|
|
|
conflict_j->unique_name_len_in_out);
|
|
|
|
|
|
|
|
if (string_match(conflict_name, conflict_name_j)){
|
2017-12-01 18:04:07 +00:00
|
|
|
hit_conflict = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hit_conflict){
|
|
|
|
has_conflicts = true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
--unresolved_count;
|
|
|
|
unresolved[i] = unresolved[unresolved_count];
|
|
|
|
--i;
|
|
|
|
}
|
2017-11-30 23:25:49 +00:00
|
|
|
}
|
2017-12-01 18:04:07 +00:00
|
|
|
|
|
|
|
if (!has_conflicts){
|
2017-11-30 23:25:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
OPEN_FILE_HOOK_SIG(default_file_settings){
|
2019-02-26 19:59:57 +00:00
|
|
|
b32 treat_as_code = false;
|
|
|
|
b32 treat_as_todo = false;
|
|
|
|
b32 lex_without_strings = false;
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8_Array extensions = global_config.code_exts;
|
2017-02-26 21:44:40 +00:00
|
|
|
|
2017-05-21 01:22:20 +00:00
|
|
|
Parse_Context_ID parse_context_id = 0;
|
|
|
|
|
2019-04-04 08:25:16 +00:00
|
|
|
Arena *scratch = context_get_arena(app);
|
2019-06-01 23:58:28 +00:00
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
2019-04-04 08:25:16 +00:00
|
|
|
|
2019-06-02 03:07:57 +00:00
|
|
|
String_Const_u8 file_name = push_buffer_file_name(app, scratch, buffer_id);
|
2019-04-04 08:25:16 +00:00
|
|
|
i32 buffer_size = 0;
|
|
|
|
buffer_get_size(app, buffer_id, &buffer_size);
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (file_name.size > 0 && buffer_size < MB(32)){
|
|
|
|
String_Const_u8 ext = string_file_extension(file_name);
|
2019-02-26 23:08:42 +00:00
|
|
|
for (i32 i = 0; i < extensions.count; ++i){
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, extensions.strings[i])){
|
2017-02-26 21:44:40 +00:00
|
|
|
treat_as_code = true;
|
2017-05-21 01:22:20 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("cs"))){
|
2017-05-21 01:22:20 +00:00
|
|
|
if (parse_context_language_cs == 0){
|
|
|
|
init_language_cs(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_cs;
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("java"))){
|
2017-05-21 01:22:20 +00:00
|
|
|
if (parse_context_language_java == 0){
|
|
|
|
init_language_java(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_java;
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("rs"))){
|
2017-05-21 01:22:20 +00:00
|
|
|
if (parse_context_language_rust == 0){
|
|
|
|
init_language_rust(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_rust;
|
2017-11-27 21:13:17 +00:00
|
|
|
lex_without_strings = true;
|
2017-05-21 01:22:20 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("cpp")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("h")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("c")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("hpp")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("cc"))){
|
2017-11-08 04:41:45 +00:00
|
|
|
if (parse_context_language_cpp == 0){
|
|
|
|
init_language_cpp(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_cpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(NAME): Real GLSL highlighting
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("glsl"))){
|
2017-06-12 17:40:54 +00:00
|
|
|
if (parse_context_language_cpp == 0){
|
|
|
|
init_language_cpp(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_cpp;
|
|
|
|
}
|
|
|
|
|
2017-06-30 01:13:20 +00:00
|
|
|
// TODO(NAME): Real Objective-C highlighting
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("m"))){
|
2017-06-30 01:13:20 +00:00
|
|
|
if (parse_context_language_cpp == 0){
|
|
|
|
init_language_cpp(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_cpp;
|
|
|
|
}
|
|
|
|
|
2017-02-26 21:44:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
2017-04-15 21:47:23 +00:00
|
|
|
|
|
|
|
if (!treat_as_code){
|
2019-06-01 23:58:28 +00:00
|
|
|
treat_as_todo = string_match_insensitive(string_front_of_path(file_name),
|
|
|
|
string_u8_litexpr("todo.txt"));
|
2017-04-15 21:47:23 +00:00
|
|
|
}
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 19:59:57 +00:00
|
|
|
i32 map_id = (treat_as_code)?((i32)default_code_map):((i32)mapid_file);
|
|
|
|
i32 map_id_query = 0;
|
2018-08-04 02:41:38 +00:00
|
|
|
|
2019-04-04 08:25:16 +00:00
|
|
|
buffer_set_setting(app, buffer_id, BufferSetting_MapID, default_lister_ui_map);
|
|
|
|
buffer_get_setting(app, buffer_id, BufferSetting_MapID, &map_id_query);
|
2018-08-04 02:41:38 +00:00
|
|
|
Assert(map_id_query == default_lister_ui_map);
|
2017-03-29 16:32:06 +00:00
|
|
|
|
2019-04-04 08:25:16 +00:00
|
|
|
buffer_set_setting(app, buffer_id, BufferSetting_WrapPosition, global_config.default_wrap_width);
|
|
|
|
buffer_set_setting(app, buffer_id, BufferSetting_MinimumBaseWrapPosition, global_config.default_min_base_width);
|
|
|
|
buffer_set_setting(app, buffer_id, BufferSetting_MapID, map_id);
|
|
|
|
buffer_get_setting(app, buffer_id, BufferSetting_MapID, &map_id_query);
|
2018-06-22 20:59:21 +00:00
|
|
|
Assert(map_id_query == map_id);
|
2019-04-04 08:25:16 +00:00
|
|
|
buffer_set_setting(app, buffer_id, BufferSetting_ParserContext, parse_context_id);
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2018-09-07 22:39:33 +00:00
|
|
|
// NOTE(allen): Decide buffer settings
|
2019-02-26 19:59:57 +00:00
|
|
|
b32 wrap_lines = true;
|
|
|
|
b32 use_virtual_whitespace = false;
|
|
|
|
b32 use_lexer = false;
|
2017-04-15 21:47:23 +00:00
|
|
|
if (treat_as_todo){
|
2018-09-07 22:39:33 +00:00
|
|
|
lex_without_strings = true;
|
|
|
|
wrap_lines = true;
|
|
|
|
use_virtual_whitespace = true;
|
|
|
|
use_lexer = true;
|
|
|
|
}
|
|
|
|
else if (treat_as_code){
|
|
|
|
wrap_lines = global_config.enable_code_wrapping;
|
|
|
|
use_virtual_whitespace = global_config.enable_virtual_whitespace;
|
|
|
|
use_lexer = true;
|
|
|
|
}
|
2019-04-04 08:25:16 +00:00
|
|
|
|
2019-06-02 03:07:57 +00:00
|
|
|
String_Const_u8 buffer_name = push_buffer_base_name(app, scratch, buffer_id);
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(buffer_name, string_u8_litexpr("*compilation*"))){
|
2018-09-07 22:39:33 +00:00
|
|
|
wrap_lines = false;
|
|
|
|
}
|
2019-04-04 08:25:16 +00:00
|
|
|
if (buffer_size >= (1 << 20)){
|
2018-09-07 22:39:33 +00:00
|
|
|
wrap_lines = false;
|
|
|
|
use_virtual_whitespace = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen|a4.0.12): There is a little bit of grossness going on here.
|
|
|
|
// If we set BufferSetting_Lex to true, it will launch a lexing job.
|
|
|
|
// If a lexing job is active when we set BufferSetting_VirtualWhitespace, the call can fail.
|
|
|
|
// Unfortunantely without tokens virtual whitespace doesn't really make sense.
|
|
|
|
// So for now I have it automatically turning on lexing when virtual whitespace is turned on.
|
|
|
|
// Cleaning some of that up is a goal for future versions.
|
2019-04-04 08:25:16 +00:00
|
|
|
buffer_set_setting(app, buffer_id, BufferSetting_LexWithoutStrings, lex_without_strings);
|
|
|
|
buffer_set_setting(app, buffer_id, BufferSetting_WrapLine, wrap_lines);
|
|
|
|
buffer_set_setting(app, buffer_id, BufferSetting_VirtualWhitespace, use_virtual_whitespace);
|
|
|
|
buffer_set_setting(app, buffer_id, BufferSetting_Lex, use_lexer);
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
end_temp(temp);
|
2017-01-29 00:03:23 +00:00
|
|
|
|
|
|
|
// no meaning for return
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2017-02-26 20:13:06 +00:00
|
|
|
OPEN_FILE_HOOK_SIG(default_new_file){
|
2017-02-26 21:44:40 +00:00
|
|
|
// no meaning for return
|
2019-04-04 08:25:16 +00:00
|
|
|
// buffer_id
|
2017-02-26 21:44:40 +00:00
|
|
|
return(0);
|
2017-02-26 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
OPEN_FILE_HOOK_SIG(default_file_save){
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 is_virtual = 0;
|
2018-05-12 07:20:37 +00:00
|
|
|
if (global_config.automatically_indent_text_on_save &&
|
2019-04-04 08:25:16 +00:00
|
|
|
buffer_get_setting(app, buffer_id, BufferSetting_VirtualWhitespace, &is_virtual)){
|
2017-01-29 00:03:23 +00:00
|
|
|
if (is_virtual){
|
2019-04-04 08:25:16 +00:00
|
|
|
i32 buffer_size = 0;
|
|
|
|
buffer_get_size(app, buffer_id, &buffer_size);
|
2019-06-01 23:58:28 +00:00
|
|
|
buffer_auto_indent(app, buffer_id, 0, buffer_size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// no meaning for return
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2019-03-22 01:27:28 +00:00
|
|
|
FILE_EDIT_RANGE_SIG(default_file_edit_range){
|
|
|
|
// no meaning for return
|
2019-04-04 08:25:16 +00:00
|
|
|
// buffer_id, range, text
|
2019-03-22 01:27:28 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE_EDIT_FINISHED_SIG(default_file_edit_finished){
|
2019-02-14 03:53:55 +00:00
|
|
|
#if 0
|
2019-04-04 08:25:16 +00:00
|
|
|
for (i32 i = 0; i < buffer_id_count; i += 1){
|
|
|
|
// buffer_ids[i]
|
2019-01-31 12:38:24 +00:00
|
|
|
}
|
2019-04-04 08:25:16 +00:00
|
|
|
#endif
|
2019-01-31 12:38:24 +00:00
|
|
|
|
|
|
|
// no meaning for return
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2017-04-18 15:41:49 +00:00
|
|
|
OPEN_FILE_HOOK_SIG(default_end_file){
|
2019-06-01 23:58:28 +00:00
|
|
|
Scratch_Block scratch(app);
|
2019-06-02 03:07:57 +00:00
|
|
|
String_Const_u8 buffer_name = push_buffer_unique_name(app, scratch, buffer_id);
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 str = string_u8_pushf(scratch, "Ending file: %.*s\n",
|
|
|
|
string_expand(buffer_name));
|
|
|
|
print_message(app, str);
|
2017-04-18 15:41:49 +00:00
|
|
|
// no meaning for return
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
// NOTE(allen|a4.0.9): The input filter allows you to modify the input
|
|
|
|
// to a frame before 4coder starts processing it at all.
|
|
|
|
//
|
|
|
|
// Right now it only has access to the mouse state, but it will be
|
|
|
|
// extended to have access to the key presses soon.
|
|
|
|
INPUT_FILTER_SIG(default_suppress_mouse_filter){
|
|
|
|
if (suppressing_mouse){
|
2019-02-25 23:42:13 +00:00
|
|
|
memset(mouse, 0, sizeof(*mouse));
|
|
|
|
mouse->p.x = -100;
|
|
|
|
mouse->p.y = -100;
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-06 21:13:49 +00:00
|
|
|
// TODO(allen): FIX FIX FIX FIX
|
2017-01-29 00:03:23 +00:00
|
|
|
// NOTE(allen|a4): scroll rule information
|
|
|
|
//
|
|
|
|
// The parameters:
|
|
|
|
// target_x, target_y
|
|
|
|
// This is where the view would like to be for the purpose of
|
|
|
|
// following the cursor, doing mouse wheel work, etc.
|
|
|
|
//
|
|
|
|
// scroll_x, scroll_y
|
|
|
|
// These are pointers to where the scrolling actually is. If you bind
|
|
|
|
// the scroll rule it is you have to update these in some way to move
|
|
|
|
// the actual location of the scrolling.
|
|
|
|
//
|
|
|
|
// view_id
|
|
|
|
// This corresponds to which view is computing it's new scrolling position.
|
2019-04-06 21:13:49 +00:00
|
|
|
// This id DOES correspond to the views that View_ _Summary contains.
|
2017-01-29 00:03:23 +00:00
|
|
|
// This will always be between 1 and 16 (0 is a null id).
|
|
|
|
// See below for an example of having state that carries across scroll udpates.
|
|
|
|
//
|
|
|
|
// is_new_target
|
|
|
|
// If the target of the view is different from the last target in either x or y
|
|
|
|
// this is true, otherwise it is false.
|
|
|
|
//
|
|
|
|
// The return:
|
|
|
|
// Should be true if and only if scroll_x or scroll_y are changed.
|
|
|
|
//
|
|
|
|
// Don't try to use the app pointer in a scroll rule, you're asking for trouble.
|
|
|
|
//
|
|
|
|
// If you don't bind scroll_rule, nothing bad will happen, yo will get default
|
|
|
|
// 4coder scrolling behavior.
|
|
|
|
//
|
|
|
|
|
2019-02-27 21:14:25 +00:00
|
|
|
Vec2 scroll_velocity_[16] = {};
|
|
|
|
Vec2 *scroll_velocity = scroll_velocity_ - 1;
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
static i32
|
2019-02-27 21:14:25 +00:00
|
|
|
smooth_camera_step(f32 target, f32 *current, f32 *vel, f32 S, f32 T){
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 result = 0;
|
2019-02-27 21:14:25 +00:00
|
|
|
f32 curr = *current;
|
|
|
|
f32 v = *vel;
|
2017-01-29 00:03:23 +00:00
|
|
|
if (curr != target){
|
|
|
|
if (curr > target - .1f && curr < target + .1f){
|
|
|
|
curr = target;
|
|
|
|
v = 1.f;
|
|
|
|
}
|
|
|
|
else{
|
2019-02-27 21:14:25 +00:00
|
|
|
f32 L = curr + T*(target - curr);
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 sign = (target > curr) - (target < curr);
|
2019-02-27 21:14:25 +00:00
|
|
|
f32 V = curr + sign*v;
|
2017-01-29 00:03:23 +00:00
|
|
|
|
|
|
|
if (sign > 0) curr = (L<V)?(L):(V);
|
|
|
|
else curr = (L>V)?(L):(V);
|
|
|
|
|
|
|
|
if (curr == V){
|
|
|
|
v *= S;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*current = curr;
|
|
|
|
*vel = v;
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCROLL_RULE_SIG(smooth_scroll_rule){
|
2019-02-27 21:14:25 +00:00
|
|
|
Vec2 *velocity = scroll_velocity + view_id;
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 result = 0;
|
2017-01-29 00:03:23 +00:00
|
|
|
if (velocity->x == 0.f){
|
|
|
|
velocity->x = 1.f;
|
|
|
|
velocity->y = 1.f;
|
|
|
|
}
|
|
|
|
if (smooth_camera_step(target_y, scroll_y, &velocity->y, 80.f, 1.f/2.f)){
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
if (smooth_camera_step(target_x, scroll_x, &velocity->x, 80.f, 1.f/2.f)){
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_all_default_hooks(Bind_Helper *context){
|
|
|
|
set_hook(context, hook_exit, default_exit);
|
2019-02-24 07:22:16 +00:00
|
|
|
set_hook(context, hook_buffer_viewer_update, default_view_adjust);
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2017-06-23 23:07:18 +00:00
|
|
|
set_start_hook(context, default_start);
|
2017-01-29 00:03:23 +00:00
|
|
|
set_open_file_hook(context, default_file_settings);
|
2017-02-26 20:13:06 +00:00
|
|
|
set_new_file_hook(context, default_new_file);
|
2017-01-29 00:03:23 +00:00
|
|
|
set_save_file_hook(context, default_file_save);
|
2019-03-22 01:27:28 +00:00
|
|
|
set_file_edit_range_hook(context, default_file_edit_range);
|
|
|
|
set_file_edit_finished_hook(context, default_file_edit_finished);
|
|
|
|
set_file_edit_range_hook(context, default_file_edit_range);
|
2017-06-16 23:10:50 +00:00
|
|
|
|
|
|
|
set_end_file_hook(context, end_file_close_jump_list);
|
2017-04-18 15:41:49 +00:00
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
set_command_caller(context, default_command_caller);
|
2018-09-22 23:45:24 +00:00
|
|
|
set_render_caller(context, default_render_caller);
|
2017-01-29 00:03:23 +00:00
|
|
|
set_input_filter(context, default_suppress_mouse_filter);
|
|
|
|
set_scroll_rule(context, smooth_scroll_rule);
|
2017-11-30 23:25:49 +00:00
|
|
|
set_buffer_name_resolver(context, default_buffer_name_resolution);
|
2019-02-25 23:42:13 +00:00
|
|
|
set_modify_color_table_hook(context, default_modify_color_table);
|
2019-02-27 05:49:35 +00:00
|
|
|
set_get_view_buffer_region_hook(context, default_view_buffer_region);
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|