From 39dbddfa3fb9e44f47fdf66b6e72bbf067dd45a0 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 24 Oct 2016 13:22:22 -0400 Subject: [PATCH 1/5] Fix label jump skipping bug --- 4ed_mem.h | 10 +-- buffer/4coder_buffer_abstract.cpp | 122 +++++++++++++++--------------- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/4ed_mem.h b/4ed_mem.h index fce85b86..ec01da91 100644 --- a/4ed_mem.h +++ b/4ed_mem.h @@ -4,7 +4,7 @@ #include "4coder_mem.h" -#define MEMORY_DEBUG +//#define MEMORY_DEBUG static void general_memory_open(System_Functions *system, General_Memory *general, void *memory, int32_t size){ @@ -57,7 +57,7 @@ general_memory_allocate(System_Functions *system, General_Memory *general, int32 return(result); } #else - return general_memory_allocate(general, memory, size); + return general_memory_allocate(general, size); #endif } @@ -68,7 +68,7 @@ general_memory_free(System_Functions *system, General_Memory *general, void *mem system->memory_free(0, memory, 0); } #else - return general_memory_free(general, memory, size); + return general_memory_free(general, memory); #endif } @@ -82,7 +82,7 @@ general_memory_reallocate(System_Functions *system, General_Memory *general, voi return(result); } #else - return general_memory_reallocate(general, memory, size); + return general_memory_reallocate(general, old, old_size, size); #endif } @@ -94,7 +94,7 @@ general_memory_reallocate_nocopy(System_Functions *system, General_Memory *gener return general_memory_allocate(system, general, size); } #else - return general_memory_reallocate_nocopy(general, memory, size); + return general_memory_reallocate_nocopy(general, old, size); #endif } diff --git a/buffer/4coder_buffer_abstract.cpp b/buffer/4coder_buffer_abstract.cpp index efdaae26..7dcfcc4d 100644 --- a/buffer/4coder_buffer_abstract.cpp +++ b/buffer/4coder_buffer_abstract.cpp @@ -761,68 +761,68 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa S.size = buffer_size(params.buffer); // Get cursor hint - i32 line_index = 0; - switch (params.seek.type){ - case buffer_seek_pos: - { - if (params.seek.pos > S.size){ - params.seek.pos = S.size; - } - if (params.seek.pos < 0){ - params.seek.pos = 0; - } - - line_index = buffer_get_line_index(params.buffer, params.seek.pos); - }break; - - case buffer_seek_character_pos: - { - i32 line_count = params.buffer->line_count; - i32 max_character = params.character_starts[line_count] - 1; - if (params.seek.pos > max_character){ - params.seek.pos = max_character; - } - if (params.seek.pos < 0){ - params.seek.pos = 0; - } - - line_index = buffer_get_line_index_from_character_pos(params.character_starts, params.seek.pos, - 0, params.buffer->line_count); - }break; - - case buffer_seek_line_char: - { - line_index = params.seek.line - 1; - if (line_index >= params.buffer->line_count){ - line_index = params.buffer->line_count - 1; - } - if (line_index < 0){ - line_index = 0; - } - }break; - - case buffer_seek_unwrapped_xy: - { - line_index = (i32)(params.seek.y / params.font_height); - if (line_index >= params.buffer->line_count){ - line_index = params.buffer->line_count - 1; - } - if (line_index < 0){ - line_index = 0; - } - }break; - - case buffer_seek_wrapped_xy: - { - line_index = buffer_get_line_index_from_wrapped_y(params.wrap_line_index, params.seek.y, params.font_height, - 0, params.buffer->line_count); - }break; - - default: InvalidCodePath; - } - - // Build the cursor hint { + i32 line_index = 0; + switch (params.seek.type){ + case buffer_seek_pos: + { + if (params.seek.pos > S.size){ + params.seek.pos = S.size; + } + if (params.seek.pos < 0){ + params.seek.pos = 0; + } + + line_index = buffer_get_line_index(params.buffer, params.seek.pos); + }break; + + case buffer_seek_character_pos: + { + i32 line_count = params.buffer->line_count; + i32 max_character = params.character_starts[line_count] - 1; + if (params.seek.pos > max_character){ + params.seek.pos = max_character; + } + if (params.seek.pos < 0){ + params.seek.pos = 0; + } + + line_index = buffer_get_line_index_from_character_pos(params.character_starts, params.seek.pos, + 0, params.buffer->line_count); + }break; + + case buffer_seek_line_char: + { + line_index = params.seek.line - 1; + if (line_index >= params.buffer->line_count){ + line_index = params.buffer->line_count - 1; + } + if (line_index < 0){ + line_index = 0; + } + }break; + + case buffer_seek_unwrapped_xy: + { + line_index = (i32)(params.seek.y / params.font_height); + if (line_index >= params.buffer->line_count){ + line_index = params.buffer->line_count - 1; + } + if (line_index < 0){ + line_index = 0; + } + }break; + + case buffer_seek_wrapped_xy: + { + line_index = buffer_get_line_index_from_wrapped_y(params.wrap_line_index, params.seek.y, params.font_height, + 0, params.buffer->line_count); + }break; + + default: InvalidCodePath; + } + + // Build the cursor hint S.next_cursor.pos = params.buffer->line_starts[line_index]; S.next_cursor.character_pos = params.character_starts[line_index]; S.next_cursor.line = line_index + 1; From e76dac49944a1998f4432dc87b4cd3c4b8bd734a Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 24 Oct 2016 19:02:10 -0400 Subject: [PATCH 2/5] minimum base width feature for code wrapping --- 4ed.cpp | 2 ++ 4ed_file.cpp | 3 ++ 4ed_file_view.cpp | 48 ++++++++++++++++++++----------- buffer/4coder_buffer_abstract.cpp | 8 ++---- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/4ed.cpp b/4ed.cpp index 65f1899b..8e61daa4 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -12,6 +12,7 @@ // App Structs #define DEFAULT_DISPLAY_WIDTH 672 +#define DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH 450 typedef enum App_State{ APP_STATE_EDIT, @@ -1659,6 +1660,7 @@ App_Init_Sig(app_init){ // NOTE(allen): file setup working_set_init(system, &models->working_set, partition, &vars->models.mem.general); models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH; + models->working_set.default_minimum_base_display_width = DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH; // NOTE(allen): clipboard setup models->working_set.clipboard_max_size = ArrayCount(models->working_set.clipboards); diff --git a/4ed_file.cpp b/4ed_file.cpp index 67bfb09b..9644b18e 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -91,6 +91,7 @@ struct Text_Effect{ struct Editing_File_Settings{ i32 base_map_id; i32 display_width; + i32 minimum_base_display_width; b32 dos_write_mode; b32 virtual_white; i16 font_id; @@ -217,6 +218,7 @@ struct Working_Set{ File_Node *sync_check_iter; i32 default_display_width; + i32 default_minimum_base_display_width; }; // @@ -452,6 +454,7 @@ working_set_alloc(Working_Set *working_set){ result->unique_buffer_id = ++working_set->unique_file_counter; dll_insert(&working_set->used_sentinel, node); result->settings.display_width = working_set->default_display_width; + result->settings.minimum_base_display_width = working_set->default_minimum_base_display_width; ++working_set->file_count; } diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index c3edf868..b58c4204 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -281,6 +281,13 @@ view_file_display_width(View *view){ return(result); } +inline f32 +view_file_minimum_base_width(View *view){ + Editing_File *file = view->file_data.file; + f32 result = (f32)file->settings.display_width; + return(result); +} + inline f32 view_file_height(View *view){ i32_Rect file_rect = view->file_region; @@ -389,7 +396,6 @@ view_compute_cursor(View *view, Buffer_Seek seek, b32 return_hint){ Buffer_Cursor_Seek_Params params; params.buffer = &file->state.buffer; params.seek = seek; - params.width = view_file_display_width(view); params.font_height = (f32)font->height; params.adv = font->advance_data; params.wrap_line_index = file->state.wrap_line_index; @@ -974,6 +980,7 @@ struct Code_Wrap_State{ Cpp_Token *token_ptr; Cpp_Token *end_token; + f32 base_x; f32 paren_nesting[32]; i32 paren_safe_top; i32 paren_top; @@ -1394,17 +1401,19 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, params.buffer = &file->state.buffer; params.wrap_line_index = file->state.wrap_line_index; params.adv = adv; - params.width = (f32)file->settings.display_width; params.virtual_white = file->settings.virtual_white; + f32 width = (f32)file->settings.display_width; + f32 minimum_base_width = (f32)file->settings.minimum_base_display_width; + i32 size = buffer_size(params.buffer); Buffer_Measure_Wrap_State state = {0}; Buffer_Layout_Stop stop = {0}; f32 edge_tolerance = 50.f; - if (edge_tolerance > params.width){ - edge_tolerance = params.width; + if (edge_tolerance > width){ + edge_tolerance = width; } f32 line_shift = 0.f; @@ -1425,7 +1434,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, wrap_state_init(&wrap_state, file, adv); use_tokens = 1; - potential_marks = push_array(part, Potential_Wrap_Indent_Pair, FLOOR32(params.width)); + potential_marks = push_array(part, Potential_Wrap_Indent_Pair, FLOOR32(width)); max_wrap_indent_mark = partition_remaining(part)/sizeof(Wrap_Indent_Pair); wrap_indent_marks = push_array(part, Wrap_Indent_Pair, max_wrap_indent_mark); @@ -1477,7 +1486,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, f32 adv = params.adv[ch]; x += adv; self_x += adv; - if (self_x > params.width){ + if (self_x > width){ goto doublebreak; } } @@ -1497,7 +1506,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, doublebreak:; wrap_unit_end = i; - if (x > params.width){ + if (x > width){ do_wrap = 1; file_allocate_wrap_positions_as_needed(system, general, file, wrap_position_index); file->state.wrap_positions[wrap_position_index++] = stop.pos; @@ -1511,10 +1520,18 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, case BLStatus_NeedWrapLineShift: case BLStatus_NeedLineShift: { + f32 current_width = width; + if (use_tokens){ Code_Wrap_State original_wrap_state = wrap_state; i32 next_line_start = params.buffer->line_starts[stop.line_index+1]; + f32 base_adjusted_width = wrap_state.base_x + minimum_base_width; + + if (minimum_base_width != 0 && current_width < base_adjusted_width){ + current_width = base_adjusted_width; + } + if (stop.status == BLStatus_NeedLineShift){ real_count = 0; potential_count = 0; @@ -1531,8 +1548,9 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, wrap_indent_marks[real_count].line_shift = clamp_bottom(0.f, current_shift); ++real_count; + wrap_state.base_x = wrap_state.paren_nesting[0]; + for (; wrap_state.token_ptr < wrap_state.end_token; ){ - Code_Wrap_Step step = {0}; b32 emit_comment_position = 0; b32 first_word = 1; @@ -1578,7 +1596,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, f32 adv = params.adv[ch]; x += adv; - if (!first_word && x > params.width){ + if (!first_word && x > current_width){ emit_comment_position = 1; goto doublebreak_stage1; } @@ -1626,7 +1644,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } b32 need_to_choose_a_wrap = 0; - if (step.final_x > params.width){ + if (step.final_x > current_width){ need_to_choose_a_wrap = 1; } @@ -1778,14 +1796,13 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, if (line_shift < 0){ line_shift = 0; } - } else{ line_shift = 0.f; } - if (line_shift > params.width - edge_tolerance){ - line_shift = params.width - edge_tolerance; + if (line_shift > current_width - edge_tolerance){ + line_shift = current_width - edge_tolerance; } if (stop.wrap_line_index >= file->state.line_indent_max){ @@ -1794,8 +1811,6 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, file->state.line_indents[stop.wrap_line_index] = line_shift; file->state.wrap_line_count = stop.wrap_line_index; - - //wrap_state_set_x(&wrap_state, line_shift); }break; } }while(stop.status != BLStatus_Finished); @@ -4220,8 +4235,7 @@ append_label(String *string, i32 indent_level, char *message){ } internal void -show_gui_line(GUI_Target *target, String *string, - i32 indent_level, i32 h_align, char *message, char *follow_up){ +show_gui_line(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, char *follow_up){ string->size = 0; append_label(string, indent_level, message); if (follow_up){ diff --git a/buffer/4coder_buffer_abstract.cpp b/buffer/4coder_buffer_abstract.cpp index 7dcfcc4d..141bbacc 100644 --- a/buffer/4coder_buffer_abstract.cpp +++ b/buffer/4coder_buffer_abstract.cpp @@ -203,7 +203,6 @@ struct Buffer_Measure_Wrap_Params{ Buffer_Type *buffer; i32 *wrap_line_index; f32 *adv; - f32 width; b32 virtual_white; }; @@ -235,8 +234,7 @@ struct Buffer_Measure_Wrap_State{ #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } internal_4tech Buffer_Layout_Stop -buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params, - f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ +buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ Buffer_Measure_Wrap_State S = *S_ptr; Buffer_Layout_Stop S_stop; @@ -710,7 +708,6 @@ buffer_partial_from_line_character(Buffer_Type *buffer, i32 line, i32 character) struct Buffer_Cursor_Seek_Params{ Buffer_Type *buffer; Buffer_Seek seek; - f32 width; f32 font_height; f32 *adv; i32 *wrap_line_index; @@ -745,8 +742,7 @@ struct Buffer_Cursor_Seek_State{ #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } internal_4tech Buffer_Layout_Stop -buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, - f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ +buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ Buffer_Cursor_Seek_State S = *S_ptr; Buffer_Layout_Stop S_stop; From ad5b203b57ab9430b5b7e9c80e5061ee32c6cec1 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 24 Oct 2016 20:26:52 -0400 Subject: [PATCH 3/5] preprocessor code wrapping rule --- 4coder_API.html | 4 +-- 4cpp_lexer_types.h | 4 +-- 4ed.cpp | 2 +- 4ed_file_view.cpp | 83 +++++++++++++++++++++++++++++----------------- TODO.txt | 5 +-- 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/4coder_API.html b/4coder_API.html index 1c51b70e..3ec9d69d 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -408,9 +408,7 @@ than the current size of the array the operation is ignored.
See Also
cpp_make_token_array

§5.4.19: cpp_lex_file

void cpp_lex_file(
char *data,
int32_t size,
Cpp_Token_Array *token_array_out
)
Parameters
data
The file data to be lexed in a single contiguous block.
size
The number of bytes in data.
token_array_out
The token array where the output tokens will be pushed. This token array must be previously allocated with cpp_make_token_array
Description
Lexes an entire file and manages the interaction with the lexer system so that it is quick and convenient to lex files.

-

Cpp_Token_Array lex_file(char *file_name){
    File_Data file = read_whole_file(file_name);
    
    // This array will be automatically grown if it runs
    // out of memory.
    Cpp_Token_Array array = cpp_make_token_array(100);
    
    cpp_lex_file(file.data, file.size, &array);
    
    return(array);
}
See Also

§5.5 Lexer Type Descriptions

§5.5.1: Cpp_Token_Type

enum Cpp_Token_Type;
Description
A Cpp_Token_Type classifies a token to make parsing easier. Some types are not -actually output by the lexer, but exist because parsers will also make use of token -types in their own output.

Values
CPP_TOKEN_JUNK = 0
CPP_TOKEN_COMMENT = 1
CPP_PP_INCLUDE = 2
CPP_PP_DEFINE = 3
CPP_PP_UNDEF = 4
CPP_PP_IF = 5
CPP_PP_IFDEF = 6
CPP_PP_IFNDEF = 7
CPP_PP_ELSE = 8
CPP_PP_ELIF = 9
CPP_PP_ENDIF = 10
CPP_PP_ERROR = 11
CPP_PP_IMPORT = 12
CPP_PP_USING = 13
CPP_PP_LINE = 14
CPP_PP_PRAGMA = 15
CPP_PP_STRINGIFY = 16
CPP_PP_CONCAT = 17
CPP_PP_UNKNOWN = 18
CPP_PP_DEFINED = 19
CPP_PP_INCLUDE_FILE = 20
CPP_PP_ERROR_MESSAGE = 21
CPP_TOKEN_KEY_TYPE = 22
CPP_TOKEN_KEY_MODIFIER = 23
CPP_TOKEN_KEY_QUALIFIER = 24
CPP_TOKEN_KEY_OPERATOR = 25
This type is not stored in token output from the lexer.

CPP_TOKEN_KEY_CONTROL_FLOW = 26
CPP_TOKEN_KEY_CAST = 27
CPP_TOKEN_KEY_TYPE_DECLARATION = 28
CPP_TOKEN_KEY_ACCESS = 29
CPP_TOKEN_KEY_LINKAGE = 30
CPP_TOKEN_KEY_OTHER = 31
CPP_TOKEN_IDENTIFIER = 32
CPP_TOKEN_INTEGER_CONSTANT = 33
CPP_TOKEN_CHARACTER_CONSTANT = 34
CPP_TOKEN_FLOATING_CONSTANT = 35
CPP_TOKEN_STRING_CONSTANT = 36
CPP_TOKEN_BOOLEAN_CONSTANT = 37
CPP_TOKEN_STATIC_ASSERT = 38
CPP_TOKEN_BRACKET_OPEN = 39
CPP_TOKEN_BRACKET_CLOSE = 40
CPP_TOKEN_PARENTHESE_OPEN = 41
CPP_TOKEN_PARENTHESE_CLOSE = 42
CPP_TOKEN_BRACE_OPEN = 43
CPP_TOKEN_BRACE_CLOSE = 44
CPP_TOKEN_SEMICOLON = 45
CPP_TOKEN_ELLIPSIS = 46
CPP_TOKEN_STAR = 47
This is an 'ambiguous' token type because it requires +

Cpp_Token_Array lex_file(char *file_name){
    File_Data file = read_whole_file(file_name);
    
    // This array will be automatically grown if it runs
    // out of memory.
    Cpp_Token_Array array = cpp_make_token_array(100);
    
    cpp_lex_file(file.data, file.size, &array);
    
    return(array);
}
See Also

§5.5 Lexer Type Descriptions

§5.5.1: Cpp_Token_Type

enum Cpp_Token_Type;
Description
A Cpp_Token_Type classifies a token to make parsing easier. Some types are not actually output by the lexer, but exist because parsers will also make use of token types in their own output.

Values
CPP_TOKEN_JUNK = 0
CPP_TOKEN_COMMENT = 1
CPP_PP_INCLUDE = 2
CPP_PP_DEFINE = 3
CPP_PP_UNDEF = 4
CPP_PP_IF = 5
CPP_PP_IFDEF = 6
CPP_PP_IFNDEF = 7
CPP_PP_ELSE = 8
CPP_PP_ELIF = 9
CPP_PP_ENDIF = 10
CPP_PP_ERROR = 11
CPP_PP_IMPORT = 12
CPP_PP_USING = 13
CPP_PP_LINE = 14
CPP_PP_PRAGMA = 15
CPP_PP_STRINGIFY = 16
CPP_PP_CONCAT = 17
CPP_PP_UNKNOWN = 18
CPP_PP_DEFINED = 19
CPP_PP_INCLUDE_FILE = 20
CPP_PP_ERROR_MESSAGE = 21
CPP_TOKEN_KEY_TYPE = 22
CPP_TOKEN_KEY_MODIFIER = 23
CPP_TOKEN_KEY_QUALIFIER = 24
CPP_TOKEN_KEY_OPERATOR = 25
This type is not stored in token output from the lexer.

CPP_TOKEN_KEY_CONTROL_FLOW = 26
CPP_TOKEN_KEY_CAST = 27
CPP_TOKEN_KEY_TYPE_DECLARATION = 28
CPP_TOKEN_KEY_ACCESS = 29
CPP_TOKEN_KEY_LINKAGE = 30
CPP_TOKEN_KEY_OTHER = 31
CPP_TOKEN_IDENTIFIER = 32
CPP_TOKEN_INTEGER_CONSTANT = 33
CPP_TOKEN_CHARACTER_CONSTANT = 34
CPP_TOKEN_FLOATING_CONSTANT = 35
CPP_TOKEN_STRING_CONSTANT = 36
CPP_TOKEN_BOOLEAN_CONSTANT = 37
CPP_TOKEN_STATIC_ASSERT = 38
CPP_TOKEN_BRACKET_OPEN = 39
CPP_TOKEN_BRACKET_CLOSE = 40
CPP_TOKEN_PARENTHESE_OPEN = 41
CPP_TOKEN_PARENTHESE_CLOSE = 42
CPP_TOKEN_BRACE_OPEN = 43
CPP_TOKEN_BRACE_CLOSE = 44
CPP_TOKEN_SEMICOLON = 45
CPP_TOKEN_ELLIPSIS = 46
CPP_TOKEN_STAR = 47
This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.

CPP_TOKEN_AMPERSAND = 48
This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.

CPP_TOKEN_TILDE = 49
This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.

CPP_TOKEN_PLUS = 50
This is an 'ambiguous' token type because it requires diff --git a/4cpp_lexer_types.h b/4cpp_lexer_types.h index 30ba13f9..2abf182e 100644 --- a/4cpp_lexer_types.h +++ b/4cpp_lexer_types.h @@ -16,9 +16,7 @@ #define struct_internal struct #endif -/* DOC(A Cpp_Token_Type classifies a token to make parsing easier. Some types are not -actually output by the lexer, but exist because parsers will also make use of token -types in their own output.) */ +/* DOC(A Cpp_Token_Type classifies a token to make parsing easier. Some types are not actually output by the lexer, but exist because parsers will also make use of token types in their own output.) */ ENUM(uint32_t, Cpp_Token_Type){ CPP_TOKEN_JUNK = 0, diff --git a/4ed.cpp b/4ed.cpp index 8e61daa4..7ad73be3 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -12,7 +12,7 @@ // App Structs #define DEFAULT_DISPLAY_WIDTH 672 -#define DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH 450 +#define DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH 550 typedef enum App_State{ APP_STATE_EDIT, diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index b58c4204..4a359957 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -975,15 +975,23 @@ file_allocate_wrap_positions_as_needed(System_Functions *system, General_Memory file_allocate_metadata_as_needed(system, general, &file->state.buffer, (void**)&file->state.wrap_positions, &file->state.wrap_position_max, min_amount, sizeof(f32)); } +struct Code_Wrap_X{ + f32 base_x; + f32 paren_nesting[32]; + i32 paren_safe_top; + i32 paren_top; +}; +globalvar Code_Wrap_X null_wrap_x = {0}; + struct Code_Wrap_State{ Cpp_Token_Array token_array; Cpp_Token *token_ptr; Cpp_Token *end_token; - f32 base_x; - f32 paren_nesting[32]; - i32 paren_safe_top; - i32 paren_top; + Code_Wrap_X wrap_x; + + b32 in_pp_body; + Code_Wrap_X plane_wrap_x; i32 *line_starts; i32 line_index; @@ -1028,8 +1036,8 @@ wrap_state_set_i(Code_Wrap_State *state, i32 i){ internal void wrap_state_set_top(Code_Wrap_State *state, f32 line_shift){ - if (state->paren_nesting[state->paren_safe_top] > line_shift){ - state->paren_nesting[state->paren_safe_top] = line_shift; + if (state->wrap_x.paren_nesting[state->wrap_x.paren_safe_top] > line_shift){ + state->wrap_x.paren_nesting[state->wrap_x.paren_safe_top] = line_shift; } } @@ -1056,9 +1064,24 @@ wrap_state_consume_token(Code_Wrap_State *state, i32 fixed_end_point){ state->consume_newline = 0; } + if (state->in_pp_body){ + if (!(state->token_ptr->flags & CPP_TFLAG_PP_BODY)){ + state->in_pp_body = 0; + state->wrap_x = state->plane_wrap_x; + } + } + + if (!state->in_pp_body){ + if (state->token_ptr->flags & CPP_TFLAG_PP_DIRECTIVE){ + state->in_pp_body = 1; + state->plane_wrap_x = state->wrap_x; + state->wrap_x = null_wrap_x; + } + } + b32 skipping_whitespace = 0; if (i >= state->next_line_start){ - state->x = state->paren_nesting[state->paren_safe_top]; + state->x = state->wrap_x.paren_nesting[state->wrap_x.paren_safe_top]; skipping_whitespace = 1; } @@ -1128,42 +1151,42 @@ wrap_state_consume_token(Code_Wrap_State *state, i32 fixed_end_point){ switch (state->token_ptr->type){ case CPP_TOKEN_BRACE_OPEN: { - state->paren_nesting[state->paren_safe_top] += state->tab_indent_amount; + state->wrap_x.paren_nesting[state->wrap_x.paren_safe_top] += state->tab_indent_amount; }break; case CPP_TOKEN_BRACE_CLOSE: { - state->paren_nesting[state->paren_safe_top] -= state->tab_indent_amount; + state->wrap_x.paren_nesting[state->wrap_x.paren_safe_top] -= state->tab_indent_amount; }break; case CPP_TOKEN_PARENTHESE_OPEN: case CPP_TOKEN_BRACKET_OPEN: { - ++state->paren_top; + ++state->wrap_x.paren_top; - i32 top = state->paren_top; - if (top >= ArrayCount(state->paren_nesting)){ - top = ArrayCount(state->paren_nesting) - 1; + i32 top = state->wrap_x.paren_top; + if (top >= ArrayCount(state->wrap_x.paren_nesting)){ + top = ArrayCount(state->wrap_x.paren_nesting) - 1; } - state->paren_safe_top = top; + state->wrap_x.paren_safe_top = top; - state->paren_nesting[top] = state->x; + state->wrap_x.paren_nesting[top] = state->x; }break; case CPP_TOKEN_PARENTHESE_CLOSE: case CPP_TOKEN_BRACKET_CLOSE: { - --state->paren_top; + --state->wrap_x.paren_top; - if (state->paren_top < 0){ - state->paren_top = 0; + if (state->wrap_x.paren_top < 0){ + state->wrap_x.paren_top = 0; } - i32 top = state->paren_top; - if (top >= ArrayCount(state->paren_nesting)){ - top = ArrayCount(state->paren_nesting) - 1; + i32 top = state->wrap_x.paren_top; + if (top >= ArrayCount(state->wrap_x.paren_nesting)){ + top = ArrayCount(state->wrap_x.paren_nesting) - 1; } - state->paren_safe_top = top; + state->wrap_x.paren_safe_top = top; }break; } @@ -1332,20 +1355,20 @@ stickieness_guess(Cpp_Token_Type type, Cpp_Token_Type other_type, u16 flags, u16 internal f32 get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start, b32 *adjust_top_to_this){ - f32 current_shift = wrap_state->paren_nesting[wrap_state->paren_safe_top]; + f32 current_shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top]; Assert(adjust_top_to_this != 0); if (wrap_state->token_ptr > wrap_state->token_array.tokens){ Cpp_Token prev_token = *(wrap_state->token_ptr-1); - if (wrap_state->paren_safe_top != 0 && prev_token.type == CPP_TOKEN_PARENTHESE_OPEN){ - current_shift = wrap_state->paren_nesting[wrap_state->paren_safe_top-1] + wrap_state->tab_indent_amount; + if (wrap_state->wrap_x.paren_safe_top != 0 && prev_token.type == CPP_TOKEN_PARENTHESE_OPEN){ + current_shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top-1] + wrap_state->tab_indent_amount; *adjust_top_to_this = 1; } f32 statement_continuation_indent = 0.f; - if (current_shift != 0.f && wrap_state->paren_safe_top == 0){ + if (current_shift != 0.f && wrap_state->wrap_x.paren_safe_top == 0){ if (!(prev_token.flags & CPP_TFLAG_PP_BODY) && !(prev_token.flags & CPP_TFLAG_PP_DIRECTIVE)){ switch (prev_token.type){ @@ -1375,7 +1398,7 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start, b32 *adjust_ switch (wrap_state->token_ptr->type){ case CPP_TOKEN_BRACE_CLOSE: { - if (wrap_state->paren_safe_top == 0){ + if (wrap_state->wrap_x.paren_safe_top == 0){ current_shift -= wrap_state->tab_indent_amount; } }break; @@ -1526,7 +1549,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, Code_Wrap_State original_wrap_state = wrap_state; i32 next_line_start = params.buffer->line_starts[stop.line_index+1]; - f32 base_adjusted_width = wrap_state.base_x + minimum_base_width; + f32 base_adjusted_width = wrap_state.wrap_x.base_x + minimum_base_width; if (minimum_base_width != 0 && current_width < base_adjusted_width){ current_width = base_adjusted_width; @@ -1548,7 +1571,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, wrap_indent_marks[real_count].line_shift = clamp_bottom(0.f, current_shift); ++real_count; - wrap_state.base_x = wrap_state.paren_nesting[0]; + wrap_state.wrap_x.base_x = wrap_state.wrap_x.paren_nesting[0]; for (; wrap_state.token_ptr < wrap_state.end_token; ){ Code_Wrap_Step step = {0}; @@ -1696,7 +1719,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } wrappable_score = 64*50; - wrappable_score += 101 - general_stickieness - wrap_state.paren_safe_top*80; + wrappable_score += 101 - general_stickieness - wrap_state.wrap_x.paren_safe_top*80; potential_marks[potential_count].wrap_position = wrap_position; potential_marks[potential_count].line_shift = current_shift; diff --git a/TODO.txt b/TODO.txt index d957a6f6..6c3b6694 100644 --- a/TODO.txt +++ b/TODO.txt @@ -176,9 +176,10 @@ ; [X] smarter wrap rule ; [X] handle unclosed statements ; [X] wrapped line indication +; [X] additional width for nesting? +; [X] handle comments +; [] solve the comment lead whitespace problem ; [] special indent rules in preprocessor body -; [] handle comments -; [] additional width for nesting? ; [] fix issues when relexing happens in parallel ; [] remeasure version of measure_wraps From 54bea311a2815aa5816f5c900405c5546ca7d8a1 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 24 Oct 2016 22:45:34 -0400 Subject: [PATCH 4/5] getting buffer font info --- 4coder_API.html | 24 ++++++++++++------------ 4coder_custom_api.h | 7 +++++++ 4coder_default_bindings.cpp | 20 +++++++++++++++++++- 4coder_default_include.cpp | 11 +++++++---- 4ed_api_implementation.cpp | 20 ++++++++++++++++++++ 4ed_file_view.cpp | 3 +-- 4ed_font_set.cpp | 34 ++++++++++++++++++++-------------- 4ed_rendering.h | 18 +++++------------- TODO.txt | 4 ++-- 9 files changed, 93 insertions(+), 48 deletions(-) diff --git a/4coder_API.html b/4coder_API.html index 3ec9d69d..b0d1fd9c 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -2,7 +2,7 @@

4coder API

Table of Contents

§1 Introduction

This is the documentation for the 4cpp lexer version 1.1. The documentation is the newest piece of this lexer project so it may still have problems. What is here should be correct and mostly complete.

If you have questions or discover errors please contact editor@4coder.net or to get help from community members you can post on the 4coder forums hosted on handmade.network at 4coder.handmade.network

This is the documentation for alpha 4.0.12 The documentation is still under construction so some of the links are linking to sections that have not been written yet. What is here should be correct and I suspect useful even without some of the other sections.

If you have questions or discover errors please contact editor@4coder.net or to get help from community members you can post on the 4coder forums hosted on handmade.network at 4coder.handmade.network

§2 4coder Systems

Coming Soon
-

§3 Types and Functions

§3.1 Function List

§3.2 Type List

§3.3 Function Descriptions

§3.3.1: exec_command

bool32 exec_command(
Application_Links *app,
Command_ID command_id
)
Parameters
command_id
The command_id parameter specifies which internal command to execute.
Return
This call returns non-zero if command_id named a valid internal command.
Description
A call to exec_command executes an internal command. +

§3 Types and Functions

§3.1 Function List

§3.2 Type List

§3.3 Function Descriptions

§3.3.1: exec_command

bool32 exec_command(
Application_Links *app,
Command_ID command_id
)
Parameters
command_id
The command_id parameter specifies which internal command to execute.
Return
This call returns non-zero if command_id named a valid internal command.
Description
A call to exec_command executes an internal command. If command_id is invalid a warning is posted to *messages*.

See Also

§3.3.2: exec_system_command

bool32 exec_system_command(
Application_Links *app,
View_Summary *view,
Buffer_Identifier buffer,
char *path,
int32_t path_len,
char *command,
int32_t command_len,
Command_Line_Interface_Flag flags
)
Parameters
view
If the view parameter is non-null it specifies a view to display the command's output buffer.
buffer
The buffer the command will output to is specified by the buffer parameter. See Buffer_Identifier for information on how this type specifies a buffer.
path
The path parameter specifies the path in which the command shall be executed. The string need not be null terminated.
path_len
The parameter path_len specifies the length of the path string.
command
The command parameter specifies the command that shall be executed. The string need not be null terminated.
command_len
The parameter command_len specifies the length of the command string.
flags
Flags for the behavior of the call are specified in the flags parameter.
Return
This call returns non-zero on success.
Description
A call to exec_system_command executes a command as if called from the command line, and sends the output to a buffer. The buffer identifier can either name a new buffer that does not exist, name a buffer that does @@ -70,33 +70,33 @@ GUI element that can overlap a buffer or other 4coder GUI. The contents of the can be changed after the call to start_query_bar and the query bar shown by 4coder will reflect the change. Since the bar stops showing when the command exits the only use for this call is in an interactive command that makes calls to get_user_input.


§3.3.47: end_query_bar

void end_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
Parameters
bar
This parameter should be a bar pointer of a currently active query bar.
flags
This parameter is not currently used and should be 0 for now.
Description
Stops showing the particular query bar specified by the bar parameter.



§3.3.49: change_theme

void change_theme(
Application_Links *app,
char *name,
int32_t len
)
Parameters
name
The name parameter specifies the name of the theme to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call changes 4coder's color pallet to one of the built in themes.


§3.3.50: change_font

void change_font(
Application_Links *app,
char *name,
int32_t len,
bool32 apply_to_all_files
)
Parameters
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
apply_to_all_files
If this is set all open files change to this font. Usually this should be true -durring the start hook because several files already exist at that time.
Description
This call changes 4coder's default font to one of the built in fonts.


§3.3.51: buffer_set_font

void buffer_set_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name,
int32_t len
)
Parameters
buffer
This parameter the buffer that shall have it's font changed
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call sets the display font of a particular buffer.


§3.3.52: set_theme_colors

void set_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
The colors pointer provides an array of color structs pairing differet style tags to color codes.
count
The count parameter specifies the number of Theme_Color structs in the colors array.
Description
For each struct in the array, the slot in the main color pallet specified by the +durring the start hook because several files already exist at that time.
Description
This call changes 4coder's default font to one of the built in fonts.


§3.3.51: buffer_set_font

void buffer_set_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name,
int32_t len
)
Parameters
buffer
This parameter the buffer that shall have it's font changed
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call sets the display font of a particular buffer.


§3.3.52: buffer_get_font

int32_t buffer_get_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name_out,
int32_t name_max
)
No documentation generated for this function.

§3.3.53: set_theme_colors

void set_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
The colors pointer provides an array of color structs pairing differet style tags to color codes.
count
The count parameter specifies the number of Theme_Color structs in the colors array.
Description
For each struct in the array, the slot in the main color pallet specified by the struct's tag is set to the color code in the struct. If the tag value is invalid -no change is made to the color pallet.


§3.3.53: get_theme_colors

void get_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
an array of color structs listing style tags to get color values for
count
the number of color structs in the colors array
Description
For each struct in the array, the color field of the struct is filled with the +no change is made to the color pallet.


§3.3.54: get_theme_colors

void get_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
an array of color structs listing style tags to get color values for
count
the number of color structs in the colors array
Description
For each struct in the array, the color field of the struct is filled with the color from the slot in the main color pallet specified by the tag. If the tag -value is invalid the color is filled with black.


§3.3.54: directory_get_hot

int32_t directory_get_hot(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the 4coder 'hot directory'.
capacity
This parameter specifies the maximum size to be output to the out buffer.
Return
This call returns the size of the string written into the buffer.
Description
4coder has a concept of a 'hot directory' which is the directory most recently +value is invalid the color is filled with black.


§3.3.55: directory_get_hot

int32_t directory_get_hot(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the 4coder 'hot directory'.
capacity
This parameter specifies the maximum size to be output to the out buffer.
Return
This call returns the size of the string written into the buffer.
Description
4coder has a concept of a 'hot directory' which is the directory most recently accessed in the GUI. Whenever the GUI is opened it shows the hot directory.

In the future this will be deprecated and eliminated in favor of more flexible -directories controlled on the custom side.


§3.3.55: get_file_list

File_List get_file_list(
Application_Links *app,
char *dir,
int32_t len
)
Parameters
dir
This parameter specifies the directory whose files will be enumerated in the returned list; it need not be null terminated.
len
This parameter the length of the dir string.
Return
This call returns a File_List struct containing pointers to the names of the files in +directories controlled on the custom side.


§3.3.56: get_file_list

File_List get_file_list(
Application_Links *app,
char *dir,
int32_t len
)
Parameters
dir
This parameter specifies the directory whose files will be enumerated in the returned list; it need not be null terminated.
len
This parameter the length of the dir string.
Return
This call returns a File_List struct containing pointers to the names of the files in the specified directory. The File_List returned should be passed to free_file_list -when it is no longer in use.

§3.3.56: free_file_list

void free_file_list(
Application_Links *app,
File_List list
)
Parameters
list
This parameter provides the file list to be freed.
Description
After this call the file list passed in should not be read or written to.


§3.3.57: memory_allocate

void* memory_allocate(
Application_Links *app,
int32_t size
)
Parameters
size
The size in bytes of the block that should be returned.
Description
This calls to a low level OS allocator which means it is best used +when it is no longer in use.

§3.3.57: free_file_list

void free_file_list(
Application_Links *app,
File_List list
)
Parameters
list
This parameter provides the file list to be freed.
Description
After this call the file list passed in should not be read or written to.


§3.3.58: memory_allocate

void* memory_allocate(
Application_Links *app,
int32_t size
)
Parameters
size
The size in bytes of the block that should be returned.
Description
This calls to a low level OS allocator which means it is best used for infrequent, large allocations. The size of the block must be remembered -if it will be freed or if it's mem protection status will be changed.

See Also

§3.3.58: memory_set_protection

bool32 memory_set_protection(
Application_Links *app,
void *ptr,
int32_t size,
Memory_Protect_Flags flags
)
Parameters
ptr
The base of the block on which to set memory protection flags.
size
The size that was originally used to allocate this block.
flags
The new memory protection flags.
Description
This call sets the memory protection flags of a block of memory that was previously -allocate by memory_allocate.

See Also

§3.3.59: memory_free

void memory_free(
Application_Links *app,
void *ptr,
int32_t size
)
Parameters
mem
The base of a block to free.
size
The size that was originally used to allocate this block.
Description
This call frees a block of memory that was previously allocated by -memory_allocate.

See Also

§3.3.60: file_exists

bool32 file_exists(
Application_Links *app,
char *filename,
int32_t len
)
Parameters
filename
This parameter specifies the full path to a file; it need not be null terminated.
len
This parameter specifies the length of the filename string.
Return
This call returns non-zero if and only if the file exists.

§3.3.61: directory_cd

bool32 directory_cd(
Application_Links *app,
char *dir,
int32_t *len,
int32_t capacity,
char *rel_path,
int32_t rel_len
)
Parameters
dir
This parameter provides a character buffer that stores a directory; it need not be null terminated.
len
This parameter specifies the length of the dir string.
capacity
This parameter specifies the maximum size of the dir string.
rel_path
This parameter specifies the path to change to, may include '.' or '..'; it need not be null terminated.
rel_len
This parameter specifies the length of the rel_path string.
Return
This call returns non-zero if the call succeeds.
Description
This call succeeds if the new directory exists and the it fits inside the +if it will be freed or if it's mem protection status will be changed.

See Also

§3.3.59: memory_set_protection

bool32 memory_set_protection(
Application_Links *app,
void *ptr,
int32_t size,
Memory_Protect_Flags flags
)
Parameters
ptr
The base of the block on which to set memory protection flags.
size
The size that was originally used to allocate this block.
flags
The new memory protection flags.
Description
This call sets the memory protection flags of a block of memory that was previously +allocate by memory_allocate.

See Also

§3.3.60: memory_free

void memory_free(
Application_Links *app,
void *ptr,
int32_t size
)
Parameters
mem
The base of a block to free.
size
The size that was originally used to allocate this block.
Description
This call frees a block of memory that was previously allocated by +memory_allocate.

See Also

§3.3.61: file_exists

bool32 file_exists(
Application_Links *app,
char *filename,
int32_t len
)
Parameters
filename
This parameter specifies the full path to a file; it need not be null terminated.
len
This parameter specifies the length of the filename string.
Return
This call returns non-zero if and only if the file exists.

§3.3.62: directory_cd

bool32 directory_cd(
Application_Links *app,
char *dir,
int32_t *len,
int32_t capacity,
char *rel_path,
int32_t rel_len
)
Parameters
dir
This parameter provides a character buffer that stores a directory; it need not be null terminated.
len
This parameter specifies the length of the dir string.
capacity
This parameter specifies the maximum size of the dir string.
rel_path
This parameter specifies the path to change to, may include '.' or '..'; it need not be null terminated.
rel_len
This parameter specifies the length of the rel_path string.
Return
This call returns non-zero if the call succeeds.
Description
This call succeeds if the new directory exists and the it fits inside the dir buffer. If the call succeeds the dir buffer is filled with the new directory and len is overwritten with the length of the new string in the buffer.

For instance if dir contains "C:/Users/MySelf" and rel is "Documents" the buffer will contain "C:/Users/MySelf/Documents" and len will contain the length of that string. This call can also be used with rel set to ".." to traverse to parent -folders.


§3.3.62: get_4ed_path

bool32 get_4ed_path(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the path to the 4ed executable file.
capacity
This parameter specifies the maximum capacity of the out buffer.
Return
This call returns non-zero on success.

§3.3.63: show_mouse_cursor

void show_mouse_cursor(
Application_Links *app,
Mouse_Cursor_Show_Type show
)
Parameters
show
This parameter specifies the new state of the mouse cursor.
See Also

§3.3.64: toggle_fullscreen

void toggle_fullscreen(
Application_Links *app
)
Description
This call tells 4coder to switch into or out of full screen mode. +folders.


§3.3.63: get_4ed_path

bool32 get_4ed_path(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the path to the 4ed executable file.
capacity
This parameter specifies the maximum capacity of the out buffer.
Return
This call returns non-zero on success.

§3.3.64: show_mouse_cursor

void show_mouse_cursor(
Application_Links *app,
Mouse_Cursor_Show_Type show
)
Parameters
show
This parameter specifies the new state of the mouse cursor.
See Also

§3.3.65: toggle_fullscreen

void toggle_fullscreen(
Application_Links *app
)
Description
This call tells 4coder to switch into or out of full screen mode. The changes of full screen mode do not take effect until the end of the current frame. On Windows this call will not work unless 4coder was started in "stream mode". -Stream mode can be enabled with -S or -F flags on the command line to 4ed.


§3.3.65: is_fullscreen

bool32 is_fullscreen(
Application_Links *app
)
Description
This call returns true if the 4coder is in full screen mode. This call +Stream mode can be enabled with -S or -F flags on the command line to 4ed.


§3.3.66: is_fullscreen

bool32 is_fullscreen(
Application_Links *app
)
Description
This call returns true if the 4coder is in full screen mode. This call takes toggles that have already occured this frame into account. So it may return true even though the frame has not ended and actually put 4coder into full screen. If it returns true though, 4coder will definitely be full screen by the beginning of the next -frame if the state is not changed.


§3.3.66: send_exit_signal

void send_exit_signal(
Application_Links *app
)
Description
This call sends a signal to 4coder to attempt to exit. If there are unsaved +frame if the state is not changed.


§3.3.67: send_exit_signal

void send_exit_signal(
Application_Links *app
)
Description
This call sends a signal to 4coder to attempt to exit. If there are unsaved files this triggers a dialogue ensuring you're okay with closing.


§3.4 Type Descriptions

§3.4.1: bool32

typedef int32_t bool32;
Description
bool32 is an alias name to signal that an integer parameter or field is for true/false vales.


§3.4.2: int_color

typedef uint32_t int_color;
Description
int_color is an alias name to signal that an integer parameter or field is for a color value, colors are specified as 24 bit integers in 3 channels: 0xRRGGBB.


§3.4.3: Key_Code

typedef unsigned char Key_Code;
Description
Key_Code is the alias for key codes including raw codes and codes translated diff --git a/4coder_custom_api.h b/4coder_custom_api.h index b78bcdbf..b1e8075f 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -49,6 +49,7 @@ #define CHANGE_THEME_SIG(n) void n(Application_Links *app, char *name, int32_t len) #define CHANGE_FONT_SIG(n) void n(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files) #define BUFFER_SET_FONT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len) +#define BUFFER_GET_FONT_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max) #define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count) #define GET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count) #define DIRECTORY_GET_HOT_SIG(n) int32_t n(Application_Links *app, char *out, int32_t capacity) @@ -115,6 +116,7 @@ typedef PRINT_MESSAGE_SIG(Print_Message_Function); typedef CHANGE_THEME_SIG(Change_Theme_Function); typedef CHANGE_FONT_SIG(Change_Font_Function); typedef BUFFER_SET_FONT_SIG(Buffer_Set_Font_Function); +typedef BUFFER_GET_FONT_SIG(Buffer_Get_Font_Function); typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function); typedef GET_THEME_COLORS_SIG(Get_Theme_Colors_Function); typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot_Function); @@ -183,6 +185,7 @@ Print_Message_Function *print_message; Change_Theme_Function *change_theme; Change_Font_Function *change_font; Buffer_Set_Font_Function *buffer_set_font; +Buffer_Get_Font_Function *buffer_get_font; Set_Theme_Colors_Function *set_theme_colors; Get_Theme_Colors_Function *get_theme_colors; Directory_Get_Hot_Function *directory_get_hot; @@ -250,6 +253,7 @@ Print_Message_Function *print_message_; Change_Theme_Function *change_theme_; Change_Font_Function *change_font_; Buffer_Set_Font_Function *buffer_set_font_; +Buffer_Get_Font_Function *buffer_get_font_; Set_Theme_Colors_Function *set_theme_colors_; Get_Theme_Colors_Function *get_theme_colors_; Directory_Get_Hot_Function *directory_get_hot_; @@ -325,6 +329,7 @@ app_links->print_message_ = Print_Message;\ app_links->change_theme_ = Change_Theme;\ app_links->change_font_ = Change_Font;\ app_links->buffer_set_font_ = Buffer_Set_Font;\ +app_links->buffer_get_font_ = Buffer_Get_Font;\ app_links->set_theme_colors_ = Set_Theme_Colors;\ app_links->get_theme_colors_ = Get_Theme_Colors;\ app_links->directory_get_hot_ = Directory_Get_Hot;\ @@ -392,6 +397,7 @@ static inline void print_message(Application_Links *app, char *str, int32_t len) static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme(app, name, len));} static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font(app, name, len, apply_to_all_files));} static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font(app, buffer, name, len));} +static inline int32_t buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font(app, buffer, name_out, name_max));} static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors(app, colors, count));} static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors(app, colors, count));} static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot(app, out, capacity));} @@ -459,6 +465,7 @@ static inline void print_message(Application_Links *app, char *str, int32_t len) static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme_(app, name, len));} static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font_(app, name, len, apply_to_all_files));} static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font_(app, buffer, name, len));} +static inline int32_t buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font_(app, buffer, name_out, name_max));} static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors_(app, colors, count));} static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors_(app, colors, count));} static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot_(app, out, capacity));} diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index e5ad4bfc..5fa3e8ab 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -158,6 +158,22 @@ HOOK_SIG(my_exit){ return(1); } +// NOTE(allen|a4.0.12): This is for testing it may be removed and replaced with a better test for the buffer_get_font when you eventally read this and wonder what it's about. +CUSTOM_COMMAND_SIG(write_name_of_font){ + View_Summary view = get_active_view(app, AccessOpen); + Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); + + char font_name[256]; + int32_t font_max = 256; + int32_t font_len = buffer_get_font(app, &buffer, font_name, font_max); + + if (font_len != 0){ + write_string(app, &view, &buffer, make_string(font_name, font_len)); + } + + print_message(app, literal("TRIED WRITING FONT NAME")); +} + CUSTOM_COMMAND_SIG(newline_or_goto_position){ View_Summary view = get_active_view(app, AccessProtected); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); @@ -176,7 +192,7 @@ OPEN_FILE_HOOK_SIG(my_file_settings){ // NOTE(allen|a4.0.8): The get_parameter_buffer was eliminated // and instead the buffer is passed as an explicit parameter through // the function call. That is where buffer_id comes from here. - uint32_t access = AccessProtected|AccessHidden; + uint32_t access = AccessAll; Buffer_Summary buffer = get_buffer(app, buffer_id, access); assert(buffer.exists); @@ -412,6 +428,8 @@ default_keys(Bind_Helper *context){ bind(context, '\n', MDFR_SHIFT, newline_or_goto_position); bind(context, ' ', MDFR_SHIFT, write_character); + bind(context, ';', MDFR_ALT, write_name_of_font); + end_map(context); } diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index e21fe9cf..fa595830 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -1965,15 +1965,18 @@ seek_command(alphanumeric_or_camel, left, BoundaryAlphanumeric | BoundaryCamelC // special string writing commands // +static void +write_string(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, String string){ + buffer_replace_range(app, buffer, view->cursor.pos, view->cursor.pos, string.str, string.size); + view_set_cursor(app, view, seek_pos(view->cursor.pos + string.size), 1); +} + static void write_string(Application_Links *app, String string){ uint32_t access = AccessOpen; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - buffer_replace_range(app, &buffer, - view.cursor.pos, view.cursor.pos, - string.str, string.size); - view_set_cursor(app, &view, seek_pos(view.cursor.pos + string.size), true); + write_string(app, &view, &buffer, string); } CUSTOM_COMMAND_SIG(write_increment){ diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index ce7b46a0..c428ffb7 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -2071,6 +2071,26 @@ DOC(This call sets the display font of a particular buffer.) } } +API_EXPORT int32_t +Buffer_Get_Font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max) +{ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + Models *models = cmd->models; + Editing_File *file = imp_get_file(cmd, buffer); + + int32_t result = 0; + if (file){ + Font_Set *set = models->font_set; + String name = make_string_cap(name_out, 0, name_max); + if (font_set_get_name(set, file->settings.font_id, &name)){ + result = name.size; + } + } + + return(result); +} + API_EXPORT void Set_Theme_Colors(Application_Links *app, Theme_Color *colors, int32_t count) /* diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 4a359957..886dc137 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -4558,7 +4558,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su Assert(view->file_data.file); Font_Set *font_set = models->font_set; - Font_Info *info = 0; i16 i = 1, count = (i16)models->font_set->count + 1; @@ -4577,7 +4576,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su i16 new_font_id = font_id; for (i = 1; i < count; ++i){ - info = get_font_info(font_set, i); + Font_Info *info = get_font_info(font_set, i); id.id[0] = (u64)i; if (i != font_id){ if (gui_do_font_button(target, id, i, info->name)){ diff --git a/4ed_font_set.cpp b/4ed_font_set.cpp index 386c906c..b2e11c80 100644 --- a/4ed_font_set.cpp +++ b/4ed_font_set.cpp @@ -204,18 +204,20 @@ font_set_add(Partition *partition, Font_Set *set, internal b32 font_set_find_pos(Font_Set *set, String name, u32 *position){ - b32 result; - u32 hash, i, j; - hash = font_hash(name); - i = hash % set->max; - j = i - 1; - if (j <= 1) j += set->max; + u32 hash = font_hash(name); + u32 i = hash % set->max; + u32 j = i - 1; + if (j <= 1){ + j += set->max; + } - result = 0; - Font_Table_Entry *entry; + b32 result = 0; for (; i != j; ++i){ - if (i == set->max) i = 0; - entry = set->entries + i; + if (i == set->max){ + i = 0; + } + + Font_Table_Entry *entry = set->entries + i; if (entry->hash == hash){ if (match_ss(name, entry->name)){ result = 1; @@ -228,16 +230,20 @@ font_set_find_pos(Font_Set *set, String name, u32 *position){ return(result); } +internal b32 +font_set_get_name(Font_Set *set, i16 font_id, String *name){ + Font_Info *info = get_font_info(set, font_id); + b32 result = copy_checked_ss(name, info->name); + return(result); +} + internal b32 font_set_extract(Font_Set *set, String name, i16 *font_id){ - b32 result; u32 position; - - result = font_set_find_pos(set, name, &position); + b32 result = font_set_find_pos(set, name, &position); if (result){ *font_id = set->entries[position].font_id; } - return(result); } diff --git a/4ed_rendering.h b/4ed_rendering.h index fef4b342..eadb253f 100644 --- a/4ed_rendering.h +++ b/4ed_rendering.h @@ -102,17 +102,9 @@ typedef Draw_Pop_Clip_Sig(Draw_Pop_Clip); #define Draw_Push_Piece_Sig(name) void name(Render_Target *target, Render_Piece_Combined piece) typedef Draw_Push_Piece_Sig(Draw_Push_Piece); -#define Font_Load_Sig(name) i32 name( \ - Render_Font *font_out, \ - char *filename, \ - char *fontname, \ - i32 pt_size, \ - i32 tab_width, \ - b32 store_texture) +#define Font_Load_Sig(name) i32 name(Render_Font *font_out, char *filename, char *fontname, i32 pt_size, i32 tab_width, b32 store_texture) typedef Font_Load_Sig(Font_Load); - - #define Release_Font_Sig(name) void name(Render_Font *font) typedef Release_Font_Sig(Release_Font); @@ -140,15 +132,15 @@ struct Font_Set{ Font_Info *info; Font_Table_Entry *entries; u32 count, max; - + void *font_block; Font_Slot free_slots; Font_Slot used_slots; - + //Font_Info_Load *font_info_load; Font_Load *font_load; Release_Font *release_font; - + b8 *font_used_flags; i16 used_this_frame; i16 live_max; @@ -159,7 +151,7 @@ struct Render_Target{ void *context; i32_Rect clip_boxes[5]; i32 clip_top; - i32 width, height; + i32 width, height; i32 bound_texture; u32 color; diff --git a/TODO.txt b/TODO.txt index 6c3b6694..d8cb636d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -177,9 +177,9 @@ ; [X] handle unclosed statements ; [X] wrapped line indication ; [X] additional width for nesting? +; [X] special indent rules in preprocessor body ; [X] handle comments -; [] solve the comment lead whitespace problem -; [] special indent rules in preprocessor body +; [] solve the comment lead whitespace problem ; [] fix issues when relexing happens in parallel ; [] remeasure version of measure_wraps From e8b392028404a3a554bc5325ab0733edae85c298 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 24 Oct 2016 22:46:03 -0400 Subject: [PATCH 5/5] update todo file --- TODO.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.txt b/TODO.txt index d8cb636d..77f233fd 100644 --- a/TODO.txt +++ b/TODO.txt @@ -88,10 +88,10 @@ ; BEFORE I SHIP ; +; [X] query buffer font info ; [] ad hoc call for setting up/down keys for interactive screens ; [] miblo's various number editors ; [] API docs have duplicate ids? -; [] query buffer font info ; [] option to not open *messages* every startup ; [] issues with drive letters ; [] strong options for indentation rules for text & presentation