Recursive subtree layouting and drawing
This commit is contained in:
1 parent
e12892f688
commit
d947cc9eeb
1 file changed
+61
-2
@@ -199,6 +199,9 @@ struct GUI_Subtree {
|
||||
int offset_own_size_percentage_x;
|
||||
int offset_own_size_percentage_y;
|
||||
};
|
||||
#define GUI_SUBTREE_PARENT(node) ((GUI_Subtree*)(node)->rdic_node.parent)
|
||||
#define GUI_SUBTREE_SIBLING(node) ((GUI_Subtree*)(node)->rdic_node.sibling)
|
||||
#define GUI_SUBTREE_FIRST_CHILD(node) ((GUI_Subtree*)(node)->rdic_node.first_child)
|
||||
typedef union GUI_Subtree_Reference {
|
||||
RDIC_Node_Reference rdic_ref;
|
||||
struct {
|
||||
@@ -218,7 +221,7 @@ typedef struct {
|
||||
|
||||
GUI_Draw_Command *first_draw_command;
|
||||
int num_draw_commands;
|
||||
Pixel_Buffer pixel_buffer;
|
||||
Pixel_Buffer *pixel_buffer;
|
||||
} GUI_Layer;
|
||||
|
||||
|
||||
@@ -3174,6 +3177,59 @@ void gui_draw_image(
|
||||
}
|
||||
|
||||
|
||||
//CURSOR
|
||||
void gui_layout_and_draw_subtree(
|
||||
GUI_Context *context,
|
||||
GUI_Subtree *subtree,
|
||||
Pixel_Buffer *pixel_buffer)
|
||||
{
|
||||
gui_layout_nodes((GUI_Node*)subtree->rdic.root);
|
||||
gui_generate_draw_commands(
|
||||
subtree,
|
||||
context->draw_command_arena,
|
||||
&context->num_draw_commands);
|
||||
|
||||
GUI_Draw_Command *draw_commands =
|
||||
(GUI_Draw_Command*)(context->draw_command_arena->memory);
|
||||
for(int i = 0; i < context->num_draw_commands; i++)
|
||||
{
|
||||
GUI_Draw_Command *draw_command = draw_commands+i;
|
||||
gui_draw_rect (pixel_buffer, draw_command);
|
||||
gui_draw_image(pixel_buffer, draw_command);
|
||||
gui_draw_text (pixel_buffer, draw_command);
|
||||
}
|
||||
|
||||
// TODO NOTE(Zelaven): There may arise an issue where the subtrees won't
|
||||
// generate draw commands even if they are overdrawn by changes in a
|
||||
// parent subtree.
|
||||
GUI_Subtree *first_child = GUI_SUBTREE_FIRST_CHILD(subtree);
|
||||
if(first_child != NULL)
|
||||
{
|
||||
gui_layout_and_draw_subtree(context, first_child, pixel_buffer);
|
||||
}
|
||||
GUI_Subtree *sibling = GUI_SUBTREE_SIBLING(subtree);
|
||||
if(sibling != NULL)
|
||||
{
|
||||
gui_layout_and_draw_subtree(context, sibling, pixel_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void gui_layout_and_draw(GUI_Context *context)
|
||||
{
|
||||
// TODO(Zelaven): Handle all layers.
|
||||
for(
|
||||
GUI_Subtree *current = (GUI_Subtree*)context->background_layer.subtree_rdic.root;
|
||||
current != NULL;
|
||||
current = NULL)//current->next)
|
||||
{
|
||||
gui_layout_and_draw_subtree(
|
||||
context,
|
||||
current,
|
||||
context->background_layer.pixel_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include <unistd.h> // usleep.
|
||||
int main(void)
|
||||
@@ -3241,6 +3297,7 @@ int main(void)
|
||||
|
||||
context.background_layer = (GUI_Layer){
|
||||
.subtree_rdic.freelist = &subtree_freelist,
|
||||
.pixel_buffer = &xwindow.pixel_buffer,
|
||||
};
|
||||
context.top_layer = (GUI_Layer){
|
||||
.subtree_rdic.freelist = &subtree_freelist,
|
||||
@@ -3383,6 +3440,8 @@ int main(void)
|
||||
gui(&context, screen_rectangle);
|
||||
//gui_layout_nodes(&context);
|
||||
#if 1
|
||||
gui_layout_and_draw(&context);
|
||||
#else
|
||||
for(
|
||||
GUI_Subtree *current = (GUI_Subtree*)context.background_layer.subtree_rdic.root;
|
||||
current != NULL;
|
||||
@@ -3414,7 +3473,7 @@ int main(void)
|
||||
draw_command+i);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#elseif 0
|
||||
gui_generate_draw_commands(
|
||||
(GUI_Node*)context.first_subtree->rdic.root,
|
||||
&draw_command_arena,
|
||||
|
||||
Reference in new issue
Block a user