예제 #1
0
gboolean
gimp_palette_editor_set_index (GimpPaletteEditor *editor,
                               gint               index,
                               GimpRGB           *color)
{
  GimpPalette *palette;

  g_return_val_if_fail (GIMP_IS_PALETTE_EDITOR (editor), FALSE);

  palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);

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

      index = CLAMP (index, 0, gimp_palette_get_n_colors (palette) - 1);

      entry = gimp_palette_get_entry (palette, index);

      gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view),
                                      entry);

      if (color)
        *color = editor->color->color;

      return TRUE;
    }

  return FALSE;
}
예제 #2
0
static gboolean
gimp_palette_view_expose (GtkWidget      *widget,
                          GdkEventExpose *eevent)
{
  GimpPaletteView *pal_view = GIMP_PALETTE_VIEW (widget);
  GimpView        *view     = GIMP_VIEW (widget);

  if (! gtk_widget_is_drawable (widget))
    return FALSE;

  GTK_WIDGET_CLASS (parent_class)->expose_event (widget, eevent);

  if (view->renderer->viewable && pal_view->selected)
    {
      GimpViewRendererPalette *renderer;
      GtkStyle                *style = gtk_widget_get_style (widget);
      GtkAllocation            allocation;
      cairo_t                 *cr;
      gint                     row, col;

      renderer = GIMP_VIEW_RENDERER_PALETTE (view->renderer);

      gtk_widget_get_allocation (widget, &allocation);

      row = pal_view->selected->position / renderer->columns;
      col = pal_view->selected->position % renderer->columns;

      cr = gdk_cairo_create (gtk_widget_get_window (widget));
      gdk_cairo_region (cr, eevent->region);
      cairo_clip (cr);

      cairo_translate (cr, allocation.x, allocation.y);

      cairo_rectangle (cr,
                       col * renderer->cell_width  + 0.5,
                       row * renderer->cell_height + 0.5,
                       renderer->cell_width,
                       renderer->cell_height);

      cairo_set_line_width (cr, 1.0);
      gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_SELECTED]);
      cairo_stroke_preserve (cr);

      if (gimp_cairo_set_focus_line_pattern (cr, widget))
        {
          gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]);
          cairo_stroke (cr);
        }

      cairo_destroy (cr);
    }

  return FALSE;
}
예제 #3
0
static void
gimp_palette_view_drag_color (GtkWidget *widget,
                              GimpRGB   *color,
                              gpointer   data)
{
  GimpPaletteView *view = GIMP_PALETTE_VIEW (data);

  if (view->dnd_entry)
    *color = view->dnd_entry->color;
  else
    gimp_rgba_set (color, 0.0, 0.0, 0.0, 1.0);
}
예제 #4
0
static void
gimp_palette_view_unrealize (GtkWidget *widget)
{
  GimpPaletteView *view = GIMP_PALETTE_VIEW (widget);

  if (view->gc)
    {
      g_object_unref (view->gc);
      view->gc = NULL;
    }

  GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}
예제 #5
0
static void
gimp_palette_view_realize (GtkWidget *widget)
{
  GimpPaletteView *view = GIMP_PALETTE_VIEW (widget);

  GTK_WIDGET_CLASS (parent_class)->realize (widget);

  view->gc = gdk_gc_new (widget->window);

  gdk_gc_set_function (view->gc, GDK_INVERT);
  gdk_gc_set_line_attributes (view->gc, 1,
                              GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_ROUND);
}
예제 #6
0
static gboolean
gimp_palette_view_button_press (GtkWidget      *widget,
                                GdkEventButton *bevent)
{
  GimpPaletteView  *view = GIMP_PALETTE_VIEW (widget);
  GimpPaletteEntry *entry;

  if (GTK_WIDGET_CAN_FOCUS (widget) && ! GTK_WIDGET_HAS_FOCUS (widget))
    gtk_widget_grab_focus (widget);

  entry = gimp_palette_view_find_entry (view, bevent->x, bevent->y);

  view->dnd_entry = entry;

  if (! entry || bevent->button == 2)
    return FALSE;

  if (bevent->type == GDK_BUTTON_PRESS)
    g_signal_emit (view, view_signals[ENTRY_CLICKED], 0,
                   entry, bevent->state);

  switch (bevent->button)
    {
    case 1:
      if (bevent->type == GDK_BUTTON_PRESS)
        {
          gimp_palette_view_select_entry (view, entry);
        }
      else if (bevent->type == GDK_2BUTTON_PRESS && entry == view->selected)
        {
          g_signal_emit (view, view_signals[ENTRY_ACTIVATED], 0, entry);
        }
      break;

    case 3:
      if (bevent->type == GDK_BUTTON_PRESS)
        {
          if (entry != view->selected)
            gimp_palette_view_select_entry (view, entry);

          g_signal_emit (view, view_signals[ENTRY_CONTEXT], 0, entry);
        }
      break;

    default:
      break;
    }

  return FALSE;
}
예제 #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_palette_view_drop_color (GtkWidget     *widget,
                              gint           x,
                              gint           y,
                              const GimpRGB *color,
                              gpointer       data)
{
  GimpPaletteView  *view = GIMP_PALETTE_VIEW (data);
  GimpPaletteEntry *entry;

  entry = gimp_palette_view_find_entry (view, x, y);

  g_signal_emit (view, view_signals[COLOR_DROPPED], 0,
                 entry, color);
}
예제 #9
0
static gboolean
gimp_palette_view_expose (GtkWidget      *widget,
                          GdkEventExpose *eevent)
{
  if (GTK_WIDGET_DRAWABLE (widget))
    {
      GimpPaletteView *view = GIMP_PALETTE_VIEW (widget);

      GTK_WIDGET_CLASS (parent_class)->expose_event (widget, eevent);

      if (view->selected)
        gimp_palette_view_draw_selected (view, &eevent->area);
    }

  return FALSE;
}
예제 #10
0
static void
gimp_palette_view_set_viewable (GimpView     *view,
                                GimpViewable *old_viewable,
                                GimpViewable *new_viewable)
{
  GimpPaletteView *pal_view = GIMP_PALETTE_VIEW (view);

  pal_view->dnd_entry = NULL;
  gimp_palette_view_select_entry (pal_view, NULL);

  if (old_viewable)
    {
      g_signal_handlers_disconnect_by_func (old_viewable,
                                            gimp_palette_view_invalidate,
                                            view);

      if (! new_viewable)
        {
          gimp_dnd_color_source_remove (GTK_WIDGET (view));
          gimp_dnd_color_dest_remove (GTK_WIDGET (view));
        }
    }

  GIMP_VIEW_CLASS (parent_class)->set_viewable (view,
                                                old_viewable, new_viewable);

  if (new_viewable)
    {
      g_signal_connect (new_viewable, "invalidate-preview",
                        G_CALLBACK (gimp_palette_view_invalidate),
                        view);

      /*  unset the palette drag handler set by GimpView  */
      gimp_dnd_viewable_source_remove (GTK_WIDGET (view), GIMP_TYPE_PALETTE);

      if (! old_viewable)
        {
          gimp_dnd_color_source_add (GTK_WIDGET (view),
                                     gimp_palette_view_drag_color,
                                     view);
          gimp_dnd_color_dest_add (GTK_WIDGET (view),
                                   gimp_palette_view_drop_color,
                                   view);
        }
    }
}
예제 #11
0
static void
palette_editor_drop_color (GtkWidget     *widget,
                           gint           x,
                           gint           y,
                           const GimpRGB *color,
                           gpointer       data)
{
  GimpPaletteEditor *editor = data;

  if (GIMP_DATA_EDITOR (editor)->data_editable)
    {
      GimpPalette      *palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
      GimpPaletteEntry *entry;

      entry = gimp_palette_add_entry (palette, -1, NULL, color);
      gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view), entry);
    }
}
예제 #12
0
static void
palette_editor_color_dropped (GimpPaletteView   *view,
                              GimpPaletteEntry  *entry,
                              const GimpRGB     *color,
                              GimpPaletteEditor *editor)
{
  if (GIMP_DATA_EDITOR (editor)->data_editable)
    {
      GimpPalette *palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
      gint         pos     = -1;

      if (entry)
        pos = entry->position;

      entry = gimp_palette_add_entry (palette, pos, NULL, color);
      gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view), entry);
    }
}
예제 #13
0
static gboolean
gimp_palette_view_key_press (GtkWidget   *widget,
                             GdkEventKey *kevent)
{
  GimpPaletteView *view = GIMP_PALETTE_VIEW (widget);

  if (view->selected &&
      (kevent->keyval == GDK_KEY_space    ||
       kevent->keyval == GDK_KEY_KP_Space ||
       kevent->keyval == GDK_KEY_Return   ||
       kevent->keyval == GDK_KEY_KP_Enter ||
       kevent->keyval == GDK_KEY_ISO_Enter))
    {
      g_signal_emit (view, view_signals[ENTRY_CLICKED], 0,
                     view->selected, kevent->state);
    }

  return FALSE;
}
예제 #14
0
static gboolean
gimp_palette_view_button_press (GtkWidget      *widget,
                                GdkEventButton *bevent)
{
  GimpPaletteView  *view = GIMP_PALETTE_VIEW (widget);
  GimpPaletteEntry *entry;

  if (gtk_widget_get_can_focus (widget) && ! gtk_widget_has_focus (widget))
    gtk_widget_grab_focus (widget);

  entry = gimp_palette_view_find_entry (view, bevent->x, bevent->y);

  view->dnd_entry = entry;

  if (! entry || bevent->button == 2)
    return TRUE;

  if (bevent->type == GDK_BUTTON_PRESS)
    g_signal_emit (view, view_signals[ENTRY_CLICKED], 0,
                   entry, bevent->state);

  if (gdk_event_triggers_context_menu ((GdkEvent *) bevent))
    {
      if (entry != view->selected)
        gimp_palette_view_select_entry (view, entry);

      g_signal_emit (view, view_signals[ENTRY_CONTEXT], 0, entry);
    }
  else if (bevent->button == 1)
    {
      if (bevent->type == GDK_BUTTON_PRESS)
        {
          gimp_palette_view_select_entry (view, entry);
        }
      else if (bevent->type == GDK_2BUTTON_PRESS && entry == view->selected)
        {
          g_signal_emit (view, view_signals[ENTRY_ACTIVATED], 0, entry);
        }
    }

  return TRUE;
}
예제 #15
0
void
palette_editor_new_color_cmd_callback (GtkAction *action,
                                       gint       value,
                                       gpointer   data)
{
  GimpPaletteEditor *editor      = GIMP_PALETTE_EDITOR (data);
  GimpDataEditor    *data_editor = GIMP_DATA_EDITOR (data);

  if (data_editor->data_editable)
    {
      GimpPalette      *palette = GIMP_PALETTE (data_editor->data);
      GimpPaletteEntry *entry;
      GimpRGB           color;

      if (value)
        gimp_context_get_background (data_editor->context, &color);
      else
        gimp_context_get_foreground (data_editor->context, &color);

      entry = gimp_palette_add_entry (palette, -1, NULL, &color);
      gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view), entry);
    }
}
예제 #16
0
void
gimp_palette_editor_pick_color (GimpPaletteEditor  *editor,
                                const GimpRGB      *color,
                                GimpColorPickState  pick_state)
{
  g_return_if_fail (GIMP_IS_PALETTE_EDITOR (editor));
  g_return_if_fail (color != NULL);

  if (GIMP_DATA_EDITOR (editor)->data_editable)
    {
      GimpPaletteEntry *entry;
      GimpData         *data;
      gint              index = -1;

      data = gimp_data_editor_get_data (GIMP_DATA_EDITOR (editor));

      switch (pick_state)
        {
        case GIMP_COLOR_PICK_STATE_NEW:
          if (editor->color)
            index = editor->color->position + 1;

          entry = gimp_palette_add_entry (GIMP_PALETTE (data), index,
                                          NULL, color);
          gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view),
                                          entry);
          break;

        case GIMP_COLOR_PICK_STATE_UPDATE:
          gimp_palette_set_entry_color (GIMP_PALETTE (data),
                                        editor->color->position,
                                        color);
          break;
        }
    }
}
예제 #17
0
static gboolean
gimp_palette_view_focus (GtkWidget        *widget,
                         GtkDirectionType  direction)
{
  GimpPaletteView *view = GIMP_PALETTE_VIEW (widget);
  GimpPalette     *palette;

  palette = GIMP_PALETTE (GIMP_VIEW (view)->renderer->viewable);

  if (gtk_widget_get_can_focus (widget) &&
      ! gtk_widget_has_focus (widget))
    {
      gtk_widget_grab_focus (widget);

      if (! view->selected &&
          palette && gimp_palette_get_n_colors (palette) > 0)
        {
          GimpPaletteEntry *entry = gimp_palette_get_entry (palette, 0);

          gimp_palette_view_select_entry (view, entry);
        }

      return TRUE;
    }

  if (view->selected)
    {
      GimpViewRendererPalette *renderer;
      gint                     skip = 0;

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

      switch (direction)
        {
        case GTK_DIR_UP:
          skip = -renderer->columns;
          break;
        case GTK_DIR_DOWN:
          skip = renderer->columns;
          break;
        case GTK_DIR_LEFT:
          skip = -1;
          break;
        case GTK_DIR_RIGHT:
          skip = 1;
          break;

        case GTK_DIR_TAB_FORWARD:
        case GTK_DIR_TAB_BACKWARD:
          return FALSE;
        }

      if (skip != 0)
        {
          GimpPaletteEntry *entry;
          gint              position;

          position = view->selected->position + skip;

          entry = gimp_palette_get_entry (palette, position);

          if (entry)
            gimp_palette_view_select_entry (view, entry);
        }

      return TRUE;
    }

  return FALSE;
}