static void gimp_rotate_tool_prepare (GimpTransformTool *tr_tool) { GimpRotateTool *rotate = GIMP_ROTATE_TOOL (tr_tool); GimpDisplay *display = GIMP_TOOL (tr_tool)->display; GimpImage *image = gimp_display_get_image (display); gdouble xres; gdouble yres; tr_tool->px = (gdouble) (tr_tool->x1 + tr_tool->x2) / 2.0; tr_tool->py = (gdouble) (tr_tool->y1 + tr_tool->y2) / 2.0; tr_tool->trans_info[ANGLE] = 0.0; tr_tool->trans_info[REAL_ANGLE] = 0.0; tr_tool->trans_info[PIVOT_X] = tr_tool->px; tr_tool->trans_info[PIVOT_Y] = tr_tool->py; gimp_image_get_resolution (image, &xres, &yres); g_signal_handlers_block_by_func (rotate->sizeentry, rotate_center_changed, tr_tool); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (rotate->sizeentry), gimp_display_get_shell (display)->unit); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (rotate->sizeentry), 0, xres, FALSE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (rotate->sizeentry), 1, yres, FALSE); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (rotate->sizeentry), 0, -65536, 65536 + gimp_image_get_width (image)); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (rotate->sizeentry), 1, -65536, 65536 + gimp_image_get_height (image)); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (rotate->sizeentry), 0, tr_tool->x1, tr_tool->x2); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (rotate->sizeentry), 1, tr_tool->y1, tr_tool->y2); g_signal_handlers_unblock_by_func (rotate->sizeentry, rotate_center_changed, tr_tool); }
static gint dialog (gint32 image_ID, GimpDrawable *drawable) { GtkWidget *dlg; GtkWidget *main_vbox; GtkWidget *vbox; GtkSizeGroup *group; GtkWidget *label; GtkWidget *preview; GtkWidget *button; GtkWidget *width; GtkWidget *space; GtkWidget *offset; GtkWidget *chain_button; GtkWidget *table; GimpUnit unit; gdouble xres; gdouble yres; gboolean run; g_return_val_if_fail (main_dialog == NULL, FALSE); gimp_ui_init (PLUG_IN_BINARY, TRUE); main_dialog = dlg = gimp_dialog_new (_("Grid"), PLUG_IN_ROLE, NULL, 0, gimp_standard_help_func, PLUG_IN_PROC, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dlg), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gimp_window_set_transient (GTK_WINDOW (dlg)); /* Get the image resolution and unit */ gimp_image_get_resolution (image_ID, &xres, &yres); unit = gimp_image_get_unit (image_ID); main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), main_vbox, TRUE, TRUE, 0); gtk_widget_show (main_vbox); preview = gimp_drawable_preview_new (drawable, NULL); gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0); gtk_widget_show (preview); g_signal_connect (preview, "invalidated", G_CALLBACK (update_preview), drawable); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0); gtk_widget_show (vbox); /* The width entries */ width = gimp_size_entry_new (3, /* number_of_fields */ unit, /* unit */ "%a", /* unit_format */ TRUE, /* menu_show_pixels */ TRUE, /* menu_show_percent */ FALSE, /* show_refval */ SPIN_BUTTON_WIDTH, /* spinbutton_usize */ GIMP_SIZE_ENTRY_UPDATE_SIZE); /* update_policy */ gtk_box_pack_start (GTK_BOX (vbox), width, FALSE, FALSE, 0); gtk_widget_show (width); /* set the unit back to pixels, since most times we will want pixels */ gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (width), GIMP_UNIT_PIXEL); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 0, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 1, yres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 2, xres, TRUE); /* set the size (in pixels) that will be treated as 0% and 100% */ gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 2, 0.0, drawable->width); /* set upper and lower limits (in pixels) */ gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 0, 0.0, drawable->height); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 1, 0.0, drawable->width); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 2, 0.0, MAX (drawable->width, drawable->height)); gtk_table_set_row_spacing (GTK_TABLE (width), 0, 6); gtk_table_set_col_spacings (GTK_TABLE (width), 6); gtk_table_set_col_spacing (GTK_TABLE (width), 2, 12); /* initialize the values */ gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (width), 0, grid_cfg.hwidth); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (width), 1, grid_cfg.vwidth); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (width), 2, grid_cfg.iwidth); /* attach labels */ gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Horizontal\nLines"), 0, 1, 0.0); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Vertical\nLines"), 0, 2, 0.0); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Intersection"), 0, 3, 0.0); label = gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Width:"), 1, 0, 0.0); group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); gtk_size_group_add_widget (group, label); g_object_unref (group); /* put a chain_button under the size_entries */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (grid_cfg.hwidth == grid_cfg.vwidth) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (width), chain_button, 1, 3, 2, 3); gtk_widget_show (chain_button); /* connect to the 'value-changed' signal because we have to take care * of keeping the entries in sync when the chainbutton is active */ g_signal_connect (width, "value-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect_swapped (width, "value-changed", G_CALLBACK (gimp_preview_invalidate), preview); /* The spacing entries */ space = gimp_size_entry_new (3, /* number_of_fields */ unit, /* unit */ "%a", /* unit_format */ TRUE, /* menu_show_pixels */ TRUE, /* menu_show_percent */ FALSE, /* show_refval */ SPIN_BUTTON_WIDTH, /* spinbutton_usize */ GIMP_SIZE_ENTRY_UPDATE_SIZE); /* update_policy */ gtk_box_pack_start (GTK_BOX (vbox), space, FALSE, FALSE, 0); gtk_widget_show (space); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (space), GIMP_UNIT_PIXEL); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 0, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 1, yres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 2, xres, TRUE); /* set the size (in pixels) that will be treated as 0% and 100% */ gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 2, 0.0, drawable->width); /* set upper and lower limits (in pixels) */ gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 0, 1.0, drawable->height); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 1, 1.0, drawable->width); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 2, 0.0, MAX (drawable->width, drawable->height)); gtk_table_set_col_spacings (GTK_TABLE (space), 6); gtk_table_set_col_spacing (GTK_TABLE (space), 2, 12); /* initialize the values */ gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (space), 0, grid_cfg.hspace); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (space), 1, grid_cfg.vspace); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (space), 2, grid_cfg.ispace); /* attach labels */ label = gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (space), _("Spacing:"), 1, 0, 0.0); gtk_size_group_add_widget (group, label); /* put a chain_button under the spacing_entries */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (grid_cfg.hspace == grid_cfg.vspace) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (space), chain_button, 1, 3, 2, 3); gtk_widget_show (chain_button); /* connect to the 'value-changed' and "unit-changed" signals because * we have to take care of keeping the entries in sync when the * chainbutton is active */ g_signal_connect (space, "value-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect (space, "unit-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect_swapped (space, "value-changed", G_CALLBACK (gimp_preview_invalidate), preview); /* The offset entries */ offset = gimp_size_entry_new (3, /* number_of_fields */ unit, /* unit */ "%a", /* unit_format */ TRUE, /* menu_show_pixels */ TRUE, /* menu_show_percent */ FALSE, /* show_refval */ SPIN_BUTTON_WIDTH, /* spinbutton_usize */ GIMP_SIZE_ENTRY_UPDATE_SIZE); /* update_policy */ gtk_box_pack_start (GTK_BOX (vbox), offset, FALSE, FALSE, 0); gtk_widget_show (offset); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (offset), GIMP_UNIT_PIXEL); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 0, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 1, yres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 2, xres, TRUE); /* set the size (in pixels) that will be treated as 0% and 100% */ gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 2, 0.0, drawable->width); /* set upper and lower limits (in pixels) */ gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 0, 0.0, drawable->height); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 1, 0.0, drawable->width); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 2, 0.0, MAX (drawable->width, drawable->height)); gtk_table_set_col_spacings (GTK_TABLE (offset), 6); gtk_table_set_col_spacing (GTK_TABLE (offset), 2, 12); /* initialize the values */ gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (offset), 0, grid_cfg.hoffset); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (offset), 1, grid_cfg.voffset); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (offset), 2, grid_cfg.ioffset); /* attach labels */ label = gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (offset), _("Offset:"), 1, 0, 0.0); gtk_size_group_add_widget (group, label); /* this is a weird hack: we put a table into the offset table */ table = gtk_table_new (3, 3, FALSE); gtk_table_attach_defaults (GTK_TABLE (offset), table, 1, 4, 2, 3); gtk_table_set_row_spacing (GTK_TABLE (table), 0, 10); gtk_table_set_col_spacing (GTK_TABLE (table), 1, 12); /* put a chain_button under the offset_entries */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (grid_cfg.hoffset == grid_cfg.voffset) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), chain_button, 0, 2, 0, 1); gtk_widget_show (chain_button); /* connect to the 'value-changed' and "unit-changed" signals because * we have to take care of keeping the entries in sync when the * chainbutton is active */ g_signal_connect (offset, "value-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect (offset, "unit-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect_swapped (offset, "value-changed", G_CALLBACK (gimp_preview_invalidate), preview); /* put a chain_button under the color_buttons */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (gimp_rgba_distance (&grid_cfg.hcolor, &grid_cfg.vcolor) < 0.0001) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), chain_button, 0, 2, 2, 3); gtk_widget_show (chain_button); /* attach color selectors */ hcolor_button = gimp_color_button_new (_("Horizontal Color"), COLOR_BUTTON_WIDTH, 16, &grid_cfg.hcolor, GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_button_set_update (GIMP_COLOR_BUTTON (hcolor_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), hcolor_button, 0, 1, 1, 2); gtk_widget_show (hcolor_button); g_signal_connect (hcolor_button, "color-changed", G_CALLBACK (gimp_color_button_get_color), &grid_cfg.hcolor); g_signal_connect (hcolor_button, "color-changed", G_CALLBACK (color_callback), chain_button); g_signal_connect_swapped (hcolor_button, "color-changed", G_CALLBACK (gimp_preview_invalidate), preview); vcolor_button = gimp_color_button_new (_("Vertical Color"), COLOR_BUTTON_WIDTH, 16, &grid_cfg.vcolor, GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_button_set_update (GIMP_COLOR_BUTTON (vcolor_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), vcolor_button, 1, 2, 1, 2); gtk_widget_show (vcolor_button); g_signal_connect (vcolor_button, "color-changed", G_CALLBACK (gimp_color_button_get_color), &grid_cfg.vcolor); g_signal_connect (vcolor_button, "color-changed", G_CALLBACK (color_callback), chain_button); g_signal_connect_swapped (vcolor_button, "color-changed", G_CALLBACK (gimp_preview_invalidate), preview); button = gimp_color_button_new (_("Intersection Color"), COLOR_BUTTON_WIDTH, 16, &grid_cfg.icolor, GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), button, 2, 3, 1, 2); gtk_widget_show (button); g_signal_connect (button, "color-changed", G_CALLBACK (gimp_color_button_get_color), &grid_cfg.icolor); g_signal_connect_swapped (button, "color-changed", G_CALLBACK (gimp_preview_invalidate), preview); gtk_widget_show (table); gtk_widget_show (dlg); g_object_set_data (G_OBJECT (dlg), "width", width); g_object_set_data (G_OBJECT (dlg), "space", space); g_object_set_data (G_OBJECT (dlg), "offset", offset); run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK); if (run) update_values (); gtk_widget_destroy (dlg); return run; }
/** * gimp_coordinates_new: * @unit: The initial unit of the #GimpUnitMenu. * @unit_format: A printf-like unit-format string as is used with * gimp_unit_menu_new(). * @menu_show_pixels: %TRUE if the #GimpUnitMenu should contain an item * for GIMP_UNIT_PIXEL. * @menu_show_percent: %TRUE if the #GimpUnitMenu should contain an item * for GIMP_UNIT_PERCENT. * @spinbutton_width: The horizontal size of the #GimpSizeEntry's * #GtkSpinButton's. * @update_policy: The update policy for the #GimpSizeEntry. * @chainbutton_active: %TRUE if the attached #GimpChainButton should be * active. * @chain_constrains_ratio: %TRUE if the chainbutton should constrain the * fields' aspect ratio. If %FALSE, the values will * be constrained. * @xlabel: The label for the X coordinate. * @x: The initial value of the X coordinate. * @xres: The horizontal resolution in DPI. * @lower_boundary_x: The lower boundary of the X coordinate. * @upper_boundary_x: The upper boundary of the X coordinate. * @xsize_0: The X value which will be treated as 0%. * @xsize_100: The X value which will be treated as 100%. * @ylabel: The label for the Y coordinate. * @y: The initial value of the Y coordinate. * @yres: The vertical resolution in DPI. * @lower_boundary_y: The lower boundary of the Y coordinate. * @upper_boundary_y: The upper boundary of the Y coordinate. * @ysize_0: The Y value which will be treated as 0%. * @ysize_100: The Y value which will be treated as 100%. * * Convenience function that creates a #GimpSizeEntry with two fields for x/y * coordinates/sizes with a #GimpChainButton attached to constrain either the * two fields' values or the ratio between them. * * Returns: The new #GimpSizeEntry. **/ GtkWidget * gimp_coordinates_new (GimpUnit unit, const gchar *unit_format, gboolean menu_show_pixels, gboolean menu_show_percent, gint spinbutton_width, GimpSizeEntryUpdatePolicy update_policy, gboolean chainbutton_active, gboolean chain_constrains_ratio, const gchar *xlabel, gdouble x, gdouble xres, gdouble lower_boundary_x, gdouble upper_boundary_x, gdouble xsize_0, /* % */ gdouble xsize_100, /* % */ const gchar *ylabel, gdouble y, gdouble yres, gdouble lower_boundary_y, gdouble upper_boundary_y, gdouble ysize_0, /* % */ gdouble ysize_100 /* % */) { GimpCoordinatesData *data; GtkObject *adjustment; GtkWidget *spinbutton; GtkWidget *sizeentry; GtkWidget *chainbutton; spinbutton = gimp_spin_button_new (&adjustment, 1, 0, 1, 1, 10, 0, 1, 2); if (spinbutton_width > 0) { if (spinbutton_width < 17) gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), spinbutton_width); else gtk_widget_set_size_request (spinbutton, spinbutton_width, -1); } sizeentry = gimp_size_entry_new (1, unit, unit_format, menu_show_pixels, menu_show_percent, FALSE, spinbutton_width, update_policy); gtk_table_set_col_spacing (GTK_TABLE (sizeentry), 0, 4); gtk_table_set_col_spacing (GTK_TABLE (sizeentry), 2, 4); gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry), GTK_SPIN_BUTTON (spinbutton), NULL); gtk_table_attach_defaults (GTK_TABLE (sizeentry), spinbutton, 1, 2, 0, 1); gtk_widget_show (spinbutton); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry), (update_policy == GIMP_SIZE_ENTRY_UPDATE_RESOLUTION) || (menu_show_pixels == FALSE) ? GIMP_UNIT_INCH : GIMP_UNIT_PIXEL); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1, yres, TRUE); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0, lower_boundary_x, upper_boundary_x); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1, lower_boundary_y, upper_boundary_y); if (menu_show_percent) { gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 0, xsize_0, xsize_100); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 1, ysize_0, ysize_100); } gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, x); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1, y); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (sizeentry), xlabel, 0, 0, 0.0); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (sizeentry), ylabel, 1, 0, 0.0); chainbutton = gimp_chain_button_new (GIMP_CHAIN_RIGHT); if (chainbutton_active) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chainbutton), TRUE); gtk_table_attach (GTK_TABLE (sizeentry), chainbutton, 2, 3, 0, 2, GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); gtk_widget_show (chainbutton); data = g_slice_new (GimpCoordinatesData); data->chainbutton = GIMP_CHAIN_BUTTON (chainbutton); data->chain_constrains_ratio = chain_constrains_ratio; data->orig_x = x; data->orig_y = y; data->last_x = x; data->last_y = y; g_object_set_data_full (G_OBJECT (sizeentry), "coordinates-data", data, (GDestroyNotify) gimp_coordinates_data_free); g_signal_connect (sizeentry, "value-changed", G_CALLBACK (gimp_coordinates_callback), data); g_object_set_data (G_OBJECT (sizeentry), "chainbutton", chainbutton); g_signal_connect (chainbutton, "toggled", G_CALLBACK (gimp_coordinates_chainbutton_toggled), sizeentry); return sizeentry; }
LayerOptionsDialog * layer_options_dialog_new (GimpImage *image, GimpLayer *layer, GimpContext *context, GtkWidget *parent, const gchar *layer_name, GimpFillType layer_fill_type, const gchar *title, const gchar *role, const gchar *stock_id, const gchar *desc, const gchar *help_id) { LayerOptionsDialog *options; GimpViewable *viewable; GtkWidget *vbox; GtkWidget *table; GtkWidget *label; GtkObject *adjustment; GtkWidget *spinbutton; GtkWidget *frame; GtkWidget *button; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (layer == NULL || GIMP_IS_LAYER (layer), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL); options = g_slice_new0 (LayerOptionsDialog); options->image = image; options->context = context; options->layer = layer; options->fill_type = layer_fill_type; if (layer) viewable = GIMP_VIEWABLE (layer); else viewable = GIMP_VIEWABLE (image); options->dialog = gimp_viewable_dialog_new (viewable, context, title, role, stock_id, desc, parent, gimp_standard_help_func, help_id, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); g_object_weak_ref (G_OBJECT (options->dialog), (GWeakNotify) layer_options_dialog_free, options); gtk_dialog_set_alternative_button_order (GTK_DIALOG (options->dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_container_set_border_width (GTK_CONTAINER (vbox), 12); gtk_box_set_spacing (GTK_BOX (vbox), 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (options->dialog))), vbox, TRUE, TRUE, 0); gtk_widget_show (vbox); table = gtk_table_new (layer ? 1 : 3, 2, FALSE); gtk_table_set_col_spacing (GTK_TABLE (table), 0, 6); gtk_table_set_row_spacing (GTK_TABLE (table), 0, 6); gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0); gtk_widget_show (table); /* The name label and entry */ options->name_entry = gtk_entry_new (); gimp_table_attach_aligned (GTK_TABLE (table), 0, 0, _("Layer _name:"), 0.0, 0.5, options->name_entry, 1, FALSE); gtk_entry_set_activates_default (GTK_ENTRY (options->name_entry), TRUE); gtk_entry_set_text (GTK_ENTRY (options->name_entry), layer_name); if (! layer) { gdouble xres; gdouble yres; gimp_image_get_resolution (image, &xres, &yres); /* The size labels */ label = gtk_label_new (_("Width:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0); gtk_widget_show (label); label = gtk_label_new (_("Height:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0); gtk_widget_show (label); /* The size sizeentry */ spinbutton = gimp_spin_button_new (&adjustment, 1, 1, 1, 1, 10, 0, 1, 2); gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 10); options->size_se = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a", TRUE, TRUE, FALSE, 10, GIMP_SIZE_ENTRY_UPDATE_SIZE); gtk_table_set_col_spacing (GTK_TABLE (options->size_se), 1, 4); gtk_table_set_row_spacing (GTK_TABLE (options->size_se), 0, 2); gimp_size_entry_add_field (GIMP_SIZE_ENTRY (options->size_se), GTK_SPIN_BUTTON (spinbutton), NULL); gtk_table_attach_defaults (GTK_TABLE (options->size_se), spinbutton, 1, 2, 0, 1); gtk_widget_show (spinbutton); gtk_table_attach (GTK_TABLE (table), options->size_se, 1, 2, 1, 3, GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); gtk_widget_show (options->size_se); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (options->size_se), GIMP_UNIT_PIXEL); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (options->size_se), 0, xres, FALSE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (options->size_se), 1, yres, FALSE); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (options->size_se), 0, GIMP_MIN_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (options->size_se), 1, GIMP_MIN_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (options->size_se), 0, 0, gimp_image_get_width (image)); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (options->size_se), 1, 0, gimp_image_get_height (image)); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (options->size_se), 0, gimp_image_get_width (image)); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (options->size_se), 1, gimp_image_get_height (image)); /* The radio frame */ frame = gimp_enum_radio_frame_new_with_range (GIMP_TYPE_FILL_TYPE, GIMP_FOREGROUND_FILL, GIMP_TRANSPARENT_FILL, gtk_label_new (_("Layer Fill Type")), G_CALLBACK (gimp_radio_button_update), &options->fill_type, &button); gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button), options->fill_type); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); } else { GimpContainer *filters; GtkWidget *frame; GtkWidget *view; /* For text layers add a toggle to control "auto-rename" */ if (gimp_item_is_text_layer (GIMP_ITEM (layer))) { options->rename_toggle = gtk_check_button_new_with_mnemonic (_("Set name from _text")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->rename_toggle), GIMP_TEXT_LAYER (layer)->auto_rename); gtk_table_attach (GTK_TABLE (table), options->rename_toggle, 1, 2, 1, 2, GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); gtk_widget_show (options->rename_toggle); g_signal_connect (options->rename_toggle, "toggled", G_CALLBACK (layer_options_dialog_toggle_rename), options); } frame = gimp_frame_new ("Active Filters"); gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0); gtk_widget_show (frame); filters = gimp_drawable_get_filters (GIMP_DRAWABLE (layer)); view = gimp_container_tree_view_new (filters, context, GIMP_VIEW_SIZE_SMALL, 0); gtk_container_add (GTK_CONTAINER (frame), view); gtk_widget_show (view); } return options; }
GtkWidget * offset_dialog_new (GimpDrawable *drawable, GimpContext *context, GtkWidget *parent) { GimpItem *item; OffsetDialog *dialog; GtkWidget *main_vbox; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *button; GtkWidget *spinbutton; GtkWidget *frame; GtkWidget *radio_button; GtkAdjustment *adjustment; gdouble xres; gdouble yres; const gchar *title = NULL; g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL); dialog = g_slice_new0 (OffsetDialog); dialog->context = context; dialog->fill_type = gimp_drawable_has_alpha (drawable) | WRAP_AROUND; item = GIMP_ITEM (drawable); dialog->image = gimp_item_get_image (item); gimp_image_get_resolution (dialog->image, &xres, &yres); if (GIMP_IS_LAYER (drawable)) title = _("Offset Layer"); else if (GIMP_IS_LAYER_MASK (drawable)) title = _("Offset Layer Mask"); else if (GIMP_IS_CHANNEL (drawable)) title = _("Offset Channel"); else g_warning ("%s: unexpected drawable type", G_STRFUNC); dialog->dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (drawable), context, _("Offset"), "gimp-drawable-offset", GIMP_STOCK_TOOL_MOVE, title, parent, gimp_standard_help_func, GIMP_HELP_LAYER_OFFSET, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, /* offset, used as a verb */ _("_Offset"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); g_object_weak_ref (G_OBJECT (dialog->dialog), (GWeakNotify) offset_dialog_free, dialog); g_signal_connect (dialog->dialog, "response", G_CALLBACK (offset_response), dialog); main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), main_vbox, TRUE, TRUE, 0); gtk_widget_show (main_vbox); /* The offset frame */ frame = gimp_frame_new (_("Offset")); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show (vbox); adjustment = (GtkAdjustment *) gtk_adjustment_new (1, 1, 1, 1, 10, 0); spinbutton = gtk_spin_button_new (adjustment, 1.0, 2); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 10); dialog->off_se = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a", TRUE, TRUE, FALSE, 10, GIMP_SIZE_ENTRY_UPDATE_SIZE); gtk_table_set_col_spacing (GTK_TABLE (dialog->off_se), 0, 4); gtk_table_set_col_spacing (GTK_TABLE (dialog->off_se), 1, 4); gtk_table_set_row_spacing (GTK_TABLE (dialog->off_se), 0, 2); gimp_size_entry_add_field (GIMP_SIZE_ENTRY (dialog->off_se), GTK_SPIN_BUTTON (spinbutton), NULL); gtk_table_attach_defaults (GTK_TABLE (dialog->off_se), spinbutton, 1, 2, 0, 1); gtk_widget_show (spinbutton); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (dialog->off_se), _("_X:"), 0, 0, 0.0); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (dialog->off_se), _("_Y:"), 1, 0, 0.0); gtk_box_pack_start (GTK_BOX (vbox), dialog->off_se, FALSE, FALSE, 0); gtk_widget_show (dialog->off_se); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (dialog->off_se), GIMP_UNIT_PIXEL); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (dialog->off_se), 0, xres, FALSE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (dialog->off_se), 1, yres, FALSE); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (dialog->off_se), 0, - gimp_item_get_width (item), gimp_item_get_width (item)); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (dialog->off_se), 1, - gimp_item_get_height (item), gimp_item_get_height (item)); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (dialog->off_se), 0, 0, gimp_item_get_width (item)); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (dialog->off_se), 1, 0, gimp_item_get_height (item)); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (dialog->off_se), 0, 0); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (dialog->off_se), 1, 0); button = gtk_button_new_with_mnemonic (_("By width/_2, height/2")); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_widget_show (button); g_signal_connect (button, "clicked", G_CALLBACK (offset_half_xy_callback), dialog); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); button = gtk_button_new_with_mnemonic ("By _width/2"); gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); gtk_widget_show (button); g_signal_connect (button, "clicked", G_CALLBACK (offset_half_x_callback), dialog); button = gtk_button_new_with_mnemonic ("By _height/2"); gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); gtk_widget_show (button); g_signal_connect (button, "clicked", G_CALLBACK (offset_half_y_callback), dialog); /* The edge behavior frame */ frame = gimp_int_radio_group_new (TRUE, _("Edge Behavior"), G_CALLBACK (gimp_radio_button_update), &dialog->fill_type, dialog->fill_type, _("W_rap around"), WRAP_AROUND, NULL, _("Fill with _background color"), GIMP_OFFSET_BACKGROUND, NULL, _("Make _transparent"), GIMP_OFFSET_TRANSPARENT, &radio_button, NULL); if (! gimp_drawable_has_alpha (drawable)) gtk_widget_set_sensitive (radio_button, FALSE); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); return dialog->dialog; }