88 lines
2.2 KiB
C
88 lines
2.2 KiB
C
|
|
#include "gui_component.h"
|
||
|
|
#include "listeners/xdg_surface_listener.h"
|
||
|
|
|
||
|
|
#include <stdlib.h>
|
||
|
|
|
||
|
|
/*
|
||
|
|
listener to be bound on XDG surfaces
|
||
|
|
|
||
|
|
the only event declared by the xdg_surface is the "configure" one
|
||
|
|
indicates the hint for the client to update the arrangement of surfaces ( i.e. change of resolution )
|
||
|
|
*/
|
||
|
|
const struct xdg_surface_listener surface_listener = {
|
||
|
|
surface_configure
|
||
|
|
};
|
||
|
|
|
||
|
|
gui_component_graphics* gui_component_graphics_new(
|
||
|
|
ui_position *pos,
|
||
|
|
ui_dimensions *dim,
|
||
|
|
surface_builders *builders
|
||
|
|
){
|
||
|
|
gui_component_graphics *g = malloc( sizeof( gui_component_graphics));
|
||
|
|
g->dimensions = dim;
|
||
|
|
g->position = pos;
|
||
|
|
|
||
|
|
g->surface = wl_compositor_create_surface( builders->compositor);
|
||
|
|
g->xdg_surface = xdg_wm_base_get_xdg_surface( builders->xdg_wm_base, g->surface);
|
||
|
|
xdg_surface_add_listener( g->xdg_surface, &surface_listener, NULL);
|
||
|
|
|
||
|
|
return g;
|
||
|
|
}
|
||
|
|
|
||
|
|
gui_component* gui_component_new_begin(
|
||
|
|
gui_component *parent,
|
||
|
|
ui_position *pos,
|
||
|
|
ui_dimensions *dim,
|
||
|
|
void (*draw_callback) ( gui_component*, int),
|
||
|
|
void (*resize_callback) ( gui_component*, resize_event*),
|
||
|
|
void (*input_callback) ( gui_component*, resize_event*),
|
||
|
|
surface_builders *builders
|
||
|
|
){
|
||
|
|
gui_component* c = malloc( sizeof( gui_component));
|
||
|
|
|
||
|
|
c->specialization = NULL;
|
||
|
|
c->graphics = gui_component_graphics_new( pos, dim, builders);
|
||
|
|
c->draw_callback = draw_callback;
|
||
|
|
|
||
|
|
if( parent){
|
||
|
|
gui_component_add_child( parent, c);
|
||
|
|
}
|
||
|
|
|
||
|
|
c->children = gui_components_list_new();
|
||
|
|
return c;
|
||
|
|
}
|
||
|
|
|
||
|
|
void gui_component_new_end( gui_component* toComplete){
|
||
|
|
/*
|
||
|
|
must be called at the end of the configuration
|
||
|
|
*/
|
||
|
|
wl_surface_commit( toComplete->graphics->surface);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void gui_component_add_child( gui_component *parent, gui_component *child){
|
||
|
|
/* missing args */
|
||
|
|
if( ! parent || ! child){
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/* components cannot be moved around at the moment, plug once and bye */
|
||
|
|
if( child->parent){
|
||
|
|
}
|
||
|
|
|
||
|
|
child->parent = parent;
|
||
|
|
gui_components_list_add( parent->children, child);
|
||
|
|
}
|
||
|
|
|
||
|
|
void child_draw( gui_component* child, void *extra){
|
||
|
|
int *casted = (int*) extra;
|
||
|
|
int deltaTime = *casted;
|
||
|
|
gui_component_draw( child, deltaTime);
|
||
|
|
}
|
||
|
|
|
||
|
|
void gui_component_draw( gui_component *c, int deltaTime){
|
||
|
|
c->draw_callback( c, deltaTime);
|
||
|
|
gui_components_list_foreach( c->children, child_draw, (void*) &deltaTime);
|
||
|
|
}
|