81 lines
2.0 KiB
C
81 lines
2.0 KiB
C
|
|
#include "window.h"
|
||
|
|
#include "listeners/xdg_toplevel_listener.h"
|
||
|
|
|
||
|
|
#include "../../os/WAYLAND/xdg-shell.h"
|
||
|
|
|
||
|
|
#include <wayland-egl.h>
|
||
|
|
|
||
|
|
#include <GLES2/gl2.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
|
||
|
|
|
||
|
|
const struct xdg_toplevel_listener toplevel_listener = {
|
||
|
|
toplevel_configure,
|
||
|
|
toplevel_close
|
||
|
|
};
|
||
|
|
|
||
|
|
/******************************/
|
||
|
|
/************APIs**************/
|
||
|
|
/******************************/
|
||
|
|
|
||
|
|
window_gui_enrichment *window_gui_enrichment_new(
|
||
|
|
struct xdg_surface *xdg_surface,
|
||
|
|
const char *title,
|
||
|
|
application_context *ctx
|
||
|
|
){
|
||
|
|
window_gui_enrichment *win;
|
||
|
|
|
||
|
|
win->egl_window = NULL;
|
||
|
|
win->egl_surface = NULL;
|
||
|
|
win->ctx = ctx;
|
||
|
|
|
||
|
|
win->xdg_toplevel = xdg_surface_get_toplevel( xdg_surface);
|
||
|
|
xdg_toplevel_set_title( win->xdg_toplevel, title);
|
||
|
|
xdg_toplevel_add_listener( win->xdg_toplevel, &toplevel_listener, win);
|
||
|
|
|
||
|
|
return win;
|
||
|
|
}
|
||
|
|
|
||
|
|
void swapBuffers( application_context *app){
|
||
|
|
|
||
|
|
window_gui_enrichment *win = (window_gui_enrichment*) app->win->specialization;
|
||
|
|
wl_display_dispatch_pending(app->w_context->display);
|
||
|
|
eglSwapBuffers( app->e_context->display, win->egl_surface);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void draw_callback( gui_component* toDraw, int deltaTime){
|
||
|
|
glClearColor(1, 0, 0, 0);
|
||
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||
|
|
|
||
|
|
/* should iterate on all the children */
|
||
|
|
|
||
|
|
window_gui_enrichment *win = toDraw->specialization;
|
||
|
|
swapBuffers( win->ctx);
|
||
|
|
}
|
||
|
|
|
||
|
|
gui_component* window_new(
|
||
|
|
const char *title,
|
||
|
|
ui_dimensions *dim,
|
||
|
|
application_context *app
|
||
|
|
){
|
||
|
|
void (*resize_callback) ( gui_component*, resize_event*) = 0;
|
||
|
|
void (*input_callback) ( gui_component*, resize_event*) = 0;
|
||
|
|
|
||
|
|
fprintf(stderr, "WINDOW NEW\n");
|
||
|
|
|
||
|
|
gui_component *c = gui_component_new_begin( NULL, ui_position_new(0, 0), dim, draw_callback, resize_callback, input_callback, app->w_context->builders );
|
||
|
|
|
||
|
|
fprintf(stderr, "WINDOW DID GUI_COMP_NEW\n");
|
||
|
|
|
||
|
|
window_gui_enrichment *spec = window_gui_enrichment_new( c->graphics->xdg_surface, title, app);
|
||
|
|
c->specialization = (void*) spec;
|
||
|
|
|
||
|
|
fprintf(stderr, "WINDOW DID ENRICHMENT NEW\n");
|
||
|
|
|
||
|
|
|
||
|
|
gui_component_new_end( c);
|
||
|
|
return c;
|
||
|
|
}
|