mirror of https://github.com/GNOME/gimp.git
remove the ->position entry from GimpPaletteEntry
This commit is contained in:
parent
4cf38d784f
commit
9c96e34be2
|
@ -192,7 +192,6 @@ gimp_palette_load (GimpContext *context,
|
|||
255);
|
||||
|
||||
entry->name = g_strdup (tok ? tok : _("Untitled"));
|
||||
entry->position = gimp_palette_get_n_colors (palette);
|
||||
|
||||
palette->colors = g_list_prepend (palette->colors, entry);
|
||||
palette->n_colors++;
|
||||
|
|
|
@ -399,49 +399,16 @@ gimp_palette_move_entry (GimpPalette *palette,
|
|||
GimpPaletteEntry *entry,
|
||||
gint position)
|
||||
{
|
||||
GList *list;
|
||||
gint pos = 0;
|
||||
|
||||
g_return_if_fail (GIMP_IS_PALETTE (palette));
|
||||
g_return_if_fail (entry != NULL);
|
||||
|
||||
if (g_list_find (palette->colors, entry))
|
||||
{
|
||||
pos = entry->position;
|
||||
|
||||
if (entry->position == position)
|
||||
return;
|
||||
|
||||
entry->position = position;
|
||||
palette->colors = g_list_remove (palette->colors,
|
||||
entry);
|
||||
palette->colors = g_list_insert (palette->colors,
|
||||
entry, position);
|
||||
|
||||
if (pos < position)
|
||||
{
|
||||
for (list = g_list_nth (palette->colors, pos);
|
||||
list && pos < position;
|
||||
list = g_list_next (list))
|
||||
{
|
||||
entry = (GimpPaletteEntry *) list->data;
|
||||
|
||||
entry->position = pos++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (list = g_list_nth (palette->colors, position + 1);
|
||||
list && position < pos;
|
||||
list = g_list_next (list))
|
||||
{
|
||||
entry = (GimpPaletteEntry *) list->data;
|
||||
|
||||
entry->position += 1;
|
||||
pos--;
|
||||
}
|
||||
}
|
||||
|
||||
gimp_data_dirty (GIMP_DATA (palette));
|
||||
}
|
||||
}
|
||||
|
@ -464,25 +431,11 @@ gimp_palette_add_entry (GimpPalette *palette,
|
|||
|
||||
if (position < 0 || position >= palette->n_colors)
|
||||
{
|
||||
entry->position = palette->n_colors;
|
||||
palette->colors = g_list_append (palette->colors, entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
GList *list;
|
||||
|
||||
entry->position = position;
|
||||
palette->colors = g_list_insert (palette->colors, entry, position);
|
||||
|
||||
/* renumber the displaced entries */
|
||||
for (list = g_list_nth (palette->colors, position + 1);
|
||||
list;
|
||||
list = g_list_next (list))
|
||||
{
|
||||
GimpPaletteEntry *entry2 = list->data;
|
||||
|
||||
entry2->position += 1;
|
||||
}
|
||||
}
|
||||
|
||||
palette->n_colors += 1;
|
||||
|
@ -496,30 +449,17 @@ void
|
|||
gimp_palette_delete_entry (GimpPalette *palette,
|
||||
GimpPaletteEntry *entry)
|
||||
{
|
||||
GList *list;
|
||||
gint pos = 0;
|
||||
|
||||
g_return_if_fail (GIMP_IS_PALETTE (palette));
|
||||
g_return_if_fail (entry != NULL);
|
||||
|
||||
if (g_list_find (palette->colors, entry))
|
||||
{
|
||||
pos = entry->position;
|
||||
gimp_palette_entry_free (entry);
|
||||
|
||||
palette->colors = g_list_remove (palette->colors, entry);
|
||||
|
||||
palette->n_colors--;
|
||||
|
||||
for (list = g_list_nth (palette->colors, pos);
|
||||
list;
|
||||
list = g_list_next (list))
|
||||
{
|
||||
entry = (GimpPaletteEntry *) list->data;
|
||||
|
||||
entry->position = pos++;
|
||||
}
|
||||
|
||||
gimp_data_dirty (GIMP_DATA (palette));
|
||||
}
|
||||
}
|
||||
|
@ -607,6 +547,16 @@ gimp_palette_get_entry (GimpPalette *palette,
|
|||
return g_list_nth_data (palette->colors, position);
|
||||
}
|
||||
|
||||
gint
|
||||
gimp_palette_get_entry_position (GimpPalette *palette,
|
||||
GimpPaletteEntry *entry)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_PALETTE (palette), -1);
|
||||
g_return_val_if_fail (entry != NULL, -1);
|
||||
|
||||
return g_list_index (palette->colors, entry);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_palette_set_columns (GimpPalette *palette,
|
||||
gint columns)
|
||||
|
|
|
@ -34,9 +34,6 @@ struct _GimpPaletteEntry
|
|||
{
|
||||
GimpRGB color;
|
||||
gchar *name;
|
||||
|
||||
/* EEK */
|
||||
gint position;
|
||||
};
|
||||
|
||||
|
||||
|
@ -90,6 +87,8 @@ gboolean gimp_palette_set_entry_name (GimpPalette *palette,
|
|||
const gchar *name);
|
||||
GimpPaletteEntry * gimp_palette_get_entry (GimpPalette *palette,
|
||||
gint position);
|
||||
gint gimp_palette_get_entry_position (GimpPalette *palette,
|
||||
GimpPaletteEntry *entry);
|
||||
|
||||
void gimp_palette_set_columns (GimpPalette *palette,
|
||||
gint columns);
|
||||
|
|
|
@ -400,7 +400,7 @@ palette_add_entry_invoker (GimpProcedure *procedure,
|
|||
GimpPaletteEntry *entry =
|
||||
gimp_palette_add_entry (palette, -1, entry_name, &color);
|
||||
|
||||
entry_num = entry->position;
|
||||
entry_num = gimp_palette_get_entry_position (palette, entry);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
|
|
|
@ -590,7 +590,12 @@ gimp_colormap_selection_entry_clicked (GimpPaletteView *view,
|
|||
GdkModifierType state,
|
||||
GimpColormapSelection *selection)
|
||||
{
|
||||
gimp_colormap_selection_set_index (selection, entry->position, NULL);
|
||||
GimpPalette *palette;
|
||||
gint index;
|
||||
|
||||
palette = gimp_image_get_colormap_palette (selection->active_image);
|
||||
index = gimp_palette_get_entry_position (palette, entry);
|
||||
gimp_colormap_selection_set_index (selection, index, NULL);
|
||||
|
||||
g_signal_emit (selection, signals[COLOR_CLICKED], 0, entry, state);
|
||||
}
|
||||
|
@ -600,7 +605,12 @@ gimp_colormap_selection_entry_selected (GimpPaletteView *view,
|
|||
GimpPaletteEntry *entry,
|
||||
GimpColormapSelection *selection)
|
||||
{
|
||||
gint index = entry ? entry->position : 0;
|
||||
GimpPalette *palette;
|
||||
gint index = 0;
|
||||
|
||||
palette = gimp_image_get_colormap_palette (selection->active_image);
|
||||
if (entry)
|
||||
index = gimp_palette_get_entry_position (palette, entry);
|
||||
|
||||
gimp_colormap_selection_set_index (selection, index, NULL);
|
||||
}
|
||||
|
@ -610,7 +620,12 @@ gimp_colormap_selection_entry_activated (GimpPaletteView *view,
|
|||
GimpPaletteEntry *entry,
|
||||
GimpColormapSelection *selection)
|
||||
{
|
||||
gimp_colormap_selection_set_index (selection, entry->position, NULL);
|
||||
GimpPalette *palette;
|
||||
gint index;
|
||||
|
||||
palette = gimp_image_get_colormap_palette (selection->active_image);
|
||||
index = gimp_palette_get_entry_position (palette, entry);
|
||||
gimp_colormap_selection_set_index (selection, index, NULL);
|
||||
|
||||
g_signal_emit (selection, signals[COLOR_ACTIVATED], 0, entry);
|
||||
}
|
||||
|
|
|
@ -537,12 +537,14 @@ gimp_palette_editor_pick_color (GimpPaletteEditor *editor,
|
|||
gint index = -1;
|
||||
|
||||
data = gimp_data_editor_get_data (GIMP_DATA_EDITOR (editor));
|
||||
index = gimp_palette_get_entry_position (GIMP_PALETTE (data),
|
||||
editor->color);
|
||||
|
||||
switch (pick_state)
|
||||
{
|
||||
case GIMP_COLOR_PICK_STATE_START:
|
||||
if (editor->color)
|
||||
index = editor->color->position + 1;
|
||||
index += 1;
|
||||
|
||||
entry = gimp_palette_add_entry (GIMP_PALETTE (data), index,
|
||||
NULL, color);
|
||||
|
@ -553,8 +555,7 @@ gimp_palette_editor_pick_color (GimpPaletteEditor *editor,
|
|||
case GIMP_COLOR_PICK_STATE_UPDATE:
|
||||
case GIMP_COLOR_PICK_STATE_END:
|
||||
gimp_palette_set_entry_color (GIMP_PALETTE (data),
|
||||
editor->color->position,
|
||||
color);
|
||||
index, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -649,7 +650,7 @@ gimp_palette_editor_get_index (GimpPaletteEditor *editor,
|
|||
entry = gimp_palette_find_entry (palette, search, editor->color);
|
||||
|
||||
if (entry)
|
||||
return entry->position;
|
||||
return gimp_palette_get_entry_position (palette, entry);
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -792,9 +793,17 @@ palette_editor_entry_selected (GimpPaletteView *view,
|
|||
editor->color = entry;
|
||||
|
||||
if (entry)
|
||||
g_snprintf (index, sizeof (index), "%04i", entry->position);
|
||||
{
|
||||
GimpPalette *palette = GIMP_PALETTE (data_editor->data);
|
||||
gint pos;
|
||||
|
||||
pos = gimp_palette_get_entry_position (palette, entry);
|
||||
g_snprintf (index, sizeof (index), "%04i", pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_snprintf (index, sizeof (index), "####");
|
||||
}
|
||||
|
||||
gtk_label_set_text (GTK_LABEL (editor->index_label), index);
|
||||
|
||||
|
@ -877,7 +886,7 @@ palette_editor_color_dropped (GimpPaletteView *view,
|
|||
gint pos = -1;
|
||||
|
||||
if (entry)
|
||||
pos = entry->position;
|
||||
pos = gimp_palette_get_entry_position (palette, entry);
|
||||
|
||||
entry = gimp_palette_add_entry (palette, pos, NULL, color);
|
||||
gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view), entry);
|
||||
|
@ -895,10 +904,12 @@ palette_editor_color_name_changed (GtkWidget *widget,
|
|||
{
|
||||
GimpPalette *palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
|
||||
const gchar *name;
|
||||
gint pos;
|
||||
|
||||
name = gtk_entry_get_text (GTK_ENTRY (editor->color_name));
|
||||
|
||||
gimp_palette_set_entry_name (palette, editor->color->position, name);
|
||||
pos = gimp_palette_get_entry_position (palette, editor->color);
|
||||
gimp_palette_set_entry_name (palette, pos, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -152,6 +152,9 @@ gimp_palette_view_draw (GtkWidget *widget,
|
|||
{
|
||||
GimpPaletteView *pal_view = GIMP_PALETTE_VIEW (widget);
|
||||
GimpView *view = GIMP_VIEW (widget);
|
||||
GimpPalette *palette;
|
||||
|
||||
palette = GIMP_PALETTE (GIMP_VIEW (view)->renderer->viewable);
|
||||
|
||||
cairo_save (cr);
|
||||
GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
|
||||
|
@ -161,14 +164,16 @@ gimp_palette_view_draw (GtkWidget *widget,
|
|||
{
|
||||
GimpViewRendererPalette *renderer;
|
||||
GtkAllocation allocation;
|
||||
gint row, col;
|
||||
gint pos, 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;
|
||||
pos = gimp_palette_get_entry_position (palette, pal_view->selected);
|
||||
|
||||
row = pos / renderer->columns;
|
||||
col = pos % renderer->columns;
|
||||
|
||||
cairo_rectangle (cr,
|
||||
col * renderer->cell_width + 0.5,
|
||||
|
@ -310,9 +315,12 @@ gimp_palette_view_focus (GtkWidget *widget,
|
|||
if (skip != 0)
|
||||
{
|
||||
GimpPaletteEntry *entry;
|
||||
GimpPalette *palette;
|
||||
gint position;
|
||||
|
||||
position = view->selected->position + skip;
|
||||
palette = GIMP_PALETTE (GIMP_VIEW (view)->renderer->viewable);
|
||||
position = gimp_palette_get_entry_position (palette, view->selected);
|
||||
position += skip;
|
||||
|
||||
entry = gimp_palette_get_entry (palette, position);
|
||||
|
||||
|
@ -410,8 +418,9 @@ gimp_palette_view_get_entry_rect (GimpPaletteView *view,
|
|||
GdkRectangle *rect)
|
||||
{
|
||||
GimpViewRendererPalette *renderer;
|
||||
GimpPalette *palette;
|
||||
GtkAllocation allocation;
|
||||
gint row, col;
|
||||
gint pos, row, col;
|
||||
|
||||
g_return_if_fail (GIMP_IS_PALETTE_VIEW (view));
|
||||
g_return_if_fail (entry);
|
||||
|
@ -420,8 +429,10 @@ gimp_palette_view_get_entry_rect (GimpPaletteView *view,
|
|||
gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
|
||||
|
||||
renderer = GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (view)->renderer);
|
||||
row = entry->position / renderer->columns;
|
||||
col = entry->position % renderer->columns;
|
||||
palette = GIMP_PALETTE (GIMP_VIEW_RENDERER (renderer)->viewable);
|
||||
pos = gimp_palette_get_entry_position (palette, entry);
|
||||
row = pos / renderer->columns;
|
||||
col = pos % renderer->columns;
|
||||
|
||||
rect->x = allocation.x + col * renderer->cell_width;
|
||||
rect->y = allocation.y + row * renderer->cell_height;
|
||||
|
@ -442,8 +453,8 @@ gimp_palette_view_find_entry (GimpPaletteView *view,
|
|||
GimpPaletteEntry *entry = NULL;
|
||||
gint col, row;
|
||||
|
||||
palette = GIMP_PALETTE (GIMP_VIEW (view)->renderer->viewable);
|
||||
renderer = GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (view)->renderer);
|
||||
palette = GIMP_PALETTE (GIMP_VIEW_RENDERER (renderer)->viewable);
|
||||
|
||||
if (! palette || ! gimp_palette_get_n_colors (palette))
|
||||
return NULL;
|
||||
|
@ -466,16 +477,19 @@ gimp_palette_view_expose_entry (GimpPaletteView *view,
|
|||
GimpPaletteEntry *entry)
|
||||
{
|
||||
GimpViewRendererPalette *renderer;
|
||||
gint row, col;
|
||||
gint pos, row, col;
|
||||
GtkWidget *widget = GTK_WIDGET (view);
|
||||
GtkAllocation allocation;
|
||||
GimpPalette *palette;
|
||||
|
||||
renderer = GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (view)->renderer);
|
||||
palette = GIMP_PALETTE (GIMP_VIEW_RENDERER (renderer)->viewable);
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
row = entry->position / renderer->columns;
|
||||
col = entry->position % renderer->columns;
|
||||
pos = gimp_palette_get_entry_position (palette, entry);
|
||||
row = pos / renderer->columns;
|
||||
col = pos % renderer->columns;
|
||||
|
||||
gtk_widget_queue_draw_area (GTK_WIDGET (view),
|
||||
allocation.x + col * renderer->cell_width,
|
||||
|
|
|
@ -359,7 +359,7 @@ HELP
|
|||
GimpPaletteEntry *entry =
|
||||
gimp_palette_add_entry (palette, -1, entry_name, &color);
|
||||
|
||||
entry_num = entry->position;
|
||||
entry_num = gimp_palette_get_entry_position (palette, entry);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
|
|
Loading…
Reference in New Issue