2017-03-12 23:24:18 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 09.02.2016
|
|
|
|
*
|
|
|
|
* Shared system functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2017-03-19 18:25:12 +00:00
|
|
|
#include "4ed_system_shared.h"
|
2017-03-12 23:24:18 +00:00
|
|
|
#include "font/4coder_font_interface.h"
|
2017-03-13 23:48:11 +00:00
|
|
|
#include "font/4coder_font_interface_to_os.h"
|
|
|
|
#include "font/4coder_font_data.h"
|
|
|
|
|
|
|
|
struct Win32_Fonts{
|
|
|
|
Partition part;
|
|
|
|
Render_Font fonts[5];
|
|
|
|
u32 font_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
global Win32_Fonts win32_fonts = {0};
|
2017-03-12 23:24:18 +00:00
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Font_Get_Count_Sig(system_font_get_count){
|
2017-03-13 23:48:11 +00:00
|
|
|
return(5);
|
2017-03-12 23:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Font_Get_IDs_By_Index_Sig(system_font_get_ids_by_index){
|
2017-03-13 23:48:11 +00:00
|
|
|
b32 result = false;
|
|
|
|
u32 stop_index = first_index + index_count;
|
2017-03-18 18:43:30 +00:00
|
|
|
if (stop_index <= win32_fonts.font_count){
|
2017-03-13 23:48:11 +00:00
|
|
|
result = true;
|
|
|
|
for (u32 i = first_index; i < stop_index; ++i){
|
2017-03-18 18:43:30 +00:00
|
|
|
id_out[i-first_index] = i;
|
2017-03-13 23:48:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
2017-03-12 23:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Font_Get_Name_By_Index_Sig(system_font_get_name_by_index){
|
2017-03-13 23:48:11 +00:00
|
|
|
u32 length = 0;
|
|
|
|
if (font_index < win32_fonts.font_count){
|
|
|
|
Render_Font *font = &win32_fonts.fonts[font_index];
|
|
|
|
char *name = font->name;
|
2017-03-18 18:43:30 +00:00
|
|
|
length = font->name_len;
|
|
|
|
copy_partial_cs(str_out, str_out_cap, make_string(name, length));
|
2017-03-13 23:48:11 +00:00
|
|
|
}
|
|
|
|
return(length);
|
2017-03-12 23:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Font_Get_Name_By_ID_Sig(system_font_get_name_by_id){
|
2017-03-13 23:48:11 +00:00
|
|
|
u32 font_index = font_id;
|
|
|
|
u32 result = system_font_get_name_by_index(font_index, str_out, str_out_cap);
|
|
|
|
return(result);
|
2017-03-12 23:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Font_Get_Render_Data_By_ID_Sig(system_font_get_render_data_by_id){
|
2017-03-13 23:48:11 +00:00
|
|
|
Render_Font *result = 0;
|
|
|
|
u32 font_index = font_id;
|
|
|
|
if (font_index < win32_fonts.font_count){
|
|
|
|
result = &win32_fonts.fonts[font_index];
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Font_Load_Page_Sig(system_font_load_page){
|
|
|
|
system_set_page(&win32vars.system, &win32_fonts.part, font, page, page_number, 16, true);
|
2017-03-12 23:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Font_Allocate_Sig(system_font_allocate){
|
2017-03-13 23:48:11 +00:00
|
|
|
void *result = system_memory_allocate(size);
|
|
|
|
return(result);
|
2017-03-12 23:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Font_Free_Sig(system_font_free){
|
2017-03-13 23:48:11 +00:00
|
|
|
system_memory_free(ptr, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Font_Init_Sig(system_font_init){
|
|
|
|
font->get_count = system_font_get_count;
|
|
|
|
font->get_ids_by_index = system_font_get_ids_by_index;
|
|
|
|
font->get_name_by_index = system_font_get_name_by_index;
|
|
|
|
font->get_name_by_id = system_font_get_name_by_id;
|
|
|
|
font->get_render_data_by_id = system_font_get_render_data_by_id;
|
|
|
|
font->load_page = system_font_load_page;
|
|
|
|
font->allocate = system_font_allocate;
|
|
|
|
font->free = system_font_free;
|
|
|
|
|
|
|
|
font_size = clamp_bottom(8, font_size);
|
2017-03-12 23:24:18 +00:00
|
|
|
|
2017-03-13 23:48:11 +00:00
|
|
|
struct Font_Setup{
|
|
|
|
char *c_filename;
|
|
|
|
i32 filename_len;
|
|
|
|
char *c_name;
|
|
|
|
i32 name_len;
|
|
|
|
u32 pt_size;
|
|
|
|
};
|
|
|
|
Font_Setup font_setup[] = {
|
|
|
|
{literal("LiberationSans-Regular.ttf"), literal("Liberation Sans"), font_size},
|
|
|
|
{literal("liberation-mono.ttf"), literal("Liberation Mono"), font_size},
|
|
|
|
{literal("Hack-Regular.ttf"), literal("Hack"), font_size},
|
|
|
|
{literal("CutiveMono-Regular.ttf"), literal("Cutive Mono"), font_size},
|
|
|
|
{literal("Inconsolata-Regular.ttf"), literal("Inconsolata"), font_size},
|
|
|
|
};
|
|
|
|
|
|
|
|
u32 font_count = Min(ArrayCount(win32_fonts.fonts), ArrayCount(font_setup));
|
|
|
|
for (u32 i = 0; i < font_count; ++i){
|
|
|
|
String filename = make_string(font_setup[i].c_filename, font_setup[i].filename_len);
|
|
|
|
String name = make_string(font_setup[i].c_name, font_setup[i].name_len);
|
|
|
|
u32 pt_size = font_setup[i].pt_size;
|
|
|
|
Render_Font *render_font = &win32_fonts.fonts[i];
|
|
|
|
|
|
|
|
char full_filename_space[256];
|
|
|
|
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, pt_size, use_hinting);
|
|
|
|
}
|
|
|
|
|
|
|
|
win32_fonts.font_count = font_count;
|
2017-03-12 23:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|