예제 #1
0
static GimpValueArray *
palettes_get_palette_invoker (GimpProcedure         *procedure,
                              Gimp                  *gimp,
                              GimpContext           *context,
                              GimpProgress          *progress,
                              const GimpValueArray  *args,
                              GError               **error)
{
  gboolean success = TRUE;
  GimpValueArray *return_vals;
  gchar *name = NULL;
  gint32 num_colors = 0;

  GimpPalette *palette = gimp_context_get_palette (context);

  if (palette)
    {
      name       = g_strdup (gimp_object_get_name (palette));
      num_colors = gimp_palette_get_n_colors (palette);
    }
  else
    success = FALSE;

  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    {
      g_value_take_string (gimp_value_array_index (return_vals, 1), name);
      g_value_set_int (gimp_value_array_index (return_vals, 2), num_colors);
    }

  return return_vals;
}
예제 #2
0
static void
gimp_color_selector_palette_set_config (GimpColorSelector *selector,
                                        GimpColorConfig   *config)
{
  GimpColorSelectorPalette *select = GIMP_COLOR_SELECTOR_PALETTE (selector);

  if (select->context)
    {
      g_signal_handlers_disconnect_by_func (select->context,
                                            gimp_color_selector_palette_palette_changed,
                                            select);
      select->context = NULL;
    }

  if (config)
    select->context = g_object_get_data (G_OBJECT (config), "gimp-context");

  if (select->context)
    {
      if (! select->view)
        {
          GtkWidget *frame;

          frame = gtk_frame_new (NULL);
          gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
          gtk_container_add (GTK_CONTAINER (select), frame);
          gtk_widget_show (frame);

          select->view = gimp_view_new_full_by_types (select->context,
                                                      GIMP_TYPE_PALETTE_VIEW,
                                                      GIMP_TYPE_PALETTE,
                                                      100, 100, 0,
                                                      FALSE, TRUE, FALSE);
          gimp_view_set_expand (GIMP_VIEW (select->view), TRUE);
          gimp_view_renderer_palette_set_cell_size
            (GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (select->view)->renderer),
             -1);
          gimp_view_renderer_palette_set_draw_grid
            (GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (select->view)->renderer),
             TRUE);
          gtk_container_add (GTK_CONTAINER (frame), select->view);
          gtk_widget_show (select->view);

          g_signal_connect (select->view, "entry-clicked",
                            G_CALLBACK (gimp_color_selector_palette_entry_clicked),
                            select);
        }

      g_signal_connect_object (select->context, "palette-changed",
                               G_CALLBACK (gimp_color_selector_palette_palette_changed),
                               select, 0);

      gimp_color_selector_palette_palette_changed (select->context,
                                                   gimp_context_get_palette (select->context),
                                                   select);
    }
}
예제 #3
0
static GimpValueArray *
palettes_get_palette_entry_invoker (GimpProcedure         *procedure,
                                    Gimp                  *gimp,
                                    GimpContext           *context,
                                    GimpProgress          *progress,
                                    const GimpValueArray  *args,
                                    GError               **error)
{
  gboolean success = TRUE;
  GimpValueArray *return_vals;
  const gchar *name;
  gint32 entry_num;
  gchar *actual_name = NULL;
  gint32 num_colors = 0;
  GimpRGB color = { 0.0, 0.0, 0.0, 1.0 };

  name = g_value_get_string (gimp_value_array_index (args, 0));
  entry_num = g_value_get_int (gimp_value_array_index (args, 1));

  if (success)
    {
      GimpPalette *palette;

      if (name && strlen (name))
        palette = gimp_pdb_get_palette (gimp, name, FALSE, error);
      else
        palette = gimp_context_get_palette (context);

      if (palette)
        {
          GimpPaletteEntry *entry = gimp_palette_get_entry (palette, entry_num);

          if (entry)
            {
              actual_name = g_strdup (gimp_object_get_name (palette));
              num_colors  = gimp_palette_get_n_colors (palette);
              color       = entry->color;
            }
          else
            success = FALSE;
        }
      else
        success = FALSE;
    }

  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    {
      g_value_take_string (gimp_value_array_index (return_vals, 1), actual_name);
      g_value_set_int (gimp_value_array_index (return_vals, 2), num_colors);
      gimp_value_set_rgb (gimp_value_array_index (return_vals, 3), &color);
    }

  return return_vals;
}
예제 #4
0
GtkWidget *
gimp_palette_editor_new (GimpContext     *context,
                         GimpMenuFactory *menu_factory)
{
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);

  return g_object_new (GIMP_TYPE_PALETTE_EDITOR,
                       "menu-factory",    menu_factory,
                       "menu-identifier", "<PaletteEditor>",
                       "ui-path",         "/palette-editor-popup",
                       "data-factory",    context->gimp->palette_factory,
                       "context",         context,
                       "data",            gimp_context_get_palette (context),
                       NULL);
}
예제 #5
0
void
palettes_actions_update (GimpActionGroup *group,
                         gpointer         user_data)
{
  GimpContext *context = action_data_get_context (user_data);
  GimpPalette *palette = NULL;
  GimpData    *data    = NULL;
  GFile       *file    = NULL;

  if (context)
    {
      palette = gimp_context_get_palette (context);

      if (action_data_sel_count (user_data) > 1)
        {
          palette = NULL;
        }

      if (palette)
        {
          data = GIMP_DATA (palette);

          file = gimp_data_get_file (data);
        }
    }

#define SET_SENSITIVE(action,condition) \
        gimp_action_group_set_action_sensitive (group, action, (condition) != 0)

  SET_SENSITIVE ("palettes-edit",                 palette);
  SET_SENSITIVE ("palettes-duplicate",            palette && GIMP_DATA_GET_CLASS (data)->duplicate);
  SET_SENSITIVE ("palettes-merge",                FALSE); /* FIXME palette && GIMP_IS_CONTAINER_LIST_VIEW (editor->view)); */
  SET_SENSITIVE ("palettes-copy-location",        file);
  SET_SENSITIVE ("palettes-show-in-file-manager", file);
  SET_SENSITIVE ("palettes-delete",               palette && gimp_data_is_deletable (data));

#undef SET_SENSITIVE
}
예제 #6
0
/*
  Returns 2048 samples of the palette.
  Each sample is (R'G'B'A float) or (Y'A float), depending on the drawable
 */
static gdouble *
get_samples_palette (gint32 drawable_id)
{
  gchar      *palette_name;
  GimpRGB     color_sample;
  gdouble    *d_samples, *d_samp;
  gboolean    is_rgb;
  gdouble     factor;
  gint        pal_entry, num_colors;
  gint        nb_color_chan, nb_chan, i;
  const Babl *format;

  palette_name = gimp_context_get_palette ();
  gimp_palette_get_info (palette_name, &num_colors);

  is_rgb = gimp_drawable_is_rgb (drawable_id);

  factor = ((double) num_colors) / NSAMPLES;
  format = is_rgb ? babl_format ("R'G'B'A double") : babl_format ("Y'A double");
  nb_color_chan = is_rgb ? 3 : 1;
  nb_chan = nb_color_chan + 1;

  d_samples = g_new (gdouble, NSAMPLES * nb_chan);

  for (i = 0; i < NSAMPLES; i++)
    {
      d_samp = &d_samples[i * nb_chan];
      pal_entry = CLAMP ((int)(i * factor), 0, num_colors - 1);

      gimp_palette_entry_get_color (palette_name, pal_entry, &color_sample);
      gimp_rgb_get_pixel (&color_sample,
                          format,
                          d_samp);
    }

  g_free (palette_name);
  return d_samples;
}
예제 #7
0
static void
gimp_color_selector_palette_set_color (GimpColorSelector *selector,
                                       const GimpRGB     *rgb,
                                       const GimpHSV     *hsv)
{
  GimpColorSelectorPalette *select = GIMP_COLOR_SELECTOR_PALETTE (selector);

  if (select->context)
    {
      GimpPalette *palette = gimp_context_get_palette (select->context);

      if (palette && palette->n_colors > 0)
        {
          GimpPaletteEntry *entry;

          entry = gimp_palette_find_entry (palette, rgb,
                                           GIMP_PALETTE_VIEW (select->view)->selected);

          if (entry)
            gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (select->view),
                                            entry);
        }
    }
}
예제 #8
0
static void
gimp_color_tool_real_picked (GimpColorTool      *color_tool,
                             GimpColorPickState  pick_state,
                             gdouble             x,
                             gdouble             y,
                             const Babl         *sample_format,
                             const GimpRGB      *color,
                             gint                color_index)
{
  GimpTool          *tool = GIMP_TOOL (color_tool);
  GimpContext       *context;

  /*  use this tool's own options here (NOT color_tool->options)  */
  context = GIMP_CONTEXT (gimp_tool_get_options (tool));

  if (color_tool->pick_mode == GIMP_COLOR_PICK_MODE_FOREGROUND ||
      color_tool->pick_mode == GIMP_COLOR_PICK_MODE_BACKGROUND)
    {
      GtkWidget *widget;

      if (babl_format_is_palette (sample_format))
        {
          widget = gimp_dialog_factory_find_widget (gimp_dialog_factory_get_singleton (),
                                                    "gimp-indexed-palette");
          if (widget)
            {
              GimpColormapEditor *editor;

              editor = GIMP_COLORMAP_EDITOR (gtk_bin_get_child (GTK_BIN (widget)));

              gimp_colormap_editor_set_index (editor, color_index, NULL);
            }
        }

      if (TRUE)
        {
          widget = gimp_dialog_factory_find_widget (gimp_dialog_factory_get_singleton (),
                                                    "gimp-palette-editor");
          if (widget)
            {
              GimpPaletteEditor *editor;
              gint               index;

              editor = GIMP_PALETTE_EDITOR (gtk_bin_get_child (GTK_BIN (widget)));

              index = gimp_palette_editor_get_index (editor, color);
              if (index != -1)
                gimp_palette_editor_set_index (editor, index, NULL);
            }
        }
    }

  switch (color_tool->pick_mode)
    {
    case GIMP_COLOR_PICK_MODE_NONE:
      break;

    case GIMP_COLOR_PICK_MODE_FOREGROUND:
      gimp_context_set_foreground (context, color);
      break;

    case GIMP_COLOR_PICK_MODE_BACKGROUND:
      gimp_context_set_background (context, color);
      break;

    case GIMP_COLOR_PICK_MODE_PALETTE:
      {
        GimpDisplayShell *shell  = gimp_display_get_shell (tool->display);
        GdkScreen        *screen = gtk_widget_get_screen (GTK_WIDGET (shell));
        GtkWidget        *dockable;

        dockable =
          gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy (tool->display->gimp)),
                                                     tool->display->gimp,
                                                     gimp_dialog_factory_get_singleton (),
                                                     screen,
                                                     "gimp-palette-editor");

        if (dockable)
          {
            GtkWidget *palette_editor;
            GimpData  *data;

            /* don't blink like mad when updating */
            if (pick_state == GIMP_COLOR_PICK_STATE_UPDATE)
              gimp_dockable_blink_cancel (GIMP_DOCKABLE (dockable));

            palette_editor = gtk_bin_get_child (GTK_BIN (dockable));

            data = gimp_data_editor_get_data (GIMP_DATA_EDITOR (palette_editor));

            if (! data)
              {
                data = GIMP_DATA (gimp_context_get_palette (context));

                gimp_data_editor_set_data (GIMP_DATA_EDITOR (palette_editor),
                                           data);
              }

            gimp_palette_editor_pick_color (GIMP_PALETTE_EDITOR (palette_editor),
                                            color, pick_state);
          }
      }
      break;
    }
}
예제 #9
0
static void
gimp_color_tool_real_picked (GimpColorTool      *color_tool,
                             GimpColorPickState  pick_state,
                             GimpImageType       sample_type,
                             GimpRGB            *color,
                             gint                color_index)
{
  GimpTool          *tool = GIMP_TOOL (color_tool);
  GimpContext       *context;
  GimpDialogFactory *dialog_factory;

  /*  use this tool's own options here (NOT color_tool->options)  */
  context = GIMP_CONTEXT (gimp_tool_get_options (tool));

  dialog_factory = gimp_dialog_factory_from_name ("dock");

  if (color_tool->pick_mode == GIMP_COLOR_PICK_MODE_FOREGROUND ||
      color_tool->pick_mode == GIMP_COLOR_PICK_MODE_BACKGROUND)
    {
      GimpSessionInfo *info;

      if (GIMP_IMAGE_TYPE_IS_INDEXED (sample_type))
        {
          info = gimp_dialog_factory_find_session_info (dialog_factory,
                                                        "gimp-indexed-palette");
          if (info && info->widget)
            {
              GimpColormapEditor *editor;

              editor = GIMP_COLORMAP_EDITOR (gtk_bin_get_child (GTK_BIN (info->widget)));

              gimp_colormap_editor_set_index (editor, color_index, NULL);
            }
        }

      if (TRUE)
        {
          info = gimp_dialog_factory_find_session_info (dialog_factory,
                                                        "gimp-palette-editor");
          if (info && info->widget)
            {
              GimpPaletteEditor *editor;
              gint               index;

              editor = GIMP_PALETTE_EDITOR (gtk_bin_get_child (GTK_BIN (info->widget)));

              index = gimp_palette_editor_get_index (editor, color);
              if (index != -1)
                gimp_palette_editor_set_index (editor, index, NULL);
            }
        }
    }

  switch (color_tool->pick_mode)
    {
    case GIMP_COLOR_PICK_MODE_NONE:
      break;

    case GIMP_COLOR_PICK_MODE_FOREGROUND:
      gimp_context_set_foreground (context, color);
      break;

    case GIMP_COLOR_PICK_MODE_BACKGROUND:
      gimp_context_set_background (context, color);
      break;

    case GIMP_COLOR_PICK_MODE_PALETTE:
      {
        GdkScreen *screen;
        GtkWidget *dockable;

        screen = gtk_widget_get_screen (tool->display->shell);
        dockable = gimp_dialog_factory_dialog_raise (dialog_factory, screen,
                                                     "gimp-palette-editor",
                                                     -1);
        if (dockable)
          {
            GtkWidget *palette_editor;
            GimpData  *data;

            /* don't blink like mad when updating */
            if (pick_state == GIMP_COLOR_PICK_STATE_UPDATE)
              gimp_dockable_blink_cancel (GIMP_DOCKABLE (dockable));

            palette_editor = gtk_bin_get_child (GTK_BIN (dockable));

            data = gimp_data_editor_get_data (GIMP_DATA_EDITOR (palette_editor));

            if (! data)
              {
                data = GIMP_DATA (gimp_context_get_palette (context));

                gimp_data_editor_set_data (GIMP_DATA_EDITOR (palette_editor),
                                           data);
              }

            gimp_palette_editor_pick_color (GIMP_PALETTE_EDITOR (palette_editor),
                                            color, pick_state);
          }
      }
      break;
    }
}