finished font folder system on windows build, fixed mouse wheel on windows build

master
Allen Webster 2017-03-24 23:42:16 -04:00
parent fbe5c3ff4f
commit 7521c2f436
4 changed files with 92 additions and 38 deletions

View File

@ -78,6 +78,13 @@ partition_allocate(Partition *data, i32_4tech size){
return ret; return ret;
} }
inline void
partition_reduce(Partition *data, i32_4tech size){
if (size > 0 && size <= data->pos){
data->pos -= size;
}
}
inline void inline void
partition_align(Partition *data, u32_4tech boundary){ partition_align(Partition *data, u32_4tech boundary){
--boundary; --boundary;

View File

@ -703,6 +703,14 @@ font_load(System_Functions *system, Partition *part, Render_Font *font, i32 pt_s
FT_Request_Size(face, &size); FT_Request_Size(face, &size);
// set size & metrics // set size & metrics
char *name = face->family_name;
u32 name_len = 0;
for (;name[name_len];++name_len);
name_len = clamp_top(name_len, sizeof(font->name)-1);
memcpy(font->name, name, name_len);
font->name[name_len] = 0;
font->name_len = name_len;
font->ascent = ceil32 (face->size->metrics.ascender / 64.0f); font->ascent = ceil32 (face->size->metrics.ascender / 64.0f);
font->descent = floor32 (face->size->metrics.descender / 64.0f); font->descent = floor32 (face->size->metrics.descender / 64.0f);
font->advance = ceil32 (face->size->metrics.max_advance / 64.0f); font->advance = ceil32 (face->size->metrics.max_advance / 64.0f);
@ -762,28 +770,30 @@ system_set_page(System_Functions *system, Partition *part, Render_Font *font, Gl
} }
internal void internal void
system_set_font(System_Functions *system, Partition *part, Render_Font *font, String filename, String name, u32 pt_size, b32 use_hinting){ system_set_font(System_Functions *system, Partition *part, Render_Font *font, char *filename, u32 pt_size, b32 use_hinting){
memset(font, 0, sizeof(*font)); memset(font, 0, sizeof(*font));
copy_partial_cs(font->filename, sizeof(font->filename)-1, filename); u32 filename_len = 0;
font->filename_len = filename.size; for (;filename[filename_len];++filename_len);
font->filename[font->filename_len] = 0;
copy_partial_cs(font->name, sizeof(font->name)-1, name);
font->name_len = name.size;
font->name[font->name_len] = 0;
if (part->base == 0){ if (filename_len <= sizeof(font->filename)-1){
*part = sysshared_scratch_partition(MB(8)); memcpy(font->filename, filename, filename_len);
} font->filename[filename_len] = 0;
font->filename_len = filename_len;
b32 success = false; if (part->base == 0){
for (u32 R = 0; R < 3; ++R){ *part = sysshared_scratch_partition(MB(8));
success = font_load(system, part, font, pt_size, use_hinting);
if (success){
break;
} }
else{
sysshared_partition_double(part); b32 success = false;
for (u32 R = 0; R < 3; ++R){
success = font_load(system, part, font, pt_size, use_hinting);
if (success){
break;
}
else{
sysshared_partition_double(part);
}
} }
} }
} }

View File

@ -1833,7 +1833,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
{ {
win32vars.got_useful_event = 1; win32vars.got_useful_event = 1;
Font_ID rotation = GET_WHEEL_DELTA_WPARAM(wParam); i32 rotation = GET_WHEEL_DELTA_WPARAM(wParam);
if (rotation > 0){ if (rotation > 0){
win32vars.input_chunk.trans.mouse_wheel = 1; win32vars.input_chunk.trans.mouse_wheel = 1;
} }

View File

@ -24,7 +24,7 @@ global Win32_Fonts win32_fonts = {0};
internal internal
Sys_Font_Get_Count_Sig(system_font_get_count){ Sys_Font_Get_Count_Sig(system_font_get_count){
return(5); return(win32_fonts.font_count);
} }
internal internal
@ -101,6 +101,7 @@ Sys_Font_Init_Sig(system_font_init){
font_size = clamp_bottom(8, font_size); font_size = clamp_bottom(8, font_size);
#if 0
struct TEST_DATA{ struct TEST_DATA{
char *c_filename; char *c_filename;
i32 filename_len; i32 filename_len;
@ -115,17 +116,6 @@ Sys_Font_Init_Sig(system_font_init){
{literal("fonts/Inconsolata-Regular.ttf"), literal("Inconsolata"), }, {literal("fonts/Inconsolata-Regular.ttf"), literal("Inconsolata"), },
}; };
struct Font_Setup{
Font_Setup *next_font;
char *c_filename;
char *c_name;
i32 filename_len;
i32 name_len;
};
Font_Setup *first_setup = 0;
Font_Setup *head_setup = 0;
u32 TEST_COUNT = ArrayCount(TEST_SETUP); u32 TEST_COUNT = ArrayCount(TEST_SETUP);
for (u32 i = 0; i < TEST_COUNT; ++i){ for (u32 i = 0; i < TEST_COUNT; ++i){
if (first_setup == 0){ if (first_setup == 0){
@ -149,21 +139,68 @@ Sys_Font_Init_Sig(system_font_init){
partition_align(scratch, 8); partition_align(scratch, 8);
} }
#endif
struct Font_Setup{
Font_Setup *next_font;
char *c_filename;
};
Font_Setup *first_setup = 0;
Font_Setup *head_setup = 0;
u32 dir_max = KB(32);
u8 *directory = push_array(scratch, u8, dir_max);
DWORD dir_len = GetModuleFileName_utf8(0, directory, dir_max-1);
Assert(dir_len < dir_max);
{
String dir_str = make_string_cap(directory, dir_len, dir_max);
remove_last_folder(&dir_str);
set_last_folder_sc(&dir_str, "fonts", '\\');
terminate_with_null(&dir_str);
dir_len = dir_str.size;
}
partition_reduce(scratch, dir_max - dir_len - 1);
partition_align(scratch, 8);
File_List file_list = {0};
system_set_file_list(&file_list, (char*)directory, 0, 0, 0);
for (u32 i = 0; i < file_list.count; ++i){
File_Info *info = &file_list.infos[i];
if (first_setup == 0){
first_setup = push_struct(scratch, Font_Setup);
head_setup = first_setup;
}
else{
head_setup->next_font = push_struct(scratch, Font_Setup);
head_setup = head_setup->next_font;
}
head_setup->next_font = 0;
char *filename = info->filename;
u32 len = 0;
for (;filename[len];++len);
head_setup->c_filename = push_array(scratch, char, dir_len+len+1);
memcpy(head_setup->c_filename, directory, dir_len);
memcpy(head_setup->c_filename + dir_len, filename, len+1);
partition_align(scratch, 8);
}
system_set_file_list(&file_list, 0, 0, 0, 0);
u32 font_count_max = ArrayCount(win32_fonts.fonts); u32 font_count_max = ArrayCount(win32_fonts.fonts);
u32 font_count = 0; u32 font_count = 0;
u32 i = 0; u32 i = 0;
for (Font_Setup *ptr = first_setup; ptr != 0; ptr = ptr->next_font, ++i){ for (Font_Setup *ptr = first_setup; ptr != 0; ptr = ptr->next_font, ++i){
if (i < font_count_max){ if (i < font_count_max){
String filename = make_string(ptr->c_filename, ptr->filename_len);
String name = make_string(ptr->c_name, ptr->name_len);
Render_Font *render_font = &win32_fonts.fonts[i]; Render_Font *render_font = &win32_fonts.fonts[i];
char full_filename_space[256]; system_set_font(&win32vars.system, &win32_fonts.part, render_font, ptr->c_filename, font_size, use_hinting);
String full_filename = make_fixed_width_string(full_filename_space);
sysshared_to_binary_path(&full_filename, filename.str);
system_set_font(&win32vars.system, &win32_fonts.part, render_font, full_filename, name, font_size, use_hinting);
} }
++font_count; ++font_count;