void gg_dialog_init(gg_dialog_t *dialog, gg_widget_t *child, char *title, gg_dialog_t *parent, int flags) { gg_bin_init((gg_bin_t *) dialog, child); dialog->input = gg_dialog_input; dialog->destroy = gg_dialog_destroy; dialog->id = gg_dialog_get_class_id(); dialog->flags = flags; dialog->dialog_state = 0; dialog->parent_dialog = parent; dialog->modal = 0; if (title) { dialog->title = malloc(strlen(title) + 1); strcpy(dialog->title, title); } else dialog->title = NULL; child->get_requested_size(child, &dialog->width, &dialog->height); child->set_size(child, dialog->width, dialog->height); gg_dialog_set_position(dialog, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 0.5f, 0.5f); //dialog_reset_transition(1); }
static gg_dialog_t *create_current_tiles_dialog() { gg_widget_t *dialog; gg_widget_t *hbox; gg_widget_t *widget; gg_widget_t *vbox; hbox = gg_hbox_create(0); slots[0] = gg_image_create(get_tile_tex(get_tile_slot(0))); widget = gg_action_create(slots[0]); gg_action_set_callback(GG_ACTION(widget), open_selector, (int*)0); gg_container_append(GG_CONTAINER(hbox), widget); slots[1] = gg_image_create(get_tile_tex(get_tile_slot(1))); widget = gg_action_create(slots[1]); gg_action_set_callback(GG_ACTION(widget), open_selector, (int*)1); gg_container_append(GG_CONTAINER(hbox), widget); slots[2] = gg_image_create(get_tile_tex(get_tile_slot(2))); widget = gg_action_create(slots[2]); gg_action_set_callback(GG_ACTION(widget), open_selector, (int*)2); gg_container_append(GG_CONTAINER(hbox), widget); vbox = gg_vbox_create(0); gg_container_append(GG_CONTAINER(vbox), hbox); widget = gg_option_create(); gg_option_append_label(GG_OPTION(widget), "PL", 0.5f, 0.0f); gg_option_append_label(GG_OPTION(widget), "FG", 0.5f, 0.0f); gg_option_append_label(GG_OPTION(widget), "Obs", 0.5f, 0.0f); gg_option_set_callback(GG_OPTION(widget), edit_layer_changed, NULL); gg_container_append(GG_CONTAINER(vbox), widget); dialog = gg_dialog_create(vbox, "Tiles", CURRENT_TILES_DIALOG); gg_dialog_set_position(GG_DIALOG(dialog), 510, 375, 0.0f, 0.0f); gg_dialog_set_style(GG_DIALOG(dialog), get_menu_style() ); return GG_DIALOG(dialog); }
int gg_dialog_input(gg_widget_t *widget, gg_event_t event) { gg_dialog_t *dialog = GG_DIALOG(widget); gg_widget_t *child = gg_bin_get_child(GG_BIN(widget)); int x, y; if (dialog->flags & GG_DIALOG_HIDDEN) return 0; if (!dialog->modal && event.type == GG_EVENT_KEY && event.key == GG_KEY_ESCAPE ) gg_dialog_close(); if (!dialog->modal && event.type == GG_EVENT_MOUSE && event.mouse.type == GG_MOUSE_BUTTON_DOWN && event.mouse.button == 2 ) gg_dialog_close(); gg_dialog_get_screen_pos(dialog, &x, &y); if (event.type == GG_EVENT_MOUSE) { int size = 0; event.mouse.x -= x; event.mouse.y -= y; if (dialog->style.textured) gg_system_get_image_size(dialog->style.border.image[0], &size, NULL); if (event.mouse.type == GG_MOUSE_BUTTON_DOWN && event.mouse.button == 0) { if (dialog->title) { int text_height; int titlebar_height; gg_system_get_string_size(dialog->title, NULL, &text_height); titlebar_height = text_height * GG_DIALOG_TITLE_FACT; dialog->dialog_state |= GG_DIALOG_LEFT_BUTTON; /* Mouse click outside of dialog */ if (event.mouse.y >= dialog->height || event.mouse.y < 0 || event.mouse.x >= dialog->width || event.mouse.x < 0) return 0; gg_dialog_set_active(dialog); /* Title bar click */ if (event.mouse.y >= dialog->height - size - titlebar_height && event.mouse.y < dialog->height - size && event.mouse.x >= size && event.mouse.x < dialog->width - size) { dialog->dialog_state |= GG_DIALOG_MOVING; dialog->movement_org_x = event.mouse.x; dialog->movement_org_y = event.mouse.y; return 1; } } } else if (event.mouse.type == GG_MOUSE_BUTTON_UP && event.mouse.button == 0) { if (dialog->title) { dialog->dialog_state &= ~GG_DIALOG_LEFT_BUTTON; if (dialog->dialog_state & GG_DIALOG_MOVING) { dialog->dialog_state &= ~GG_DIALOG_MOVING; return 1; } } } if ((event.mouse.type == GG_MOUSE_MOVE) && (dialog->dialog_state & GG_DIALOG_MOVING)) { int xoff = dialog->width * dialog->pos.x_align; int yoff = dialog->height * dialog->pos.y_align; gg_dialog_set_position(dialog, x + event.mouse.x - dialog->movement_org_x + xoff, y + event.mouse.y - dialog->movement_org_y + yoff, dialog->pos.x_align, dialog->pos.y_align); } event.mouse.x -= size + dialog->style.hor_pad; event.mouse.y -= size + dialog->style.vert_pad; if (!(event.mouse.type == GG_MOUSE_MOVE && dialog->dialog_state & GG_DIALOG_LEFT_BUTTON)) { gg_widget_t *child = gg_bin_get_child(GG_BIN(dialog)); if (event.mouse.x >= 0 && event.mouse.x < child->width_a && event.mouse.y >= 0 && event.mouse.y < child->height_a) dialog->set_focus_pos(GG_WIDGET(dialog), event.mouse.x, event.mouse.y); } } if (child->input) return child->input(child, event); return 0; }