Exemplo n.º 1
0
static void
gimp_operation_tool_create_gui (GimpOperationTool *op_tool)
{
  GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (op_tool);
  GtkWidget      *options_gui;
  gint            off_x, off_y;
  GeglRectangle   area;
  gint            aux;

  gimp_filter_tool_get_drawable_area (filter_tool, &off_x, &off_y, &area);

  options_gui =
    gimp_prop_gui_new (G_OBJECT (filter_tool->config),
                       G_TYPE_FROM_INSTANCE (filter_tool->config), 0,
                       &area,
                       GIMP_CONTEXT (GIMP_TOOL_GET_OPTIONS (op_tool)),
                       (GimpCreatePickerFunc) gimp_filter_tool_add_color_picker,
                       (GimpCreateControllerFunc) gimp_filter_tool_add_controller,
                       filter_tool);
  g_weak_ref_set (&op_tool->options_gui_ref, options_gui);

  for (aux = 1; ; aux++)
    {
      gchar pad[32];
      gchar label[32];

      if (aux == 1)
        {
          g_snprintf (pad,   sizeof (pad),   "aux");
          /* don't translate "Aux" */
          g_snprintf (label, sizeof (label), _("Aux Input"));
        }
      else
        {
          g_snprintf (pad,   sizeof (pad),   "aux%d", aux);
          /* don't translate "Aux" */
          g_snprintf (label, sizeof (label), _("Aux%d Input"), aux);
        }

      if (gegl_node_has_pad (filter_tool->operation, pad))
        {
          AuxInput *input;

          input = gimp_operation_tool_aux_input_new (op_tool,
                                                     filter_tool->operation, pad,
                                                     label);

          op_tool->aux_inputs = g_list_append (op_tool->aux_inputs, input);
        }
      else
        {
          break;
        }
    }
}
Exemplo n.º 2
0
void
gimp_operation_tool_set_operation (GimpOperationTool *tool,
                                   const gchar       *operation,
                                   const gchar       *undo_desc,
                                   const gchar       *icon_name)
{
    GimpImageMapTool *im_tool;
    GtkSizeGroup     *size_group = NULL;
    gint              aux;

    g_return_if_fail (GIMP_IS_OPERATION_TOOL (tool));
    g_return_if_fail (operation != NULL);

    im_tool = GIMP_IMAGE_MAP_TOOL (tool);

    if (tool->operation)
        g_free (tool->operation);

    if (tool->undo_desc)
        g_free (tool->undo_desc);

    if (tool->icon_name)
        g_free (tool->icon_name);

    tool->operation = g_strdup (operation);
    tool->undo_desc = g_strdup (undo_desc);
    tool->icon_name = g_strdup (icon_name);

    g_list_free_full (tool->aux_inputs,
                      (GDestroyNotify) gimp_operation_tool_aux_input_free);
    tool->aux_inputs = NULL;

    gimp_image_map_tool_get_operation (im_tool);

    if (undo_desc)
        GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->settings_name = "yes"; /* XXX hack */
    else
        GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->settings_name = NULL; /* XXX hack */

    if (tool->options_gui)
    {
        gtk_widget_destroy (tool->options_gui);
        tool->options_gui = NULL;

        if (im_tool->active_picker)
        {
            im_tool->active_picker = NULL;
            gimp_color_tool_disable (GIMP_COLOR_TOOL (tool));
        }
    }

    for (aux = 1; ; aux++)
    {
        gchar pad[32];
        gchar label[32];

        if (aux == 1)
        {
            g_snprintf (pad,   sizeof (pad),   "aux");
            g_snprintf (label, sizeof (label), _("Aux Input"));
        }
        else
        {
            g_snprintf (pad,   sizeof (pad),   "aux%d", aux);
            g_snprintf (label, sizeof (label), _("Aux%d Input"), aux);
        }

        if (gegl_node_has_pad (im_tool->operation, pad))
        {
            AuxInput  *input;
            GtkWidget *toggle;

            if (! size_group)
                size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);

            input = gimp_operation_tool_aux_input_new (tool,
                    im_tool->operation, pad,
                    label);

            tool->aux_inputs = g_list_append (tool->aux_inputs, input);

            toggle = gimp_buffer_source_box_get_toggle (GIMP_BUFFER_SOURCE_BOX (input->box));
            gtk_size_group_add_widget (size_group, toggle);

            if (tool->options_box)
            {
                gtk_box_pack_start (GTK_BOX (tool->options_box), input->box,
                                    FALSE, FALSE, 0);
                gtk_widget_show (input->box);
            }
        }
        else
        {
            break;
        }
    }

    if (size_group)
        g_object_unref (size_group);

    if (im_tool->config)
    {
        tool->options_gui =
            gimp_prop_gui_new (G_OBJECT (im_tool->config),
                               G_TYPE_FROM_INSTANCE (im_tool->config),
                               GIMP_CONTEXT (GIMP_TOOL_GET_OPTIONS (tool)),
                               (GimpCreatePickerFunc) gimp_image_map_tool_add_color_picker,
                               tool);

        if (tool->options_box)
        {
            gtk_box_pack_start (GTK_BOX (tool->options_box), tool->options_gui,
                                FALSE, FALSE, 0);
            gtk_widget_show (tool->options_gui);
        }
    }

    if (im_tool->gui)
    {
        if (undo_desc)
            gimp_tool_gui_set_description (im_tool->gui, undo_desc);

        if (icon_name)
            gimp_tool_gui_set_icon_name (im_tool->gui, icon_name);
    }

    if (GIMP_TOOL (tool)->drawable)
    {
        gimp_operation_tool_sync_op (tool, GIMP_TOOL (tool)->drawable);
        gimp_image_map_tool_preview (im_tool);
    }
}