2019-04-01 00:36:09 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 31.03.2019
|
|
|
|
*
|
|
|
|
* Text layout representation
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
// TODO(allen): REWRITE REWRITE REWRITE!!!
|
2019-04-01 00:36:09 +00:00
|
|
|
internal void
|
|
|
|
text_layout_init(Application_Links *app, Text_Layout_Container *container){
|
|
|
|
block_zero_struct(container);
|
2019-06-01 23:58:28 +00:00
|
|
|
container->node_arena = make_arena_app_links(app);
|
2019-04-01 00:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal Text_Layout*
|
|
|
|
text_layout_new__alloc_layout(Text_Layout_Container *container){
|
|
|
|
Text_Layout_Node *node = container->free_nodes;
|
|
|
|
if (node == 0){
|
|
|
|
node = push_array(&container->node_arena, Text_Layout_Node, 1);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
container->free_nodes = node->next;
|
|
|
|
}
|
|
|
|
return(&node->layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Text_Layout_ID
|
2019-08-01 03:16:53 +00:00
|
|
|
text_layout_new(Heap *heap, Text_Layout_Container *container, Buffer_ID buffer_id, Buffer_Point point, Range on_screen_range, f32 height, Text_Layout_Coordinates coordinates, int_color *item_colors){
|
2019-04-01 00:36:09 +00:00
|
|
|
Text_Layout *new_layout_data = text_layout_new__alloc_layout(container);
|
|
|
|
new_layout_data->buffer_id = buffer_id;
|
|
|
|
new_layout_data->point = point;
|
2019-04-01 06:40:24 +00:00
|
|
|
new_layout_data->on_screen_range = on_screen_range;
|
|
|
|
new_layout_data->height = height;
|
2019-08-01 02:13:36 +00:00
|
|
|
new_layout_data->coordinates = coordinates;
|
2019-08-01 03:16:53 +00:00
|
|
|
new_layout_data->item_colors = item_colors;
|
2019-04-01 00:36:09 +00:00
|
|
|
Text_Layout_ID new_id = ++container->id_counter;
|
|
|
|
insert_u32_Ptr_table(heap, &container->table, new_id, new_layout_data);
|
|
|
|
return(new_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal b32
|
|
|
|
text_layout_get(Text_Layout_Container *container, Text_Layout_ID id, Text_Layout *out){
|
|
|
|
b32 result = false;
|
|
|
|
void *ptr = 0;
|
|
|
|
if (lookup_u32_Ptr_table(&container->table, id, &ptr)){
|
|
|
|
block_copy(out, ptr, sizeof(*out));
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal b32
|
|
|
|
text_layout_erase(Text_Layout_Container *container, Text_Layout_ID id){
|
|
|
|
b32 result = false;
|
|
|
|
void *ptr = 0;
|
|
|
|
if (lookup_u32_Ptr_table(&container->table, id, &ptr)){
|
|
|
|
erase_u32_Ptr_table(&container->table, id);
|
|
|
|
Text_Layout_Node *node = CastFromMember(Text_Layout_Node, layout, ptr);
|
|
|
|
node->next = container->free_nodes;
|
|
|
|
container->free_nodes = node;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|