Commit ef1db26b authored by David Odin's avatar David Odin
Browse files

plug-ins/gfig/gfig-dialog.c plug-ins/gfig/gfig-dialog.h

* plug-ins/gfig/gfig-dialog.c
* plug-ins/gfig/gfig-dialog.h
* plug-ins/gfig/gfig-dobject.c
* plug-ins/gfig/gfig-dobject.h
* plug-ins/gfig/gfig-types.h
* plug-ins/gfig/gfig.c
* plug-ins/gfig/gfig.h: replace the crappy DAllObjs struct by a GList.
  Makes the code cleaner and less error prone.
parent 6e1ea086
2004-11-14 DindinX <dindinx@gimp.org>
* plug-ins/gfig/gfig-dialog.c
* plug-ins/gfig/gfig-dialog.h
* plug-ins/gfig/gfig-dobject.c
* plug-ins/gfig/gfig-dobject.h
* plug-ins/gfig/gfig-types.h
* plug-ins/gfig/gfig.c
* plug-ins/gfig/gfig.h: replace the crappy DAllObjs struct by a GList.
Makes the code cleaner and less error prone.
2004-11-14 Sven Neumann <sven@gimp.org>
 
* plug-ins/pagecurl/pagecurl.c: applied a patch from Karine Proot
......
......@@ -939,42 +939,25 @@ static void
raise_selected_obj_to_top (GtkWidget *widget,
gpointer data)
{
DAllObjs *entry;
DAllObjs *prev_entry = NULL;
DAllObjs *found_entry = NULL;
if (!gfig_context->selected_obj)
return;
entry = gfig_context->current_obj->obj_list;
while (entry)
if (g_list_find (gfig_context->current_obj->obj_list,
gfig_context->selected_obj))
{
if (entry->obj == gfig_context->selected_obj)
{
/* Found the entry to raise, remove it from list */
found_entry = entry;
if (prev_entry)
prev_entry->next = entry->next;
else
gfig_context->current_obj->obj_list = entry->next;
}
prev_entry = entry;
entry = entry->next;
gfig_context->current_obj->obj_list =
g_list_remove (gfig_context->current_obj->obj_list,
gfig_context->selected_obj);
gfig_context->current_obj->obj_list =
g_list_append (gfig_context->current_obj->obj_list,
gfig_context->selected_obj);
}
if (!found_entry)
else
{
g_message ("Trying to raise object that does not exist.");
return;
}
/* tack found entry onto end of list */
prev_entry->next = found_entry;
found_entry->next = NULL;
gfig_paint_callback ();
}
......@@ -982,46 +965,25 @@ static void
lower_selected_obj_to_bottom (GtkWidget *widget,
gpointer data)
{
DAllObjs *entry;
DAllObjs *prev_entry = NULL;
DAllObjs *found_entry = NULL;
if (!gfig_context->selected_obj)
return;
entry = gfig_context->current_obj->obj_list;
while (entry)
if (g_list_find (gfig_context->current_obj->obj_list,
gfig_context->selected_obj))
{
if (entry->obj == gfig_context->selected_obj)
{
/* Found the entry to lower, remove it from list */
found_entry = entry;
if (prev_entry)
{
prev_entry->next = found_entry->next;
break;
}
else
/* it's already at the bottom */
return;
}
prev_entry = entry;
entry = entry->next;
gfig_context->current_obj->obj_list =
g_list_remove (gfig_context->current_obj->obj_list,
gfig_context->selected_obj);
gfig_context->current_obj->obj_list =
g_list_prepend (gfig_context->current_obj->obj_list,
gfig_context->selected_obj);
}
if (!found_entry)
else
{
g_message ("Trying to raise object that does not exist.");
g_message ("Trying to lower object that does not exist.");
return;
}
/* stick found entry into beginning of list */
found_entry->next = gfig_context->current_obj->obj_list;
gfig_context->current_obj->obj_list = found_entry;
gfig_paint_callback ();
}
......@@ -1029,46 +991,25 @@ static void
raise_selected_obj (GtkWidget *widget,
gpointer data)
{
DAllObjs *entry;
DAllObjs *prev_entry = NULL;
DAllObjs *following_entry = NULL;
DAllObjs *found_entry = NULL;
if (!gfig_context->selected_obj)
return;
entry = gfig_context->current_obj->obj_list;
while (entry)
if (g_list_find (gfig_context->current_obj->obj_list,
gfig_context->selected_obj))
{
if (entry->obj == gfig_context->selected_obj)
{
/* Found the entry to raise, remove it from list */
found_entry = entry;
following_entry = found_entry->next;
/* see if already on top */
if (!following_entry)
return;
if (prev_entry)
prev_entry->next = following_entry;
else
gfig_context->current_obj->obj_list = following_entry;
found_entry->next = following_entry->next;
following_entry->next = found_entry;
break;
}
prev_entry = entry;
entry = entry->next;
int position;
position = g_list_index (gfig_context->current_obj->obj_list,
gfig_context->selected_obj);
gfig_context->current_obj->obj_list =
g_list_remove (gfig_context->current_obj->obj_list,
gfig_context->selected_obj);
gfig_context->current_obj->obj_list =
g_list_insert (gfig_context->current_obj->obj_list,
gfig_context->selected_obj,
position + 1);
}
if (!found_entry)
else
{
g_message ("Trying to raise object that does not exist.");
return;
......@@ -1082,49 +1023,27 @@ static void
lower_selected_obj (GtkWidget *widget,
gpointer data)
{
DAllObjs *entry;
DAllObjs *prev_prev_entry = NULL;
DAllObjs *prev_entry = NULL;
DAllObjs *following_entry = NULL;
DAllObjs *found_entry = NULL;
if (!gfig_context->selected_obj)
return;
entry = gfig_context->current_obj->obj_list;
while (entry)
if (g_list_find (gfig_context->current_obj->obj_list,
gfig_context->selected_obj))
{
if (entry->obj == gfig_context->selected_obj)
{
/* Found the entry to lower, remove it from list */
found_entry = entry;
following_entry = found_entry->next;
/* see if already on bottom */
if (!prev_entry)
return;
prev_entry->next = following_entry;
found_entry->next = prev_entry;
if (prev_prev_entry)
prev_prev_entry->next = found_entry;
else
gfig_context->current_obj->obj_list = found_entry;
break;
}
prev_prev_entry = prev_entry;
prev_entry = entry;
entry = entry->next;
int position;
position = g_list_index (gfig_context->current_obj->obj_list,
gfig_context->selected_obj);
gfig_context->current_obj->obj_list =
g_list_remove (gfig_context->current_obj->obj_list,
gfig_context->selected_obj);
gfig_context->current_obj->obj_list =
g_list_insert (gfig_context->current_obj->obj_list,
gfig_context->selected_obj,
MAX (0, position - 1));
}
if (!found_entry)
else
{
g_message ("Trying to raise object that does not exist.");
g_message ("Trying to lower object that does not exist.");
return;
}
......@@ -1466,39 +1385,37 @@ save_file_chooser_response (GtkFileChooser *chooser,
static Dobject *
gfig_select_obj_by_number (gint count)
{
DAllObjs *objs = gfig_context->current_obj->obj_list;
gint k = 0;
GList *objs;
Dobject *object = NULL;
gint k;
gfig_context->selected_obj = NULL;
while (objs)
for (objs = gfig_context->current_obj->obj_list, k = 0;
objs;
objs = g_list_next (objs), k++)
{
if (k == obj_show_single)
{
gfig_context->selected_obj = objs->obj;
gfig_context->current_style = &objs->obj->style;
gfig_style_set_context_from_style (&objs->obj->style);
object = objs->data;
gfig_context->selected_obj = object;
gfig_context->current_style = &object->style;
gfig_style_set_context_from_style (&object->style);
break;
}
objs = objs->next;
k++;
}
return objs->obj;
return object;
}
static void
select_button_clicked (gint type)
{
gint count = 0;
DAllObjs *objs;
gint count = 0;
if (gfig_context->current_obj)
{
for (objs = gfig_context->current_obj->obj_list; objs; objs = objs->next)
count++;
count = g_list_length (gfig_context->current_obj->obj_list);
}
switch (type)
......@@ -1523,8 +1440,6 @@ select_button_clicked (gint type)
break;
}
objs = gfig_context->current_obj->obj_list;
if (obj_show_single >= 0)
gfig_select_obj_by_number (obj_show_single);
......@@ -1777,19 +1692,20 @@ paint_layer_fill (void)
void
gfig_paint_callback (void)
{
DAllObjs *objs;
gint layer_count = 0;
gchar buf[128];
gint count;
gint ccount = 0;
Style *style0;
GList *objs;
gint layer_count = 0;
gchar buf[128];
gint count;
gint ccount = 0;
Style *style0;
Dobject *object;
if (!gfig_context->enable_repaint || !gfig_context->current_obj)
return;
objs = gfig_context->current_obj->obj_list;
count = gfig_obj_counts (objs);
count = g_list_length (objs);
gimp_drawable_fill (gfig_context->drawable_id, GIMP_TRANSPARENT_FILL);
......@@ -1800,17 +1716,18 @@ gfig_paint_callback (void)
{
if (ccount == obj_show_single || obj_show_single == -1)
{
object = objs->data;
sprintf (buf, _("Gfig layer %d"), layer_count++);
gfig_style_apply (&objs->obj->style);
gfig_style_apply (&object->style);
objs->obj->class->paintfunc (objs->obj);
object->class->paintfunc (object);
gimp_selection_none (gfig_context->image_id);
}
objs = objs->next;
objs = g_list_next (objs);
ccount++;
}
......
......@@ -31,13 +31,13 @@
#define RESPONSE_SAVE 3
#define RESPONSE_PAINT 4
gint undo_water_mark; /* Last slot filled in -1 = no undo */
DAllObjs *undo_table[MAX_UNDO];
gint undo_water_mark; /* Last slot filled in -1 = no undo */
GList *undo_table[MAX_UNDO];
gint gfig_dialog (void);
void update_options (GFigObj *old_obj);
gint gfig_dialog (void);
void update_options (GFigObj *old_obj);
void tool_option_page_update (GtkWidget *button,
GtkWidget *notebook);
void tool_option_page_update (GtkWidget *button,
GtkWidget *notebook);
#endif /* __GFIG_DIALOG_H__ */
<
......@@ -321,16 +321,16 @@ get_nearest_objs (GFigObj *obj,
GdkPoint *pnt)
{
/* Nearest object to given point or NULL */
DAllObjs *all;
Dobject *test_obj;
gint count = 0;
GList *all;
Dobject *test_obj;
gint count = 0;
if (!obj)
return NULL;
for (all = obj->obj_list; all; all = all->next)
for (all = obj->obj_list; all; all = g_list_next (all))
{
test_obj = all->obj;
test_obj = all->data;
if (count == obj_show_single || obj_show_single == -1)
if (scan_obj_points (test_obj->points, pnt))
......@@ -558,41 +558,26 @@ remove_obj_from_list (GFigObj *obj,
Dobject *del_obj)
{
/* Nearest object to given point or NULL */
DAllObjs *entry;
DAllObjs *prev_entry = NULL;
g_assert (del_obj != NULL);
entry = obj->obj_list;
while (entry)
if (g_list_find (obj->obj_list, del_obj))
{
if (entry->obj == del_obj)
{
/* Found the one to delete */
if (prev_entry)
prev_entry->next = entry->next;
else
obj->obj_list = entry->next;
del_obj->class->drawfunc (del_obj);
/* Draw obj (which will actually undraw it! */
del_obj->class->drawfunc (del_obj);
obj->obj_list = g_list_remove (obj->obj_list, del_obj);
free_one_obj (del_obj);
g_free (entry);
free_one_obj (del_obj);
if (obj_show_single != -1)
{
/* We've just deleted the only visible one */
draw_grid_clear ();
obj_show_single = -1; /* Show entry again */
}
return;
if (obj_show_single != -1)
{
/* We've just deleted the only visible one */
draw_grid_clear ();
obj_show_single = -1; /* Show entry again */
}
prev_entry = entry;
entry = entry->next;
}
g_warning (_("Hey where has the object gone ?"));
else
g_warning (_("Hey where has the object gone ?"));
}
static void
......@@ -605,11 +590,11 @@ do_move_all_obj (GdkPoint *to_pnt)
if (xdiff || ydiff)
{
DAllObjs *all;
GList *all;
for (all = gfig_context->current_obj->obj_list; all; all = all->next)
{
Dobject *obj = all->obj;
Dobject *obj = all->data;
/* undraw ! */
draw_one_obj (obj);
......@@ -685,33 +670,22 @@ do_move_obj_pnt (Dobject *obj,
}
/* copy objs */
DAllObjs *
copy_all_objs (DAllObjs *objs)
GList *
copy_all_objs (GList *objs)
{
DAllObjs *nobj;
DAllObjs *new_all_objs = NULL;
DAllObjs *ret = NULL;
GList *new_all_objs = NULL;
while (objs)
{
nobj = g_new0 (DAllObjs, 1);
if (!ret)
{
ret = new_all_objs = nobj;
}
else
{
new_all_objs->next = nobj;
new_all_objs = nobj;
}
Dobject *object = objs->data;
Dobject *new_object = (Dobject *) object->class->copyfunc (object);
nobj->obj = (Dobject *) objs->obj->class->copyfunc (objs->obj);
new_all_objs = g_list_append (new_all_objs, new_object);
objs = objs->next;
}
return ret;
return new_all_objs;
}
/* Screen refresh */
......@@ -722,8 +696,8 @@ draw_one_obj (Dobject * obj)
}
void
draw_objects (DAllObjs *objs,
gint show_single)
draw_objects (GList *objs,
gboolean show_single)
{
/* Show_single - only one object to draw Unless shift
* is down in which case show all.
......@@ -734,35 +708,20 @@ draw_objects (DAllObjs *objs,
while (objs)
{
if (!show_single || count == obj_show_single || obj_show_single == -1)
draw_one_obj (objs->obj);
draw_one_obj (objs->data);
objs = objs->next;
objs = g_list_next (objs);
count++;
}
}
void
prepend_to_all_obj (GFigObj *fobj,
DAllObjs *nobj)
prepend_to_all_obj (GFigObj *fobj,
GList *nobj)
{
DAllObjs *cobj;
setup_undo (); /* Remember ME */
if (!fobj->obj_list)
{
fobj->obj_list = nobj;
return;
}
cobj = fobj->obj_list;
while (cobj->next)
{
cobj = cobj->next;
}
cobj->next = nobj;
fobj->obj_list = g_list_concat (fobj->obj_list, nobj);
}
static void
......@@ -782,11 +741,9 @@ void
add_to_all_obj (GFigObj *fobj,
Dobject *obj)
{
DAllObjs *nobj;
GList *nobj = NULL;
nobj = g_new0 (DAllObjs, 1);
nobj->obj = obj;
nobj = g_list_append (nobj, obj);
if (need_to_scale)
scale_obj_points (obj->points, scale_x_factor, scale_y_factor);
......@@ -981,18 +938,10 @@ free_one_obj (Dobject *obj)
}
void
free_all_objs (DAllObjs * objs)
free_all_objs (GList * objs)
{
/* Free all objects */
DAllObjs * next;
while (objs)
{
free_one_obj (objs->obj);
next = objs->next;
g_free (objs);
objs = next;
}
g_list_foreach (objs, (GFunc)free_one_obj, NULL);
g_list_free (objs);
}
gchar *
......@@ -1070,7 +1019,7 @@ setup_undo (void)
int loop;
/* the little one in the bed said "roll over".. */
if (undo_table[0])
free_one_obj (undo_table[0]->obj);
free_one_obj (undo_table[0]->data);
for (loop = 0; loop < undo_water_mark; loop++)
{
undo_table[loop] = undo_table[loop + 1];
......@@ -1125,14 +1074,3 @@ new_obj_2edit (GFigObj *obj)
}
}
gint
gfig_obj_counts (DAllObjs *objs)
{
gint count = 0;
for (; objs; objs = objs->next)
count++;
return count;