Exemplo n.º 1
0
static void
gimp_image_editor_set_context (GimpDocked  *docked,
                               GimpContext *context)
{
  GimpImageEditor *editor = GIMP_IMAGE_EDITOR (docked);
  GimpImage       *image  = NULL;

  if (editor->context)
    {
      g_signal_handlers_disconnect_by_func (editor->context,
                                            gimp_image_editor_set_image,
                                            editor);

      g_object_unref (editor->context);
    }

  editor->context = context;

  if (context)
    {
      g_object_ref (editor->context);

      g_signal_connect_swapped (context, "image-changed",
                                G_CALLBACK (gimp_image_editor_set_image),
                                editor);

      image = gimp_context_get_image (context);
    }

  gimp_image_editor_set_image (editor, image);
}
static void
gimp_sample_point_editor_points_changed (GimpSamplePointEditor *editor)
{
  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
  GList           *sample_points;
  gint             n_points     = 0;
  gint             i;

  if (image_editor->image)
    {
      sample_points = gimp_image_get_sample_points (image_editor->image);
      n_points = MIN (4, g_list_length (sample_points));
    }

  for (i = 0; i < n_points; i++)
    {
      gtk_widget_set_sensitive (editor->color_frames[i], TRUE);
      editor->dirty[i] = TRUE;
    }

  for (i = n_points; i < 4; i++)
    {
      gtk_widget_set_sensitive (editor->color_frames[i], FALSE);
      gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (editor->color_frames[i]));
      editor->dirty[i] = FALSE;
    }

  if (n_points > 0)
    gimp_sample_point_editor_dirty (editor, -1);
}
Exemplo n.º 3
0
static void
gimp_component_editor_clicked (GtkCellRendererToggle *cellrenderertoggle,
                               gchar                 *path_str,
                               GdkModifierType        state,
                               GimpComponentEditor   *editor)
{
  GtkTreePath *path;
  GtkTreeIter  iter;

  path = gtk_tree_path_new_from_string (path_str);

  if (gtk_tree_model_get_iter (editor->model, &iter, path))
    {
      GimpImage       *image = GIMP_IMAGE_EDITOR (editor)->image;
      GimpChannelType  channel;
      gboolean         active;

      gtk_tree_model_get (editor->model, &iter,
                          COLUMN_CHANNEL, &channel,
                          -1);
      g_object_get (cellrenderertoggle,
                    "active", &active,
                    NULL);

      gimp_image_set_component_visible (image, channel, !active);
      gimp_image_flush (image);
    }

  gtk_tree_path_free (path);
}
Exemplo n.º 4
0
static void
gimp_sample_point_editor_proj_update (GimpImage             *image,
                                      gboolean               now,
                                      gint                   x,
                                      gint                   y,
                                      gint                   width,
                                      gint                   height,
                                      GimpSamplePointEditor *editor)
{
  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
  GList           *sample_points;
  gint             n_points     = 0;
  GList           *list;
  gint             i;

  sample_points = gimp_image_get_sample_points (image_editor->image);

  n_points = MIN (4, g_list_length (sample_points));

  for (i = 0, list = sample_points;
       i < n_points;
       i++, list = g_list_next (list))
    {
      GimpSamplePoint *sample_point = list->data;

      if (sample_point->x >= x && sample_point->x < (x + width) &&
          sample_point->y >= y && sample_point->y < (y + height))
        {
          gimp_sample_point_editor_dirty (editor, i);
        }
    }
}
static gboolean
gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
{
  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
  GList           *sample_points;
  gint             n_points     = 0;
  GList           *list;
  gint             i;

  editor->dirty_idle_id = 0;

  if (! image_editor->image)
    return FALSE;

  sample_points = gimp_image_get_sample_points (image_editor->image);

  n_points = MIN (4, g_list_length (sample_points));

  for (i = 0, list = sample_points;
       i < n_points;
       i++, list = g_list_next (list))
    {
      if (editor->dirty[i])
        {
          GimpSamplePoint *sample_point = list->data;
          GimpColorFrame  *color_frame;
          const Babl      *format;
          guchar           pixel[32];
          GimpRGB          color;
          gint             x;
          gint             y;

          editor->dirty[i] = FALSE;

          color_frame = GIMP_COLOR_FRAME (editor->color_frames[i]);

          gimp_sample_point_get_position (sample_point, &x, &y);

          if (gimp_image_pick_color (image_editor->image, NULL,
                                     x, y,
                                     editor->sample_merged,
                                     FALSE, 0.0,
                                     &format,
                                     pixel,
                                     &color))
            {
              gimp_color_frame_set_color (color_frame, FALSE,
                                          format, pixel, &color);
            }
          else
            {
              gimp_color_frame_set_invalid (color_frame);
            }
        }
    }

  return FALSE;
}
Exemplo n.º 6
0
static gboolean
gimp_component_editor_button_press (GtkWidget           *widget,
                                    GdkEventButton      *bevent,
                                    GimpComponentEditor *editor)
{
  GtkTreeViewColumn *column;
  GtkTreePath       *path;

  editor->clicked_component = -1;

  if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
                                     bevent->x,
                                     bevent->y,
                                     &path, &column, NULL, NULL))
    {
      GtkTreeIter     iter;
      GimpChannelType channel;
      gboolean        active;

      active = gtk_tree_selection_path_is_selected (editor->selection, path);

      gtk_tree_model_get_iter (editor->model, &iter, path);

      gtk_tree_path_free (path);

      gtk_tree_model_get (editor->model, &iter,
                          COLUMN_CHANNEL, &channel,
                          -1);

      editor->clicked_component = channel;

      switch (bevent->button)
        {
        case 1:
          if (column != editor->eye_column && bevent->type == GDK_BUTTON_PRESS)
            {
              GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;

              gimp_image_set_component_active (image, channel, ! active);
              gimp_image_flush (image);
            }
          break;

        case 2:
          break;

        case 3:
          gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
          break;

        default:
          break;
        }
    }

  return FALSE;
}
Exemplo n.º 7
0
static void
gimp_image_editor_dispose (GObject *object)
{
  GimpImageEditor *editor = GIMP_IMAGE_EDITOR (object);

  if (editor->image)
    gimp_image_editor_set_image (editor, NULL);

  G_OBJECT_CLASS (parent_class)->dispose (object);
}
Exemplo n.º 8
0
static GimpImage *
gimp_component_editor_drag_component (GtkWidget        *widget,
                                      GimpContext     **context,
                                      GimpChannelType  *channel,
                                      gpointer          data)
{
  GimpComponentEditor *editor = GIMP_COMPONENT_EDITOR (data);

  if (GIMP_IMAGE_EDITOR (editor)->image &&
      editor->clicked_component != -1)
    {
      if (channel)
        *channel = editor->clicked_component;

      if (context)
        *context = GIMP_IMAGE_EDITOR (editor)->context;

      return GIMP_IMAGE_EDITOR (editor)->image;
    }

  return NULL;
}
Exemplo n.º 9
0
static gboolean
gimp_component_editor_get_iter (GimpComponentEditor *editor,
                                GimpChannelType      channel,
                                GtkTreeIter         *iter)
{
  gint index;

  index = gimp_image_get_component_index (GIMP_IMAGE_EDITOR (editor)->image,
                                          channel);

  if (index != -1)
    return gtk_tree_model_iter_nth_child (editor->model, iter, NULL, index);

  return FALSE;
}
Exemplo n.º 10
0
static void
gimp_selection_editor_drop_color (GtkWidget     *widget,
                                  gint           x,
                                  gint           y,
                                  const GimpRGB *color,
                                  gpointer       data)
{
  GimpImageEditor         *editor = GIMP_IMAGE_EDITOR (data);
  GimpToolInfo            *tool_info;
  GimpSelectionOptions    *sel_options;
  GimpRegionSelectOptions *options;
  GimpDrawable            *drawable;

  if (! editor->image)
    return;

  tool_info = gimp_get_tool_info (editor->image->gimp,
                                  "gimp-by-color-select-tool");
  if (! tool_info)
    return;

  sel_options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);
  options     = GIMP_REGION_SELECT_OPTIONS (tool_info->tool_options);

  drawable = gimp_image_get_active_drawable (editor->image);

  if (! drawable)
    return;

  gimp_channel_select_by_color (gimp_image_get_mask (editor->image),
                                drawable,
                                options->sample_merged,
                                color,
                                options->threshold,
                                options->select_transparent,
                                options->select_criterion,
                                sel_options->operation,
                                sel_options->antialias,
                                sel_options->feather,
                                sel_options->feather_radius,
                                sel_options->feather_radius);
  gimp_image_flush (editor->image);
}
Exemplo n.º 11
0
static gboolean
gimp_component_editor_select (GtkTreeSelection *selection,
                              GtkTreeModel     *model,
                              GtkTreePath      *path,
                              gboolean          path_currently_selected,
                              gpointer          data)
{
  GimpComponentEditor *editor = GIMP_COMPONENT_EDITOR (data);
  GtkTreeIter          iter;
  GimpChannelType      channel;
  gboolean             active;

  gtk_tree_model_get_iter (editor->model, &iter, path);
  gtk_tree_model_get (editor->model, &iter,
                      COLUMN_CHANNEL, &channel,
                      -1);

  active = gimp_image_get_component_active (GIMP_IMAGE_EDITOR (editor)->image,
                                            channel);

  return active != path_currently_selected;
}
Exemplo n.º 12
0
static void
colormap_edit_color_update (GimpColorDialog      *dialog,
                            const GimpRGB        *color,
                            GimpColorDialogState  state,
                            GimpColormapEditor   *editor)
{
  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;

  switch (state)
    {
    case GIMP_COLOR_DIALOG_UPDATE:
      break;

    case GIMP_COLOR_DIALOG_OK:
      gimp_image_set_colormap_entry (image, editor->col_index, color, TRUE);
      gimp_image_flush (image);
      /* Fall through */

    case GIMP_COLOR_DIALOG_CANCEL:
      gtk_widget_hide (editor->color_dialog);
      break;
    }
}
Exemplo n.º 13
0
static void
gimp_component_editor_create_components (GimpComponentEditor *editor)
{
  GimpImage       *image        = GIMP_IMAGE_EDITOR (editor)->image;
  gint             n_components = 0;
  GimpChannelType  components[MAX_CHANNELS];
  GEnumClass      *enum_class;
  gint             i;

  switch (gimp_image_base_type (image))
    {
    case GIMP_RGB:
      n_components  = 3;
      components[0] = GIMP_RED_CHANNEL;
      components[1] = GIMP_GREEN_CHANNEL;
      components[2] = GIMP_BLUE_CHANNEL;
      break;

    case GIMP_GRAY:
      n_components  = 1;
      components[0] = GIMP_GRAY_CHANNEL;
      break;

    case GIMP_INDEXED:
      n_components  = 1;
      components[0] = GIMP_INDEXED_CHANNEL;
      break;
    }

  if (gimp_image_has_alpha (image))
    components[n_components++] = GIMP_ALPHA_CHANNEL;

  enum_class = g_type_class_ref (GIMP_TYPE_CHANNEL_TYPE);

  for (i = 0; i < n_components; i++)
    {
      GimpViewRenderer *renderer;
      GtkTreeIter       iter;
      GEnumValue       *enum_value;
      const gchar      *desc;
      gboolean          visible;

      visible = gimp_image_get_component_visible (image, components[i]);

      renderer = gimp_view_renderer_new (GIMP_IMAGE_EDITOR (editor)->context,
                                         G_TYPE_FROM_INSTANCE (image),
                                         editor->view_size, 1, FALSE);
      gimp_view_renderer_set_viewable (renderer, GIMP_VIEWABLE (image));
      gimp_view_renderer_remove_idle (renderer);

      GIMP_VIEW_RENDERER_IMAGE (renderer)->channel = components[i];

      g_signal_connect (renderer, "update",
                        G_CALLBACK (gimp_component_editor_renderer_update),
                        editor);

      enum_value = g_enum_get_value (enum_class, components[i]);
      desc = gimp_enum_value_get_desc (enum_class, enum_value);

      gtk_list_store_append (GTK_LIST_STORE (editor->model), &iter);

      gtk_list_store_set (GTK_LIST_STORE (editor->model), &iter,
                          COLUMN_CHANNEL,  components[i],
                          COLUMN_VISIBLE,  visible,
                          COLUMN_RENDERER, renderer,
                          COLUMN_NAME,     desc,
                          -1);

      g_object_unref (renderer);

      if (gimp_image_get_component_active (image, components[i]))
        gtk_tree_selection_select_iter (editor->selection, &iter);
    }

  g_type_class_unref (enum_class);
}
Exemplo n.º 14
0
static gboolean
gimp_selection_view_button_press (GtkWidget           *widget,
                                  GdkEventButton      *bevent,
                                  GimpSelectionEditor *editor)
{
  GimpImageEditor      *image_editor = GIMP_IMAGE_EDITOR (editor);
  GimpViewRenderer     *renderer;
  GimpToolInfo         *tool_info;
  GimpSelectionOptions *options;
  GimpDrawable         *drawable;
  GimpChannelOps        operation = GIMP_CHANNEL_OP_REPLACE;
  gint                  x, y;
  GimpRGB               color;

  if (! image_editor->image)
    return TRUE;

  renderer = GIMP_VIEW (editor->view)->renderer;

  tool_info = gimp_get_tool_info (image_editor->image->gimp,
                                  "gimp-by-color-select-tool");

  if (! tool_info)
    return TRUE;

  options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);

  drawable = gimp_image_get_active_drawable (image_editor->image);

  if (! drawable)
    return TRUE;

  if (bevent->state & GDK_SHIFT_MASK)
    {
      if (bevent->state & GDK_CONTROL_MASK)
        {
          operation = GIMP_CHANNEL_OP_INTERSECT;
        }
      else
        {
          operation = GIMP_CHANNEL_OP_ADD;
        }
    }
  else if (bevent->state & GDK_CONTROL_MASK)
    {
      operation = GIMP_CHANNEL_OP_SUBTRACT;
    }

  x = image_editor->image->width  * bevent->x / renderer->width;
  y = image_editor->image->height * bevent->y / renderer->height;

  if (gimp_image_pick_color (image_editor->image, drawable, x, y,
                             options->sample_merged,
                             FALSE, 0.0,
                             NULL,
                             &color, NULL))
    {
      gimp_channel_select_by_color (gimp_image_get_mask (image_editor->image),
                                    drawable,
                                    options->sample_merged,
                                    &color,
                                    options->threshold,
                                    options->select_transparent,
                                    options->select_criterion,
                                    operation,
                                    options->antialias,
                                    options->feather,
                                    options->feather_radius,
                                    options->feather_radius);
      gimp_image_flush (image_editor->image);
    }

  return TRUE;
}
Exemplo n.º 15
0
static gboolean
gimp_selection_view_button_press (GtkWidget           *widget,
                                  GdkEventButton      *bevent,
                                  GimpSelectionEditor *editor)
{
  GimpImageEditor         *image_editor = GIMP_IMAGE_EDITOR (editor);
  GimpViewRenderer        *renderer;
  GimpToolInfo            *tool_info;
  GimpSelectionOptions    *sel_options;
  GimpRegionSelectOptions *options;
  GimpDrawable            *drawable;
  GimpChannelOps           operation;
  gint                     x, y;
  GimpRGB                  color;

  if (! image_editor->image)
    return TRUE;

  renderer = GIMP_VIEW (editor->view)->renderer;

  tool_info = gimp_get_tool_info (image_editor->image->gimp,
                                  "gimp-by-color-select-tool");

  if (! tool_info)
    return TRUE;

  sel_options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);
  options     = GIMP_REGION_SELECT_OPTIONS (tool_info->tool_options);

  drawable = gimp_image_get_active_drawable (image_editor->image);

  if (! drawable)
    return TRUE;

  operation = gimp_modifiers_to_channel_op (bevent->state);

  x = gimp_image_get_width  (image_editor->image) * bevent->x / renderer->width;
  y = gimp_image_get_height (image_editor->image) * bevent->y / renderer->height;

  if (gimp_image_pick_color (image_editor->image, drawable, x, y,
                             options->sample_merged,
                             FALSE, 0.0,
                             NULL,
                             &color, NULL))
    {
      gimp_channel_select_by_color (gimp_image_get_mask (image_editor->image),
                                    drawable,
                                    options->sample_merged,
                                    &color,
                                    options->threshold,
                                    options->select_transparent,
                                    options->select_criterion,
                                    operation,
                                    sel_options->antialias,
                                    sel_options->feather,
                                    sel_options->feather_radius,
                                    sel_options->feather_radius);
      gimp_image_flush (image_editor->image);
    }

  return TRUE;
}
Exemplo n.º 16
0
void
plug_in_run_cmd_callback (GtkAction           *action,
                          GimpPlugInProcedure *proc,
                          gpointer             data)
{
  GimpProcedure  *procedure = GIMP_PROCEDURE (proc);
  Gimp           *gimp;
  GimpValueArray *args;
  gint            n_args    = 0;
  GimpDisplay    *display   = NULL;
  return_if_no_gimp (gimp, data);

  args = gimp_procedure_get_arguments (procedure);

  /* initialize the first argument  */
  g_value_set_int (gimp_value_array_index (args, n_args),
                   GIMP_RUN_INTERACTIVE);
  n_args++;

  switch (procedure->proc_type)
    {
    case GIMP_EXTENSION:
      break;

    case GIMP_PLUGIN:
    case GIMP_TEMPORARY:
      if (GIMP_IS_DATA_FACTORY_VIEW (data) ||
          GIMP_IS_FONT_VIEW (data)         ||
          GIMP_IS_BUFFER_VIEW (data))
        {
          GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
          GimpContainer       *container;
          GimpContext         *context;
          GimpObject          *object;

          container = gimp_container_view_get_container (editor->view);
          context   = gimp_container_view_get_context (editor->view);

          object = gimp_context_get_by_type (context,
                                             gimp_container_get_children_type (container));

          n_args = plug_in_collect_data_args (action, object,
                                              procedure->args,
                                              args, n_args);
        }
      else if (GIMP_IS_IMAGE_EDITOR (data))
        {
          GimpImageEditor *editor = GIMP_IMAGE_EDITOR (data);
          GimpImage       *image;

          image = gimp_image_editor_get_image (editor);

          n_args = plug_in_collect_image_args (action, image,
                                               procedure->args,
                                               args, n_args);
        }
      else if (GIMP_IS_ITEM_TREE_VIEW (data))
        {
          GimpItemTreeView *view = GIMP_ITEM_TREE_VIEW (data);
          GimpImage        *image;
          GimpItem         *item;

          image = gimp_item_tree_view_get_image (view);

          if (image)
            item = GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->get_active_item (image);
          else
            item = NULL;

          n_args = plug_in_collect_item_args (action, image, item,
                                              procedure->args,
                                              args, n_args);
        }
      else
        {
          display = action_data_get_display (data);

          n_args = plug_in_collect_display_args (action,
                                                 display,
                                                 procedure->args,
                                                 args, n_args);
        }
      break;

    case GIMP_INTERNAL:
      g_warning ("Unhandled procedure type.");
      n_args = -1;
      break;
    }

  if (n_args >= 1)
    plug_in_procedure_execute (proc, gimp, display, args, n_args);

  gimp_value_array_unref (args);
}