diff --git a/4coder_API/4coder_custom.h b/4coder_API/4coder_custom.h index dfa22e64..d3a59a36 100644 --- a/4coder_API/4coder_custom.h +++ b/4coder_API/4coder_custom.h @@ -9,9 +9,9 @@ #include #include +#include #include "4coder_base_types.h" -#include "4coder_base_types.cpp" #include "4coder_lib/4coder_arena.h" #include "4coder_lib/4coder_heap.h" #include "4coder_lib/4coder_string.h" @@ -22,6 +22,8 @@ #include "4coder_API/4coder_types.h" #include "4coder_generated/app_functions.h" +#include "4coder_base_types.cpp" + extern "C" _GET_VERSION_SIG(get_alpha_4coder_version){ return((maj == MAJOR && min == MINOR && patch == PATCH)); } diff --git a/4coder_base_types.cpp b/4coder_base_types.cpp index e04f61bb..5eb1a70a 100644 --- a/4coder_base_types.cpp +++ b/4coder_base_types.cpp @@ -840,6 +840,56 @@ hsla_to_rgba(Vec4 hsla){ //////////////////////////////// +static i32 +get_width(Range range){ + i32 result = range.end - range.start; + if (result < 0){ + result = 0; + } + return(result); +} + +static Range +make_range(i32 p1, i32 p2){ + Range range; + if (p1 < p2){ + range.min = p1; + range.max = p2; + } + else{ + range.min = p2; + range.max = p1; + } + return(range); +} + +static Range +rectify(Range range) { + return(make_range(range.min, range.max)); +} + +static b32 +interval_overlap(i32 a0, i32 a1, i32 b0, i32 b1){ + return(!(a1 < b0 || b1 < a0)); +} + +static b32 +interval_overlap(Range a, Range b){ + return(interval_overlap(a.first, a.one_past_last, b.first, b.one_past_last)); +} + +static b32 +interval_contains(i32 a0, i32 a1, i32 b){ + return((a0 <= b) && (b < a1)); +} + +static b32 +interval_contains(Range range, i32 b){ + return(interval_contains(range.start, range.one_past_last, b)); +} + +//////////////////////////////// + static i32_Rect i32R(i32 l, i32 t, i32 r, i32 b){ i32_Rect rect = {}; diff --git a/4coder_base_types.h b/4coder_base_types.h index 26b5c1ab..b3778f01 100644 --- a/4coder_base_types.h +++ b/4coder_base_types.h @@ -420,6 +420,14 @@ struct Rect_i32{ typedef Rect_f32 f32_Rect; typedef Rect_i32 i32_Rect; +struct f32_Rect_Pair +{ + f32_Rect E[2]; +}; + +typedef f32_Rect_Pair Rect_f32_Pair; + + #endif // BOTTOM diff --git a/4coder_casey_pending.cpp b/4coder_casey_pending.cpp new file mode 100644 index 00000000..db40874b --- /dev/null +++ b/4coder_casey_pending.cpp @@ -0,0 +1,510 @@ +/* ======================================================================== +$File: work/apps/4coder/custom/4coder_casey_pending.cpp $ +$Date: 2019/03/30 23:57:38 UTC $ +$Revision: 21 $ +$Creator: Casey Muratori $ +$Notice: (C) Copyright by Molly Rocket, Inc., All Rights Reserved. $ +======================================================================== */ + +/* NOTE(casey): + +Allen, this is a file full of things that I think 4coder should have provided natively, so unless there's something objectionable +about them, I think they could be merged? + +*/ + +#include + +static Range +clip_range_to_width(Range range, int32_t max_width) { + Range result = range; + if((result.start + max_width) < result.end) { + result.end = result.start + max_width; + } + + return(result); +} + +#define CStrCase(a) case a: return(#a) +#define StringCase(a) case a: return(make_lit_string(#a)) + +// TODO(casey): Merge this with Allen's Token_Iterator when it's ready? +struct token_iterator +{ + Buffer_ID buffer; + bool32 valid; + int32_t index; +}; + +#if 0 +static void +Append(Found_String_List *dest, Found_String_List source) +{ + if(dest->last) + { + dest->last->next = source.first; + dest->last = source.last; + dest->count += source.count; + } + else + { + *dest = source; + } +} +#endif + +static Vec2 +center_of(f32_Rect a) +{ + Vec2 result; + + result.x = 0.5f*(a.x0 + a.x1); + result.y = 0.5f*(a.y0 + a.y1); + + return(result); +} + +static f32_Rect +f32_rect_from(i32_Rect a) +{ + f32_Rect result; + + result.x0 = (float)a.x0; + result.x1 = (float)a.x1; + result.y0 = (float)a.y0; + result.y1 = (float)a.y1; + + return(result); +} + +static i32_Rect +i32_rect_from(f32_Rect a) +{ + i32_Rect result; + + result.x0 = round32(a.x0); + result.x1 = round32(a.x1); + result.y0 = round32(a.y0); + result.y1 = round32(a.y1); + + return(result); +} + +static bool32 +is_valid(Range range) +{ + bool32 result = (range.start < range.one_past_last); + return(result); +} + +static bool32 +is_in(f32_Rect a, Vec2 p) +{ + bool32 result = ((p.x >= a.x0) && + (p.x < a.x1) && + (p.y >= a.y0) && + (p.y < a.y1)); + return(result); +} + +static bool32 +is_visible(View_Summary *view, Vec2 p) +{ + bool32 result = is_in(f32_rect_from(view->render_region), p); + return(result); +} + +static token_iterator +iterate_tokens(Application_Links *app, Buffer_ID buffer, int32_t absolute_position) +{ + token_iterator iter = {}; + + iter.buffer = buffer; + + Cpp_Get_Token_Result temp; + iter.valid = buffer_get_token_index(app, buffer, absolute_position, &temp); + if(iter.valid) + { + iter.index = temp.token_index; + } + + return(iter); +} + +static Cpp_Token +get_next_token(Application_Links *app, token_iterator *iter) +{ + Cpp_Token result = {}; + + if(buffer_read_tokens(app, iter->buffer, iter->index, iter->index + 1, &result)) + { + ++iter->index; + } + else + { + iter->valid = false; + } + + return(result); +} + +static Cpp_Token +peek_token(Application_Links *app, token_iterator *iter) +{ + Cpp_Token result = {}; + + buffer_read_tokens(app, iter->buffer, iter->index, iter->index + 1, &result); + + return(result); +} + +static Cpp_Token +get_prev_token(Application_Links *app, token_iterator *iter) +{ + Cpp_Token result = {}; + + if(buffer_read_tokens(app, iter->buffer, iter->index, iter->index + 1, &result)) + { + --iter->index; + } + else + { + iter->valid = false; + } + + return(result); +} + +static String +scratch_read(Application_Links *app, Arena *scratch, Buffer_ID buffer, int32_t start, int32_t end) +{ + String result = {}; + + if(start <= end) + { + int32_t len = end - start; + result = push_string_space(scratch, len); + if(buffer_read_range(app, buffer, start, end, result.str)) + { + result.size = len; + } + } + + return(result); +} + +static String +scratch_read(Application_Links *app, Arena *scratch, Buffer_ID buffer, Range location) +{ + String result = scratch_read(app, scratch, buffer, location.start, location.one_past_last); + return(result); +} + +static String +scratch_read(Application_Links *app, Arena *scratch, Buffer_ID buffer, Cpp_Token token) +{ + String result = scratch_read(app, scratch, buffer, token.start, token.start + token.size); + return(result); +} + +static bool32 +token_text_is(Application_Links *app, Buffer_Summary *buffer, Cpp_Token token, String match) +{ + Scratch_Block scratch(app); + + String text = scratch_read(app, scratch, buffer->buffer_id, token.start, token.start + token.size); + bool32 result = (compare_ss(text, match) == 0); + + return(result); +} + +static Range +token_range_from_abs(Application_Links *app, Buffer_ID buffer, int32_t pos, bool32 favor_forward) +{ + Range result = {}; + + Cpp_Get_Token_Result get; + if(buffer_get_token_index(app, buffer, pos, &get)) + { + if(favor_forward && get.in_whitespace_after_token) + { + Cpp_Token token; + buffer_read_tokens(app, buffer, get.token_index + 1, get.token_index + 2, &token); + result = make_range(token.start, token.start + token.size); + } + else + { + result = make_range(get.token_start, get.token_one_past_last); + } + } + + return(result); +} + +static int32_t +line_from_abs(Application_Links *app, Buffer_ID buffer, int32_t pos) +{ + int32_t Result = 0; + + Buffer_Seek seek = {}; + seek.type = buffer_seek_pos; + seek.pos = pos; + Partial_Cursor at; + if(buffer_compute_cursor(app, buffer, seek, &at)) + { + Result = at.line; + } + + return(Result); +} + +static i32 +abs_from_seek(Application_Links *app, Buffer_ID buffer, Buffer_Seek seek) +{ + i32 Result = 0; + + // TODO(casey): I feel like there need to be faster methods for round-tripping through the (column/line <-> pos) routes. + Partial_Cursor at; + if(buffer_compute_cursor(app, buffer, seek, &at)) + { + Result = at.pos; + } + + return(Result); +} + +static int32_t +line_from_abs(Application_Links *app, Buffer_Summary *buffer, int32_t pos) +{ + int32_t Result = 0; + + Buffer_Seek seek = {}; + seek.type = buffer_seek_pos; + seek.pos = pos; + Partial_Cursor at; + if(buffer_compute_cursor(app, buffer, seek, &at)) + { + Result = at.line; + } + + return(Result); +} + +static int32_t +line_from_abs(Application_Links *app, View_Summary *view, int32_t pos) +{ + int32_t Result = 0; + + Buffer_Seek seek = {}; + seek.type = buffer_seek_pos; + seek.pos = pos; + Full_Cursor at; + if(view_compute_cursor(app, view, seek, &at)) + { + Result = at.line; + } + + return(Result); +} + +static bool32 +cursor_from_abs(Application_Links *app, View_Summary *view, int32_t pos, Full_Cursor *cursor) +{ + Buffer_Seek seek = {}; + seek.type = buffer_seek_pos; + seek.pos = pos; + bool32 result = view_compute_cursor(app, view, seek, cursor); + return(result); +} + +// TODO(casey): Rename these now that they are "render space", not screen space +static Vec2 +screen_p_from(View_Summary *view, Full_Cursor *at) +{ + Vec2 Result = {}; + + Result.x = (float)at->wrapped_x - (float)view->scroll_vars.scroll_x; + Result.y = (float)at->wrapped_y - (float)view->scroll_vars.scroll_y; + + return(Result); +} + +static Vec2 +screen_p_from_abs(Application_Links *app, View_Summary *view, int32_t pos) +{ + Vec2 Result = {}; + + Full_Cursor at; + if(cursor_from_abs(app, view, pos, &at)) + { + Result = screen_p_from(view, &at); + } + + return(Result); +} + +static String +read_entire_file(Partition *arena, char *filename) +{ + String result = {}; + + FILE *file = fopen(filename, "rb"); + if(file) + { + fseek(file, 0, SEEK_END); + // TODO(casey): Can't we have 64-bit sized strings? :( + i32_4tech size = (i32_4tech)ftell(file); + fseek(file, 0, SEEK_SET); + + result = string_push(arena, (i32_4tech)size); + if(result.str) + { + result.size = size; + fread(result.str, result.size, 1, file); + } + + fclose(file); + } + + return(result); +} + +static void +draw_line(Application_Links *app, Vec2 from, Vec2 to, int_color color, float thickness) +{ + // TODO(casey): Allen, this should eventually be an actual line primitive, for non-rectangular lines + float half = 0.5f*thickness; + f32_Rect rect; + rect.x0 = Min(from.x, to.x) - half; + rect.x1 = Max(from.x, to.x) + half; + rect.y0 = Min(from.y, to.y) - half; + rect.y1 = Max(from.y, to.y) + half; + draw_rectangle(app, rect, color); +} + +static void +draw_line_loop(Application_Links *app, int32_t p_count, Vec2 *p, int_color color, float thickness) +{ + if(p_count) + { + int32_t prev = p_count - 1; + for(int32_t i = 0; i < p_count; ++i) + { + draw_line(app, p[prev], p[i], color, thickness); + prev = i; + } + } +} + +static float +get_dpi_scaling_value(Application_Links *app) +{ + // TODO(casey): Allen, this should return the multiplier for the display relative to whatever 4coder + // gets tuned to. + float result = 2.0f; + return(result); +} + +static f32_Rect +minkowski_sum(f32_Rect a, Vec2 b) +{ + f32_Rect r = a; + + r.x0 -= b.x; + r.x1 += b.x; + + r.x0 -= b.y; + r.x1 += b.y; + + return(r); +} + +static f32_Rect +minkowski_sum(f32_Rect a, f32 b) +{ + f32_Rect r = minkowski_sum(a, V2(b, b)); + + return(r); +} + +static void +clear_buffer(Application_Links *app, Buffer_ID buffer_id) +{ + Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll); + if(buffer.exists) + { + buffer_replace_range(app, buffer_id, 0, buffer.size, empty_string); + } +} + +static int32_t +get_end_of_line(Application_Links *app, Buffer_ID buffer, int32_t from) +{ + int32_t result = from; + + Partial_Cursor line; + if(buffer_compute_cursor(app, buffer, seek_pos(from), &line)) + { + Partial_Cursor eol; + if(buffer_compute_cursor(app, buffer, seek_line_char(line.line, max_i32), &eol)) + { + result = eol.pos; + } + } + + return(result); +} + +enum Coordinate +{ + Coordinate_X = 0, + Coordinate_Y = 1, +}; + +enum Side +{ + Side_Min = 0, + Side_Max = 1, +}; + +static f32_Rect_Pair +split_rect(f32_Rect rect, View_Split_Kind kind, Coordinate coord, Side from_side, f32 t) +{ + f32_Rect_Pair result; + + if(kind == ViewSplitKind_FixedPixels) + { + result.E[0] = rect; + result.E[1] = rect; + + if(coord == Coordinate_X) + { + result.E[0].x1 = (from_side == Side_Max) ? (rect.x1 - t) : (rect.x0 + t); + result.E[1].x0 = result.E[0].x1; + } + else + { + Assert(coord == Coordinate_Y); + result.E[0].y1 = (from_side == Side_Max) ? (rect.y1 - t) : (rect.y0 + t); + result.E[1].y0 = result.E[0].y1; + } + } + else + { + Assert(kind == ViewSplitKind_Ratio); + + f32 pixel_count; + if(coord == Coordinate_X) + { + pixel_count = t*(rect.x1 - rect.x0); + } + else + { + Assert(coord == Coordinate_Y); + pixel_count = t*(rect.y1 - rect.y0); + } + result = split_rect(rect, ViewSplitKind_FixedPixels, coord, from_side, pixel_count); + } + + return(result); +} diff --git a/4coder_default_hooks.cpp b/4coder_default_hooks.cpp index 42092d9f..1938ceb2 100644 --- a/4coder_default_hooks.cpp +++ b/4coder_default_hooks.cpp @@ -753,10 +753,10 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View f32 dt = dts[k]; str.size = 0; if (dt == 0.f){ - push_fancy_stringf(arena, &list, white, "-----"); + push_fancy_stringf(arena, &list, white, "----------"); } else{ - push_fancy_stringf(arena, &list, white, "%5d", round32(1.f/dt)); + push_fancy_stringf(arena, &list, white, "%10.6f", dt); } push_fancy_stringf(arena, &list, green, " | "); } @@ -764,6 +764,8 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View draw_fancy_string(app, font_id, list.first, p, Stag_Default, 0, 0, V2(1.f, 0.f)); } } + + animate_in_n_milliseconds(app, 1000); } end_temp_memory(major_temp); diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 5dc9c4fa..0f1ad45d 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -44,6 +44,7 @@ #include "4coder_api_transition_30_31.cpp" +#include "4coder_hash_functions.cpp" #include "4coder_default_framework_variables.cpp" #include "4coder_buffer_seek_constructors.cpp" #include "4coder_helper.cpp" diff --git a/4coder_fancy.cpp b/4coder_fancy.cpp index a00a4a97..f1d05a8c 100644 --- a/4coder_fancy.cpp +++ b/4coder_fancy.cpp @@ -132,12 +132,10 @@ push_fancy_string(Arena *arena, String value){ static Fancy_String* push_fancy_stringfv(Arena *arena, Fancy_String_List *list, Fancy_Color fore, Fancy_Color back, char *format, va_list args){ - // TODO(casey): Allen, ideally we would have our own formatter here that just outputs into a buffer and can't ever "run out of space". - char temp[1024]; - i32 length = vsprintf(temp, format, args); + String str = string_push_fv(arena, format, args); Fancy_String *result = 0; - if (length > 0){ - result = push_fancy_string(arena, list, fore, back, make_string(temp, length)); + if (str.size > 0){ + result = push_fancy_string(arena, list, fore, back, str); } return(result); } diff --git a/4coder_generated/app_functions.h b/4coder_generated/app_functions.h index 949099aa..2a8b8e98 100644 --- a/4coder_generated/app_functions.h +++ b/4coder_generated/app_functions.h @@ -169,7 +169,8 @@ struct Application_Links; #define DRAW_COORDINATE_CENTER_POP_SIG(n) Vec2 n(Application_Links *app) #define GET_DEFAULT_FONT_FOR_VIEW_SIG(n) Face_ID n(Application_Links *app, View_ID view_id) #define TEXT_LAYOUT_GET_BUFFER_SIG(n) b32 n(Application_Links *app, Text_Layout_ID text_layout_id, Buffer_ID *buffer_id_out) -#define TEXT_LAYOUT_COMPUTE_CURSOR_SIG(n) b32 n(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 p, b32 round_down, Full_Cursor *cursor_out) +#define TEXT_LAYOUT_BUFFER_POINT_TO_LAYOUT_POINT_SIG(n) b32 n(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 buffer_relative_p, Vec2 *p_out) +#define TEXT_LAYOUT_LAYOUT_POINT_TO_BUFFER_POINT_SIG(n) b32 n(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 layout_relative_p, Vec2 *p_out) #define TEXT_LAYOUT_FREE_SIG(n) b32 n(Application_Links *app, Text_Layout_ID text_layout_id) #define COMPUTE_RENDER_LAYOUT_SIG(n) b32 n(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Rect_i32 screen_rect, Buffer_Point buffer_point, Range *on_screen_range_out, Text_Layout_ID *text_layout_id_out) #define DRAW_RENDER_LAYOUT_SIG(n) void n(Application_Links *app, View_ID view_id) @@ -347,7 +348,8 @@ typedef DRAW_COORDINATE_CENTER_PUSH_SIG(Draw_Coordinate_Center_Push_Function); typedef DRAW_COORDINATE_CENTER_POP_SIG(Draw_Coordinate_Center_Pop_Function); typedef GET_DEFAULT_FONT_FOR_VIEW_SIG(Get_Default_Font_For_View_Function); typedef TEXT_LAYOUT_GET_BUFFER_SIG(Text_Layout_Get_Buffer_Function); -typedef TEXT_LAYOUT_COMPUTE_CURSOR_SIG(Text_Layout_Compute_Cursor_Function); +typedef TEXT_LAYOUT_BUFFER_POINT_TO_LAYOUT_POINT_SIG(Text_Layout_Buffer_Point_To_Layout_Point_Function); +typedef TEXT_LAYOUT_LAYOUT_POINT_TO_BUFFER_POINT_SIG(Text_Layout_Layout_Point_To_Buffer_Point_Function); typedef TEXT_LAYOUT_FREE_SIG(Text_Layout_Free_Function); typedef COMPUTE_RENDER_LAYOUT_SIG(Compute_Render_Layout_Function); typedef DRAW_RENDER_LAYOUT_SIG(Draw_Render_Layout_Function); @@ -527,7 +529,8 @@ Draw_Coordinate_Center_Push_Function *draw_coordinate_center_push; Draw_Coordinate_Center_Pop_Function *draw_coordinate_center_pop; Get_Default_Font_For_View_Function *get_default_font_for_view; Text_Layout_Get_Buffer_Function *text_layout_get_buffer; -Text_Layout_Compute_Cursor_Function *text_layout_compute_cursor; +Text_Layout_Buffer_Point_To_Layout_Point_Function *text_layout_buffer_point_to_layout_point; +Text_Layout_Layout_Point_To_Buffer_Point_Function *text_layout_layout_point_to_buffer_point; Text_Layout_Free_Function *text_layout_free; Compute_Render_Layout_Function *compute_render_layout; Draw_Render_Layout_Function *draw_render_layout; @@ -706,7 +709,8 @@ Draw_Coordinate_Center_Push_Function *draw_coordinate_center_push_; Draw_Coordinate_Center_Pop_Function *draw_coordinate_center_pop_; Get_Default_Font_For_View_Function *get_default_font_for_view_; Text_Layout_Get_Buffer_Function *text_layout_get_buffer_; -Text_Layout_Compute_Cursor_Function *text_layout_compute_cursor_; +Text_Layout_Buffer_Point_To_Layout_Point_Function *text_layout_buffer_point_to_layout_point_; +Text_Layout_Layout_Point_To_Buffer_Point_Function *text_layout_layout_point_to_buffer_point_; Text_Layout_Free_Function *text_layout_free_; Compute_Render_Layout_Function *compute_render_layout_; Draw_Render_Layout_Function *draw_render_layout_; @@ -893,7 +897,8 @@ app_links->draw_coordinate_center_push_ = Draw_Coordinate_Center_Push;\ app_links->draw_coordinate_center_pop_ = Draw_Coordinate_Center_Pop;\ app_links->get_default_font_for_view_ = Get_Default_Font_For_View;\ app_links->text_layout_get_buffer_ = Text_Layout_Get_Buffer;\ -app_links->text_layout_compute_cursor_ = Text_Layout_Compute_Cursor;\ +app_links->text_layout_buffer_point_to_layout_point_ = Text_Layout_Buffer_Point_To_Layout_Point;\ +app_links->text_layout_layout_point_to_buffer_point_ = Text_Layout_Layout_Point_To_Buffer_Point;\ app_links->text_layout_free_ = Text_Layout_Free;\ app_links->compute_render_layout_ = Compute_Render_Layout;\ app_links->draw_render_layout_ = Draw_Render_Layout;\ @@ -1072,7 +1077,8 @@ static void draw_coordinate_center_push(Application_Links *app, Vec2 point){(app static Vec2 draw_coordinate_center_pop(Application_Links *app){return(app->draw_coordinate_center_pop(app));} static Face_ID get_default_font_for_view(Application_Links *app, View_ID view_id){return(app->get_default_font_for_view(app, view_id));} static b32 text_layout_get_buffer(Application_Links *app, Text_Layout_ID text_layout_id, Buffer_ID *buffer_id_out){return(app->text_layout_get_buffer(app, text_layout_id, buffer_id_out));} -static b32 text_layout_compute_cursor(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 p, b32 round_down, Full_Cursor *cursor_out){return(app->text_layout_compute_cursor(app, text_layout_id, p, round_down, cursor_out));} +static b32 text_layout_buffer_point_to_layout_point(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 buffer_relative_p, Vec2 *p_out){return(app->text_layout_buffer_point_to_layout_point(app, text_layout_id, buffer_relative_p, p_out));} +static b32 text_layout_layout_point_to_buffer_point(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 layout_relative_p, Vec2 *p_out){return(app->text_layout_layout_point_to_buffer_point(app, text_layout_id, layout_relative_p, p_out));} static b32 text_layout_free(Application_Links *app, Text_Layout_ID text_layout_id){return(app->text_layout_free(app, text_layout_id));} static b32 compute_render_layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Rect_i32 screen_rect, Buffer_Point buffer_point, Range *on_screen_range_out, Text_Layout_ID *text_layout_id_out){return(app->compute_render_layout(app, view_id, buffer_id, screen_rect, buffer_point, on_screen_range_out, text_layout_id_out));} static void draw_render_layout(Application_Links *app, View_ID view_id){(app->draw_render_layout(app, view_id));} @@ -1251,7 +1257,8 @@ static void draw_coordinate_center_push(Application_Links *app, Vec2 point){(app static Vec2 draw_coordinate_center_pop(Application_Links *app){return(app->draw_coordinate_center_pop_(app));} static Face_ID get_default_font_for_view(Application_Links *app, View_ID view_id){return(app->get_default_font_for_view_(app, view_id));} static b32 text_layout_get_buffer(Application_Links *app, Text_Layout_ID text_layout_id, Buffer_ID *buffer_id_out){return(app->text_layout_get_buffer_(app, text_layout_id, buffer_id_out));} -static b32 text_layout_compute_cursor(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 p, b32 round_down, Full_Cursor *cursor_out){return(app->text_layout_compute_cursor_(app, text_layout_id, p, round_down, cursor_out));} +static b32 text_layout_buffer_point_to_layout_point(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 buffer_relative_p, Vec2 *p_out){return(app->text_layout_buffer_point_to_layout_point_(app, text_layout_id, buffer_relative_p, p_out));} +static b32 text_layout_layout_point_to_buffer_point(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 layout_relative_p, Vec2 *p_out){return(app->text_layout_layout_point_to_buffer_point_(app, text_layout_id, layout_relative_p, p_out));} static b32 text_layout_free(Application_Links *app, Text_Layout_ID text_layout_id){return(app->text_layout_free_(app, text_layout_id));} static b32 compute_render_layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Rect_i32 screen_rect, Buffer_Point buffer_point, Range *on_screen_range_out, Text_Layout_ID *text_layout_id_out){return(app->compute_render_layout_(app, view_id, buffer_id, screen_rect, buffer_point, on_screen_range_out, text_layout_id_out));} static void draw_render_layout(Application_Links *app, View_ID view_id){(app->draw_render_layout_(app, view_id));} diff --git a/4coder_generated/command_metadata.h b/4coder_generated/command_metadata.h index 73311ab3..c8824f95 100644 --- a/4coder_generated/command_metadata.h +++ b/4coder_generated/command_metadata.h @@ -319,11 +319,11 @@ static Command_Metadata fcoder_metacmd_table[234] = { { PROC_LINKS(if0_off, 0), "if0_off", 7, "Surround the range between the cursor and mark with an '#if 0' and an '#endif'", 78, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 79 }, { PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 601 }, { PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 579 }, -{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 28, 776 }, +{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 28, 774 }, { PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 28, 886 }, { PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 28, 918 }, { PROC_LINKS(interactive_open_or_new, 0), "interactive_open_or_new", 23, "Interactively open a file out of the file system.", 49, "w:\\4ed\\code\\4coder_lists.cpp", 28, 848 }, -{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 28, 757 }, +{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 28, 755 }, { PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1625 }, { PROC_LINKS(kill_rect, 0), "kill_rect", 9, "Delete characters in a rectangular region. Range testing is done by unwrapped-xy coordinates.", 93, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 26 }, { PROC_LINKS(left_adjust_view, 0), "left_adjust_view", 16, "Sets the left size of the view near the x position of the cursor.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 167 }, @@ -331,16 +331,16 @@ static Command_Metadata fcoder_metacmd_table[234] = { { PROC_LINKS(list_all_functions_all_buffers_lister, 0), "list_all_functions_all_buffers_lister", 37, "Creates a lister of locations that look like function definitions and declarations all buffers.", 95, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 338 }, { PROC_LINKS(list_all_functions_current_buffer, 0), "list_all_functions_current_buffer", 33, "Creates a jump list of lines of the current buffer that appear to define or declare functions.", 94, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 309 }, { PROC_LINKS(list_all_functions_current_buffer_lister, 0), "list_all_functions_current_buffer_lister", 40, "Creates a lister of locations that look like function definitions and declarations in the buffer.", 97, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 319 }, -{ PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "w:\\4ed\\code\\4coder_search.cpp", 29, 833 }, -{ PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "w:\\4ed\\code\\4coder_search.cpp", 29, 847 }, -{ PROC_LINKS(list_all_locations_of_identifier, 0), "list_all_locations_of_identifier", 32, "Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.", 102, "w:\\4ed\\code\\4coder_search.cpp", 29, 861 }, -{ PROC_LINKS(list_all_locations_of_identifier_case_insensitive, 0), "list_all_locations_of_identifier_case_insensitive", 49, "Reads a token or word under the cursor and lists all exact case-insensitive mathces in all open buffers.", 104, "w:\\4ed\\code\\4coder_search.cpp", 29, 868 }, -{ PROC_LINKS(list_all_locations_of_selection, 0), "list_all_locations_of_selection", 31, "Reads the string in the selected range and lists all exact case-sensitive mathces in all open buffers.", 102, "w:\\4ed\\code\\4coder_search.cpp", 29, 875 }, -{ PROC_LINKS(list_all_locations_of_selection_case_insensitive, 0), "list_all_locations_of_selection_case_insensitive", 48, "Reads the string in the selected range and lists all exact case-insensitive mathces in all open buffers.", 104, "w:\\4ed\\code\\4coder_search.cpp", 29, 882 }, -{ PROC_LINKS(list_all_locations_of_type_definition, 0), "list_all_locations_of_type_definition", 37, "Queries user for string, lists all locations of strings that appear to define a type whose name matches the input string.", 121, "w:\\4ed\\code\\4coder_search.cpp", 29, 889 }, -{ PROC_LINKS(list_all_locations_of_type_definition_of_identifier, 0), "list_all_locations_of_type_definition_of_identifier", 51, "Reads a token or word under the cursor and lists all locations of strings that appear to define a type whose name matches it.", 125, "w:\\4ed\\code\\4coder_search.cpp", 29, 900 }, -{ PROC_LINKS(list_all_substring_locations, 0), "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "w:\\4ed\\code\\4coder_search.cpp", 29, 840 }, -{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "w:\\4ed\\code\\4coder_search.cpp", 29, 854 }, +{ PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "w:\\4ed\\code\\4coder_search.cpp", 29, 792 }, +{ PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "w:\\4ed\\code\\4coder_search.cpp", 29, 806 }, +{ PROC_LINKS(list_all_locations_of_identifier, 0), "list_all_locations_of_identifier", 32, "Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.", 102, "w:\\4ed\\code\\4coder_search.cpp", 29, 820 }, +{ PROC_LINKS(list_all_locations_of_identifier_case_insensitive, 0), "list_all_locations_of_identifier_case_insensitive", 49, "Reads a token or word under the cursor and lists all exact case-insensitive mathces in all open buffers.", 104, "w:\\4ed\\code\\4coder_search.cpp", 29, 827 }, +{ PROC_LINKS(list_all_locations_of_selection, 0), "list_all_locations_of_selection", 31, "Reads the string in the selected range and lists all exact case-sensitive mathces in all open buffers.", 102, "w:\\4ed\\code\\4coder_search.cpp", 29, 834 }, +{ PROC_LINKS(list_all_locations_of_selection_case_insensitive, 0), "list_all_locations_of_selection_case_insensitive", 48, "Reads the string in the selected range and lists all exact case-insensitive mathces in all open buffers.", 104, "w:\\4ed\\code\\4coder_search.cpp", 29, 841 }, +{ PROC_LINKS(list_all_locations_of_type_definition, 0), "list_all_locations_of_type_definition", 37, "Queries user for string, lists all locations of strings that appear to define a type whose name matches the input string.", 121, "w:\\4ed\\code\\4coder_search.cpp", 29, 848 }, +{ PROC_LINKS(list_all_locations_of_type_definition_of_identifier, 0), "list_all_locations_of_type_definition_of_identifier", 51, "Reads a token or word under the cursor and lists all locations of strings that appear to define a type whose name matches it.", 125, "w:\\4ed\\code\\4coder_search.cpp", 29, 859 }, +{ PROC_LINKS(list_all_substring_locations, 0), "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "w:\\4ed\\code\\4coder_search.cpp", 29, 799 }, +{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "w:\\4ed\\code\\4coder_search.cpp", 29, 813 }, { PROC_LINKS(lister__activate, 0), "lister__activate", 16, "A lister mode command that activates the list's action on the highlighted item.", 79, "w:\\4ed\\code\\4coder_lists.cpp", 28, 15 }, { PROC_LINKS(lister__backspace_text_field, 0), "lister__backspace_text_field", 28, "A lister mode command that dispatches to the lister's backspace text field handler.", 83, "w:\\4ed\\code\\4coder_lists.cpp", 28, 41 }, { PROC_LINKS(lister__backspace_text_field__default, 0), "lister__backspace_text_field__default", 37, "A lister mode command that backspaces one character from the text field.", 72, "w:\\4ed\\code\\4coder_lists.cpp", 28, 145 }, @@ -478,7 +478,7 @@ static Command_Metadata fcoder_metacmd_table[234] = { { PROC_LINKS(undo_this_buffer, 0), "undo_this_buffer", 16, "Advances backwards through the undo history of the current buffer.", 66, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1702 }, { PROC_LINKS(view_buffer_other_panel, 0), "view_buffer_other_panel", 23, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1582 }, { PROC_LINKS(view_jump_list_with_lister, 0), "view_jump_list_with_lister", 26, "When executed on a buffer with jumps, creates a persistent lister for all the jumps", 83, "w:\\4ed\\code\\4coder_jump_lister.cpp", 34, 106 }, -{ PROC_LINKS(word_complete, 0), "word_complete", 13, "Iteratively tries completing the word to the left of the cursor with other words in open buffers that have the same prefix string.", 130, "w:\\4ed\\code\\4coder_search.cpp", 29, 920 }, +{ PROC_LINKS(word_complete, 0), "word_complete", 13, "Iteratively tries completing the word to the left of the cursor with other words in open buffers that have the same prefix string.", 130, "w:\\4ed\\code\\4coder_search.cpp", 29, 879 }, { PROC_LINKS(write_and_auto_tab, 0), "write_and_auto_tab", 18, "Inserts a character and auto-indents the line on which the cursor sits.", 71, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 652 }, { PROC_LINKS(write_block, 0), "write_block", 11, "At the cursor, insert a block comment.", 38, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 103 }, { PROC_LINKS(write_character, 0), "write_character", 15, "Inserts whatever character was used to trigger this command.", 60, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 67 }, diff --git a/4ed_hash_functions.cpp b/4coder_hash_functions.cpp similarity index 93% rename from 4ed_hash_functions.cpp rename to 4coder_hash_functions.cpp index f76914b4..332b1522 100644 --- a/4ed_hash_functions.cpp +++ b/4coder_hash_functions.cpp @@ -9,7 +9,10 @@ // TOP -internal u64 +#if !defined(FCODER_HASH_FUNCTIONS_CPP) +#define FCODER_HASH_FUNCTIONS_CPP + +static u64 table_hash_u8(u8 *v, i32 size){ u64 hash = 0; for (u8 *p = v, *e = v + size; p < e; p += 1){ @@ -22,7 +25,7 @@ table_hash_u8(u8 *v, i32 size){ } return(hash); } -internal u64 +static u64 table_hash_u16(u16 *v, i32 size){ u64 hash = 0; for (u16 *p = v, *e = v + size; p < e; p += 1){ @@ -35,7 +38,7 @@ table_hash_u16(u16 *v, i32 size){ } return(hash); } -internal u64 +static u64 table_hash_u32(u32 *v, i32 size){ u64 hash = 0; for (u32 *p = v, *e = v + size; p < e; p += 1){ @@ -48,7 +51,7 @@ table_hash_u32(u32 *v, i32 size){ } return(hash); } -internal u64 +static u64 table_hash_u64(u64 *v, i32 size){ u64 hash = 0; for (u64 *p = v, *e = v + size; p < e; p += 1){ @@ -61,7 +64,7 @@ table_hash_u64(u64 *v, i32 size){ } return(hash); } -internal u64 +static u64 table_hash(void *v, i32 it_size, i32 size){ u64 hash = 0; switch (it_size){ @@ -89,6 +92,7 @@ table_hash(void *v, i32 it_size, i32 size){ return(hash); } +#endif + // BOTTOM - diff --git a/4coder_helper.cpp b/4coder_helper.cpp index 5602a7ae..2ab9dc7a 100644 --- a/4coder_helper.cpp +++ b/4coder_helper.cpp @@ -4,6 +4,74 @@ // TOP +static String +string_push(Arena *arena, i32 size){ + String result = {}; + if (size != 0){ + result.str = push_array(arena, char, size); + if (result.str != 0){ + result.memory_size = size; + } + } + return(result); +} + +static String +string_push_copy(Arena *arena, String str){ + String result = {}; + if (str.str != 0){ + result.str = push_array(arena, char, str.size + 1); + if (result.str != 0){ + result.memory_size = str.size + 1; + copy(&result, str); + result.str[result.size] = 0; + } + } + return(result); +} + +static String +string_push_fv(Arena *arena, char *format, va_list args){ + char temp[KB(4)]; + i32 n = vsnprintf(temp, sizeof(temp), format, args); + String result = {}; + if (0 <= n && n < sizeof(temp)){ + result = string_push_copy(arena, make_string(temp, n)); + } + return(result); +} + +static String +string_push_fv(Partition *part, char *format, va_list args){ + char temp[KB(4)]; + i32 n = vsnprintf(temp, sizeof(temp), format, args); + String result = {}; + if (0 <= n && n < sizeof(temp)){ + result = string_push_copy(part, make_string(temp, n)); + } + return(result); +} + +static String +string_push_f(Arena *arena, char *format, ...){ + va_list args; + va_start(args, format); + String result = string_push_fv(arena, format, args); + va_end(args); + return(result); +} + +static String +string_push_f(Partition *part, char *format, ...){ + va_list args; + va_start(args, format); + String result = string_push_fv(part, format, args); + va_end(args); + return(result); +} + +//////////////////////////////// + static Binding_Unit* write_unit(Bind_Helper *helper, Binding_Unit unit){ Binding_Unit *p = 0; @@ -423,6 +491,11 @@ query_user_number(Application_Links *app, Query_Bar *bar){ return(query_user_general(app, bar, true)); } +static i32 +buffer_replace_range_compute_shift(i32 start, i32 end, i32 len){ + return(len - (end - start)); +} + static char buffer_get_char(Application_Links *app, Buffer_ID buffer_id, i32 pos){ i32 buffer_size = 0; @@ -452,20 +525,6 @@ buffer_identifier(Buffer_ID id){ return(identifier); } -static Range -make_range(i32 p1, i32 p2){ - Range range; - if (p1 < p2){ - range.min = p1; - range.max = p2; - } - else{ - range.min = p2; - range.max = p1; - } - return(range); -} - static void adjust_all_buffer_wrap_widths(Application_Links *app, i32 wrap_width, i32 min_base_width){ for (Buffer_Summary buffer = get_buffer_first(app, AccessAll); @@ -737,6 +796,15 @@ get_view_range(View_Summary *view){ return(make_range(view->cursor.pos, view->mark.pos)); } +static String +buffer_read_string(Application_Links *app, Buffer_ID buffer, Range range, void *dest) { + String result = {}; + if (dest != 0 && buffer_read_range(app, buffer, range.start, range.end, (char *)dest)){ + result = make_string((char *)dest, get_width(range)); + } + return(result); +} + static b32 read_line(Application_Links *app, Partition *part, Buffer_ID buffer_id, i32 line, String *str, Partial_Cursor *start_out, Partial_Cursor *one_past_last_out){ @@ -788,12 +856,42 @@ scratch_read(Application_Links *app, Partition *scratch, Buffer_ID buffer, i32 s return(result); } +static String +scratch_read(Application_Links *app, Partition *scratch, Buffer_ID buffer, Range range){ + return(scratch_read(app, scratch, buffer, range.first, range.one_past_last)); +} + +static String +scratch_read(Application_Links *app, Arena *scratch, Buffer_ID buffer, i32 start, i32 end){ + String result = {}; + if (start <= end){ + i32 len = end - start; + result = string_push(scratch, len); + if (buffer_read_range(app, buffer, start, end, result.str)){ + result.size = len; + } + } + return(result); +} + +static String +scratch_read(Application_Links *app, Arena *scratch, Buffer_ID buffer, Range range){ + return(scratch_read(app, scratch, buffer, range.first, range.one_past_last)); +} + static String scratch_read(Application_Links *app, Partition *scratch, Buffer_ID buffer, Cpp_Token token){ String result = scratch_read(app, scratch, buffer, token.start, token.start + token.size); return(result); } +static String +read_entire_buffer(Application_Links *app, Buffer_ID buffer_id, Arena *scratch){ + i32 size = 0; + buffer_get_size(app, buffer_id, &size); + return(scratch_read(app, scratch, buffer_id, 0, size)); +} + static i32 buffer_get_line_start(Application_Links *app, Buffer_ID buffer_id, i32 line){ i32 result = 0; @@ -1221,131 +1319,6 @@ get_token_or_word_under_pos(Application_Links *app, Buffer_Summary *buffer, i32 return(result); } -static String -build_string(Partition *part, char *s0, char *s1, char *s2){ - String sr = {}; - sr.memory_size = str_size(s0) + str_size(s1) + str_size(s2) + 1; - sr.str = push_array(part, char, sr.memory_size); - if (sr.str != 0){ - append(&sr, s0); - append(&sr, s1); - append(&sr, s2); - } - return(sr); -} - -static String -build_string(Partition *part, char *s0, char *s1, String s2){ - String sr = {}; - sr.memory_size = str_size(s0) + str_size(s1) + s2.size + 1; - sr.str = push_array(part, char, sr.memory_size); - if (sr.str != 0){ - append(&sr, s0); - append(&sr, s1); - append(&sr, s2); - } - terminate_with_null(&sr); - return(sr); -} - -static String -build_string(Partition *part, char *s0, String s1, char *s2){ - String sr = {}; - sr.memory_size = str_size(s0) + s1.size + str_size(s2) + 1; - sr.str = push_array(part, char, sr.memory_size); - if (sr.str != 0){ - append(&sr, s0); - append(&sr, s1); - append(&sr, s2); - } - terminate_with_null(&sr); - return(sr); -} - -static String -build_string(Partition *part, char *s0, String s1, String s2){ - String sr = {}; - sr.memory_size = str_size(s0) + s1.size + s2.size + 1; - sr.str = push_array(part, char, sr.memory_size); - if (sr.str != 0){ - append(&sr, s0); - append(&sr, s1); - append(&sr, s2); - } - terminate_with_null(&sr); - return(sr); -} - -static String -build_string(Partition *part, String s0, char *s1, char *s2){ - String sr = {}; - sr.memory_size = s0.size + str_size(s1) + str_size(s2) + 1; - sr.str = push_array(part, char, sr.memory_size); - if (sr.str != 0){ - append(&sr, s0); - append(&sr, s1); - append(&sr, s2); - } - terminate_with_null(&sr); - return(sr); -} - -static String -build_string(Partition *part, String s0, char *s1, String s2){ - String sr = {}; - sr.memory_size = s0.size + str_size(s1) + s2.size + 1; - sr.str = push_array(part, char, sr.memory_size); - if (sr.str != 0){ - append(&sr, s0); - append(&sr, s1); - append(&sr, s2); - } - terminate_with_null(&sr); - return(sr); -} - -static String -build_string(Partition *part, String s0, String s1, char *s2){ - String sr = {}; - sr.memory_size = s0.size + s1.size + str_size(s2) + 1; - sr.str = push_array(part, char, sr.memory_size); - if (sr.str != 0){ - append(&sr, s0); - append(&sr, s1); - append(&sr, s2); - } - terminate_with_null(&sr); - return(sr); -} - -static String -build_string(Partition *part, String s0, String s1, String s2){ - String sr = {}; - sr.memory_size = s0.size + s1.size + s2.size + 1; - sr.str = push_array(part, char, sr.memory_size); - if (sr.str != 0){ - append(&sr, s0); - append(&sr, s1); - append(&sr, s2); - } - terminate_with_null(&sr); - return(sr); -} - -static String -string_push_copy(Arena *arena, String str){ - String result = {}; - if (str.str != 0){ - result.str = push_array(arena, char, str.size + 1); - if (result.str != 0){ - result.memory_size = str.size + 1; - copy(&result, str); - result.str[result.size] = 0; - } - } - return(result); -} - static void append_int_to_str_left_pad(String *str, i32 x, i32 minimum_width, char pad_char){ i32 length = int_to_str_size(x); diff --git a/4coder_helper.h b/4coder_helper.h index 29a76690..c1126050 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -7,10 +7,6 @@ #if !defined(FCODER_HELPER_H) #define FCODER_HELPER_H -// TODO(allen): Stop handling files this way! My own API should be able to do this!!?!?!?!!?!?!!!!? -// NOTE(allen): Actually need binary buffers for some stuff to work, but not this parsing thing here. -#include - struct Bind_Helper{ Binding_Unit *cursor, *start, *end; Binding_Unit *header, *group; diff --git a/4coder_insertion.cpp b/4coder_insertion.cpp index 39268572..ac0e103a 100644 --- a/4coder_insertion.cpp +++ b/4coder_insertion.cpp @@ -35,21 +35,15 @@ insert_string(Buffer_Insertion *insertion, String string){ static i32 insertf(Buffer_Insertion *insertion, char *format, ...){ - // TODO(casey): Allen, ideally we would have our own formatter here that just outputs into a buffer and can't ever "run out of space". - char temp[1024]; - + Arena *arena = context_get_arena(insertion->app); + Temp_Memory_Arena temp = begin_temp_memory(arena); va_list args; - // TODO(casey): Allen, ideally we would have our own formatted here that could handle our string type, via %S or something, so - // we don't have to keep doing %.*s and passing two parameters and all that garbage. va_start(args, format); - // TODO(casey): Allen, ideally we would have our own formatted here that could handle our string type, via %S or something, so - // we don't have to keep doing %.*s and passing two parameters and all that garbage. - i32 result = vsprintf(temp, format, args); + String string = string_push_fv(arena, format, args); va_end(args); - - insert_string(insertion, make_string(temp, result)); - - return(result); + insert_string(insertion, string); + end_temp_memory(temp); + return(string.size); } static void diff --git a/4coder_lib/4coder_arena.cpp b/4coder_lib/4coder_arena.cpp index aea1b09c..0efd564e 100644 --- a/4coder_lib/4coder_arena.cpp +++ b/4coder_lib/4coder_arena.cpp @@ -263,6 +263,21 @@ push_allocator_align(Arena *arena, i32_4tech b){ arena_align(arena, b); } +//////////////////////////////// + +Scratch_Block::Scratch_Block(Application_Links *app){ + scratch = context_get_arena(app); + temp = begin_temp_memory(scratch); +} + +Scratch_Block::~Scratch_Block(){ + end_temp_memory(temp); +} + +Scratch_Block::operator Arena*(){ + return(scratch); +} + #endif //////////////////////////////// diff --git a/4coder_lib/4coder_arena.h b/4coder_lib/4coder_arena.h index 36ba5791..f16ba58f 100644 --- a/4coder_lib/4coder_arena.h +++ b/4coder_lib/4coder_arena.h @@ -80,6 +80,15 @@ struct Temp_Memory_Arena_Light{ i32_4tech pos; }; +struct Scratch_Block{ + Scratch_Block(Application_Links *app); + ~Scratch_Block(); + operator Arena *(); + + Arena *scratch; + Temp_Memory_Arena temp; +}; + #endif #endif diff --git a/4coder_lists.cpp b/4coder_lists.cpp index b81d234c..a460e727 100644 --- a/4coder_lists.cpp +++ b/4coder_lists.cpp @@ -573,8 +573,7 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){ info < one_past_last; info += 1){ if (!info->folder) continue; - String file_name = build_string(arena_use_as_part(&lister->arena, info->filename_len + 1), - make_string(info->filename, info->filename_len), "/", ""); + String file_name = string_push_f(&lister->arena, "%.*s/", info->filename_len, info->filename); lister_add_item(lister, lister_prealloced(file_name), empty_string_prealloced, file_name.str, 0); } @@ -613,8 +612,7 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){ case DirtyState_UnsavedChangesAndUnloadedChanges: status_flag = " *!"; break; } } - i32 more_than_enough_memory = 32; - String status = build_string(arena_use_as_part(&lister->arena, more_than_enough_memory), is_loaded, status_flag, ""); + String status = string_push_f(&lister->arena, "%s%s", is_loaded, status_flag); lister_add_item(lister, lister_prealloced(file_name), lister_prealloced(status), file_name.str, 0); } } @@ -796,10 +794,12 @@ activate_open_or_new__generic(Application_Links *app, Partition *scratch, View_S Temp_Memory temp = begin_temp_memory(scratch); String full_file_name = {}; if (path.size == 0 || !char_is_slash(path.str[path.size - 1])){ - full_file_name = build_string(scratch, path, "/", file_name); + full_file_name = string_push_f(scratch, "%.*s/%.*s", + path.size, path.str, file_name.size, file_name.str); } else{ - full_file_name = build_string(scratch, path, "", file_name); + full_file_name = string_push_f(scratch, "%.*s%.*s", + path.size, path.str, file_name.size, file_name.str); } if (is_folder){ directory_set_hot(app, full_file_name.str, full_file_name.size); diff --git a/4coder_search.cpp b/4coder_search.cpp index 22a1901f..9dd4dd46 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -601,47 +601,6 @@ buffered_print_buffer_length(Partition *part, Temp_Memory temp){ return(part->pos - temp.pos); } -#if 0 -static void -buffered_print_match_jump_line(Application_Links *app, Partition *part, Temp_Memory temp, Partition *line_part, Buffer_Summary *output_buffer, - Buffer_Summary *match_buffer, Partial_Cursor word_pos){ - char *file_name = match_buffer->buffer_name; - int32_t file_len = match_buffer->buffer_name_len; - - int32_t line_num_len = int_to_str_size(word_pos.line); - int32_t column_num_len = int_to_str_size(word_pos.character); - - Temp_Memory line_temp = begin_temp_memory(line_part); - String line_str = {}; - if (read_line(app, line_part, match_buffer, word_pos.line, &line_str)){ - line_str = skip_chop_whitespace(line_str); - - int32_t str_len = file_len + 1 + line_num_len + 1 + column_num_len + 1 + 1 + line_str.size + 1; - - char *spare = buffered_memory_reserve(app, part, temp, output_buffer, str_len); - - String out_line = make_string_cap(spare, 0, str_len); - append_ss(&out_line, make_string(file_name, file_len)); - append_s_char(&out_line, ':'); - append_int_to_str(&out_line, word_pos.line); - append_s_char(&out_line, ':'); - append_int_to_str(&out_line, word_pos.character); - append_s_char(&out_line, ':'); - append_s_char(&out_line, ' '); - append_ss(&out_line, line_str); - append_s_char(&out_line, '\n'); - Assert(out_line.size == str_len); - } - - end_temp_memory(line_temp); -} -#endif - -#if 0 -static b32 -search_buffer_edit_handler(Application_Links *app, Buffer_ID buffer_id, int32_t start, int32_t one_past_last, String text); -#endif - static String search_name = make_lit_string("*search*"); static void @@ -804,15 +763,15 @@ list_type_definition__parameters(Application_Links *app, Heap *heap, Partition * String match_strings[9]; int32_t i = 0; - match_strings[i++] = build_string(scratch, "struct ", str, "{"); - match_strings[i++] = build_string(scratch, "struct ", str, "\n{"); - match_strings[i++] = build_string(scratch, "struct ", str, " {"); - match_strings[i++] = build_string(scratch, "union " , str, "{"); - match_strings[i++] = build_string(scratch, "union " , str, "\n{"); - match_strings[i++] = build_string(scratch, "union " , str, " {"); - match_strings[i++] = build_string(scratch, "enum " , str, "{"); - match_strings[i++] = build_string(scratch, "enum " , str, "\n{"); - match_strings[i++] = build_string(scratch, "enum " , str, " {"); + match_strings[i++] = string_push_f(scratch, "struct %.*s{" , str.size, str.str); + match_strings[i++] = string_push_f(scratch, "struct %.*s\n{", str.size, str.str); + match_strings[i++] = string_push_f(scratch, "struct %.*s {" , str.size, str.str); + match_strings[i++] = string_push_f(scratch, "union %.*s{" , str.size, str.str); + match_strings[i++] = string_push_f(scratch, "union %.*s\n{" , str.size, str.str); + match_strings[i++] = string_push_f(scratch, "union %.*s {" , str.size, str.str); + match_strings[i++] = string_push_f(scratch, "enum %.*s{" , str.size, str.str); + match_strings[i++] = string_push_f(scratch, "enum %.*s\n{" , str.size, str.str); + match_strings[i++] = string_push_f(scratch, "enum %.*s {" , str.size, str.str); list__parameters(app, heap, scratch, match_strings, ArrayCount(match_strings), 0, diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index cac45289..05e38e62 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -4617,7 +4617,7 @@ Text_Layout_Get_Buffer(Application_Links *app, Text_Layout_ID text_layout_id, Bu } API_EXPORT b32 -Text_Layout_Compute_Cursor(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 p, b32 round_down, Full_Cursor *cursor_out){ +Text_Layout_Buffer_Point_To_Layout_Point(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 buffer_relative_p, Vec2 *p_out){ Models *models = (Models*)app->cmd_context; Text_Layout layout = {}; b32 result = false; @@ -4625,15 +4625,39 @@ Text_Layout_Compute_Cursor(Application_Links *app, Text_Layout_ID text_layout_id Editing_File *file = imp_get_file(models, layout.buffer_id); if (buffer_api_check_file(file)){ System_Functions *system = models->system; + // TODO(allen): this could be computed and stored _once_ right? Full_Cursor top = file_compute_cursor(system, file, seek_line_char(layout.point.line_number, 1)); f32 top_y = top.wrapped_y; if (file->settings.unwrapped_lines){ top_y = top.unwrapped_y; } - p += layout.point.pixel_shift; - p.y += top_y; - Buffer_Seek seek = seek_xy(p.x, p.y, round_down, file->settings.unwrapped_lines); - *cursor_out = file_compute_cursor(system, file, seek); + buffer_relative_p -= layout.point.pixel_shift; + buffer_relative_p.y -= top_y; + *p_out = buffer_relative_p; + result = true; + } + } + return(result); +} + +API_EXPORT b32 +Text_Layout_Layout_Point_To_Buffer_Point(Application_Links *app, Text_Layout_ID text_layout_id, Vec2 layout_relative_p, Vec2 *p_out){ + Models *models = (Models*)app->cmd_context; + Text_Layout layout = {}; + b32 result = false; + if (text_layout_get(&models->text_layouts, text_layout_id, &layout)){ + Editing_File *file = imp_get_file(models, layout.buffer_id); + if (buffer_api_check_file(file)){ + System_Functions *system = models->system; + // TODO(allen): this could be computed and stored _once_ right? + Full_Cursor top = file_compute_cursor(system, file, seek_line_char(layout.point.line_number, 1)); + f32 top_y = top.wrapped_y; + if (file->settings.unwrapped_lines){ + top_y = top.unwrapped_y; + } + layout_relative_p += layout.point.pixel_shift; + layout_relative_p.y += top_y; + *p_out = layout_relative_p; result = true; } } diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 99001cdf..e18bb960 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -66,7 +66,6 @@ struct Mem_Options{ #include "4ed_app_models.h" #include "4ed_mem.cpp" -#include "4ed_hash_functions.cpp" #include "4ed_ptr_check.cpp" #include "4ed_memory_bank.cpp" #include "4ed_dynamic_variables.cpp" diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index 10b618ad..083661c3 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -126,7 +126,7 @@ global System_Functions sysfunc; #include "4ed_font.cpp" #include "4ed_mem.cpp" -#include "4ed_hash_functions.cpp" +#include "4coder_hash_functions.cpp" //////////////////////////////// diff --git a/string/internal_4coder_string.cpp b/string/internal_4coder_string.cpp index 8a47e86c..c8a202db 100644 --- a/string/internal_4coder_string.cpp +++ b/string/internal_4coder_string.cpp @@ -39,6 +39,7 @@ typedef struct String{ } String; static String null_string = {}; +static String empty_string = {"", 0, 0}; #endif FSTRING_DECLS