Selaa lähdekoodia

WIP GUI_Layer

master
Patrick Jakobsen 7 kuukautta sitten
vanhempi
commit
5cd73cf2c5
1 muutettua tiedostoa jossa 45 lisäystä ja 13 poistoa
  1. +45
    -13
      gui/gui.c

+ 45
- 13
gui/gui.c Näytä tiedosto

@ -188,6 +188,9 @@ struct GUI_Subtree {
GUI_Subtree *next;
GUI_Subtree *structural_parent;
// TODO(Zelaven):
// GUI_Rectangle cliprect;
GUI_Node_Reference relative_to;
int flat_offset_x;
int flat_offset_y;
@ -195,20 +198,30 @@ struct GUI_Subtree {
int offset_relative_node_percentage_y;
int offset_own_size_percentage_x;
int offset_own_size_percentage_y;
};
typedef struct {
GUI_Subtree *first_subtree;
//GUI_Subtree *last_subtree;
//GUI_Subtree *current_subtree;
GUI_Draw_Command *first_draw_command;
int num_draw_commands;
Pixel_Buffer *pixel_buffer;
};
Pixel_Buffer pixel_buffer;
} GUI_Layer;
typedef struct {
//RDIC_Context rdic;
GUI_Subtree *first_subtree;
GUI_Subtree *last_subtree;
//GUI_Subtree *first_subtree;
//GUI_Subtree *last_subtree;
GUI_Subtree *current_subtree;
GUI_Layer background_layer;
GUI_Layer top_layer;
GUI_Node_Reference focused_node;
GUI_Node_Reference hovered_node;
GUI_Node_Reference top_node_under_cursor;
@ -316,8 +329,25 @@ void gui_apply_input(
int mouse_x,
int mouse_y)
{
// --- Mouse Input ---
// NOTE(Zelaven): First hit test against layers.
GUI_Layer *hit_layer = &context->background_layer;
{
GUI_Layer *top_layer = &context->top_layer;
if(top_layer->first_subtree != NULL)
{
GUI_Node *top_layer_root =
(GUI_Node*)top_layer->first_subtree->rdic.root;
if(point_in_rect(mouse_x, mouse_y, top_layer_root->rect))
{
hit_layer = &context->top_layer;
}
}
}
//GUI_Node *top_node_under_cursor = (GUI_Node*)context->rdic.root;
GUI_Node *top_node_under_cursor = (GUI_Node*)context->first_subtree->rdic.root;
//GUI_Node *top_node_under_cursor = (GUI_Node*)context->first_subtree->rdic.root;
GUI_Node *top_node_under_cursor = (GUI_Node*)hit_layer->first_subtree->rdic.root;
GUI_Node *current_node = (GUI_Node*)top_node_under_cursor->rdic_node.first_child;
int mouse_over_node = 0;
while(current_node != NULL)
@ -410,8 +440,8 @@ GUI_Node_Reference gui_context_start_frame(
static GUI_Subtree background_subtree = {0};
background_subtree.rdic.node_freelist = context->node_freelist;
context->first_subtree = &background_subtree;
context->last_subtree = &background_subtree;
context->background_layer.first_subtree = &background_subtree;
//context->background_layer.last_subtree = &background_subtree;
context->current_subtree = &background_subtree;
GUI_Node_Reference new_root_reference = {
@ -445,8 +475,9 @@ GUI_Node_Reference gui_context_start_frame(
void gui_context_finish_frame(
GUI_Context *context)
{
rdic_context_finish_frame(&context->first_subtree->rdic);
context->node_freelist = context->first_subtree->rdic.node_freelist;
rdic_context_finish_frame(&context->background_layer.first_subtree->rdic);
context->node_freelist =
context->background_layer.first_subtree->rdic.node_freelist;
}
GUI_Node_Reference gui_push_subtree(
@ -461,9 +492,10 @@ GUI_Node_Reference gui_push_subtree(
context->node_freelist = context->current_subtree->rdic.node_freelist;
subtree->rdic.node_freelist = context->node_freelist;
context->last_subtree->next = subtree;
subtree->prev = context->last_subtree;
context->last_subtree = subtree;
// NOTE(Zelaven): Well, not being able to do this is a problem...
//context->last_subtree->next = subtree;
//subtree->prev = context->last_subtree;
//context->last_subtree = subtree;
subtree->structural_parent = context->current_subtree;
context->current_subtree = subtree;
@ -3158,7 +3190,7 @@ int main(void)
//gui_layout_nodes(&context);
#if 1
for(
GUI_Subtree *current = context.first_subtree;
GUI_Subtree *current = context.background_layer.first_subtree;
current != NULL;
current = current->next)
{

Ladataan…
Peruuta
Tallenna