src/graphics, src/ui: now capable of generating multiple GLArea and their stack

This commit is contained in:
Adrien Bourmault 2024-01-10 18:27:46 +01:00
parent ff35840a26
commit 53c2fd9209
5 changed files with 30 additions and 36 deletions

View File

@ -43,8 +43,6 @@ int draw_one_arrow_vertex (const int stack_id,
int arrow_y, int arrow_y,
int arrow_z) int arrow_z)
{ {
struct graphic_stack_t *stack = &graphic_stack[stack_id];
float max = fmax(space_X_int, space_Y_int); float max = fmax(space_X_int, space_Y_int);
max = fmax(max, space_Z_int); max = fmax(max, space_Z_int);

View File

@ -41,20 +41,20 @@ void graphics_draw_vertex (const int stack_id,
GLfloat y, GLfloat y,
GLfloat z) GLfloat z)
{ {
//g_printerr("stack_id is %d\n", stack_id); g_printerr("stack_id is %d\n", stack_id);
//g_printerr("stack_id is %d\n", stack_id); g_printerr("stack_id is %d\n", stack_id);
//g_printerr("graphic_stack is at %p\n", graphic_stack); g_printerr("graphic_stack is at %p\n", graphic_stack);
//g_printerr("graphic_stack[stack_id] is at %p\n", graphic_stack + stack_id); g_printerr("graphic_stack[stack_id] is at %p\n", graphic_stack + stack_id);
struct graphic_stack_t *stack = &graphic_stack[stack_id]; volatile struct graphic_stack_t *stack = &graphic_stack[stack_id];
g_printerr("Currently stack->buffer_vertex_origin @ %p\n", stack->buffer_vertex_origin);
//assert (stack->buffer_vertex_origin); //assert (stack->buffer_vertex_origin);
//g_printerr("Currently stack->buffer_vertex_origin @ %p\n", stack->buffer_vertex_origin);
stack->buffer_vertex_origin = stack->buffer_vertex_origin =
g_realloc (stack->buffer_vertex_origin, g_realloc (stack->buffer_vertex_origin,
(stack->buffer_vertex_size + 3) * sizeof(GLfloat)); (stack->buffer_vertex_size + 3) * sizeof(GLfloat));
//print_stack(stack_id); print_stack(stack_id);
stack->buffer_vertex_origin[stack->buffer_vertex_size + 0] = x; stack->buffer_vertex_origin[stack->buffer_vertex_size + 0] = x;
stack->buffer_vertex_origin[stack->buffer_vertex_size + 1] = y; stack->buffer_vertex_origin[stack->buffer_vertex_size + 1] = y;

View File

@ -132,6 +132,8 @@ int graphics_init(void *error_buffer)
} }
} }
memset(&graphic_stack[cur_id], 0, sizeof(struct graphic_stack_t));
/* g_printerr("[debug] graphics_init() : graphic_stack (@0x%p) has %ld elements\n", */ /* g_printerr("[debug] graphics_init() : graphic_stack (@0x%p) has %ld elements\n", */
/* graphic_stack, */ /* graphic_stack, */
/* graphic_stack_size); */ /* graphic_stack_size); */
@ -152,7 +154,7 @@ int graphics_init(void *error_buffer)
glDebugMessageCallback(graphics_debug_callback, NULL); glDebugMessageCallback(graphics_debug_callback, NULL);
//print_stack(cur_id); print_stack(cur_id);
return cur_id; return cur_id;
} }

View File

@ -84,19 +84,19 @@ long ui_is_graphic_stack_ready(void *container_widget)
*/ */
bool ui_init_graphic_stack(void *container_widget, GError *error_buffer) bool ui_init_graphic_stack(void *container_widget, GError *error_buffer)
{ {
//g_printerr("[debug] ui_init_graphic_stack()\n"); g_printerr("[debug] ui_init_graphic_stack()\n");
//g_printerr("[debug] ui_init_graphic_stack() : target is %p\n", container_widget); g_printerr("[debug] ui_init_graphic_stack() : target is %p\n", container_widget);
// look for stack_index entry // look for stack_index entry
for (int i = 0; i < stack_index_size; i++) { for (int i = 0; i < stack_index_size; i++) {
//g_printerr("[debug] ui_init_graphic_stack() : i is %d\n", i); g_printerr("[debug] ui_init_graphic_stack() : i is %d\n", i);
//g_printerr("[debug] ui_init_graphic_stack() : target would be %p\n", g_printerr("[debug] ui_init_graphic_stack() : target would be %p\n",
//stack_index[i].container_widget); stack_index[i].container_widget);
if (stack_index[i].container_widget == (void *)container_widget) { if (stack_index[i].container_widget == (void *)container_widget) {
stack_index[i].stack_id = graphics_init(&error_buffer); stack_index[i].stack_id = graphics_init(&error_buffer);
//g_printerr("[debug] ui_init_graphic_stack() : stack_id is %d\n", g_printerr("[debug] ui_init_graphic_stack() : stack_id is %d\n",
//stack_index[i].stack_id); stack_index[i].stack_id);
if (stack_index[i].stack_id >= 0) if (stack_index[i].stack_id >= 0)
return true; return true;
else else

View File

@ -51,6 +51,8 @@ struct _GemGraphClientWindow
GtkLabel *toast_text; GtkLabel *toast_text;
GtkBox *control_zone; GtkBox *control_zone;
GtkBox *run_glarea_box; GtkBox *run_glarea_box;
GtkBox *edition_glarea_box;
GtkBox *presentation_glarea_box;
}; };
G_DEFINE_FINAL_TYPE (GemGraphClientWindow, G_DEFINE_FINAL_TYPE (GemGraphClientWindow,
@ -105,6 +107,12 @@ static void gem_graph_client_window_class_init(GemGraphClientWindowClass *klass)
gtk_widget_class_bind_template_child(widget_class, gtk_widget_class_bind_template_child(widget_class,
GemGraphClientWindow, GemGraphClientWindow,
run_glarea_box); run_glarea_box);
gtk_widget_class_bind_template_child(widget_class,
GemGraphClientWindow,
edition_glarea_box);
gtk_widget_class_bind_template_child(widget_class,
GemGraphClientWindow,
presentation_glarea_box);
} }
static void gem_graph_client_window_init(GemGraphClientWindow *self) static void gem_graph_client_window_init(GemGraphClientWindow *self)
@ -120,7 +128,7 @@ static void gem_graph_client_window_init(GemGraphClientWindow *self)
void ui_set_stack(int mode) void ui_set_stack(int mode)
{ {
g_printerr("[debug] ui_set_stack()\n"); //g_printerr("[debug] ui_set_stack()\n");
if (window->main_stack == NULL) { if (window->main_stack == NULL) {
g_printerr("Can't find self->main_stack !\n"); g_printerr("Can't find self->main_stack !\n");
@ -142,6 +150,7 @@ void ui_set_stack(int mode)
GTK_STACK_TRANSITION_TYPE_CROSSFADE); GTK_STACK_TRANSITION_TYPE_CROSSFADE);
gtk_menu_button_set_icon_name(window->main_button_mode, gtk_menu_button_set_icon_name(window->main_button_mode,
"document-edit-symbolic"); "document-edit-symbolic");
ui_setup_glarea(EDIT_MODE, GTK_WIDGET(window->edition_glarea_box));
break; break;
case RUN_MODE: case RUN_MODE:
gtk_stack_set_visible_child_full(window->main_stack, gtk_stack_set_visible_child_full(window->main_stack,
@ -163,6 +172,8 @@ void ui_set_stack(int mode)
GTK_STACK_TRANSITION_TYPE_CROSSFADE); GTK_STACK_TRANSITION_TYPE_CROSSFADE);
gtk_menu_button_set_icon_name(window->main_button_mode, gtk_menu_button_set_icon_name(window->main_button_mode,
"x-office-presentation-symbolic"); "x-office-presentation-symbolic");
ui_setup_glarea(PRESENTATION_MODE,
GTK_WIDGET(window->presentation_glarea_box));
break; break;
case HOME_MODE: case HOME_MODE:
gtk_stack_set_visible_child_full(window->main_stack, gtk_stack_set_visible_child_full(window->main_stack,
@ -223,20 +234,3 @@ void ui_toggle_sidebar(void)
gtk_paned_set_position(window->main_paned, 400); gtk_paned_set_position(window->main_paned, 400);
} }
} }
void ui_run_attach_glarea(GtkWidget *glarea)
{
gtk_box_append(window->run_glarea_box, glarea);
gtk_widget_show(glarea);
}
void ui_run_detach_glarea(GtkWidget *glarea)
{
gtk_box_remove(window->run_glarea_box, glarea);
}
void ui_attach_controls(GtkWidget *controls)
{
gtk_box_append(window->control_zone, controls);
gtk_widget_show(controls);
}