setup the page loading on request, setup the rendering with the new system, still fixing bugs

This commit is contained in:
Allen Webster 2017-03-13 19:48:11 -04:00
parent b4409c9cf5
commit 12c8b920d2
21 changed files with 585 additions and 514 deletions

File diff suppressed because it is too large Load Diff

68
4ed.cpp
View File

@ -962,7 +962,6 @@ enum Command_Line_Action{
CLAct_WindowStreamMode, CLAct_WindowStreamMode,
CLAct_FontSize, CLAct_FontSize,
CLAct_FontStartHinting, CLAct_FontStartHinting,
CLAct_FontCustom,
CLAct_Count CLAct_Count
}; };
@ -1010,8 +1009,6 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
case 'u': action = CLAct_UserFile; strict = 0; break; case 'u': action = CLAct_UserFile; strict = 0; break;
case 'U': action = CLAct_UserFile; strict = 1; break; case 'U': action = CLAct_UserFile; strict = 1; break;
case 'c': action = CLAct_FontCustom; break;
case 'd': action = CLAct_CustomDLL; strict = 0; break; case 'd': action = CLAct_CustomDLL; strict = 0; break;
case 'D': action = CLAct_CustomDLL; strict = 1; break; case 'D': action = CLAct_CustomDLL; strict = 1; break;
@ -1115,16 +1112,6 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
action = CLAct_Nothing; action = CLAct_Nothing;
}break; }break;
case CLAct_FontCustom:
{
if ((i + 3) <= clparams.argc){
settings->custom_font_file = clparams.argv[i++];
settings->custom_font_name = clparams.argv[i++];
settings->custom_font_size = str_to_int_c(clparams.argv[i]);
}
action = CLAct_Nothing;
}break;
case CLAct_FontStartHinting: case CLAct_FontStartHinting:
{ {
plat_settings->use_hinting = 1; plat_settings->use_hinting = 1;
@ -1158,8 +1145,6 @@ app_setup_memory(System_Functions *system, Application_Memory *memory){
return(vars); return(vars);
} }
static App_Settings null_app_settings = {0};
App_Read_Command_Line_Sig(app_read_command_line){ App_Read_Command_Line_Sig(app_read_command_line){
i32 out_size = 0; i32 out_size = 0;
App_Vars *vars = app_setup_memory(system, memory); App_Vars *vars = app_setup_memory(system, memory);
@ -1452,59 +1437,6 @@ App_Init_Sig(app_init){
setup_ui_commands(&models->map_ui, &models->mem.part, global_map); setup_ui_commands(&models->map_ui, &models->mem.part, global_map);
} }
#if 0
// NOTE(allen): font setup
{
models->font_set = &target->font_set;
struct Font_Setup{
char *c_file_name;
i32 file_name_len;
char *c_name;
i32 name_len;
i32 pt_size;
};
i32 font_size = models->settings.font_size;
char *custom_font_file = models->settings.custom_font_file;
char *custom_font_name = models->settings.custom_font_name;
i32 custom_font_size = models->settings.custom_font_size;
b32 use_custom_font = true;
if (custom_font_file == 0){
use_custom_font = false;
custom_font_file = "";
custom_font_name = "";
}
font_size = clamp_bottom(8, font_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},
{custom_font_file, str_size(custom_font_file),
custom_font_name, str_size(custom_font_name),
custom_font_size},
};
i32 font_count = ArrayCount(font_setup);
if (!use_custom_font){
--font_count;
}
font_set_init(models->font_set, partition, 16, 6);
for (i32 i = 0; i < font_count; ++i){
String file_name = make_string(font_setup[i].c_file_name, font_setup[i].file_name_len);
String name = make_string(font_setup[i].c_name, font_setup[i].name_len);
i32 pt_size = font_setup[i].pt_size;
font_set_add(models->font_set, file_name, name, pt_size);
}
}
#endif
// NOTE(allen): file setup // NOTE(allen): file setup
working_set_init(&models->working_set, partition, &vars->models.mem.general); working_set_init(&models->working_set, partition, &vars->models.mem.general);
models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH; models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH;

7
4ed.h
View File

@ -64,12 +64,7 @@ typedef struct Plat_Settings{
} Plat_Settings; } Plat_Settings;
#define App_Read_Command_Line_Sig(name) \ #define App_Read_Command_Line_Sig(name) \
i32 name(System_Functions *system, \ i32 name(System_Functions *system, Application_Memory *memory, String current_directory, Plat_Settings *plat_settings, char ***files, i32 **file_count, Command_Line_Parameters clparams)
Application_Memory *memory, \
String current_directory, \
Plat_Settings *plat_settings, \
char ***files, i32 **file_count, \
Command_Line_Parameters clparams)
typedef App_Read_Command_Line_Sig(App_Read_Command_Line); typedef App_Read_Command_Line_Sig(App_Read_Command_Line);

View File

@ -29,6 +29,7 @@ struct App_Settings{
i32 custom_arg_start; i32 custom_arg_start;
i32 custom_arg_end; i32 custom_arg_end;
}; };
global_const App_Settings null_app_settings = {0};
struct Debug_Input_Event{ struct Debug_Input_Event{
Key_Code key; Key_Code key;

View File

@ -1015,7 +1015,7 @@ struct Code_Wrap_State{
}; };
internal void internal void
wrap_state_init(Code_Wrap_State *state, Editing_File *file, Render_Font *font){ wrap_state_init(System_Functions *system, Code_Wrap_State *state, Editing_File *file, Render_Font *font){
state->token_array = file->state.token_array; state->token_array = file->state.token_array;
state->token_ptr = state->token_array.tokens; state->token_ptr = state->token_array.tokens;
state->end_token = state->token_ptr + state->token_array.count; state->end_token = state->token_ptr + state->token_array.count;
@ -1031,10 +1031,7 @@ wrap_state_init(Code_Wrap_State *state, Editing_File *file, Render_Font *font){
state->font = font; state->font = font;
#if 0 state->tab_indent_amount = font_get_glyph_advance(system, font, '\t');
state->tab_indent_amount = get_codepoint_advance(font, '\t');
#endif
state->tab_indent_amount = 2.f;
state->byte_advance = font_get_byte_advance(font); state->byte_advance = font_get_byte_advance(font);
state->tran = null_buffer_translating_state; state->tran = null_buffer_translating_state;
@ -1146,10 +1143,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
u32 n = state->step.value; u32 n = state->step.value;
f32 adv = 0; f32 adv = 0;
if (state->behavior.do_codepoint_advance){ if (state->behavior.do_codepoint_advance){
#if 0 adv = font_get_glyph_advance(system, state->font, n);
adv = get_codepoint_advance(state->font, n);
#endif
adv = 2.f;
if (n != ' ' && n != '\t'){ if (n != ' ' && n != '\t'){
skipping_whitespace = false; skipping_whitespace = false;
@ -1406,14 +1400,12 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start, b32 *adjust_
if (wrap_state->wrap_x.paren_safe_top != 0 && prev_token.type == CPP_TOKEN_PARENTHESE_OPEN){ 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; 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; *adjust_top_to_this = 1;
} }
f32 statement_continuation_indent = 0.f; f32 statement_continuation_indent = 0.f;
if (current_shift != 0.f && wrap_state->wrap_x.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)){ if (!(prev_token.flags & (CPP_TFLAG_PP_DIRECTIVE|CPP_TFLAG_PP_BODY))){
switch (prev_token.type){ switch (prev_token.type){
case CPP_TOKEN_BRACKET_OPEN: case CPP_TOKEN_BRACKET_OPEN:
case CPP_TOKEN_BRACE_OPEN: case CPP_TOKEN_BRACE_OPEN:
@ -1499,7 +1491,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
i32 max_wrap_indent_mark = 0; i32 max_wrap_indent_mark = 0;
if (params.virtual_white && file->state.tokens_complete && !file->state.still_lexing){ if (params.virtual_white && file->state.tokens_complete && !file->state.still_lexing){
wrap_state_init(&wrap_state, file, font); wrap_state_init(system, &wrap_state, file, font);
use_tokens = 1; use_tokens = 1;
potential_marks = push_array(part, Potential_Wrap_Indent_Pair, floor32(width)); potential_marks = push_array(part, Potential_Wrap_Indent_Pair, floor32(width));
@ -1551,10 +1543,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
word_stage = 1; word_stage = 1;
} }
else{ else{
#if 0 f32 adv = font_get_glyph_advance(params.system, params.font, ch);
f32 adv = get_codepoint_advance(params.font, ch);
#endif
f32 adv = 2.f;
x += adv; x += adv;
self_x += adv; self_x += adv;
@ -1682,11 +1671,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
goto doublebreak_stage1; goto doublebreak_stage1;
} }
#if 0 f32 adv = font_get_glyph_advance(params.system, params.font, ch);
f32 adv = get_codepoint_advance(params.font, ch);
#endif
f32 adv = 2.f;
x += adv; x += adv;
if (!first_word && x > current_width){ if (!first_word && x > current_width){
emit_comment_position = 1; emit_comment_position = 1;
@ -1713,10 +1698,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
} }
#if 0 f32 adv = font_get_glyph_advance(params.system, params.font, ch);
f32 adv = get_codepoint_advance(params.font, ch);
#endif
f32 adv = 2.f;
x += adv; x += adv;
} }
@ -1978,7 +1960,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
Font_ID font_id = models->global_font_id; Font_ID font_id = models->global_font_id;
file->settings.font_id = font_id; file->settings.font_id = font_id;
Render_Font *font = 0; Render_Font *font = system->font.get_render_data_by_id(font_id);
file_measure_starts(general, &file->state.buffer); file_measure_starts(general, &file->state.buffer);
@ -3243,8 +3225,7 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file
Assert(scratch_size > 0); Assert(scratch_size > 0);
i32 request_amount = 0; i32 request_amount = 0;
Assert(end <= buffer_size(&file->state.buffer)); Assert(end <= buffer_size(&file->state.buffer));
while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount, while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount, part->base + part->pos, scratch_size, &request_amount)){
part->base + part->pos, scratch_size, &request_amount)){
void *new_data = 0; void *new_data = 0;
if (request_amount > 0){ if (request_amount > 0){
new_data = general_memory_allocate(general, request_amount); new_data = general_memory_allocate(general, request_amount);
@ -3273,8 +3254,7 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file
i32 new_line_count = buffer_count_newlines(&file->state.buffer, start, start+str_len); i32 new_line_count = buffer_count_newlines(&file->state.buffer, start, start+str_len);
i32 line_shift = new_line_count - replaced_line_count; i32 line_shift = new_line_count - replaced_line_count;
//Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; Render_Font *font = system->font.get_render_data_by_id(file->settings.font_id);
Render_Font *font = 0;
file_grow_starts_as_needed(general, buffer, line_shift); file_grow_starts_as_needed(general, buffer, line_shift);
buffer_remeasure_starts(buffer, line_start, line_end, line_shift, shift_amount); buffer_remeasure_starts(buffer, line_start, line_end, line_shift, shift_amount);
@ -3396,8 +3376,7 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file,
Buffer_Measure_Starts measure_state = {}; Buffer_Measure_Starts measure_state = {};
buffer_measure_starts(&measure_state, &file->state.buffer); buffer_measure_starts(&measure_state, &file->state.buffer);
//Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; Render_Font *font = system->font.get_render_data_by_id(file->settings.font_id);
Render_Font *font = 0;
// TODO(allen): write the remeasurement version // TODO(allen): write the remeasurement version
file_allocate_character_starts_as_needed(&models->mem.general, file); file_allocate_character_starts_as_needed(&models->mem.general, file);
@ -3682,9 +3661,7 @@ style_get_color(Style *style, Cpp_Token token){
internal void internal void
file_set_font(System_Functions *system, Models *models, Editing_File *file, Font_ID font_id){ file_set_font(System_Functions *system, Models *models, Editing_File *file, Font_ID font_id){
file->settings.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 = system->font.get_render_data_by_id(font_id);
//Render_Font *font = font_info->font;
Render_Font *font = 0;
file_measure_wraps_and_fix_cursor(system, models, file, font); file_measure_wraps_and_fix_cursor(system, models, file, font);
Editing_Layout *layout = &models->layout; Editing_Layout *layout = &models->layout;
@ -4148,9 +4125,9 @@ struct File_Bar{
}; };
internal void internal void
intbar_draw_string(Render_Target *target, File_Bar *bar, String str, u32 char_color){ intbar_draw_string(System_Functions *system, Render_Target *target, File_Bar *bar, String str, u32 char_color){
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); draw_string(system, 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); bar->pos_x += font_string_width(system, target, bar->font_id, str);
} }
internal GUI_Scroll_Vars internal GUI_Scroll_Vars
@ -5938,8 +5915,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act
Buffer_Render_Item *items = push_array(part, Buffer_Render_Item, max); Buffer_Render_Item *items = push_array(part, Buffer_Render_Item, max);
Font_ID 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 = system->font.get_render_data_by_id(font_id);
Render_Font *font = 0;
f32 scroll_x = view->edit_pos->scroll.scroll_x; f32 scroll_x = view->edit_pos->scroll.scroll_x;
f32 scroll_y = view->edit_pos->scroll.scroll_y; f32 scroll_y = view->edit_pos->scroll.scroll_y;
@ -6145,7 +6121,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act
} }
internal void internal void
draw_text_field(Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, String p, String t){ draw_text_field(System_Functions *system, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, String p, String t){
Models *models = view->persistent.models; Models *models = view->persistent.models;
Style *style = main_style(models); Style *style = main_style(models);
@ -6158,13 +6134,13 @@ draw_text_field(Render_Target *target, View *view, Font_ID font_id, i32_Rect rec
if (target){ if (target){
draw_rectangle(target, rect, back_color); draw_rectangle(target, rect, back_color);
x = ceil32(draw_string(target, font_id, p, x, y, text2_color)); x = ceil32(draw_string(system, target, font_id, p, x, y, text2_color));
draw_string(target, font_id, t, x, y, text1_color); draw_string(system, target, font_id, t, x, y, text1_color);
} }
} }
internal void internal void
draw_text_with_cursor(Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, String s, i32 pos){ draw_text_with_cursor(System_Functions *system, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, String s, i32 pos){
Models *models = view->persistent.models; Models *models = view->persistent.models;
Style *style = main_style(models); Style *style = main_style(models);
@ -6180,35 +6156,33 @@ draw_text_with_cursor(Render_Target *target, View *view, Font_ID font_id, i32_Re
draw_rectangle(target, rect, back_color); draw_rectangle(target, rect, back_color);
if (pos >= 0 && pos < s.size){ if (pos >= 0 && pos < s.size){
//Render_Font *font = get_font_info(models->font_set, font_id)->font; Render_Font *font = system->font.get_render_data_by_id(font_id);
Render_Font *font = 0; AllowLocal(font);
String part1 = substr(s, 0, pos); String part1 = substr(s, 0, pos);
String part2 = substr(s, pos, 1); String part2 = substr(s, pos, 1);
String part3 = substr(s, pos+1, s.size-pos-1); String part3 = substr(s, pos+1, s.size-pos-1);
x = draw_string(target, font_id, part1, floor32(x), y, text_color); x = draw_string(system, target, font_id, part1, floor32(x), y, text_color);
//f32 adv = get_codepoint_advance(font, s.str[pos]); f32 adv = font_get_glyph_advance(system, font, s.str[pos]);
f32 adv = 2.f;
i32_Rect cursor_rect; i32_Rect cursor_rect;
cursor_rect.x0 = floor32(x); cursor_rect.x0 = floor32(x);
cursor_rect.x1 = floor32(x) + ceil32(adv); cursor_rect.x1 = floor32(x) + ceil32(adv);
cursor_rect.y0 = y; cursor_rect.y0 = y;
cursor_rect.y1 = y + view->line_height; cursor_rect.y1 = y + view->line_height;
draw_rectangle(target, cursor_rect, cursor_color); draw_rectangle(target, cursor_rect, cursor_color);
x = draw_string(target, font_id, part2, floor32(x), y, at_cursor_color); x = draw_string(system, target, font_id, part2, floor32(x), y, at_cursor_color);
draw_string(target, font_id, part3, floor32(x), y, text_color); draw_string(system, target, font_id, part3, floor32(x), y, text_color);
} }
else{ else{
draw_string(target, font_id, s, floor32(x), y, text_color); draw_string(system, target, font_id, s, floor32(x), y, text_color);
} }
} }
} }
internal void internal void
draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect rect){ draw_file_bar(System_Functions *system, Render_Target *target, View *view, Editing_File *file, i32_Rect rect){
File_Bar bar; File_Bar bar;
Models *models = view->persistent.models; Models *models = view->persistent.models;
Style *style = main_style(models); Style *style = main_style(models);
@ -6232,11 +6206,11 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re
Assert(file); Assert(file);
intbar_draw_string(target, &bar, file->name.live_name, base_color); intbar_draw_string(system, target, &bar, file->name.live_name, base_color);
intbar_draw_string(target, &bar, make_lit_string(" -"), base_color); intbar_draw_string(system, target, &bar, make_lit_string(" -"), base_color);
if (file->is_loading){ if (file->is_loading){
intbar_draw_string(target, &bar, make_lit_string(" loading"), base_color); intbar_draw_string(system, target, &bar, make_lit_string(" loading"), base_color);
} }
else{ else{
char bar_space[526]; char bar_space[526];
@ -6255,11 +6229,11 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re
append_ss(&bar_text, make_lit_string(" nix")); append_ss(&bar_text, make_lit_string(" nix"));
} }
intbar_draw_string(target, &bar, bar_text, base_color); intbar_draw_string(system, target, &bar, bar_text, base_color);
if (file->state.still_lexing){ if (file->state.still_lexing){
intbar_draw_string(target, &bar, make_lit_string(" parsing"), pop1_color); intbar_draw_string(system, target, &bar, make_lit_string(" parsing"), pop1_color);
} }
if (!file->settings.unimportant){ if (!file->settings.unimportant){
@ -6267,13 +6241,13 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re
case DirtyState_UnloadedChanges: case DirtyState_UnloadedChanges:
{ {
local_persist String out_of_sync = make_lit_string(" !"); local_persist String out_of_sync = make_lit_string(" !");
intbar_draw_string(target, &bar, out_of_sync, pop2_color); intbar_draw_string(system, target, &bar, out_of_sync, pop2_color);
}break; }break;
case DirtyState_UnsavedChanges: case DirtyState_UnsavedChanges:
{ {
local_persist String out_of_sync = make_lit_string(" *"); local_persist String out_of_sync = make_lit_string(" *");
intbar_draw_string(target, &bar, out_of_sync, pop2_color); intbar_draw_string(system, target, &bar, out_of_sync, pop2_color);
}break; }break;
} }
} }
@ -6303,7 +6277,7 @@ get_margin_color(i32 active_level, Style *style){
} }
internal void internal void
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){ draw_color_button(System_Functions *system, 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); i32 active_level = gui_active_level(gui_target, id);
if (active_level > 0){ if (active_level > 0){
@ -6311,11 +6285,11 @@ draw_color_button(GUI_Target *gui_target, Render_Target *target, View *view, Fon
} }
draw_rectangle(target, rect, back); draw_rectangle(target, rect, back);
draw_string(target, font_id, text, rect.x0, rect.y0 + 1, fore); draw_string(system, target, font_id, text, rect.x0, rect.y0 + 1, fore);
} }
internal void internal void
draw_font_button(GUI_Target *gui_target, Render_Target *target, View *view, i32_Rect rect, GUI_id id, Font_ID font_id, String text){ draw_font_button(System_Functions *system, 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; Models *models = view->persistent.models;
Style *style = main_style(models); Style *style = main_style(models);
@ -6327,12 +6301,11 @@ draw_font_button(GUI_Target *gui_target, Render_Target *target, View *view, i32_
draw_rectangle(target, rect, back_color); draw_rectangle(target, rect, back_color);
draw_rectangle_outline(target, rect, margin_color); draw_rectangle_outline(target, rect, margin_color);
draw_string(target, font_id, text, rect.x0, rect.y0 + 1, text_color); draw_string(system, target, font_id, text, rect.x0, rect.y0 + 1, text_color);
} }
internal void internal void
draw_fat_option_block(GUI_Target *gui_target, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, GUI_id id, draw_fat_option_block(System_Functions *system, 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){
String text, String pop, i8 checkbox = -1){
Models *models = view->persistent.models; Models *models = view->persistent.models;
Style *style = main_style(models); Style *style = main_style(models);
@ -6367,12 +6340,12 @@ draw_fat_option_block(GUI_Target *gui_target, Render_Target *target, View *view,
x = checkbox_rect.x1 + 3; x = checkbox_rect.x1 + 3;
} }
x = ceil32(draw_string(target, font_id, text, x, y, text_color)); x = ceil32(draw_string(system, target, font_id, text, x, y, text_color));
draw_string(target, font_id, pop, x, y, pop_color); draw_string(system, target, font_id, pop, x, y, pop_color);
} }
internal void internal void
draw_button(GUI_Target *gui_target, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, GUI_id id, String text){ draw_button(System_Functions *system, 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; Models *models = view->persistent.models;
Style *style = main_style(models); Style *style = main_style(models);
@ -6387,13 +6360,13 @@ draw_button(GUI_Target *gui_target, Render_Target *target, View *view, Font_ID f
i32 h = view->line_height; i32 h = view->line_height;
i32 y = inner.y0 + h/2 - 1; i32 y = inner.y0 + h/2 - 1;
i32 w = (i32)font_string_width(target, font_id, text); i32 w = (i32)font_string_width(system, target, font_id, text);
i32 x = (inner.x1 + inner.x0 - w)/2; i32 x = (inner.x1 + inner.x0 - w)/2;
draw_rectangle(target, inner, back); draw_rectangle(target, inner, back);
draw_rectangle_outline(target, inner, margin); draw_rectangle_outline(target, inner, margin);
draw_string(target, font_id, text, x, y, text_color); draw_string(system, target, font_id, text, x, y, text_color);
} }
internal void internal void
@ -6401,7 +6374,6 @@ draw_style_preview(System_Functions *system, GUI_Target *gui_target, Render_Targ
Models *models = view->persistent.models; AllowLocal(models); Models *models = view->persistent.models; AllowLocal(models);
i32 active_level = gui_active_level(gui_target, id); i32 active_level = gui_active_level(gui_target, id);
//Font_Info *info = get_font_info(models->font_set, font_id);
char font_name_space[256]; char font_name_space[256];
String font_name = make_fixed_width_string(font_name_space); String font_name = make_fixed_width_string(font_name_space);
font_name.size = system->font.get_name_by_id(font_id, font_name.str, font_name.memory_size); font_name.size = system->font.get_name_by_id(font_id, font_name.str, font_name.memory_size);
@ -6421,26 +6393,26 @@ draw_style_preview(System_Functions *system, GUI_Target *gui_target, Render_Targ
i32 y = inner.y0; i32 y = inner.y0;
i32 x = inner.x0; i32 x = inner.x0;
x = ceil32(draw_string(target, font_id, style->name.str, x, y, text_color)); x = ceil32(draw_string(system, target, font_id, style->name.str, x, y, text_color));
i32 font_x = (i32)(inner.x1 - font_string_width(target, font_id, font_name)); i32 font_x = (i32)(inner.x1 - font_string_width(system, target, font_id, font_name));
if (font_x > x + 10){ if (font_x > x + 10){
draw_string(target, font_id, font_name, font_x, y, text_color); draw_string(system, target, font_id, font_name, font_x, y, text_color);
} }
i32 height = font_get_height(font); i32 height = font_get_height(font);
x = inner.x0; x = inner.x0;
y += height; y += height;
x = ceil32(draw_string(target, font_id, "if", x, y, keyword_color)); x = ceil32(draw_string(system, target, font_id, "if", x, y, keyword_color));
x = ceil32(draw_string(target, font_id, "(x < ", x, y, text_color)); x = ceil32(draw_string(system, target, font_id, "(x < ", x, y, text_color));
x = ceil32(draw_string(target, font_id, "0", x, y, int_constant_color)); x = ceil32(draw_string(system, target, font_id, "0", x, y, int_constant_color));
x = ceil32(draw_string(target, font_id, ") { x = ", x, y, text_color)); x = ceil32(draw_string(system, target, font_id, ") { x = ", x, y, text_color));
x = ceil32(draw_string(target, font_id, "0", x, y, int_constant_color)); x = ceil32(draw_string(system, target, font_id, "0", x, y, int_constant_color));
x = ceil32(draw_string(target, font_id, "; } ", x, y, text_color)); x = ceil32(draw_string(system, target, font_id, "; } ", x, y, text_color));
x = ceil32(draw_string(target, font_id, "// comment", x, y, comment_color)); x = ceil32(draw_string(system, target, font_id, "// comment", x, y, comment_color));
x = inner.x0; x = inner.x0;
y += height; y += height;
draw_string(target, font_id, "[] () {}; * -> +-/ <>= ! && || % ^", x, y, text_color); draw_string(system, target, font_id, "[] () {}; * -> +-/ <>= ! && || % ^", x, y, text_color);
} }
internal i32 internal i32
@ -6483,7 +6455,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol
switch (h->type){ switch (h->type){
case guicom_top_bar: case guicom_top_bar:
{ {
draw_file_bar(target, view, file, gui_session.rect); draw_file_bar(system, target, view, file, gui_session.rect);
}break; }break;
case guicom_file: case guicom_file:
@ -6498,7 +6470,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol
void *ptr = (h+1); void *ptr = (h+1);
String p = gui_read_string(&ptr); String p = gui_read_string(&ptr);
String t = gui_read_string(&ptr); String t = gui_read_string(&ptr);
draw_text_field(target, view, font_id, gui_session.rect, p, t); draw_text_field(system, target, view, font_id, gui_session.rect, p, t);
}break; }break;
case guicom_text_with_cursor: case guicom_text_with_cursor:
@ -6507,7 +6479,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol
String s = gui_read_string(&ptr); String s = gui_read_string(&ptr);
i32 pos = gui_read_integer(&ptr); i32 pos = gui_read_integer(&ptr);
draw_text_with_cursor(target, view, font_id, gui_session.rect, s, pos); draw_text_with_cursor(system, target, view, font_id, gui_session.rect, s, pos);
}break; }break;
case guicom_color_button: case guicom_color_button:
@ -6518,7 +6490,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol
u32 back = (u32)gui_read_integer(&ptr); u32 back = (u32)gui_read_integer(&ptr);
String t = gui_read_string(&ptr); String t = gui_read_string(&ptr);
draw_color_button(gui_target, target, view, font_id, gui_session.rect, b->id, fore, back, t); draw_color_button(system, gui_target, target, view, font_id, gui_session.rect, b->id, fore, back, t);
}break; }break;
case guicom_font_button: case guicom_font_button:
@ -6528,7 +6500,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol
Font_ID font_id = (Font_ID)gui_read_integer(&ptr); Font_ID font_id = (Font_ID)gui_read_integer(&ptr);
String t = gui_read_string(&ptr); String t = gui_read_string(&ptr);
draw_font_button(gui_target, target, view, gui_session.rect, b->id, font_id, t); draw_font_button(system, gui_target, target, view, gui_session.rect, b->id, font_id, t);
}break; }break;
case guicom_file_option: case guicom_file_option:
@ -6543,7 +6515,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol
append_s_char(&f, '/'); append_s_char(&f, '/');
} }
draw_fat_option_block(gui_target, target, view, font_id, gui_session.rect, b->id, f, m); draw_fat_option_block(system, gui_target, target, view, font_id, gui_session.rect, b->id, f, m);
}break; }break;
case guicom_style_preview: case guicom_style_preview:
@ -6568,7 +6540,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol
status = (i8)gui_read_byte(&ptr); status = (i8)gui_read_byte(&ptr);
} }
draw_fat_option_block(gui_target, target, view, font_id, gui_session.rect, b->id, f, m, status); draw_fat_option_block(system, gui_target, target, view, font_id, gui_session.rect, b->id, f, m, status);
}break; }break;
case guicom_button: case guicom_button:
@ -6577,7 +6549,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol
void *ptr = (b + 1); void *ptr = (b + 1);
String t = gui_read_string(&ptr); String t = gui_read_string(&ptr);
draw_button(gui_target, target, view, font_id, gui_session.rect, b->id, t); draw_button(system, gui_target, target, view, font_id, gui_session.rect, b->id, t);
}break; }break;
case guicom_scrollable_bar: case guicom_scrollable_bar:

View File

@ -431,18 +431,6 @@ unlerp(f32 a, f32 x, f32 b){
return(r); return(r);
} }
inline f32
clamp_bottom(f32 a, f32 n){
if (n < a) n = a;
return (n);
}
inline f32
clamp_top(f32 n, f32 z){
if (n > z) n = z;
return (n);
}
inline f32 inline f32
clamp(f32 a, f32 n, f32 z){ clamp(f32 a, f32 n, f32 z){
if (n < a) n = a; if (n < a) n = a;
@ -450,18 +438,6 @@ clamp(f32 a, f32 n, f32 z){
return (n); return (n);
} }
inline i32
clamp_bottom(i32 a, i32 n){
if (n < a) n = a;
return (n);
}
inline i32
clamp_top(i32 n, i32 z){
if (n > z) n = z;
return (n);
}
inline i32 inline i32
clamp(i32 a, i32 n, i32 z){ clamp(i32 a, i32 n, i32 z){
if (n < a) n = a; if (n < a) n = a;
@ -469,30 +445,6 @@ clamp(i32 a, i32 n, i32 z){
return (n); return (n);
} }
inline u32
clamp_bottom(u32 a, u32 n){
if (n < a) n = a;
return (n);
}
inline u64
clamp_bottom(u64 a, u64 n){
if (n < a) n = a;
return (n);
}
inline u32
clamp_top(u32 n, u32 z){
if (n > z) n = z;
return (n);
}
inline u64
clamp_top(u64 n, u64 z){
if (n > z) n = z;
return (n);
}
inline u32 inline u32
clamp(u32 a, u32 n, u32 z){ clamp(u32 a, u32 n, u32 z){
if (n < a) n = a; if (n < a) n = a;
@ -500,6 +452,9 @@ clamp(u32 a, u32 n, u32 z){
return (n); return (n);
} }
#define clamp_top(a,b) Min(a,b)
#define clamp_bottom(a,b) Max(a,b)
/* /*
* Color * Color
*/ */

View File

@ -130,19 +130,15 @@ font_draw_glyph(Render_Target *target, Font_ID font_id, u32 codepoint, f32 x, f3
} }
internal f32 internal f32
draw_string_base(Render_Target *target, Font_ID font_id, i32 type, String str_, i32 x_, i32 y_, u32 color){ draw_string_base(System_Functions *system, Render_Target *target, Font_ID font_id, i32 type, String str_, i32 x_, i32 y_, u32 color){
f32 x = 0; f32 x = 0;
#if 0 Render_Font *font = system->font.get_render_data_by_id(font_id);
Font_Info *font_info = get_font_info(&target->font_set, font_id); if (font != 0){
Render_Font *font = font_info->font;
if (font){
f32 y = (f32)y_; f32 y = (f32)y_;
x = (f32)x_; x = (f32)x_;
f32 byte_advance = font->byte_advance; f32 byte_advance = font_get_byte_advance(font);
u8 *str = (u8*)str_.str; u8 *str = (u8*)str_.str;
u8 *str_end = str + str_.size; u8 *str_end = str + str_.size;
@ -169,7 +165,7 @@ draw_string_base(Render_Target *target, Font_ID font_id, i32 type, String str_,
if (color != 0){ if (color != 0){
font_draw_glyph(target, font_id, type, (u8)codepoint, x, y, color); font_draw_glyph(target, font_id, type, (u8)codepoint, x, y, color);
} }
x += get_codepoint_advance(font, codepoint); x += font_get_glyph_advance(system, font, codepoint);
} }
else if (do_numbers){ else if (do_numbers){
for (;byte < str; ++byte){ for (;byte < str; ++byte){
@ -179,10 +175,12 @@ draw_string_base(Render_Target *target, Font_ID font_id, i32 type, String str_,
cs[0] = '\\'; cs[0] = '\\';
byte_to_ascii(n, cs+1); byte_to_ascii(n, cs+1);
f32 *advances = font_get_byte_sub_advances(font);
f32 xx = x; f32 xx = x;
for (u32 j = 0; j < 3; ++j){ for (u32 j = 0; j < 3; ++j){
font_draw_glyph(target, font_id, type, cs[j], xx, y, color); font_draw_glyph(target, font_id, type, cs[j], xx, y, color);
xx += byte_advance; xx += advances[j];
} }
} }
@ -191,47 +189,46 @@ draw_string_base(Render_Target *target, Font_ID font_id, i32 type, String str_,
} }
} }
} }
#endif
return(x); return(x);
} }
internal f32 internal f32
draw_string(Render_Target *target, Font_ID font_id, String str, i32 x, i32 y, u32 color){ draw_string(System_Functions *system, 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); f32 w = draw_string_base(system, target, font_id, piece_type_glyph, str, x, y, color);
return(w); return(w);
} }
internal f32 internal f32
draw_string(Render_Target *target, Font_ID font_id, char *str, i32 x, i32 y, u32 color){ draw_string(System_Functions *system, Render_Target *target, Font_ID font_id, char *str, i32 x, i32 y, u32 color){
String string = make_string_slowly(str); String string = make_string_slowly(str);
f32 w = draw_string_base(target, font_id, piece_type_glyph, string, x, y, color); f32 w = draw_string_base(system, target, font_id, piece_type_glyph, string, x, y, color);
return(w); return(w);
} }
internal f32 internal f32
draw_string_mono(Render_Target *target, Font_ID font_id, String str, i32 x, i32 y, f32 advance, u32 color){ draw_string_mono(System_Functions *system, 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); f32 w = draw_string_base(system, target, font_id, piece_type_mono_glyph, str, x, y, color);
return(w); return(w);
} }
internal f32 internal f32
draw_string_mono(Render_Target *target, Font_ID font_id, char *str, i32 x, i32 y, f32 advance, u32 color){ draw_string_mono(System_Functions *system, Render_Target *target, Font_ID font_id, char *str, i32 x, i32 y, f32 advance, u32 color){
String string = make_string_slowly(str); String string = make_string_slowly(str);
f32 w = draw_string_base(target, font_id, piece_type_mono_glyph, string, x, y, color); f32 w = draw_string_base(system, target, font_id, piece_type_mono_glyph, string, x, y, color);
return(w); return(w);
} }
internal f32 internal f32
font_string_width(Render_Target *target, Font_ID font_id, String str){ font_string_width(System_Functions *system, Render_Target *target, Font_ID font_id, String str){
f32 w = draw_string_base(target, font_id, piece_type_glyph, str, 0, 0, 0); f32 w = draw_string_base(system, target, font_id, piece_type_glyph, str, 0, 0, 0);
return(w); return(w);
} }
internal f32 internal f32
font_string_width(Render_Target *target, Font_ID font_id, char *str){ font_string_width(System_Functions *system, Render_Target *target, Font_ID font_id, char *str){
String string = make_string_slowly(str); String string = make_string_slowly(str);
f32 w = draw_string_base(target, font_id, piece_type_glyph, string, 0, 0, 0); f32 w = draw_string_base(system, target, font_id, piece_type_glyph, string, 0, 0, 0);
return(w); return(w);
} }

View File

@ -424,10 +424,9 @@ get_exact_render_quad(Glyph_Bounds *b, i32 pw, i32 ph, float xpos, float ypos){
} }
inline void inline void
private_draw_glyph(Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, u32 color){ private_draw_glyph(System_Functions *system, Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, u32 color){
#if 0 Glyph_Data glyph = font_get_glyph(system, font, codepoint);
Glyph_Data glyph = {0}; if (glyph.tex != 0){
if (get_codepoint_glyph_data(font, character, &glyph)){
Render_Quad q = get_render_quad(&glyph.bounds, glyph.tex_width, glyph.tex_height, x, y); Render_Quad q = get_render_quad(&glyph.bounds, glyph.tex_width, glyph.tex_height, x, y);
draw_set_color(target, color); draw_set_color(target, color);
@ -441,14 +440,12 @@ private_draw_glyph(Render_Target *target, Render_Font *font, u32 codepoint, f32
} }
glEnd(); glEnd();
} }
#endif
} }
inline void inline void
private_draw_glyph_mono(Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, f32 advance, u32 color){ private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, f32 advance, u32 color){
#if 0 Glyph_Data glyph = font_get_glyph(system, font, codepoint);
Glyph_Data glyph = {0}; if (glyph.tex != 0){
if (get_codepoint_glyph_data(font, character, &glyph)){
f32 left = glyph.bounds.x0; f32 left = glyph.bounds.x0;
f32 right = glyph.bounds.x1; f32 right = glyph.bounds.x1;
f32 width = (right - left); f32 width = (right - left);
@ -469,18 +466,16 @@ private_draw_glyph_mono(Render_Target *target, Render_Font *font, u32 codepoint,
} }
glEnd(); glEnd();
} }
#endif
} }
inline void inline void
private_draw_glyph_mono(Render_Target *target, Render_Font *font, u32 character, f32 x, f32 y, u32 color){ private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_Font *font, u32 character, f32 x, f32 y, u32 color){
f32 advance = (f32)font_get_advance(font); f32 advance = (f32)font_get_advance(font);
private_draw_glyph_mono(target, font, character, x, y, advance, color); private_draw_glyph_mono(system, target, font, character, x, y, advance, color);
} }
internal void internal void
launch_rendering(Render_Target *target){ launch_rendering(System_Functions *system, Render_Target *target){
char *cursor = target->push_buffer; char *cursor = target->push_buffer;
char *cursor_end = cursor + target->size; char *cursor_end = cursor + target->size;
@ -509,44 +504,34 @@ launch_rendering(Render_Target *target){
case piece_type_glyph: case piece_type_glyph:
{ {
#if 0
Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph); Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph);
Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; Render_Font *font = system->font.get_render_data_by_id(glyph->font_id);
if (font){ Assert(font != 0);
private_draw_glyph(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->color); private_draw_glyph(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color);
}
#endif
}break; }break;
case piece_type_mono_glyph: case piece_type_mono_glyph:
{ {
#if 0
Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph); Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph);
Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; Render_Font *font = system->font.get_render_data_by_id(glyph->font_id);
if (font){ Assert(font != 0);
private_draw_glyph_mono(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->color); private_draw_glyph_mono(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color);
}
#endif
}break; }break;
case piece_type_mono_glyph_advance: case piece_type_mono_glyph_advance:
{ {
#if 0
Render_Piece_Glyph_Advance *glyph = ExtractStruct(Render_Piece_Glyph_Advance); Render_Piece_Glyph_Advance *glyph = ExtractStruct(Render_Piece_Glyph_Advance);
Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; Render_Font *font = system->font.get_render_data_by_id(glyph->font_id);
if (font){ Assert(font != 0);
private_draw_glyph_mono(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->advance, glyph->color); private_draw_glyph_mono(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->advance, glyph->color);
}
#endif
}break; }break;
case piece_type_change_clip: case piece_type_change_clip:
{ {
Render_Piece_Change_Clip *clip = Render_Piece_Change_Clip *clip = ExtractStruct(Render_Piece_Change_Clip);
ExtractStruct(Render_Piece_Change_Clip);
draw_set_clip(target, clip->box); draw_set_clip(target, clip->box);
}break; }break;
} }
@ -684,7 +669,9 @@ font_load_page_inner(Partition *part, Render_Font *font, FT_Library ft, FT_Face
} }
internal b32 internal b32
font_load_page(System_Functions *system, Partition *part, Render_Font *font, char *filename, i32 pt_size, i32 tab_width, b32 use_hinting, u32 page_number){ font_load_page(System_Functions *system, Partition *part, Render_Font *font, Glyph_Page *page, u32 page_number, u32 pt_size, b32 use_hinting){
char *filename = font->filename;
// TODO(allen): Stop redoing all this init for each call. // TODO(allen): Stop redoing all this init for each call.
FT_Library ft; FT_Library ft;
@ -694,8 +681,7 @@ font_load_page(System_Functions *system, Partition *part, Render_Font *font, cha
FT_New_Face(ft, filename, 0, &face); FT_New_Face(ft, filename, 0, &face);
// NOTE(allen): set texture and glyph data. // NOTE(allen): set texture and glyph data.
Glyph_Page *page = font_get_or_make_page(system, font, page_number); font_load_page_inner(part, font, ft, face, use_hinting, page, page_number, 4);
font_load_page_inner(part, font, ft, face, use_hinting, page, page_number, tab_width);
FT_Done_FreeType(ft); FT_Done_FreeType(ft);
@ -703,9 +689,9 @@ font_load_page(System_Functions *system, Partition *part, Render_Font *font, cha
} }
internal b32 internal b32
font_load(System_Functions *system, Partition *part, Render_Font *font, char *filename, i32 pt_size, i32 tab_width, b32 use_hinting){ font_load(System_Functions *system, Partition *part, Render_Font *font, i32 pt_size, b32 use_hinting){
memset(font, 0, sizeof(*font)); char *filename = font->filename;
// TODO(allen): Stop redoing all this init for each call. // TODO(allen): Stop redoing all this init for each call.
FT_Library ft; FT_Library ft;
@ -731,7 +717,6 @@ font_load(System_Functions *system, Partition *part, Render_Font *font, char *fi
// NOTE(allen): set texture and glyph data. // NOTE(allen): set texture and glyph data.
Glyph_Page *page = font_get_or_make_page(system, font, 0); Glyph_Page *page = font_get_or_make_page(system, font, 0);
font_load_page_inner(part, font, ft, face, use_hinting, page, 0, tab_width);
// NOTE(allen): Setup some basic spacing stuff. // NOTE(allen): Setup some basic spacing stuff.
f32 backslash_adv = page->advance['\\']; f32 backslash_adv = page->advance['\\'];
@ -750,12 +735,63 @@ font_load(System_Functions *system, Partition *part, Render_Font *font, char *fi
} }
font->byte_advance = backslash_adv + max_hex_advance*2; font->byte_advance = backslash_adv + max_hex_advance*2;
font->byte_sub_advances[0] = backslash_adv;
font->byte_sub_advances[1] = max_hex_advance;
font->byte_sub_advances[2] = max_hex_advance;
FT_Done_FreeType(ft); FT_Done_FreeType(ft);
return(true); return(true);
} }
internal void
system_set_page(System_Functions *system, Partition *part, Render_Font *font, Glyph_Page *page, u32 page_number, u32 pt_size, b32 use_hinting){
memset(page, 0, sizeof(*page));
if (part->base == 0){
*part = sysshared_scratch_partition(MB(8));
}
b32 success = false;
for (u32 R = 0; R < 3; ++R){
success = font_load_page(system, part, font, page, page_number, pt_size, use_hinting);
if (success){
break;
}
else{
sysshared_partition_double(part);
}
}
}
internal void
system_set_font(System_Functions *system, Partition *part, Render_Font *font, String filename, String name, u32 pt_size, b32 use_hinting){
memset(font, 0, sizeof(*font));
copy_partial_cs(font->filename, sizeof(font->filename)-1, filename);
font->filename_len = filename.size;
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){
*part = sysshared_scratch_partition(MB(8));
}
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);
}
}
}
#endif #endif
// BOTTOM // BOTTOM

View File

@ -922,17 +922,12 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
} }
else if (S.behavior.do_number_advance || S.behavior.do_codepoint_advance){ else if (S.behavior.do_number_advance || S.behavior.do_codepoint_advance){
if (!S.skipping_whitespace){ if (!S.skipping_whitespace){
S.current_adv = 2.f;
#if 0
if (S.behavior.do_codepoint_advance){ if (S.behavior.do_codepoint_advance){
S.current_adv = get_codepoint_advance(params.font, S.tran.step_current.value); S.current_adv = font_get_glyph_advance(params.system, params.font, S.step.value);
} }
else{ else{
S.current_adv = params.font->byte_advance; S.current_adv = font_get_byte_advance(params.font);
} }
#endif
S.did_wrap = false; S.did_wrap = false;
if (S.i >= S.wrap_unit_end){ if (S.i >= S.wrap_unit_end){
@ -1438,9 +1433,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
switch (params.seek.type){ switch (params.seek.type){
case buffer_seek_pos: case buffer_seek_pos:
{ {
if (params.seek.pos > S.size){ params.seek.pos = clamp(0, params.seek.pos, S.size);
params.seek.pos = S.size;
}
line_index = buffer_get_line_index(params.buffer, params.seek.pos); line_index = buffer_get_line_index(params.buffer, params.seek.pos);
}break; }break;
@ -1449,34 +1442,21 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
{ {
i32 line_count = params.buffer->line_count; i32 line_count = params.buffer->line_count;
i32 max_character = params.character_starts[line_count] - 1; i32 max_character = params.character_starts[line_count] - 1;
if (params.seek.pos > max_character){ params.seek.pos = clamp(0, params.seek.pos, max_character);
params.seek.pos = max_character;
}
line_index = buffer_get_line_index_from_character_pos(params.character_starts, params.seek.pos, line_index = buffer_get_line_index_from_character_pos(params.character_starts, params.seek.pos, 0, params.buffer->line_count);
0, params.buffer->line_count);
}break; }break;
case buffer_seek_line_char: case buffer_seek_line_char:
{ {
line_index = params.seek.line - 1; line_index = params.seek.line - 1;
if (line_index >= params.buffer->line_count){ line_index = clamp_bottom(0, line_index);
line_index = params.buffer->line_count - 1;
}
if (line_index < 0){
line_index = 0;
}
}break; }break;
case buffer_seek_unwrapped_xy: case buffer_seek_unwrapped_xy:
{ {
line_index = (i32)(params.seek.y / S.font_height); line_index = (i32)(params.seek.y / S.font_height);
if (line_index >= params.buffer->line_count){ line_index = clamp_bottom(0, line_index);
line_index = params.buffer->line_count - 1;
}
if (line_index < 0){
line_index = 0;
}
}break; }break;
case buffer_seek_wrapped_xy: case buffer_seek_wrapped_xy:
@ -1487,15 +1467,20 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
default: InvalidCodePath; default: InvalidCodePath;
} }
i32 safe_line_index = line_index;
if (line_index >= params.buffer->line_count){
safe_line_index = params.buffer->line_count-1;
}
// Build the cursor hint // Build the cursor hint
S.next_cursor.pos = params.buffer->line_starts[line_index]; S.next_cursor.pos = params.buffer->line_starts[safe_line_index];
S.next_cursor.character_pos = params.character_starts[line_index]; S.next_cursor.character_pos = params.character_starts[safe_line_index];
S.next_cursor.line = line_index + 1; S.next_cursor.line = line_index + 1;
S.next_cursor.character = 1; S.next_cursor.character = 1;
S.next_cursor.wrap_line = params.wrap_line_index[line_index] + 1; S.next_cursor.wrap_line = params.wrap_line_index[safe_line_index] + 1;
S.next_cursor.unwrapped_y = (f32)(line_index * S.font_height); S.next_cursor.unwrapped_y = (f32)(safe_line_index * S.font_height);
S.next_cursor.unwrapped_x = 0; S.next_cursor.unwrapped_x = 0;
S.next_cursor.wrapped_y = (f32)(params.wrap_line_index[line_index] * S.font_height); S.next_cursor.wrapped_y = (f32)(params.wrap_line_index[safe_line_index] * S.font_height);
S.next_cursor.wrapped_x = 0; S.next_cursor.wrapped_x = 0;
} }
@ -1624,16 +1609,12 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
} }
else if (S.behavior.do_number_advance || S.behavior.do_codepoint_advance){ else if (S.behavior.do_number_advance || S.behavior.do_codepoint_advance){
S.ch_width = 2.f; if (S.behavior.do_codepoint_advance){
S.ch_width = font_get_glyph_advance(params.system, params.font, S.step.value);
#if 0
if (S.tran.do_codepoint_advance){
S.ch_width = get_codepoint_advance(params.font, S.tran.step_current.value);
} }
else{ else{
S.ch_width = params.font->byte_advance; S.ch_width = font_get_byte_advance(params.font);
} }
#endif
if (S.step.i >= S.wrap_unit_end){ if (S.step.i >= S.wrap_unit_end){
S_stop.status = BLStatus_NeedWrapDetermination; S_stop.status = BLStatus_NeedWrapDetermination;
@ -1821,6 +1802,7 @@ typedef struct Buffer_Render_Item{
typedef struct Render_Item_Write{ typedef struct Render_Item_Write{
Buffer_Render_Item *item; Buffer_Render_Item *item;
f32 x, y; f32 x, y;
System_Functions *system;
Render_Font *font; Render_Font *font;
i32 font_height; i32 font_height;
f32 x_min; f32 x_min;
@ -1830,11 +1812,7 @@ typedef struct Render_Item_Write{
inline Render_Item_Write inline Render_Item_Write
write_render_item(Render_Item_Write write, i32 index, u32 codepoint, u32 flags){ write_render_item(Render_Item_Write write, i32 index, u32 codepoint, u32 flags){
#if 0 f32 ch_width = font_get_glyph_advance(write.system, write.font, codepoint);
f32 ch_width = get_codepoint_advance(write.font, codepoint);
#endif
f32 ch_width = 2.f;
if (write.x <= write.x_max && write.x + ch_width >= write.x_min){ if (write.x <= write.x_max && write.x + ch_width >= write.x_min){
write.item->index = index; write.item->index = index;
@ -1945,6 +1923,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
S.write.item = params.items; S.write.item = params.items;
S.write.x = S.shift_x + line_shift; S.write.x = S.shift_x + line_shift;
S.write.y = S.shift_y; S.write.y = S.shift_y;
S.write.system = params.system;
S.write.font = params.font; S.write.font = params.font;
S.write.font_height = font_get_height(params.font); S.write.font_height = font_get_height(params.font);
S.write.x_min = params.port_x; S.write.x_min = params.port_x;
@ -2055,10 +2034,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
case '\t': case '\t':
{ {
#if 0 S.ch_width = font_get_glyph_advance(params.system, params.font, '\t');
S.ch_width = get_codepoint_advance(params.font, '\t');
#endif
S.ch_width = 2.f;
f32 new_x = S.write.x + S.ch_width; f32 new_x = S.write.x + S.ch_width;
S.write = write_render_item(S.write, I, ' ', 0); S.write = write_render_item(S.write, I, ' ', 0);

View File

@ -18,6 +18,7 @@ struct Translation_State{
global_const Translation_State null_buffer_translating_state = {0}; global_const Translation_State null_buffer_translating_state = {0};
enum{ enum{
TranLBH_None,
TranLBH_Rebuffer, TranLBH_Rebuffer,
TranLBH_EmitAsCP, TranLBH_EmitAsCP,
}; };
@ -41,6 +42,8 @@ struct Translation_Emits{
u32 step_count; u32 step_count;
}; };
#define SINGLE_BYTE_ERROR_CLASS max_u8
internal void internal void
translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Byte_Description *desc_out){ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Byte_Description *desc_out){
desc_out->byte_class = 0; desc_out->byte_class = 0;
@ -48,7 +51,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl
desc_out->byte_class = 1; desc_out->byte_class = 1;
} }
else if (ch < 0xC0){ else if (ch < 0xC0){
desc_out->byte_class = max_u8; desc_out->byte_class = SINGLE_BYTE_ERROR_CLASS;
} }
else if (ch < 0xE0){ else if (ch < 0xE0){
desc_out->byte_class = 2; desc_out->byte_class = 2;
@ -61,7 +64,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl
} }
desc_out->prelim_emit_type = BufferModelUnit_None; desc_out->prelim_emit_type = BufferModelUnit_None;
desc_out->last_byte_handler = 0; desc_out->last_byte_handler = TranLBH_None;
if (tran->fill_expected == 0){ if (tran->fill_expected == 0){
tran->fill_buffer[0] = ch; tran->fill_buffer[0] = ch;
tran->fill_start_i = i; tran->fill_start_i = i;
@ -70,7 +73,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl
if (desc_out->byte_class == 1){ if (desc_out->byte_class == 1){
desc_out->prelim_emit_type = BufferModelUnit_Codepoint; desc_out->prelim_emit_type = BufferModelUnit_Codepoint;
} }
else if (desc_out->byte_class == 0 || desc_out->byte_class == 1000){ else if (desc_out->byte_class == 0 || desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){
desc_out->prelim_emit_type = BufferModelUnit_Numbers; desc_out->prelim_emit_type = BufferModelUnit_Numbers;
} }
else{ else{
@ -78,7 +81,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl
} }
} }
else{ else{
if (desc_out->byte_class == 1000){ if (desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){
tran->fill_buffer[tran->fill_i] = ch; tran->fill_buffer[tran->fill_i] = ch;
++tran->fill_i; ++tran->fill_i;

View File

@ -38,12 +38,13 @@ struct Render_Font{
Glyph_Page **pages; Glyph_Page **pages;
u32 page_count, page_max; u32 page_count, page_max;
f32 byte_advance; f32 byte_advance;
f32 byte_sub_advances[3];
i32 height, ascent, descent, line_skip, advance; i32 height, ascent, descent, line_skip, advance;
char filename[256];
char name[256];
u32 filename_len; u32 filename_len;
u32 name_len; u32 name_len;
char filename[256];
char name[256];
}; };
struct Glyph_Data{ struct Glyph_Data{
@ -56,4 +57,3 @@ struct Glyph_Data{
// BOTTOM // BOTTOM

View File

@ -26,13 +26,16 @@ typedef Sys_Font_Get_IDs_By_Index_Sig(Font_Get_IDs_By_Index_Function);
#define Sys_Font_Get_Name_By_Index_Sig(name_) u32 (name_)(u32 font_index, char *str_out, u32 str_out_cap) #define Sys_Font_Get_Name_By_Index_Sig(name_) u32 (name_)(u32 font_index, char *str_out, u32 str_out_cap)
typedef Sys_Font_Get_Name_By_Index_Sig(Font_Get_Name_By_Index_Function); typedef Sys_Font_Get_Name_By_Index_Sig(Font_Get_Name_By_Index_Function);
#define Sys_Font_Get_Name_By_ID_Sig(name_) u32 (name_)(u32 font_index, char *str_out, u32 str_out_cap) #define Sys_Font_Get_Name_By_ID_Sig(name_) u32 (name_)(u32 font_id, char *str_out, u32 str_out_cap)
typedef Sys_Font_Get_Name_By_ID_Sig(Font_Get_Name_By_ID_Function); typedef Sys_Font_Get_Name_By_ID_Sig(Font_Get_Name_By_ID_Function);
#define Sys_Font_Get_Render_Data_By_ID_Sig(name_) Render_Font* (name_)(u32 font_id) #define Sys_Font_Get_Render_Data_By_ID_Sig(name_) Render_Font* (name_)(u32 font_id)
typedef Sys_Font_Get_Render_Data_By_ID_Sig(Font_Get_Render_Data_By_ID_Function); typedef Sys_Font_Get_Render_Data_By_ID_Sig(Font_Get_Render_Data_By_ID_Function);
#define Sys_Font_Allocate_Sig(name_) void* (name_)(umem size) #define Sys_Font_Load_Page_Sig(name_) void (name_)(Render_Font *font, Glyph_Page *page, u32 page_number)
typedef Sys_Font_Load_Page_Sig(Font_Load_Page_Function);
#define Sys_Font_Allocate_Sig(name_) void* (name_)(i32 size)
typedef Sys_Font_Allocate_Sig(Font_Allocate_Function); typedef Sys_Font_Allocate_Sig(Font_Allocate_Function);
#define Sys_Font_Free_Sig(name_) void (name_)(void *ptr) #define Sys_Font_Free_Sig(name_) void (name_)(void *ptr)
@ -44,12 +47,14 @@ struct Font_Functions{
Font_Get_Name_By_Index_Function *get_name_by_index; Font_Get_Name_By_Index_Function *get_name_by_index;
Font_Get_Name_By_ID_Function *get_name_by_id; Font_Get_Name_By_ID_Function *get_name_by_id;
Font_Get_Render_Data_By_ID_Function *get_render_data_by_id; Font_Get_Render_Data_By_ID_Function *get_render_data_by_id;
Font_Load_Page_Function *load_page;
Font_Allocate_Function *allocate; Font_Allocate_Function *allocate;
Font_Free_Function *free; Font_Free_Function *free;
}; };
internal f32 font_get_byte_advance(Render_Font *font); internal f32 font_get_byte_advance(Render_Font *font);
internal f32*font_get_byte_sub_advances(Render_Font *font);
internal i32 font_get_height(Render_Font *font); internal i32 font_get_height(Render_Font *font);
internal i32 font_get_ascent(Render_Font *font); internal i32 font_get_ascent(Render_Font *font);
internal i32 font_get_descent(Render_Font *font); internal i32 font_get_descent(Render_Font *font);
@ -57,6 +62,10 @@ internal i32 font_get_line_skip(Render_Font *font);
internal i32 font_get_advance(Render_Font *font); internal i32 font_get_advance(Render_Font *font);
internal b32 font_can_render(struct System_Functions *system, Render_Font *font, u32 codepoint); internal b32 font_can_render(struct System_Functions *system, Render_Font *font, u32 codepoint);
internal f32 font_get_glyph_advance(struct System_Functions *system, Render_Font *font, u32 codepoint);
struct Glyph_Data;
internal Glyph_Data font_get_glyph(System_Functions *system, Render_Font *font, u32 codepoint);
internal Glyph_Page *font_get_or_make_page(struct System_Functions *system, Render_Font *font, u32 page_number); internal Glyph_Page *font_get_or_make_page(struct System_Functions *system, Render_Font *font, u32 page_number);

View File

@ -0,0 +1,24 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 13.03.2017
*
* Font system interface to the OS layer.
*
*/
// TOP
#if !defined(FCODER_FONT_INTERFACE_TO_OS_H)
#define FCODER_FONT_INTERFACE_TO_OS_H
#define Sys_Font_Init_Sig(name_) void (name_)(Font_Functions *font, void *memory, umem memory_size, u32 font_size, b32 use_hinting)
internal Sys_Font_Init_Sig(system_font_init);
#endif
// BOTTOM

View File

@ -16,6 +16,11 @@ font_get_byte_advance(Render_Font *font){
return(font->byte_advance); return(font->byte_advance);
} }
internal f32*
font_get_byte_sub_advances(Render_Font *font){
return(font->byte_sub_advances);
}
internal i32 internal i32
font_get_height(Render_Font *font){ font_get_height(Render_Font *font){
return(font->height); return(font->height);
@ -46,12 +51,37 @@ font_can_render(System_Functions *system, Render_Font *font, u32 codepoint){
b32 result = false; b32 result = false;
u32 page_number = (codepoint >> 8); u32 page_number = (codepoint >> 8);
u32 glyph_index = codepoint & 0xFF; u32 glyph_index = codepoint & 0xFF;
Glyph_Page *page = font_get_or_make_page(system, font, page_number); Glyph_Page *page = font_get_or_make_page(system, font, page_number);
if (page != 0 && page->advance[glyph_index] > 0.f){ if (page != 0 && page->advance[glyph_index] > 0.f){
result = true; result = true;
} }
return(result);
}
internal f32
font_get_glyph_advance(System_Functions *system, Render_Font *font, u32 codepoint){
f32 result = 0.f;
u32 page_number = (codepoint >> 8);
u32 glyph_index = codepoint & 0xFF;
Glyph_Page *page = font_get_or_make_page(system, font, page_number);
if (page != 0 && page->advance[glyph_index] > 0.f){
result = page->advance[glyph_index];
}
return(result);
}
internal Glyph_Data
font_get_glyph(System_Functions *system, Render_Font *font, u32 codepoint){
Glyph_Data result = {0};
u32 page_number = (codepoint >> 8);
u32 glyph_index = codepoint & 0xFF;
Glyph_Page *page = font_get_or_make_page(system, font, page_number);
if (page != 0 && page->advance[glyph_index] > 0.f){
result.bounds = page->glyphs[glyph_index];
result.tex = page->tex;
result.tex_width = page->tex_width;
result.tex_height = page->tex_height;
}
return(result); return(result);
} }
@ -153,14 +183,16 @@ font_get_or_make_page(System_Functions *system, Render_Font *font, u32 page_numb
*dest = new_page; *dest = new_page;
font->page_count += new_page_count; font->page_count += new_page_count;
result = new_page; result = new_page;
system->font.load_page(font, new_page, page_number);
} }
} }
} }
else{
result = *page_get_result;
}
} }
return(result); return(result);
} }
// BOTTOM // BOTTOM

View File

@ -2424,10 +2424,6 @@ LinuxGetXSettingsDPI(Display* dpy, int screen)
internal b32 internal b32
LinuxX11WindowInit(int argc, char** argv, int* WinWidth, int* WinHeight) LinuxX11WindowInit(int argc, char** argv, int* WinWidth, int* WinHeight)
{ {
// NOTE(allen): Here begins the linux screen setup stuff.
// Behold the true nature of this wonderful OS:
// (thanks again to Casey for providing this stuff)
#define BASE_W 800 #define BASE_W 800
#define BASE_H 600 #define BASE_H 600
@ -2454,17 +2450,10 @@ LinuxX11WindowInit(int argc, char** argv, int* WinWidth, int* WinHeight)
swa.backing_store = WhenMapped; swa.backing_store = WhenMapped;
swa.event_mask = StructureNotifyMask; swa.event_mask = StructureNotifyMask;
swa.bit_gravity = NorthWestGravity; swa.bit_gravity = NorthWestGravity;
swa.colormap = XCreateColormap(linuxvars.XDisplay, swa.colormap = XCreateColormap(linuxvars.XDisplay, RootWindow(linuxvars.XDisplay, Config.BestInfo.screen), Config.BestInfo.visual, AllocNone);
RootWindow(linuxvars.XDisplay, Config.BestInfo.screen),
Config.BestInfo.visual, AllocNone);
linuxvars.XWindow = linuxvars.XWindow = XCreateWindow(linuxvars.XDisplay, RootWindow(linuxvars.XDisplay, Config.BestInfo.screen),
XCreateWindow(linuxvars.XDisplay, 0, 0, *WinWidth, *WinHeight, 0, Config.BestInfo.depth, InputOutput, Config.BestInfo.visual, CWBackingStore|CWBitGravity|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &swa);
RootWindow(linuxvars.XDisplay, Config.BestInfo.screen),
0, 0, *WinWidth, *WinHeight,
0, Config.BestInfo.depth, InputOutput,
Config.BestInfo.visual,
CWBackingStore|CWBitGravity|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &swa);
if (!linuxvars.XWindow){ if (!linuxvars.XWindow){
LinuxFatalErrorMsg("XCreateWindow failed. Make sure your display is set up correctly."); LinuxFatalErrorMsg("XCreateWindow failed. Make sure your display is set up correctly.");

View File

@ -1,5 +1,5 @@
1 1
0 0
63 68

Binary file not shown.

View File

@ -970,6 +970,23 @@ This call returns non-zero on a successful copy.) */{
return 1; return 1;
} }
CPP_NAME(copy_checked)
API_EXPORT FSTRING_LINK b32_4tech
copy_checked_cs(char *dest, i32_4tech dest_cap, String src)/*
DOC(This call performs a copy from the src string to the dest string.
The value dest_cap is checked before any coppying is done.
This call returns non-zero on a successful copy.)
*/{
i32_4tech i;
if (dest_cap < src.size){
return 0;
}
for (i = 0; i < src.size; ++i){
dest[i] = src.str[i];
}
return 1;
}
CPP_NAME(copy_partial) CPP_NAME(copy_partial)
API_EXPORT FSTRING_LINK b32_4tech API_EXPORT FSTRING_LINK b32_4tech
copy_partial_sc(String *dest, char *src)/* copy_partial_sc(String *dest, char *src)/*
@ -995,9 +1012,9 @@ CPP_NAME(copy_partial)
API_EXPORT FSTRING_LINK b32_4tech API_EXPORT FSTRING_LINK b32_4tech
copy_partial_ss(String *dest, String src)/* copy_partial_ss(String *dest, String src)/*
DOC(This call performs a copy from the src string to the dest string. DOC(This call performs a copy from the src string to the dest string.
The memory_size of dest is checked if the entire copy cannot be performed, The memory_size of dest is checked. If the entire copy cannot be performed,
as many bytes as possible are coppied to dest. This call returns non-zero as many bytes as possible are coppied to dest.
if the entire string is coppied to dest.) */{ This call returns non-zero if the entire string is coppied to dest.) */{
char *dest_str = dest->str; char *dest_str = dest->str;
i32_4tech memory_size = dest->memory_size; i32_4tech memory_size = dest->memory_size;
b32_4tech result = 0; b32_4tech result = 0;
@ -1009,7 +1026,28 @@ if the entire string is coppied to dest.) */{
dest_str[i] = src.str[i]; dest_str[i] = src.str[i];
} }
dest->size = memory_size; dest->size = memory_size;
return result; return(result);
}
CPP_NAME(copy_partial)
API_EXPORT FSTRING_LINK b32_4tech
copy_partial_cs(char *dest, i32_4tech dest_cap, String src)/*
DOC(This call performs a copy from the src string to the dest string.
The value dest_cap is checked. If the entire copy cannot be performed,
as many bytes as possible are coppied to dest.
This call returns non-zero if the entire string is coppied to dest.)
*/{
b32_4tech result = 0;
i32_4tech copy_size = dest_cap;
i32_4tech i;
if (dest_cap >= src.size){
result = 1;
copy_size = src.size;
}
for (i = 0; i < copy_size; ++i){
dest[i] = src.str[i];
}
return(result);
} }
CPP_NAME(copy) CPP_NAME(copy)

View File

@ -184,10 +184,8 @@ typedef struct Win32_Vars{
b32 next_clipboard_is_self; b32 next_clipboard_is_self;
DWORD clipboard_sequence; DWORD clipboard_sequence;
HWND window_handle; HWND window_handle;
Render_Target target; Render_Target target;
Partition font_part;
#if SUPPORT_DPI #if SUPPORT_DPI
i32 dpi_x, dpi_y; i32 dpi_x, dpi_y;
#endif #endif
@ -332,9 +330,7 @@ Sys_Release_Lock_Sig(system_release_lock){
internal void internal void
system_wait_cv(i32 crit_id, i32 cv_id){ system_wait_cv(i32 crit_id, i32 cv_id){
SleepConditionVariableCS(win32vars.condition_vars + cv_id, SleepConditionVariableCS(win32vars.condition_vars + cv_id, win32vars.locks + crit_id, INFINITE);
win32vars.locks + crit_id,
INFINITE);
} }
internal void internal void
@ -371,9 +367,7 @@ JobThreadProc(LPVOID lpParameter){
// wrapping by the queue wrap. That was super stupid what was that? // wrapping by the queue wrap. That was super stupid what was that?
// Now it just wraps by the queue wrap. // Now it just wraps by the queue wrap.
u32 next_read_index = (read_index + 1) % QUEUE_WRAP; u32 next_read_index = (read_index + 1) % QUEUE_WRAP;
u32 safe_read_index = u32 safe_read_index = InterlockedCompareExchange(&queue->read_position, next_read_index, read_index);
InterlockedCompareExchange(&queue->read_position,
next_read_index, read_index);
if (safe_read_index == read_index){ if (safe_read_index == read_index){
Full_Job_Data *full_job = queue->jobs + safe_read_index; Full_Job_Data *full_job = queue->jobs + safe_read_index;
@ -381,16 +375,13 @@ JobThreadProc(LPVOID lpParameter){
// with the cancel job routine, which may try to cancel this job // with the cancel job routine, which may try to cancel this job
// at the same time that we try to run it // at the same time that we try to run it
i32 safe_running_thread = i32 safe_running_thread =InterlockedCompareExchange(&full_job->running_thread, thread->id, THREAD_NOT_ASSIGNED);
InterlockedCompareExchange(&full_job->running_thread,
thread->id, THREAD_NOT_ASSIGNED);
if (safe_running_thread == THREAD_NOT_ASSIGNED){ if (safe_running_thread == THREAD_NOT_ASSIGNED){
thread->job_id = full_job->id; thread->job_id = full_job->id;
thread->running = 1; thread->running = 1;
full_job->job.callback(&win32vars.system, full_job->job.callback(&win32vars.system, thread, thread_memory, full_job->job.data);
thread, thread_memory, full_job->job.data);
PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, 0, 0); PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, 0, 0);
//full_job->running_thread = 0; //full_job->running_thread = 0;
thread->running = 0; thread->running = 0;
@ -1391,6 +1382,8 @@ Sys_Send_Exit_Signal_Sig(system_send_exit_signal){
#include "4ed_system_shared.cpp" #include "4ed_system_shared.cpp"
#include "win32_4ed_fonts.cpp"
// //
// Linkage to Custom and Application // Linkage to Custom and Application
// //
@ -1458,7 +1451,6 @@ Win32LoadSystemCode(){
win32vars.system.is_fullscreen = system_is_fullscreen;win32vars.system.show_mouse_cursor = system_show_mouse_cursor; win32vars.system.is_fullscreen = system_is_fullscreen;win32vars.system.show_mouse_cursor = system_show_mouse_cursor;
win32vars.system.send_exit_signal = system_send_exit_signal; win32vars.system.send_exit_signal = system_send_exit_signal;
#if FRED_INTERNAL #if FRED_INTERNAL
win32vars.system.internal_get_thread_states = INTERNAL_get_thread_states; win32vars.system.internal_get_thread_states = INTERNAL_get_thread_states;
#endif #endif
@ -1469,11 +1461,6 @@ Win32LoadRenderCode(){
win32vars.target.push_clip = draw_push_clip; win32vars.target.push_clip = draw_push_clip;
win32vars.target.pop_clip = draw_pop_clip; win32vars.target.pop_clip = draw_pop_clip;
win32vars.target.push_piece = draw_push_piece; win32vars.target.push_piece = draw_push_piece;
#if 0
win32vars.target.font_set.font_load = font_load;
win32vars.target.font_set.release_font = draw_release_font;
#endif
} }
// //
@ -1518,7 +1505,7 @@ Win32KeycodeInit(){
internal void internal void
Win32RedrawScreen(HDC hdc){ Win32RedrawScreen(HDC hdc){
launch_rendering(&win32vars.target); launch_rendering(&win32vars.system, &win32vars.target);
glFlush(); glFlush();
SwapBuffers(hdc); SwapBuffers(hdc);
} }
@ -2034,11 +2021,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
win32vars.target.max = MB(1); win32vars.target.max = MB(1);
win32vars.target.push_buffer = (char*)system_get_memory(win32vars.target.max); win32vars.target.push_buffer = (char*)system_get_memory(win32vars.target.max);
if (!memory_vars.vars_memory || !memory_vars.target_memory || !memory_vars.user_memory || !win32vars.target.push_buffer){ if (memory_vars.vars_memory == 0 || memory_vars.target_memory == 0 || memory_vars.user_memory == 0 || win32vars.target.push_buffer == 0){
exit(1); exit(1);
} }
// //
// System and Application Layer Linkage // System and Application Layer Linkage
// //
@ -2048,17 +2034,14 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
} }
Win32LoadSystemCode(); Win32LoadSystemCode();
Win32LoadRenderCode(); Win32LoadRenderCode();
// //
// Shared Systems Init // Shared Systems Init
// //
init_shared_vars(); init_shared_vars();
// //
// Read Command Line // Read Command Line
// //
@ -2082,7 +2065,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
sysshared_filter_real_files(files, file_count); sysshared_filter_real_files(files, file_count);
// //
// Custom Layer Linkage // Custom Layer Linkage
// //
@ -2192,6 +2174,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
Win32InitGL(); Win32InitGL();
Win32Resize(window_rect.right - window_rect.left, window_rect.bottom - window_rect.top); Win32Resize(window_rect.right - window_rect.left, window_rect.bottom - window_rect.top);
//
// Font System Init
//
system_font_init(&win32vars.system.font, 0, 0, 16, true);
// //
// Misc System Initializations // Misc System Initializations

View File

@ -11,43 +11,124 @@
#include "4ed_system_shared.cpp" #include "4ed_system_shared.cpp"
#include "font/4coder_font_interface.h" #include "font/4coder_font_interface.h"
#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};
internal internal
Sys_Font_Get_Count_Sig(system_font_get_count){ Sys_Font_Get_Count_Sig(system_font_get_count){
return(5);
} }
internal internal
Sys_Font_Get_IDs_By_Index_Sig(system_font_get_ids_by_index){ Sys_Font_Get_IDs_By_Index_Sig(system_font_get_ids_by_index){
b32 result = false;
u32 stop_index = first_index + index_count;
if (stop_index < win32_fonts.font_count){
result = true;
for (u32 i = first_index; i < stop_index; ++i){
id_out[i] = i;
}
}
return(result);
} }
internal internal
Sys_Font_Get_Name_By_Index_Sig(system_font_get_name_by_index){ Sys_Font_Get_Name_By_Index_Sig(system_font_get_name_by_index){
u32 length = 0;
if (font_index < win32_fonts.font_count){
Render_Font *font = &win32_fonts.fonts[font_index];
char *name = font->name;
u32 name_len = font->name_len;
copy_partial_cs(str_out, str_out_cap, make_string(name, name_len));
}
return(length);
} }
internal internal
Sys_Font_Get_Name_By_ID_Sig(system_font_get_name_by_id){ Sys_Font_Get_Name_By_ID_Sig(system_font_get_name_by_id){
u32 font_index = font_id;
u32 result = system_font_get_name_by_index(font_index, str_out, str_out_cap);
return(result);
} }
internal internal
Sys_Font_Get_Render_Data_By_ID_Sig(system_font_get_render_data_by_id){ Sys_Font_Get_Render_Data_By_ID_Sig(system_font_get_render_data_by_id){
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);
} }
internal internal
Sys_Font_Allocate_Sig(system_font_allocate){ Sys_Font_Allocate_Sig(system_font_allocate){
void *result = system_memory_allocate(size);
return(result);
} }
internal internal
Sys_Font_Free_Sig(system_font_free){ Sys_Font_Free_Sig(system_font_free){
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);
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;
} }
// BOTTOM // BOTTOM

View File

@ -79,6 +79,7 @@ wglGetExtensionsStringARB_Function(HDC hdc);
typedef void CALL_CONVENTION typedef void CALL_CONVENTION
GLDEBUGPROC_TYPE(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char * message, const GLvoid * userParam); GLDEBUGPROC_TYPE(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char * message, const GLvoid * userParam);
// TODO(allen): these don't belong here, but the organizational stuff is not fully in place yet.
typedef GLDEBUGPROC_TYPE * GLDEBUGPROC; typedef GLDEBUGPROC_TYPE * GLDEBUGPROC;
typedef void CALL_CONVENTION typedef void CALL_CONVENTION
glDebugMessageControl_type(GLenum source, GLenum type, GLenum severity, GLsizei count, GLuint * ids, GLboolean enabled); glDebugMessageControl_type(GLenum source, GLenum type, GLenum severity, GLsizei count, GLuint * ids, GLboolean enabled);