switched indent array to using wrap_line, driving all systems through the wrapped indents array

master
Allen Webster 2016-09-27 16:28:59 -04:00
parent 8f8806f86d
commit 0d587c8fe2
2 changed files with 39 additions and 22 deletions

View File

@ -421,7 +421,7 @@ view_compute_cursor(View *view, Buffer_Seek seek){
case BLStatus_NeedWrapLineShift:
case BLStatus_NeedLineShift:
{
line_shift = file->state.line_indents[stop.line_index];
line_shift = file->state.line_indents[stop.wrap_line_index];
}break;
}
}while(stop.status != BLStatus_Finished);
@ -901,16 +901,16 @@ file_measure_starts(System_Functions *system, General_Memory *general, Buffer_Ty
// and that the buffer's line_count is correct.
internal void
file_allocate_metadata_as_needed(General_Memory *general, Buffer_Type *buffer,
void **mem, i32 *mem_max_count, i32 item_size){
void **mem, i32 *mem_max_count, i32 count, i32 item_size){
if (*mem == 0){
i32 max = ((buffer->line_count+1)*2);
i32 max = ((count+1)*2);
max = (max+(0x3FF))&(~(0x3FF));
*mem = general_memory_allocate(general, max*item_size);
*mem_max_count = max;
}
else if (*mem_max_count < buffer->line_count){
else if (*mem_max_count < count){
i32 old_max = *mem_max_count;
i32 max = ((buffer->line_count+1)*2);
i32 max = ((count+1)*2);
max = (max+(0x3FF))&(~(0x3FF));
void *new_mem = general_memory_reallocate(general, *mem, item_size*old_max, item_size*max);
@ -925,7 +925,8 @@ inline void
file_allocate_character_starts_as_needed(General_Memory *general, Editing_File *file){
file_allocate_metadata_as_needed(general, &file->state.buffer,
(void**)&file->state.character_starts,
&file->state.character_start_max, sizeof(i32));
&file->state.character_start_max,
file->state.buffer.line_count, sizeof(i32));
}
internal void
@ -936,23 +937,25 @@ file_measure_character_starts(Models *models, Editing_File *file){
}
internal void
file_allocate_indents_as_needed(General_Memory *general, Editing_File *file){
file_allocate_indents_as_needed(General_Memory *general, Editing_File *file, i32 min_amount){
file_allocate_metadata_as_needed(general, &file->state.buffer,
(void**)&file->state.line_indents,
&file->state.line_indent_max, sizeof(f32));
&file->state.line_indent_max,
min_amount, sizeof(f32));
}
inline void
file_allocate_wraps_as_needed(General_Memory *general, Editing_File *file){
file_allocate_metadata_as_needed(general, &file->state.buffer,
(void**)&file->state.wrap_line_index,
&file->state.wrap_max, sizeof(f32));
&file->state.wrap_max,
file->state.buffer.line_count, sizeof(f32));
}
internal void
file_measure_wraps(Models *models, Editing_File *file, f32 font_height, f32 *adv){
file_allocate_wraps_as_needed(&models->mem.general, file);
file_allocate_indents_as_needed(&models->mem.general, file);
file_allocate_indents_as_needed(&models->mem.general, file, file->state.buffer.line_count);
Buffer_Measure_Wrap_Params params;
params.buffer = &file->state.buffer;
@ -962,7 +965,7 @@ file_measure_wraps(Models *models, Editing_File *file, f32 font_height, f32 *adv
params.virtual_white = VWHITE;
Buffer_Measure_Wrap_State state = {0};
Buffer_Layout_Stop stop = {0};
Buffer_Layout_Measure_Stop stop = {0};
f32 edge_tolerance = 50.f;
if (edge_tolerance > params.width){
@ -976,13 +979,17 @@ file_measure_wraps(Models *models, Editing_File *file, f32 font_height, f32 *adv
case BLStatus_NeedWrapLineShift:
case BLStatus_NeedLineShift:
{
line_shift = (stop.line_index%4)*9.f;
line_shift = (stop.wrap_line_index%4)*9.f;
if (line_shift > params.width - edge_tolerance){
line_shift = params.width - edge_tolerance;
}
file->state.line_indents[stop.line_index] = line_shift;
while (stop.wrap_line_index >= file->state.line_indent_max){
file_allocate_indents_as_needed(&models->mem.general, file, file->state.line_indent_max);
}
file->state.line_indents[stop.wrap_line_index] = line_shift;
}break;
}
}while(stop.status != BLStatus_Finished);
@ -4916,7 +4923,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
case BLStatus_NeedWrapLineShift:
case BLStatus_NeedLineShift:
{
line_shift = file->state.line_indents[stop.line_index];
line_shift = file->state.line_indents[stop.wrap_line_index];
}break;
}
}while(stop.status != BLStatus_Finished);

View File

@ -223,10 +223,17 @@ struct Buffer_Layout_Stop{
i32 wrap_line_index;
};
internal_4tech Buffer_Layout_Stop
struct Buffer_Layout_Measure_Stop{
u32 status;
i32 line_index;
i32 wrap_line_index;
i32 pos;
};
internal_4tech Buffer_Layout_Measure_Stop
buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params, f32 line_shift){
Buffer_Measure_Wrap_State S = *S_ptr;
Buffer_Layout_Stop S_stop;
Buffer_Layout_Measure_Stop S_stop;
S.size = buffer_size(params.buffer);
@ -240,6 +247,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.line_index;
S_stop.wrap_line_index = S.current_wrap_index;
S_stop.pos = S.i;
DrYield(1, S_stop);
}
@ -263,6 +271,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.line_index - 1;
S_stop.wrap_line_index = S.current_wrap_index;
S_stop.pos = S.i+1;
DrYield(2, S_stop);
}
@ -286,6 +295,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
S_stop.status = BLStatus_NeedWrapLineShift;
S_stop.line_index = S.line_index - 1;
S_stop.wrap_line_index = S.current_wrap_index;
S_stop.pos = S.i+1;
DrYield(3, S_stop);
}