From c8d881c1b5125a3f0837699e982c0edc6c09d411 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 14 Jul 2016 12:41:23 -0400 Subject: [PATCH] multi-fonting, explicity monospace font for build panel --- 4coder_API.html | 97 +++++++++++++------- 4coder_custom_api.h | 6 +- 4coder_default_bindings.cpp | 10 +- 4coder_default_building.cpp | 3 + 4coder_jump_parsing.cpp | 22 +++-- 4coder_string.h | 15 +++ 4coder_types.h | 3 +- 4ed.cpp | 56 ------------ 4ed_api_implementation.cpp | 76 +++++++-------- 4ed_file.cpp | 1 + 4ed_file_view.cpp | 173 +++++++++++++++-------------------- 4ed_style.cpp | 1 - README.txt | 2 +- internal_4coder_string.cpp | 15 ++- power/4coder_experiments.cpp | 18 +++- 15 files changed, 248 insertions(+), 250 deletions(-) diff --git a/4coder_API.html b/4coder_API.html index db75485a..241285c6 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -76,6 +76,7 @@ Coming Soon
  • print_message
  • change_theme
  • change_font
  • +
  • buffer_set_font
  • set_theme_colors
  • get_theme_colors
  • directory_get_hot
  • @@ -898,11 +899,11 @@ only use for this call is in an interactive command that makes calls to get_user
    len
    The len parameter specifies the length of the name string.
    -
    Description
    This call changes 4coder's theme to one of the built in themes.

    +
    Description
    This call changes 4coder's color pallet to one of the built in themes.

    §3.3.44: change_font

    void app->change_font( -
    Application_Links *app,
    char *name,
    int32_t len
    ) +
    Application_Links *app,
    char *name,
    int32_t len,
    bool32 apply_to_all_files
    )
    Parameters
    name
    @@ -912,9 +913,32 @@ only use for this call is in an interactive command that makes calls to get_user
    len
    The len parameter specifies the length of the name string.
    -
    Description
    This call changes 4coder's font to one of the built in fonts.

    +
    +
    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.45: buffer_set_font

    +
    void app->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.45: set_theme_colors

    +

    §3.3.46: set_theme_colors

    void app->set_theme_colors(
    Application_Links *app,
    Theme_Color *colors,
    int32_t count
    )
    @@ -930,7 +954,7 @@ only use for this call is in an interactive command that makes calls to get_user 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.46: get_theme_colors

    +

    §3.3.47: get_theme_colors

    void app->get_theme_colors(
    Application_Links *app,
    Theme_Color *colors,
    int32_t count
    )
    @@ -946,7 +970,7 @@ no change is made to the color pallet.

    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.47: directory_get_hot

    +

    §3.3.48: directory_get_hot

    int32_t app->directory_get_hot(
    Application_Links *app,
    char *out,
    int32_t capacity
    )
    @@ -964,7 +988,7 @@ 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.48: get_file_list

    +

    §3.3.49: get_file_list

    File_List app->get_file_list(
    Application_Links *app,
    char *dir,
    int32_t len
    )
    @@ -980,7 +1004,7 @@ directories controlled on the custom side.

    the specified directory. The File_List returned should be passed to free_file_list when it is no longer in use.
    -

    §3.3.49: free_file_list

    +

    §3.3.50: free_file_list

    void app->free_file_list(
    Application_Links *app,
    File_List list
    )
    @@ -990,25 +1014,25 @@ when it is no longer in use.

    Description
    After this call the file list passed in should not be read or written to.

    -

    §3.3.50: memory_allocate

    +

    §3.3.51: memory_allocate

    void* app->memory_allocate(
    Application_Links *app,
    int32_t size
    )
    Description
    TODO

    -

    §3.3.51: memory_set_protection

    +

    §3.3.52: memory_set_protection

    bool32 app->memory_set_protection(
    Application_Links *app,
    void *ptr,
    int32_t size,
    Memory_Protect_Flags flags
    )
    Description
    TODO

    -

    §3.3.52: memory_free

    +

    §3.3.53: memory_free

    void app->memory_free(
    Application_Links *app,
    void *mem,
    int32_t size
    )
    Description
    TODO

    -

    §3.3.53: file_exists

    +

    §3.3.54: file_exists

    bool32 app->file_exists(
    Application_Links *app,
    char *filename,
    int len
    )
    @@ -1022,7 +1046,7 @@ when it is no longer in use.

    Return
    This call returns non-zero if and only if the file exists.

    -

    §3.3.54: directory_cd

    +

    §3.3.55: directory_cd

    bool32 app->directory_cd(
    Application_Links *app,
    char *dir,
    int *len,
    int capacity,
    char *rel_path,
    int rel_len
    )
    @@ -1055,7 +1079,7 @@ 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.55: get_4ed_path

    +

    §3.3.56: get_4ed_path

    bool32 app->get_4ed_path(
    Application_Links *app,
    char *out,
    int32_t capacity
    )
    @@ -1069,7 +1093,7 @@ folders.

    Return
    This call returns non-zero on success.

    -

    §3.3.56: show_mouse_cursor

    +

    §3.3.57: show_mouse_cursor

    void app->show_mouse_cursor(
    Application_Links *app,
    Mouse_Cursor_Show_Type show
    )
    @@ -1103,7 +1127,7 @@ when a buffer is closed it's id may be recycled by future, different buffers.§3.4.5: View_ID
    typedef int32_t View_ID;
    Description
    View_ID is used to name a 4coder view. Each view has a unique id in -the range [1,16].

    +the interval [1,16].

    §3.4.6: Key_Modifier

    enum Key_Modifier;
    @@ -2302,6 +2326,7 @@ Coming Soon
  • float_to_str_size
  • append_float_to_str
  • float_to_str
  • +
  • str_is_int
  • str_to_int
  • hexchar_to_int
  • int_to_hexchar
  • @@ -3065,81 +3090,87 @@ fstr_bool float_to_str(
    Description
    This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.

    -

    §4.3.88: str_to_int

    +

    §4.3.88: str_is_int

    +
    +fstr_bool str_is_int( +
    String str
    ) +
    +
    Description
    If str is a valid string representation of an integer, this call returns non-zero.

    +

    §4.3.89: str_to_int

    int32_t str_to_int(
    char *str
    )
    -
    Description
    If str represents a valid string representation of an integer, this call will return +
    Description
    If str is a valid string representation of an integer, this call will return the integer represented by the string. Otherwise this call returns zero.

    -

    §4.3.89: str_to_int

    +

    §4.3.90: str_to_int

    int32_t str_to_int(
    String str
    )
    Description
    If str represents a valid string representation of an integer, this call will return the integer represented by the string. Otherwise this call returns zero.

    -

    §4.3.90: hexchar_to_int

    +

    §4.3.91: hexchar_to_int

    int32_t hexchar_to_int(
    char c
    )
    Description
    If c is a valid hexadecimal digit [0-9a-fA-F] this call returns the value of the integer value of the digit. Otherwise the return is some nonsense value.

    -

    §4.3.91: int_to_hexchar

    +

    §4.3.92: int_to_hexchar

    char int_to_hexchar(
    int32_t x
    )
    Description
    If x is in the range [0,15] this call returns the equivalent lowercase hexadecimal digit. Otherwise the return is some nonsense value.

    -

    §4.3.92: hexstr_to_int

    +

    §4.3.93: hexstr_to_int

    uint32_t hexstr_to_int(
    String str
    )
    Description
    This call interprets str has a hexadecimal representation of an integer and returns the represented integer value.

    -

    §4.3.93: color_to_hexstr

    +

    §4.3.94: color_to_hexstr

    fstr_bool color_to_hexstr(
    String *s,
    uint32_t color
    )
    Description
    This call fills s with the hexadecimal representation of the color. If there is enough memory in s to represent the color this call returns non-zero.

    -

    §4.3.94: hexstr_to_color

    +

    §4.3.95: hexstr_to_color

    fstr_bool hexstr_to_color(
    String s,
    uint32_t *out
    )
    Description
    This call interprets s as a color and writes the 32-bit integer representation into out.

    -

    §4.3.95: reverse_seek_slash

    +

    §4.3.96: reverse_seek_slash

    int32_t reverse_seek_slash(
    String str,
    int32_t pos
    )
    Description
    This call searches for a slash in str by starting pos bytes from the end and going backwards.

    -

    §4.3.96: reverse_seek_slash

    +

    §4.3.97: reverse_seek_slash

    int32_t reverse_seek_slash(
    String str
    )
    Description
    This call searches for a slash in str by starting at the end and going backwards.

    -

    §4.3.97: front_of_directory

    +

    §4.3.98: front_of_directory

    String front_of_directory(
    String dir
    )
    Description
    This call returns a substring of dir containing only the file name or folder name furthest to the right in the directory.
    See Also

    -

    §4.3.98: path_of_directory

    +

    §4.3.99: path_of_directory

    String path_of_directory(
    String dir
    )
    Description
    This call returns a substring of dir containing the whole path except for the final file or folder name.
    See Also

    -

    §4.3.99: set_last_folder

    +

    §4.3.100: set_last_folder

    fstr_bool set_last_folder(
    String *dir,
    char *folder_name,
    char slash
    ) @@ -3159,7 +3190,7 @@ at the end of the directory.
    Description
    This call deletes the last file name or folder name in the dir string and appends the new provided one. If there is enough memory in dir this call returns non-zero.

    -

    §4.3.100: set_last_folder

    +

    §4.3.101: set_last_folder

    fstr_bool set_last_folder(
    String *dir,
    String folder_name,
    char slash
    ) @@ -3178,20 +3209,20 @@ fstr_bool set_last_folder(
    Description
    This call deletes the last file name or folder name in the dir string and appends the new provided one. If there is enough memory in dir this call returns non-zero.

    -

    §4.3.101: file_extension

    +

    §4.3.102: file_extension

    String file_extension(
    String str
    )
    Description
    This call returns a substring containing only the file extension of the provided filename.
    See Also

    -

    §4.3.102: remove_last_folder

    +

    §4.3.103: remove_last_folder

    fstr_bool remove_last_folder(
    String *str
    )
    Description
    This call attemps to delete a folder or filename off the end of a path string. This call returns non-zero on success.

    -

    §4.3.103: string_set_match

    +

    §4.3.104: string_set_match

    fstr_bool string_set_match(
    String *str_set,
    int32_t count,
    String str,
    int32_t *match_index
    ) diff --git a/4coder_custom_api.h b/4coder_custom_api.h index 07ac0fe0..bb6da8ff 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -41,7 +41,8 @@ #define END_QUERY_BAR_SIG(n) void n(Application_Links *app, Query_Bar *bar, uint32_t flags) #define PRINT_MESSAGE_SIG(n) void n(Application_Links *app, char *str, int32_t len) #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) +#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 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) @@ -99,6 +100,7 @@ extern "C"{ 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 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); @@ -159,6 +161,7 @@ struct Application_Links{ Print_Message_Function *print_message; Change_Theme_Function *change_theme; Change_Font_Function *change_font; + Buffer_Set_Font_Function *buffer_set_font; Set_Theme_Colors_Function *set_theme_colors; Get_Theme_Colors_Function *get_theme_colors; Directory_Get_Hot_Function *directory_get_hot; @@ -221,6 +224,7 @@ app_links->end_query_bar = End_Query_Bar;\ 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->set_theme_colors = Set_Theme_Colors;\ app_links->get_theme_colors = Get_Theme_Colors;\ app_links->directory_get_hot = Directory_Get_Hot;\ diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index 9d52437e..5bc129b1 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -126,16 +126,16 @@ CUSTOM_COMMAND_SIG(seek_whitespace_down_end_line){ } HOOK_SIG(my_start){ + init_memory(app); + + app->change_theme(app, literal("4coder")); + app->change_font(app, literal("Liberation Sans"), true); + exec_command(app, open_panel_vsplit); exec_command(app, hide_scrollbar); exec_command(app, change_active_panel); exec_command(app, hide_scrollbar); - app->change_theme(app, literal("4coder")); - app->change_font(app, literal("Liberation Sans")); - - init_memory(app); - // Theme options: // "4coder" // "Handmade Hero" diff --git a/4coder_default_building.cpp b/4coder_default_building.cpp index 6e702347..e61c468d 100644 --- a/4coder_default_building.cpp +++ b/4coder_default_building.cpp @@ -37,6 +37,9 @@ CUSTOM_COMMAND_SIG(build_in_build_panel){ execute_standard_build(app, &build_view, &original_buffer); + buffer = app->get_buffer_by_name(app, literal("*compilation*"), AccessAll); + app->buffer_set_font(app, &buffer, literal("Inconsolata")); + prev_location = null_location; } diff --git a/4coder_jump_parsing.cpp b/4coder_jump_parsing.cpp index 213797ea..fe280333 100644 --- a/4coder_jump_parsing.cpp +++ b/4coder_jump_parsing.cpp @@ -119,15 +119,19 @@ parse_error(String line, Jump_Location *location, int colon_pos1 = find(line, 0, ':'); int colon_pos2 = find(line, colon_pos1+1, ':'); - String filename = substr(line, 0, colon_pos1); - String line_number = substr(line, colon_pos1+1, colon_pos2 - colon_pos1 - 1); - - if (filename.size > 0 && line_number.size > 0){ - location->file = filename; - location->line = str_to_int(line_number); - location->column = 0; - *colon_char = colon_pos2; - result = true; + if (colon_pos2 < line.size){ + String filename = substr(line, 0, colon_pos1); + String line_number = substr(line, colon_pos1+1, colon_pos2 - colon_pos1 - 1); + + if (str_is_int(line_number)){ + if (filename.size > 0 && line_number.size > 0){ + location->file = filename; + location->line = str_to_int(line_number); + location->column = 0; + *colon_char = colon_pos2; + result = true; + } + } } } } diff --git a/4coder_string.h b/4coder_string.h index 21c8ad42..0a8e2f09 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -133,6 +133,7 @@ FSTRING_LINK fstr_bool append_u64_to_str(String *dest, uint64_t x); FSTRING_LINK int32_t float_to_str_size(float x); FSTRING_LINK fstr_bool append_float_to_str(String *dest, float x); FSTRING_LINK fstr_bool float_to_str(String *dest, float x); +FSTRING_LINK fstr_bool str_is_int(String str); FSTRING_LINK int32_t str_to_int(char *str); FSTRING_LINK int32_t str_to_int(String str); FSTRING_LINK int32_t hexchar_to_int(char c); @@ -1332,6 +1333,20 @@ float_to_str(String *dest, float x){ } #endif +#ifdef FSTRING_IMPLEMENTATION +FSTRING_LINK fstr_bool +str_is_int(String str){ + fstr_bool result = true; + for (int32_t i = 0; i < str.size; ++i){ + if (!char_is_numeric(str.str[i])){ + result = false; + break; + } + } + return(result); +} +#endif + #ifdef FSTRING_IMPLEMENTATION FSTRING_LINK int32_t str_to_int(char *str){ diff --git a/4coder_types.h b/4coder_types.h index d3864931..49c34180 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -1,6 +1,5 @@ - /* DOC(bool32 is an alias name to signal that an integer parameter or field is for true/false vales.) */ typedef int32_t bool32; @@ -18,7 +17,7 @@ when a buffer is closed it's id may be recycled by future, different buffers.) * typedef int32_t Buffer_ID; /* DOC(View_ID is used to name a 4coder view. Each view has a unique id in -the range [1,16].) */ +the interval [1,16].) */ typedef int32_t View_ID; #define ENUM(type,name) typedef type name; enum name##_ diff --git a/4ed.cpp b/4ed.cpp index 3d5e5079..f2e0603c 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -833,7 +833,6 @@ app_hardcode_styles(Models *models){ i16 fonts = 1; models->global_font.font_id = fonts + 0; - models->global_font.font_changed = 0; ///////////////// style_set_name(style, make_lit_string("4coder")); @@ -1697,17 +1696,6 @@ App_Step_Sig(app_step){ } } - // NOTE(allen): begin allowing the cursors and scroll locations - // to move around. - { - Panel *panel = 0, *used_panels = 0; - used_panels = &models->layout.used_sentinel; - for (dll_items(panel, used_panels)){ - Assert(panel->view); - view_begin_cursor_scroll_updates(panel->view); - } - } - // NOTE(allen): reorganizing panels on screen { i32 prev_width = models->layout.full_width; @@ -2319,17 +2307,6 @@ App_Step_Sig(app_step){ update_command_data(vars, cmd); - // NOTE(allen): post scroll vars back to the view's gui targets - { - Panel *panel = 0, *used_panels = 0; - - used_panels = &models->layout.used_sentinel; - for (dll_items(panel, used_panels)){ - Assert(panel->view); - view_end_cursor_scroll_updates(panel->view); - } - } - // NOTE(allen): command execution { Key_Summary key_data = get_key_data(&vars->available_input); @@ -2631,39 +2608,6 @@ App_Step_Sig(app_step){ } } - // NOTE(allen): send style change messages if the style has changed - if (models->global_font.font_changed){ - models->global_font.font_changed = 0; - - File_Node *node, *used_nodes; - Editing_File *file; - Render_Font *font = get_font_info(models->font_set, models->global_font.font_id)->font; - float *advance_data = 0; - if (font) advance_data = font->advance_data; - - used_nodes = &models->working_set.used_sentinel; - for (dll_items(node, used_nodes)){ - file = (Editing_File*)node; - file_measure_starts_widths(system, &models->mem.general, &file->state.buffer, advance_data); - } - - Panel *panel, *used_panels; - used_panels = &models->layout.used_sentinel; - for (dll_items(panel, used_panels)){ - update_view_line_height(models, panel->view); - remeasure_file_view(system, panel->view); - } - } - - // NOTE(allen): post scroll vars back to the view's gui targets - { - Panel *panel = 0, *used_panels = &models->layout.used_sentinel; - for (dll_items(panel, used_panels)){ - Assert(panel->view); - view_end_cursor_scroll_updates(panel->view); - } - } - // NOTE(allen): on the first frame there should be no scrolling if (input->first_step){ Panel *panel = 0, *used_panels = &models->layout.used_sentinel; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 31625710..39568e74 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -791,16 +791,6 @@ DOC_SEE(Buffer_Batch_Edit_Type) bool32 result = false; - app->print_message(app, literal("Buffer_Batch_Edit:\n")); - { - char space[512]; - String str = make_fixed_width_string(space); - append(&str, "edit_count: "); - append_int_to_str(&str, edit_count); - append(&str, '\n'); - app->print_message(app, str.str, str.size); - } - if (file){ Temp_Memory temp = begin_temp_memory(part); Buffer_Edit *inverse_edits = push_array(part, Buffer_Edit, edit_count); @@ -832,7 +822,6 @@ DOC_SEE(Buffer_Setting_ID) 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); bool32 result = false; @@ -1738,28 +1727,6 @@ DOC_SEE(int_color) return(result); } -/* -API_EXPORT void -View_Set_Paste_Rewrite_(Application_Links *app, View_Summary *view){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - View *vptr = imp_get_view(cmd, view); - if (vptr){ - vptr->next_mode.rewrite = true; - } -} - -API_EXPORT int -View_Get_Paste_Rewrite_(Application_Links *app, View_Summary *view){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - View *vptr = imp_get_view(cmd, view); - int result = false; - if (vptr){ - result = vptr->mode.rewrite; - } - return(result); -} -*/ - API_EXPORT User_Input Get_User_Input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type)/* DOC_PARAM(get_type, The get_type parameter specifies the set of input types that should be returned.) @@ -1895,7 +1862,7 @@ API_EXPORT void Change_Theme(Application_Links *app, char *name, int32_t len)/* DOC_PARAM(name, The name parameter specifies the name of the theme to begin using; it need not be null terminated.) DOC_PARAM(len, The len parameter specifies the length of the name string.) -DOC(This call changes 4coder's theme to one of the built in themes.) +DOC(This call changes 4coder's color pallet to one of the built in themes.) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; Style_Library *styles = &cmd->models->styles; @@ -1914,20 +1881,55 @@ DOC(This call changes 4coder's theme to one of the built in themes.) } API_EXPORT void -Change_Font(Application_Links *app, char *name, int32_t len)/* +Change_Font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files)/* DOC_PARAM(name, The name parameter specifies the name of the font to begin using; it need not be null terminated.) DOC_PARAM(len, The len parameter specifies the length of the name string.) -DOC(This call changes 4coder's font to one of the built in fonts.) +DOC_PARAM(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.) +DOC(This call changes 4coder's default font to one of the built in fonts.) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; Font_Set *set = cmd->models->font_set; + Style_Font *global_font = &cmd->models->global_font; String font_name = make_string(name, len); i16 font_id = 0; if (font_set_extract(set, font_name, &font_id)){ global_font->font_id = font_id; - global_font->font_changed = 1; + + if (apply_to_all_files){ + System_Functions *system = cmd->system; + Models *models = cmd->models; + + File_Node *node = 0; + File_Node *sentinel = &models->working_set.used_sentinel; + for (dll_items(node, sentinel)){ + Editing_File *file = (Editing_File*)node; + file_set_font(system, models, file, font_id); + } + } + } +} + +API_EXPORT void +Buffer_Set_Font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len)/* +DOC_PARAM(buffer, This parameter the buffer that shall have it's font changed) +DOC_PARAM(name, The name parameter specifies the name of the font to begin using; it need not be null terminated.) +DOC_PARAM(len, The len parameter specifies the length of the name string.) +DOC(This call sets the display font of a particular buffer.) +*/{ + 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); + + Font_Set *set = models->font_set; + String font_name = make_string(name, len); + i16 font_id = 0; + + if (font_set_extract(set, font_name, &font_id)){ + file_set_font(system, models, file, font_id); } } diff --git a/4ed_file.cpp b/4ed_file.cpp index 53ba3864..1dbe3d45 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -119,6 +119,7 @@ struct Text_Effect{ struct Editing_File_Settings{ i32 base_map_id; i32 dos_write_mode; + i16 font_id; b8 unwrapped_lines; b8 tokens_exist; b8 is_initialized; diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index c08b812f..6d426ff9 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -414,7 +414,7 @@ inline Full_Cursor view_compute_cursor_from_pos(View *view, i32 pos){ Editing_File *file = view->file_data.file; Models *models = view->persistent.models; - Render_Font *font = get_font_info(models->font_set, models->global_font.font_id)->font; + Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; Full_Cursor result = {}; if (font){ @@ -429,7 +429,7 @@ inline Full_Cursor view_compute_cursor_from_unwrapped_xy(View *view, f32 seek_x, f32 seek_y, b32 round_down = 0){ Editing_File *file = view->file_data.file; Models *models = view->persistent.models; - Render_Font *font = get_font_info(models->font_set, models->global_font.font_id)->font; + Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; Full_Cursor result = {}; if (font){ @@ -445,7 +445,7 @@ internal Full_Cursor view_compute_cursor_from_wrapped_xy(View *view, f32 seek_x, f32 seek_y, b32 round_down = 0){ Editing_File *file = view->file_data.file; Models *models = view->persistent.models; - Render_Font *font = get_font_info(models->font_set, models->global_font.font_id)->font; + Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; Full_Cursor result = {}; if (font){ @@ -462,7 +462,7 @@ internal Full_Cursor view_compute_cursor_from_line_pos(View *view, i32 line, i32 pos){ Editing_File *file = view->file_data.file; Models *models = view->persistent.models; - Render_Font *font = get_font_info(models->font_set, models->global_font.font_id)->font; + Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; Full_Cursor result = {}; if (font){ @@ -1046,22 +1046,22 @@ file_create_from_string(System_Functions *system, Models *models, General_Memory *general = &models->mem.general; Partition *part = &models->mem.part; Buffer_Init_Type init; - i32 page_size, scratch_size, init_success; file->state = editing_file_state_zero(); init = buffer_begin_init(&file->state.buffer, val.str, val.size); for (; buffer_init_need_more(&init); ){ - page_size = buffer_init_page_size(&init); + i32 page_size = buffer_init_page_size(&init); page_size = LargeRoundUp(page_size, Kbytes(4)); if (page_size < Kbytes(4)) page_size = Kbytes(4); void *data = general_memory_allocate(general, page_size); buffer_init_provide_page(&init, data, page_size); } - scratch_size = partition_remaining(part); + i32 scratch_size = partition_remaining(part); Assert(scratch_size > 0); - init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); + + b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); AllowLocal(init_success); Assert(init_success); @@ -1076,6 +1076,7 @@ file_create_from_string(System_Functions *system, Models *models, file_synchronize_times(system, file, name); i16 font_id = models->global_font.font_id; + file->settings.font_id = font_id; Render_Font *font = get_font_info(font_set, font_id)->font; float *advance_data = 0; if (font) advance_data = font->advance_data; @@ -1735,6 +1736,12 @@ file_view_nullify_file(View *view){ view->file_data = file_viewing_data_zero(); } +internal void +update_view_line_height(Models *models, View *view, i16 font_id){ + Render_Font *font = get_font_info(models->font_set, font_id)->font; + view->line_height = font->height; +} + internal void view_set_file(View *view, Editing_File *file, Models *models){ if (view->file_data.file != 0){ @@ -1760,6 +1767,11 @@ view_set_file(View *view, Editing_File *file, Models *models){ if (file_is_ready(file)){ view_measure_wraps(&models->mem.general, view); } + + update_view_line_height(models, view, file->settings.font_id); + } + else{ + update_view_line_height(models, view, models->global_font.font_id); } } @@ -2150,7 +2162,7 @@ file_do_single_edit(System_Functions *system, i32 new_line_count = buffer_count_newlines(&file->state.buffer, start, start+str_len); i32 line_shift = new_line_count - replaced_line_count; - i16 font_id = models->global_font.font_id; + i16 font_id = file->settings.font_id; Render_Font *font = get_font_info(models->font_set, font_id)->font; file_grow_starts_widths_as_needed(general, buffer, line_shift); @@ -2224,7 +2236,7 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, // NOTE(allen): meta data { Buffer_Measure_Starts state = {}; - i16 font_id = models->global_font.font_id; + i16 font_id = file->settings.font_id; Render_Font *font = get_font_info(models->font_set, font_id)->font; float *advance_data = 0; if (font) advance_data = font->advance_data; @@ -3078,12 +3090,6 @@ style_get_color(Style *style, Cpp_Token token){ return result; } -internal void -update_view_line_height(Models *models, View *view){ - Font_Info *fnt_info = get_font_info(models->font_set, models->global_font.font_id); - view->line_height = fnt_info->height; -} - internal void remeasure_file_view(System_Functions *system, View *view){ if (file_is_ready(view->file_data.file)){ @@ -3099,6 +3105,22 @@ remeasure_file_view(System_Functions *system, View *view){ } } +internal void +file_set_font(System_Functions *system, Models *models, Editing_File *file, i16 font_id){ + Render_Font *font = get_font_info(models->font_set, font_id)->font; + f32 *advance_data = font->advance_data; + file->settings.font_id = font_id; + file_measure_starts_widths(system, &models->mem.general, &file->state.buffer, advance_data); + + Editing_Layout *layout = &models->layout; + for (View_Iter iter = file_view_iter_init(layout, file, 0); + file_view_iter_good(iter); + iter = file_view_iter_next(iter)){ + update_view_line_height(models, iter.view, font_id); + remeasure_file_view(system, iter.view); + } +} + inline void view_show_GUI(View *view, View_UI ui){ view->map = &view->persistent.models->map_ui; @@ -3586,48 +3608,6 @@ view_reinit_scrolling(View *view){ return(scroll); } -// TODO(allen): GTFO! -internal void -view_begin_cursor_scroll_updates(View *view){ - -#if 0 - if (view->file_data.file && view->file_data.file == view->prev_context.file){ - Assert(view->prev_cursor_pos == view_get_cursor_pos(view)); - } -#endif - -} - -internal void -view_end_cursor_scroll_updates(View *view){ - -#if 0 - if (view->edit_pos){ - i32 set_type = view->edit_pos->last_set_type; - - switch (set_type){ - case EditPos_None: break; - - case EditPos_CursorSet: - { - if (view->gui_target.did_file){ - view->edit_pos->scroll.max_y = view_compute_max_target_y(view); - } - view_move_view_to_cursor(view, &view->edit_pos->scroll, false); - gui_post_scroll_vars(&view->gui_target, &view->edit_pos->scroll, view->scroll_region); - }break; - - case EditPos_ScrollSet: - { - view_move_cursor_to_view(view, view->edit_pos->scroll); - gui_post_scroll_vars(&view->gui_target, &view->edit_pos->scroll, view->scroll_region); - }break; - } - } -#endif - -} - internal b32 file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active, b32 *consumed_l){ i32 is_animating = 0; @@ -4079,12 +4059,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su scroll_context.id[1] = view->showing_ui; scroll_context.id[0] = (u64)(view->file_data.file); - // TODO(allen): ???? - -#if 0 - gui_get_scroll_vars(target, scroll_context, &view->scroll_region); -#endif - GUI_Scroll_Vars scroll_zero = {0}; GUI_Scroll_Vars *scroll = &scroll_zero; @@ -4168,9 +4142,12 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su } message = make_lit_string("Set Font"); - id.id[0] = (u64)(&models->global_font); - if (gui_do_button(target, id, message)){ - view->color_mode = CV_Mode_Font; + if (view->file_data.file){ + id.id[0] = (u64)(&view->file_data.file->settings.font_id); + + if (gui_do_button(target, id, message)){ + view->color_mode = CV_Mode_Font; + } } message = make_lit_string("Theme Library - Click to Select"); @@ -4198,11 +4175,12 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su case CV_Mode_Font: { + 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; - i16 font_id = 0, new_font_id = 0; String message = make_lit_string("Back"); @@ -4211,8 +4189,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su view->color_mode = CV_Mode_Library; } - font_id = models->global_font.font_id; - new_font_id = font_id; + i16 font_id = view->file_data.file->settings.font_id; + i16 new_font_id = font_id; for (i = 1; i < count; ++i){ info = get_font_info(font_set, i); @@ -4231,7 +4209,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su } } - models->global_font.font_id = (i16)(new_font_id); + file_set_font(system, models, view->file_data.file, new_font_id); }break; case CV_Mode_Adjusting: @@ -5341,7 +5319,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target i32 max = partition_remaining(part) / sizeof(Buffer_Render_Item); Buffer_Render_Item *items = push_array(part, Buffer_Render_Item, max); - i16 font_id = models->global_font.font_id; + i16 font_id = file->settings.font_id; Render_Font *font = get_font_info(models->font_set, font_id)->font; float *advance_data = 0; if (font) advance_data = font->advance_data; @@ -5496,7 +5474,8 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target } internal void -draw_text_field(Render_Target *target, View *view, i32_Rect rect, String p, String t){ +draw_text_field(Render_Target *target, View *view, i16 font_id, + i32_Rect rect, String p, String t){ Models *models = view->persistent.models; Style *style = main_style(models); @@ -5507,8 +5486,6 @@ draw_text_field(Render_Target *target, View *view, i32_Rect rect, String p, Stri i32 x = rect.x0; i32 y = rect.y0 + 2; - i16 font_id = models->global_font.font_id; - if (target){ draw_rectangle(target, rect, back_color); x = CEIL32(draw_string(target, font_id, p, x, y, text2_color)); @@ -5517,7 +5494,8 @@ draw_text_field(Render_Target *target, View *view, i32_Rect rect, String p, Stri } internal void -draw_text_with_cursor(Render_Target *target, View *view, i32_Rect rect, String s, i32 pos){ +draw_text_with_cursor(Render_Target *target, View *view, i16 font_id, + i32_Rect rect, String s, i32 pos){ Models *models = view->persistent.models; Style *style = main_style(models); @@ -5529,8 +5507,6 @@ draw_text_with_cursor(Render_Target *target, View *view, i32_Rect rect, String s f32 x = (f32)rect.x0; i32 y = rect.y0 + 2; - i16 font_id = models->global_font.font_id; - if (target){ draw_rectangle(target, rect, back_color); @@ -5565,7 +5541,6 @@ internal void draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect rect){ File_Bar bar; Models *models = view->persistent.models; - Style_Font *font = &models->global_font; Style *style = main_style(models); Interactive_Style bar_style = style->main.file_info_style; @@ -5577,7 +5552,7 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re bar.rect = rect; if (target){ - bar.font_id = font->font_id; + bar.font_id = file->settings.font_id; bar.pos_x = (f32)bar.rect.x0; bar.pos_y = (f32)bar.rect.y0; bar.text_shift_y = 2; @@ -5660,11 +5635,8 @@ get_margin_color(i32 active_level, Style *style){ internal void draw_color_button(GUI_Target *gui_target, Render_Target *target, View *view, - i32_Rect rect, GUI_id id, u32 fore, u32 back, String text){ - Models *models = view->persistent.models; - + i16 font_id, i32_Rect rect, GUI_id id, u32 fore, u32 back, String text){ i32 active_level = gui_active_level(gui_target, id); - i16 font_id = models->global_font.font_id; if (active_level > 0){ Swap(u32, back, fore); @@ -5692,13 +5664,13 @@ draw_font_button(GUI_Target *gui_target, Render_Target *target, View *view, } internal void -draw_fat_option_block(GUI_Target *gui_target, Render_Target *target, View *view, i32_Rect rect, GUI_id id, +draw_fat_option_block(GUI_Target *gui_target, Render_Target *target, View *view, + i16 font_id, i32_Rect rect, GUI_id id, String text, String pop, i8 checkbox = -1){ Models *models = view->persistent.models; Style *style = main_style(models); i32 active_level = gui_active_level(gui_target, id); - i16 font_id = models->global_font.font_id; i32_Rect inner = get_inner_rect(rect, 3); @@ -5734,12 +5706,12 @@ draw_fat_option_block(GUI_Target *gui_target, Render_Target *target, View *view, } internal void -draw_button(GUI_Target *gui_target, Render_Target *target, View *view, i32_Rect rect, GUI_id id, String text){ +draw_button(GUI_Target *gui_target, Render_Target *target, View *view, + i16 font_id, i32_Rect rect, GUI_id id, String text){ Models *models = view->persistent.models; Style *style = main_style(models); i32 active_level = gui_active_level(gui_target, id); - i16 font_id = models->global_font.font_id; i32_Rect inner = get_inner_rect(rect, 3); @@ -5760,11 +5732,11 @@ draw_button(GUI_Target *gui_target, Render_Target *target, View *view, i32_Rect } internal void -draw_style_preview(GUI_Target *gui_target, Render_Target *target, View *view, i32_Rect rect, GUI_id id, Style *style){ +draw_style_preview(GUI_Target *gui_target, Render_Target *target, View *view, + i16 font_id, i32_Rect rect, GUI_id id, Style *style){ Models *models = view->persistent.models; i32 active_level = gui_active_level(gui_target, id); - i16 font_id = models->global_font.font_id; Font_Info *info = get_font_info(models->font_set, font_id); i32_Rect inner = get_inner_rect(rect, 3); @@ -5819,6 +5791,11 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol i32 max_y = view_compute_max_target_y(view); + i16 font_id = 0; + if (file){ + font_id = file->settings.font_id; + } + if (gui_target->push.pos > 0){ gui_session_init(&gui_session, gui_target, rect, view->line_height); @@ -5857,7 +5834,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol void *ptr = (h+1); String p = gui_read_string(&ptr); String t = gui_read_string(&ptr); - draw_text_field(target, view, gui_session.rect, p, t); + draw_text_field(target, view, font_id, gui_session.rect, p, t); }break; case guicom_text_with_cursor: @@ -5866,7 +5843,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol String s = gui_read_string(&ptr); i32 pos = gui_read_integer(&ptr); - draw_text_with_cursor(target, view, gui_session.rect, s, pos); + draw_text_with_cursor(target, view, font_id, gui_session.rect, s, pos); }break; case guicom_color_button: @@ -5877,7 +5854,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol u32 back = (u32)gui_read_integer(&ptr); String t = gui_read_string(&ptr); - draw_color_button(gui_target, target, view, gui_session.rect, b->id, fore, back, t); + draw_color_button(gui_target, target, view, font_id, gui_session.rect, b->id, fore, back, t); }break; case guicom_font_button: @@ -5902,7 +5879,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol append(&f, system->slash); } - draw_fat_option_block(gui_target, target, view, gui_session.rect, b->id, f, m); + draw_fat_option_block(gui_target, target, view, font_id, gui_session.rect, b->id, f, m); }break; case guicom_style_preview: @@ -5911,7 +5888,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol i32 style_index = *(i32*)(b + 1); Style *style = get_style(view->persistent.models, style_index); - draw_style_preview(gui_target, target, view, gui_session.rect, b->id, style); + draw_style_preview(gui_target, target, view, font_id, gui_session.rect, b->id, style); }break; case guicom_fixed_option: @@ -5927,7 +5904,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol status = (i8)gui_read_byte(&ptr); } - draw_fat_option_block(gui_target, target, view, gui_session.rect, b->id, f, m, status); + draw_fat_option_block(gui_target, target, view, font_id, gui_session.rect, b->id, f, m, status); }break; case guicom_button: @@ -5936,7 +5913,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol void *ptr = (b + 1); String t = gui_read_string(&ptr); - draw_button(gui_target, target, view, gui_session.rect, b->id, t); + draw_button(gui_target, target, view, font_id, gui_session.rect, b->id, t); }break; case guicom_scrollable_bar: @@ -6061,8 +6038,6 @@ live_set_alloc_view(Live_Views *live_set, Panel *panel, Models *models){ result.view->persistent.models = models; - update_view_line_height(models, result.view); - init_query_set(&result.view->query_set); { diff --git a/4ed_style.cpp b/4ed_style.cpp index 99f629ee..d0413575 100644 --- a/4ed_style.cpp +++ b/4ed_style.cpp @@ -11,7 +11,6 @@ struct Style_Font{ i16 font_id; - i16 font_changed; }; struct Style{ diff --git a/README.txt b/README.txt index 9168ed98..84b3d518 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -Distribution Date: 12.7.2016 (dd.mm.yyyy) +Distribution Date: 14.7.2016 (dd.mm.yyyy) Thank you for contributing to the 4coder project! diff --git a/internal_4coder_string.cpp b/internal_4coder_string.cpp index ff8c319b..52db6bd0 100644 --- a/internal_4coder_string.cpp +++ b/internal_4coder_string.cpp @@ -1250,9 +1250,22 @@ space in dest this call returns non-zero.) */{ return(result); } +FSTRING_LINK fstr_bool +str_is_int(String str)/* +DOC(If str is a valid string representation of an integer, this call returns non-zero.) */{ + fstr_bool result = true; + for (int32_t i = 0; i < str.size; ++i){ + if (!char_is_numeric(str.str[i])){ + result = false; + break; + } + } + return(result); +} + FSTRING_LINK int32_t str_to_int(char *str)/* -DOC(If str represents a valid string representation of an integer, this call will return +DOC(If str is a valid string representation of an integer, this call will return the integer represented by the string. Otherwise this call returns zero.) */{ int32_t x = 0; for (; *str; ++str){ diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index 5286852f..86949d36 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -190,8 +190,8 @@ CUSTOM_COMMAND_SIG(save_theme_settings){ #include #define SETTINGS_FILE ".4coder_settings" -HOOK_SIG(experimental_start_hook){ - my_start(app); +HOOK_SIG(experimental_start){ + init_memory(app); char theme_name[128]; char font_name[128]; @@ -217,8 +217,16 @@ HOOK_SIG(experimental_start_hook){ fclose(file); - app->change_theme(app, theme_name, (int)strlen(theme_name)); - app->change_font(app, font_name, (int)strlen(font_name)); + int theme_len = (int)strlen(theme_name); + int font_len = (int)strlen(font_name); + + app->change_theme(app, theme_name, theme_len); + app->change_font(app, font_name, font_len, true); + + exec_command(app, open_panel_vsplit); + exec_command(app, hide_scrollbar); + exec_command(app, change_active_panel); + exec_command(app, hide_scrollbar); } return(0); @@ -229,7 +237,7 @@ get_bindings(void *data, int size){ Bind_Helper context_ = begin_bind_helper(data, size); Bind_Helper *context = &context_; - set_hook(context, hook_start, experimental_start_hook); + set_hook(context, hook_start, experimental_start); set_open_file_hook(context, my_file_settings); set_input_filter(context, my_suppress_mouse_filter); set_command_caller(context, default_command_caller);