diff --git a/4ed.cpp b/4ed.cpp index 59496d32..2529edf2 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -633,9 +633,6 @@ app_hardcode_styles(Models *models){ Style *styles = models->styles.styles; Style *style = styles + 1; - i16 fonts = 1; - models->global_font_id = fonts + 0; - ///////////////// style_set_name(style, make_lit_string("4coder")); @@ -1528,6 +1525,7 @@ App_Init_Sig(app_init){ } // NOTE(allen): style setup + models->global_font_id = 1; app_hardcode_styles(models); // NOTE(allen): init first panel diff --git a/4ed_app_models.h b/4ed_app_models.h index 929109b5..5b83fe6b 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -50,7 +50,7 @@ struct Models{ Mem_Options mem; App_Settings settings; - i16 global_font_id; + Font_ID global_font_id; Command_Map map_top; Command_Map map_file; diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 44d34bc7..b04c2072 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -33,6 +33,7 @@ # include "4ed_debug_mem.h" #endif +#include "font/4coder_font_data.h" #include "4ed_rendering.h" #include "4ed.h" diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index deb71e3b..f5a21318 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1986,7 +1986,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * file_allocate_character_starts_as_needed(general, file); buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white); - i16 font_id = models->global_font_id; + Font_ID font_id = models->global_font_id; file->settings.font_id = font_id; //Render_Font *font = get_font_info(font_set, font_id)->font; Render_Font *font = 0; @@ -2799,7 +2799,7 @@ file_view_nullify_file(View *view){ } internal void -update_view_line_height(Models *models, View *view, i16 font_id){ +update_view_line_height(Models *models, View *view, Font_ID font_id){ //Render_Font *font = get_font_info(models->font_set, font_id)->font; Render_Font *font = 0; view->line_height = font->height; @@ -3686,7 +3686,7 @@ style_get_color(Style *style, Cpp_Token token){ } internal void -file_set_font(Models *models, Editing_File *file, i16 font_id){ +file_set_font(Models *models, Editing_File *file, Font_ID font_id){ file->settings.font_id = font_id; //Font_Info *font_info = get_font_info(models->font_set, file->settings.font_id); //Render_Font *font = font_info->font; @@ -3702,7 +3702,7 @@ file_set_font(Models *models, Editing_File *file, i16 font_id){ } internal void -global_set_font(Models *models, i16 font_id){ +global_set_font(Models *models, Font_ID font_id){ File_Node *node = 0; File_Node *sentinel = &models->working_set.used_sentinel; for (dll_items(node, sentinel)){ @@ -4150,17 +4150,13 @@ struct File_Bar{ f32 pos_x, pos_y; f32 text_shift_x, text_shift_y; i32_Rect rect; - i16 font_id; + Font_ID font_id; }; internal void intbar_draw_string(Render_Target *target, File_Bar *bar, String str, u32 char_color){ - i16 font_id = bar->font_id; - draw_string(target, font_id, str, - (i32)(bar->pos_x + bar->text_shift_x), - (i32)(bar->pos_y + bar->text_shift_y), - char_color); - bar->pos_x += font_string_width(target, font_id, str); + draw_string(target, bar->font_id, str, (i32)(bar->pos_x + bar->text_shift_x), (i32)(bar->pos_y + bar->text_shift_y), char_color); + bar->pos_x += font_string_width(target, bar->font_id, str); } internal GUI_Scroll_Vars @@ -4788,14 +4784,14 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su view->color_mode = CV_Mode_Library; } - i16 font_id = models->global_font_id; + Font_ID font_id = models->global_font_id; if (view->color_mode == CV_Mode_Font){ font_id = view->file_data.file->settings.font_id; } - i16 new_font_id = font_id; - i16 count = 2; - for (i16 i = 1; i < count; ++i){ + Font_ID new_font_id = font_id; + Font_ID count = 2; + for (Font_ID i = 1; i < count; ++i){ String font_name = {0}; id.id[0] = (u64)i; if (i != font_id){ @@ -5940,7 +5936,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 = file->settings.font_id; + Font_ID font_id = file->settings.font_id; //Render_Font *font = get_font_info(models->font_set, font_id)->font; Render_Font *font = 0; @@ -6148,8 +6144,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target } internal void -draw_text_field(Render_Target *target, View *view, i16 font_id, - i32_Rect rect, String p, String t){ +draw_text_field(Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, String p, String t){ Models *models = view->persistent.models; Style *style = main_style(models); @@ -6168,7 +6163,7 @@ draw_text_field(Render_Target *target, View *view, i16 font_id, } internal void -draw_text_with_cursor(Render_Target *target, View *view, i16 font_id, i32_Rect rect, String s, i32 pos){ +draw_text_with_cursor(Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, String s, i32 pos){ Models *models = view->persistent.models; Style *style = main_style(models); @@ -6307,8 +6302,7 @@ get_margin_color(i32 active_level, Style *style){ } internal void -draw_color_button(GUI_Target *gui_target, Render_Target *target, View *view, - i16 font_id, i32_Rect rect, GUI_id id, u32 fore, u32 back, String text){ +draw_color_button(GUI_Target *gui_target, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, GUI_id id, u32 fore, u32 back, String text){ i32 active_level = gui_active_level(gui_target, id); if (active_level > 0){ @@ -6320,8 +6314,7 @@ draw_color_button(GUI_Target *gui_target, Render_Target *target, View *view, } internal void -draw_font_button(GUI_Target *gui_target, Render_Target *target, View *view, - i32_Rect rect, GUI_id id, i16 font_id, String text){ +draw_font_button(GUI_Target *gui_target, Render_Target *target, View *view, i32_Rect rect, GUI_id id, Font_ID font_id, String text){ Models *models = view->persistent.models; Style *style = main_style(models); @@ -6337,8 +6330,7 @@ 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, - i16 font_id, i32_Rect rect, GUI_id id, +draw_fat_option_block(GUI_Target *gui_target, Render_Target *target, View *view, Font_ID 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); @@ -6379,7 +6371,7 @@ 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, i16 font_id, i32_Rect rect, GUI_id id, String text){ +draw_button(GUI_Target *gui_target, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, GUI_id id, String text){ Models *models = view->persistent.models; Style *style = main_style(models); @@ -6404,7 +6396,7 @@ draw_button(GUI_Target *gui_target, Render_Target *target, View *view, i16 font_ } internal void -draw_style_preview(GUI_Target *gui_target, Render_Target *target, View *view, i16 font_id, i32_Rect rect, GUI_id id, Style *style){ +draw_style_preview(GUI_Target *gui_target, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, GUI_id id, Style *style){ Models *models = view->persistent.models; AllowLocal(models); i32 active_level = gui_active_level(gui_target, id); @@ -6463,11 +6455,10 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol f32 v = {0}; i32 max_y = view_compute_max_target_y(view); - i16 font_id = 0; Assert(file != 0); - font_id = file->settings.font_id; + Font_ID font_id = file->settings.font_id; if (gui_target->push.pos > 0){ gui_session_init(&gui_session, gui_target, rect, view->line_height); @@ -6533,7 +6524,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol { GUI_Interactive *b = (GUI_Interactive*)h; void *ptr = (b + 1); - i16 font_id = (i16)gui_read_integer(&ptr); + Font_ID font_id = (Font_ID)gui_read_integer(&ptr); String t = gui_read_string(&ptr); draw_font_button(gui_target, target, view, gui_session.rect, b->id, font_id, t); diff --git a/4ed_gui.cpp b/4ed_gui.cpp index 15719c2c..521bf4f7 100644 --- a/4ed_gui.cpp +++ b/4ed_gui.cpp @@ -451,7 +451,7 @@ gui_do_color_button(GUI_Target *target, GUI_id id, u32 fore, u32 back, String te } internal b32 -gui_do_font_button(GUI_Target *target, GUI_id id, i16 font_id, String text){ +gui_do_font_button(GUI_Target *target, GUI_id id, Font_ID font_id, String text){ b32 result = 0; i32 font_id32 = font_id; GUI_Interactive *b = gui_push_button_command(target, guicom_font_button, id); diff --git a/4ed_rendering.h b/4ed_rendering.h index 73e4cdd5..001c175c 100644 --- a/4ed_rendering.h +++ b/4ed_rendering.h @@ -44,7 +44,7 @@ struct Render_Piece_Gradient{ struct Render_Piece_Glyph{ Vec2 pos; u32 color; - i16 font_id; + Font_ID font_id; u8 character; }; @@ -52,7 +52,7 @@ struct Render_Piece_Glyph_Advance{ Vec2 pos; u32 color; f32 advance; - i16 font_id; + Font_ID font_id; u8 character; }; diff --git a/4ed_rendering_helper.cpp b/4ed_rendering_helper.cpp index 6523982f..cb78aaa0 100644 --- a/4ed_rendering_helper.cpp +++ b/4ed_rendering_helper.cpp @@ -113,7 +113,7 @@ font_predict_size(i32 pt_size){ } internal void -font_draw_glyph(Render_Target *target, i16 font_id, i32 type, u8 character, f32 x, f32 y, u32 color){ +font_draw_glyph(Render_Target *target, Font_ID font_id, i32 type, u8 character, f32 x, f32 y, u32 color){ #if 0 Render_Piece_Combined piece; @@ -130,12 +130,12 @@ font_draw_glyph(Render_Target *target, i16 font_id, i32 type, u8 character, f32 } internal void -font_draw_glyph(Render_Target *target, i16 font_id, u8 character, f32 x, f32 y, u32 color){ +font_draw_glyph(Render_Target *target, Font_ID font_id, u8 character, f32 x, f32 y, u32 color){ font_draw_glyph(target, font_id, piece_type_glyph, character, x, y, color); } internal f32 -draw_string_base(Render_Target *target, i16 font_id, i32 type, String str_, i32 x_, i32 y_, u32 color){ +draw_string_base(Render_Target *target, Font_ID font_id, i32 type, String str_, i32 x_, i32 y_, u32 color){ f32 x = 0; @@ -202,39 +202,39 @@ draw_string_base(Render_Target *target, i16 font_id, i32 type, String str_, i32 } internal f32 -draw_string(Render_Target *target, i16 font_id, String str, i32 x, i32 y, u32 color){ +draw_string(Render_Target *target, Font_ID font_id, String str, i32 x, i32 y, u32 color){ f32 w = draw_string_base(target, font_id, piece_type_glyph, str, x, y, color); return(w); } internal f32 -draw_string(Render_Target *target, i16 font_id, char *str, i32 x, i32 y, u32 color){ +draw_string(Render_Target *target, Font_ID font_id, char *str, i32 x, i32 y, u32 color){ String string = make_string_slowly(str); f32 w = draw_string_base(target, font_id, piece_type_glyph, string, x, y, color); return(w); } internal f32 -draw_string_mono(Render_Target *target, i16 font_id, String str, i32 x, i32 y, f32 advance, u32 color){ +draw_string_mono(Render_Target *target, Font_ID font_id, String str, i32 x, i32 y, f32 advance, u32 color){ f32 w = draw_string_base(target, font_id, piece_type_mono_glyph, str, x, y, color); return(w); } internal f32 -draw_string_mono(Render_Target *target, i16 font_id, char *str, i32 x, i32 y, f32 advance, u32 color){ +draw_string_mono(Render_Target *target, Font_ID font_id, char *str, i32 x, i32 y, f32 advance, u32 color){ String string = make_string_slowly(str); f32 w = draw_string_base(target, font_id, piece_type_mono_glyph, string, x, y, color); return(w); } internal f32 -font_string_width(Render_Target *target, i16 font_id, String str){ +font_string_width(Render_Target *target, Font_ID font_id, String str){ f32 w = draw_string_base(target, font_id, piece_type_glyph, str, 0, 0, 0); return(w); } internal f32 -font_string_width(Render_Target *target, i16 font_id, char *str){ +font_string_width(Render_Target *target, Font_ID font_id, char *str){ String string = make_string_slowly(str); f32 w = draw_string_base(target, font_id, piece_type_glyph, string, 0, 0, 0); return(w); diff --git a/4ed_style.cpp b/4ed_style.cpp index d46ef063..d22b41bf 100644 --- a/4ed_style.cpp +++ b/4ed_style.cpp @@ -10,7 +10,7 @@ // TOP struct Style_Font{ - i16 font_id; + Font_ID font_id; }; struct Style{ diff --git a/file/4coder_file.cpp b/file/4coder_file.cpp index e6558cbe..6543dbcc 100644 --- a/file/4coder_file.cpp +++ b/file/4coder_file.cpp @@ -95,13 +95,14 @@ struct Editing_File_Settings{ i32 wrap_indicator; b32 dos_write_mode; b32 virtual_white; - i16 font_id; + Font_ID font_id; b8 unwrapped_lines; b8 tokens_exist; b8 is_initialized; b8 unimportant; b8 read_only; b8 never_kill; + u8 pad[2]; }; global_const Editing_File_Settings null_editing_file_settings = {0}; diff --git a/file/4coder_working_set.cpp b/file/4coder_working_set.cpp index 6c103056..4150c39f 100644 --- a/file/4coder_working_set.cpp +++ b/file/4coder_working_set.cpp @@ -67,24 +67,20 @@ tbl_name_compare(void *a, void *b, void *arg){ internal void working_set_extend_memory(Working_Set *working_set, Editing_File *new_space, i16 number_of_files){ - Buffer_Slot_ID id; - i16 i, high_part; - Editing_File *file_ptr; - File_Node *free_sentinel; - Assert(working_set->array_count < working_set->array_max); - high_part = working_set->array_count++; + i16 high_part = working_set->array_count++; working_set->file_arrays[high_part].files = new_space; working_set->file_arrays[high_part].size = number_of_files; working_set->file_max += number_of_files; + Buffer_Slot_ID id = {0}; id.part[1] = high_part; - file_ptr = new_space; - free_sentinel = &working_set->free_sentinel; - for (i = 0; i < number_of_files; ++i, ++file_ptr){ + Editing_File *file_ptr = new_space; + File_Node *free_sentinel = &working_set->free_sentinel; + for (i16 i = 0; i < number_of_files; ++i, ++file_ptr){ id.part[0] = i; file_ptr->id = id; dll_insert(free_sentinel, &file_ptr->node); diff --git a/font/4coder_font_data.h b/font/4coder_font_data.h index 1884a092..8f072e30 100644 --- a/font/4coder_font_data.h +++ b/font/4coder_font_data.h @@ -12,6 +12,8 @@ #if !defined(FCODER_FONT_DATA_H) #define FCODER_FONT_DATA_H +typedef u32 Font_ID; + #define ITEM_PER_FONT_PAGE 256 struct Glyph_Bounds{ diff --git a/font/4coder_font_internal.cpp b/font/4coder_font_internal.cpp index bf23cada..a8e66e65 100644 --- a/font/4coder_font_internal.cpp +++ b/font/4coder_font_internal.cpp @@ -14,7 +14,7 @@ struct Font_Table_Entry{ u32 hash; String name; - i16 font_id; + Font_ID font_id; }; struct Font_Info{ @@ -26,7 +26,7 @@ struct Font_Info{ struct Font_Slot{ Font_Slot *next, *prev; - i16 font_id; + Font_ID font_id; u8 padding[6]; }; global_const Font_Slot null_font_slot = {0}; @@ -56,12 +56,12 @@ struct Font_Set{ Release_Font *release_font; b8 *font_used_flags; - i16 used_this_frame; - i16 live_max; + Font_ID used_this_frame; + Font_ID live_max; }; inline Font_Info* -get_font_info(Font_Set *set, i16 font_id){ +get_font_info(Font_Set *set, Font_ID font_id){ Font_Info *result = set->info + font_id - 1; return(result); } @@ -104,7 +104,7 @@ font__remove(Font_Slot *slot){ } internal void -font_set_init(Font_Set *set, Partition *partition, i32 max, i16 live_max){ +font_set_init(Font_Set *set, Partition *partition, i32 max, Font_ID live_max){ partition_align(partition, 8); set->info = push_array(partition, Font_Info, max); partition_align(partition, 8); @@ -139,7 +139,7 @@ font_set_can_add(Font_Set *set){ } internal void -font_set_add_hash(Font_Set *set, String name, i16 font_id){ +font_set_add_hash(Font_Set *set, String name, Font_ID font_id){ Font_Table_Entry entry; entry.hash = font_hash(name); entry.name = name; @@ -167,7 +167,7 @@ font_set_can_load(Font_Set *set){ } internal void -font_set_load(Font_Set *set, i16 font_id){ +font_set_load(Font_Set *set, Font_ID font_id){ Font_Info *info = get_font_info(set, font_id); Font_Slot *slot = set->free_slots.next; Assert(slot != &set->free_slots); @@ -185,7 +185,7 @@ font_set_evict_lru(Font_Set *set){ Font_Slot *slot = set->used_slots.prev; Assert(slot != &set->used_slots); - i16 font_id = slot->font_id; + Font_ID font_id = slot->font_id; Font_Info *info = get_font_info(set, font_id); Assert(((Font_Slot*)info->font) - 1 == slot); @@ -198,7 +198,7 @@ font_set_evict_lru(Font_Set *set){ } internal void -font_set_use(Font_Set *set, i16 font_id){ +font_set_use(Font_Set *set, Font_ID font_id){ b8 already_used = set->font_used_flags[font_id-1]; if (!already_used){ @@ -231,7 +231,7 @@ font_set_add(Font_Set *set, String filename, String name, i32 pt_size){ b32 result = false; if (font_set_can_add(set)){ Render_Font dummy_font = {0}; - i16 font_id = (i16)(++set->count); + Font_ID font_id = (i16)(++set->count); Font_Info *info = get_font_info(set, font_id); info->filename = filename; info->name = name; @@ -278,14 +278,14 @@ font_set_find_pos(Font_Set *set, String name, u32 *position){ } internal b32 -font_set_get_name(Font_Set *set, i16 font_id, String *name){ +font_set_get_name(Font_Set *set, Font_ID 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){ +font_set_extract(Font_Set *set, String name, Font_ID *font_id){ u32 position; b32 result = font_set_find_pos(set, name, &position); if (result){ diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 056125ae..184ba3a9 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -54,6 +54,7 @@ #include "4ed_math.h" #include "4ed_system.h" +#include "font/4coder_font_data.h" #include "4ed_rendering.h" #include "4ed.h" @@ -64,7 +65,6 @@ #define GL_TEXTURE_MAX_LEVEL 0x813D #include "filetrack/4tech_file_track_win32.c" -#include "font/4coder_font_data.h" #include "4ed_system_shared.h" #define SUPPORT_DPI 1 @@ -1883,7 +1883,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ case WM_MOUSEWHEEL: { win32vars.got_useful_event = 1; - i16 rotation = GET_WHEEL_DELTA_WPARAM(wParam); + Font_ID rotation = GET_WHEEL_DELTA_WPARAM(wParam); if (rotation > 0){ win32vars.input_chunk.trans.mouse_wheel = 1; }