Esempio n. 1
0
void
colormap_edit_color_cmd_callback (GtkAction *action,
                                  gpointer   data)
{
  GimpColormapEditor *editor;
  GimpImage          *image;
  const guchar       *colormap;
  GimpRGB             color;
  gchar              *desc;
  return_if_no_image (image, data);

  editor = GIMP_COLORMAP_EDITOR (data);

  colormap = gimp_image_get_colormap (image);

  gimp_rgba_set_uchar (&color,
                       colormap[editor->col_index * 3],
                       colormap[editor->col_index * 3 + 1],
                       colormap[editor->col_index * 3 + 2],
                       OPAQUE_OPACITY);

  desc = g_strdup_printf (_("Edit colormap entry #%d"), editor->col_index);

  if (! editor->color_dialog)
    {
      editor->color_dialog =
        gimp_color_dialog_new (GIMP_VIEWABLE (image),
                               action_data_get_context (data),
                               _("Edit Colormap Entry"),
                               GIMP_STOCK_COLORMAP,
                               desc,
                               GTK_WIDGET (editor),
                               gimp_dialog_factory_from_name ("toplevel"),
                               "gimp-colormap-editor-color-dialog",
                               (const GimpRGB *) &color,
                               FALSE, FALSE);

      g_signal_connect (editor->color_dialog, "destroy",
                        G_CALLBACK (gtk_widget_destroyed),
                        &editor->color_dialog);

      g_signal_connect (editor->color_dialog, "update",
                        G_CALLBACK (colormap_edit_color_update),
                        editor);
    }
  else
    {
      gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (editor->color_dialog),
                                         GIMP_VIEWABLE (image),
                                         action_data_get_context (data));
      g_object_set (editor->color_dialog, "description", desc, NULL);
      gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (editor->color_dialog),
                                   &color);
    }

  g_free (desc);

  gtk_window_present (GTK_WINDOW (editor->color_dialog));
}
Esempio n. 2
0
static void
color_area_color_clicked (GimpFgBgEditor  *editor,
                          GimpActiveColor  active_color,
                          GimpContext     *context)
{
  GimpRGB      color;
  const gchar *title;

  if (! color_dialog_active)
    {
      gimp_context_get_foreground (context, &revert_fg);
      gimp_context_get_background (context, &revert_bg);
    }

  if (active_color == GIMP_ACTIVE_COLOR_FOREGROUND)
    {
      gimp_context_get_foreground (context, &color);
      title = _("Change Foreground Color");
    }
  else
    {
      gimp_context_get_background (context, &color);
      title = _("Change Background Color");
    }

  edit_color = active_color;

  if (! color_dialog)
    {
      GimpDialogFactory *toplevel_factory;

      toplevel_factory = gimp_dialog_factory_from_name ("toplevel");

      color_dialog = gimp_color_dialog_new (NULL, context,
                                            NULL, NULL, NULL,
                                            GTK_WIDGET (editor),
                                            toplevel_factory,
                                            "gimp-toolbox-color-dialog",
                                            &color,
                                            TRUE, FALSE);

      g_signal_connect (color_dialog, "update",
                        G_CALLBACK (color_area_dialog_update),
                        context);
    }

  gtk_window_set_title (GTK_WINDOW (color_dialog), title);
  gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (color_dialog), &color);

  gtk_window_present (GTK_WINDOW (color_dialog));
  color_dialog_active = TRUE;
}
Esempio n. 3
0
GimpDialogFactory *
gimp_dialog_factory_new (const gchar       *name,
                         GimpContext       *context,
                         GimpMenuFactory   *menu_factory,
                         GimpDialogNewFunc  new_dock_func,
                         gboolean           toggle_visibility)
{
  GimpDialogFactory *factory;
  gpointer           key;

  g_return_val_if_fail (name != NULL, NULL);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
  g_return_val_if_fail (! menu_factory || GIMP_IS_MENU_FACTORY (menu_factory),
                        NULL);

  if (gimp_dialog_factory_from_name (name))
    {
      g_warning ("%s: dialog factory \"%s\" already exists",
                 G_STRFUNC, name);
      return NULL;
    }

  factory = g_object_new (GIMP_TYPE_DIALOG_FACTORY, NULL);

  gimp_object_set_name (GIMP_OBJECT (factory), name);

  /*  hack to keep the toolbox on the pool position  */
  if (strcmp (name, "toolbox") == 0)
    key = "";
  else
    key = GIMP_OBJECT (factory)->name;

  g_hash_table_insert (GIMP_DIALOG_FACTORY_GET_CLASS (factory)->factories,
                       key, factory);

  factory->context           = context;
  factory->menu_factory      = menu_factory;
  factory->new_dock_func     = new_dock_func;
  factory->toggle_visibility = toggle_visibility;

  return factory;
}
Esempio n. 4
0
void
gimp_display_shell_clear_cursor (GimpDisplayShell *shell)
{
    GimpDialogFactory *factory;
    GimpSessionInfo   *session_info;

    g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

    gimp_statusbar_clear_cursor (GIMP_STATUSBAR (shell->statusbar));

    factory = gimp_dialog_factory_from_name ("dock");
    session_info = gimp_dialog_factory_find_session_info (factory,
                   "gimp-cursor-view");
    if (session_info && session_info->widget)
    {
        GtkWidget *cursor_view;

        cursor_view = gtk_bin_get_child (GTK_BIN (session_info->widget));

        if (cursor_view)
            gimp_cursor_view_clear_cursor (GIMP_CURSOR_VIEW (cursor_view));
    }
}
Esempio n. 5
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;
    }
}
Esempio n. 6
0
void
gimp_display_shell_update_cursor (GimpDisplayShell *shell,
                                  gint              display_x,
                                  gint              display_y,
                                  gint              image_x,
                                  gint              image_y)
{
    GimpDialogFactory *factory;
    GimpSessionInfo   *session_info;
    GimpImage         *image;
    gboolean           new_cursor;

    g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

    image = shell->display->image;

    new_cursor = (shell->draw_cursor &&
                  shell->proximity   &&
                  display_x >= 0     &&
                  display_y >= 0);

    /* Erase old cursor, if necessary */

    if (shell->have_cursor && (! new_cursor                 ||
                               display_x != shell->cursor_x ||
                               display_y != shell->cursor_y))
    {
        gimp_display_shell_expose_area (shell,
                                        shell->cursor_x - 7,
                                        shell->cursor_y - 7,
                                        15, 15);
        if (! new_cursor)
            shell->have_cursor = FALSE;
    }

    shell->have_cursor = new_cursor;
    shell->cursor_x    = display_x;
    shell->cursor_y    = display_y;

    /*  use the passed image_coords for the statusbar because they are
     *  possibly snapped...
     */
    gimp_statusbar_update_cursor (GIMP_STATUSBAR (shell->statusbar),
                                  image_x, image_y);

    factory = gimp_dialog_factory_from_name ("dock");
    session_info = gimp_dialog_factory_find_session_info (factory,
                   "gimp-cursor-view");
    if (session_info && session_info->widget)
    {
        GtkWidget *cursor_view;

        cursor_view = gtk_bin_get_child (GTK_BIN (session_info->widget));

        if (cursor_view)
        {
            gint t_x = -1;
            gint t_y = -1;

            /*  ...but use the unsnapped display_coords for the info window  */
            if (display_x >= 0 && display_y >= 0)
                gimp_display_shell_untransform_xy (shell, display_x, display_y,
                                                   &t_x, &t_y, FALSE, FALSE);

            gimp_cursor_view_update_cursor (GIMP_CURSOR_VIEW (cursor_view),
                                            shell->display->image, shell->unit,
                                            t_x, t_y);
        }
    }
}