Commit ec0f00b8 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

even more undeprecated, some cleanup.

2003-01-06  Michael Natterer  <mitch@gimp.org>

	* plug-ins/gfig/gfig.c: even more undeprecated, some cleanup.
parent 4f3b58d3
2003-01-06 Michael Natterer <mitch@gimp.org>
* plug-ins/gfig/gfig.c: even more undeprecated, some cleanup.
2003-01-06 Sven Neumann <sven@gimp.org>
 
* plug-ins/gfig/gfig.c: made it a lot less deprecated. Removed
......
......@@ -48,8 +48,6 @@
#include "config.h"
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -71,22 +69,6 @@
# ifndef W_OK
# define W_OK 2
# endif
# ifndef S_ISDIR
# define S_ISDIR(m) ((m) & _S_IFDIR)
# endif
# ifndef S_ISREG
# define S_ISREG(m) ((m) & _S_IFREG)
# endif
#endif
#if defined (GTK_CHECK_VERSION) && GTK_CHECK_VERSION (1,3,0)
#define gdk_root_parent (*gdk_parent_root)
#endif
#ifdef G_OS_WIN32
extern __declspec(dllimport) void *gdk_root_parent;
#else
extern void * gdk_root_parent;
#endif
#include <libgimp/gimp.h>
......@@ -96,19 +78,20 @@ extern void * gdk_root_parent;
#include "pix_data.h"
/***** Magic numbers *****/
#define PREVIEW_SIZE 400
#define SCALE_WIDTH 120
#define PREVIEW_SIZE 400
#define SCALE_WIDTH 120
#define MIN_GRID 10
#define MAX_GRID 50
#define MAX_UNDO 10
#define MIN_UNDO 1
#define MAX_LOAD_LINE 256
#define MIN_GRID 10
#define MAX_GRID 50
#define MAX_UNDO 10
#define MIN_UNDO 1
#define MAX_LOAD_LINE 256
#define SMALL_PREVIEW_SZ 48
#define BRUSH_PREVIEW_SZ 32
#define GFIG_HEADER "GFIG Version 0.1\n"
#define GFIG_HEADER "GFIG Version 0.1\n"
#define PREVIEW_MASK (GDK_EXPOSURE_MASK | \
GDK_POINTER_MOTION_MASK | \
......@@ -119,23 +102,23 @@ extern void * gdk_root_parent;
GDK_KEY_RELEASE_MASK)
static GimpDrawable *gfig_select_drawable;
static GtkWidget *gfig_preview;
static GtkWidget *pic_preview;
static GtkWidget *gfig_gtk_list;
static gint gfig_preview_exp_id;
static gint32 gfig_image;
static gint32 gfig_drawable;
static GtkWidget *brush_page_pw;
static GtkWidget *brush_sel_button;
static GtkWidget *gfig_preview;
static GtkWidget *pic_preview;
static GtkWidget *gfig_gtk_list;
static gint gfig_preview_exp_id;
static gint32 gfig_image;
static gint32 gfig_drawable;
static GtkWidget *brush_page_pw;
static GtkWidget *brush_sel_button;
static gint tile_width, tile_height;
static gint img_width, img_height, img_bpp, real_img_bpp;
static void query (void);
static void run (gchar *name,
gint nparams,
static void run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
gint *nreturn_vals,
GimpParam **return_vals);
static gint gfig_dialog (void);
......@@ -288,22 +271,22 @@ typedef enum
} BrushType;
#define GRID_TYPE_MENU 1
#define GRID_TYPE_MENU 1
#define GRID_RENDER_MENU 2
#define GRID_IGNORE 0
#define GRID_HIGHTLIGHT 1
#define GRID_RESTORE 2
#define GRID_IGNORE 0
#define GRID_HIGHTLIGHT 1
#define GRID_RESTORE 2
#define GFIG_BLACK_GC -2
#define GFIG_WHITE_GC -3
#define GFIG_GREY_GC -4
#define GFIG_GREY_GC -4
#define PAINT_LAYERS_MENU 1
#define PAINT_BGS_MENU 2
#define PAINT_TYPE_MENU 3
#define PAINT_BGS_MENU 2
#define PAINT_TYPE_MENU 3
#define SELECT_TYPE_MENU 1
#define SELECT_ARCTYPE_MENU 2
#define SELECT_TYPE_MENU 1
#define SELECT_ARCTYPE_MENU 2
#define SELECT_TYPE_MENU_FILL 3
#define SELECT_TYPE_MENU_WHEN 4
......@@ -352,7 +335,7 @@ typedef struct
gint scaletoimage;
gdouble scaletoimagefp;
gint approxcircles;
BrushType brshtype;
BrushType brshtype;
DobjType otype;
} SelectItVals;
......@@ -387,24 +370,24 @@ static SelectItVals selvals =
typedef enum
{
ADD=0,
SUBTRACT=1,
REPLACE=2,
INTERSECT=3
ADD = 0,
SUBTRACT,
REPLACE,
INTERSECT
} SelectionType;
typedef enum
{
ARC_SEGMENT,
ARC_SEGMENT = 0,
ARC_SECTOR
} ArcType;
typedef enum
{
FILL_FOREGROUND = 0,
FILL_BACKGROUND = 1,
FILL_PATTERN = 2
FILL_BACKGROUND,
FILL_PATTERN
} FillType;
typedef enum
......@@ -415,24 +398,24 @@ typedef enum
struct selection_option
{
SelectionType type; /* ADD etc .. */
gint antia; /* Boolean for Antia */
gint feather; /* Feather it ? */
gdouble feather_radius; /* Radius to feather */
ArcType as_pie; /* Arc type selection segment/sector */
FillType fill_type; /* Fill type for selection */
FillWhen fill_when; /* Fill on each selection or after all? */
gdouble fill_opacity; /* You can guess this one */
SelectionType type; /* ADD etc .. */
gint antia; /* Boolean for Antia */
gint feather; /* Feather it ? */
gdouble feather_radius; /* Radius to feather */
ArcType as_pie; /* Arc type selection segment/sector */
FillType fill_type; /* Fill type for selection */
FillWhen fill_when; /* Fill on each selection or after all? */
gdouble fill_opacity; /* You can guess this one */
} selopt =
{
ADD, /* type */
FALSE, /* Antia */
FALSE, /* Feather */
10.0, /* feather radius */
ADD, /* type */
FALSE, /* Antia */
FALSE, /* Feather */
10.0, /* feather radius */
ARC_SEGMENT, /* Arc as a segment */
FILL_PATTERN, /* Fill as pattern */
FILL_EACH, /* Fill after each selection */
100.0, /* Max opacity */
FILL_EACH, /* Fill after each selection */
100.0, /* Max opacity */
};
......@@ -447,33 +430,33 @@ static gint spiral_toggle = 0; /* 0 = clockwise -1 = anti-clockwise */
static gint bezier_closed = 0; /* Closed curve 0 = false 1 = true */
static gint bezier_line_frame = 0; /* Show frame = false 1 = true */
static gint obj_show_single = -1; /* -1 all >= 0 object number */
static gint obj_show_single = -1; /* -1 all >= 0 object number */
/* Structures etc for the objects */
/* Points used to draw the object */
typedef struct DobjPoints
{
struct DobjPoints * next;
GdkPoint pnt;
gint found_me;
struct DobjPoints *next;
GdkPoint pnt;
gint found_me;
} DobjPoints;
struct Dobject; /* fwd declaration for DobjFunc */
typedef void (*DobjFunc) (struct Dobject *);
typedef struct Dobject *(*DobjGenFunc) (struct Dobject *);
typedef void (*DobjFunc) (struct Dobject *);
typedef struct Dobject *(*DobjGenFunc) (struct Dobject *);
typedef struct Dobject *(*DobjLoadFunc) (FILE *);
typedef void (*DobjSaveFunc) (struct Dobject *, FILE *);
/* The object itself */
typedef struct Dobject
{
DobjType type; /* What is the type? */
DobjType type; /* What is the type? */
gint type_data; /* Extra data needed by the object */
DobjPoints *points; /* List of points */
DobjFunc drawfunc; /* How do I draw myself */
DobjPoints *points; /* List of points */
DobjFunc drawfunc; /* How do I draw myself */
DobjFunc paintfunc; /* Draw me on canvas */
DobjGenFunc copyfunc; /* copy */
DobjLoadFunc loadfunc; /* Load this type of object */
......@@ -482,8 +465,8 @@ typedef struct Dobject
static Dobject *obj_creating; /* Object we are creating */
static Dobject *tmp_line; /* Needed when drawing lines */
static Dobject *tmp_bezier; /* Neeed when drawing bezier curves */
static Dobject *tmp_line; /* Needed when drawing lines */
static Dobject *tmp_bezier; /* Neeed when drawing bezier curves */
typedef struct DAllObjs
{
......@@ -498,13 +481,13 @@ typedef struct DAllObjs
typedef struct DFigObj
{
gchar *name; /* Trailing name of file */
gchar *filename; /* Filename itself */
gchar *draw_name;/* Name of the drawing */
gchar *name; /* Trailing name of file */
gchar *filename; /* Filename itself */
gchar *draw_name; /* Name of the drawing */
gfloat version; /* Version number of data file */
GfigOpts opts; /* Options enforced when fig saved */
DAllObjs *obj_list; /* Objects that make up this list */
gint obj_status; /* See above for possible values */
GfigOpts opts; /* Options enforced when fig saved */
DAllObjs *obj_list; /* Objects that make up this list */
gint obj_status; /* See above for possible values */
GtkWidget *list_item;
GtkWidget *label_widget;
GtkWidget *pixmap_widget;
......@@ -513,13 +496,13 @@ typedef struct DFigObj
typedef struct BrushDesc
{
gchar *bname; /* name of the brush */
gint32 width; /* Width of brush */
gchar *bname; /* name of the brush */
gint32 width; /* Width of brush */
gint32 height; /* Height of brush */
guchar *pv_buf; /* Buffer where brush placed */
guchar *pv_buf; /* Buffer where brush placed */
gint16 x_off;
gint16 y_off;
gint bpp; /* Depth - should ALWAYS be the same for all BrushDesc */
gint bpp; /* Depth - should ALWAYS be the same for all BrushDesc */
} BrushDesc;
static GFigObj *current_obj;
......@@ -542,8 +525,8 @@ static GtkWidget *brush_page_widget; /* Widget for the brush part of notebook */
static GtkWidget *select_page_widget; /* Widget for the selection part
* of notebook */
static gint undo_water_mark = -1; /* Last slot filled in -1 = no undo */
static gint drawing_pic = FALSE; /* If true drawing to the small preview */
static gint undo_water_mark = -1; /* Last slot filled in -1 = no undo */
static gint drawing_pic = FALSE; /* If true drawing to the small preview */
static GtkWidget *status_label_dname;
static GtkWidget *status_label_fname;
static GFigObj *gfig_obj_for_menu; /* More static data -
......@@ -676,16 +659,16 @@ query (void)
}
static void
run (gchar *name,
gint nparams,
run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
gint *nreturn_vals,
GimpParam **return_vals)
{
GimpParam * values = g_new (GimpParam, 1);
GimpDrawable *drawable;
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpParam *values = g_new (GimpParam, 1);
GimpDrawable *drawable;
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint pwidth, pheight;
......@@ -727,7 +710,7 @@ run (gchar *name,
{
pheight = MIN (sel_height, PREVIEW_SIZE);
pwidth = sel_width * pheight / sel_height;
}
}
preview_width = MAX (pwidth, 2); /* Min size is 2 */
preview_height = MAX (pheight, 2);
......@@ -736,13 +719,13 @@ run (gchar *name,
(gdouble) sel_width / (gdouble) preview_width;
org_scale_y_factor = scale_y_factor =
(gdouble) sel_height / (gdouble) preview_height;
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
/*gimp_get_data ("plug_in_gfig", &selvals);*/
INIT_I18N_UI ();
if (!gfig_dialog ())
if (! gfig_dialog ())
{
gimp_drawable_detach (drawable);
return;
......@@ -969,6 +952,7 @@ gfig_free_everything (GFigObj *gfig)
#ifdef DEBUG
printf ("Removing filename '%s'\n", gfig->filename);
#endif /* DEBUG */
remove (gfig->filename);
}
......@@ -995,12 +979,12 @@ gfig_list_free_all (void)
static void
gfig_list_load_all (GList *plist)
{
GFigObj *gfig;
GList *list;
gchar *path;
gchar *filename;
GDir *dir;
const gchar *dir_ent;
GFigObj *gfig;
GList *list;
gchar *path;
gchar *filename;
GDir *dir;
const gchar *dir_ent;
/* Make sure to clear any existing gfigs */
current_obj = pic_obj = NULL;
......@@ -1051,8 +1035,8 @@ gfig_list_load_all (GList *plist)
gfig->draw_name = g_strdup (_("First Gfig"));
gfig_list_insert (gfig);
}
pic_obj = current_obj = gfig_list->data; /* set to first entry */
pic_obj = current_obj = gfig_list->data; /* set to first entry */
}
static GFigObj *
......@@ -1129,13 +1113,13 @@ static GFigObj *
gfig_load (const gchar *filename,
const gchar *name)
{
GFigObj * gfig;
FILE * fp;
gchar load_buf[MAX_LOAD_LINE];
gchar str_buf[MAX_LOAD_LINE];
gint chk_count;
gint load_count = 0;
GFigObj *gfig;
FILE *fp;
gchar load_buf[MAX_LOAD_LINE];
gchar str_buf[MAX_LOAD_LINE];
gint chk_count;
gint load_count = 0;
g_assert (filename != NULL);
#ifdef DEBUG
......@@ -1319,6 +1303,7 @@ update_options (GFigObj *old_obj)
(GTK_MENU (gtk_option_menu_get_menu
(GTK_OPTION_MENU (gfig_opt_widget.gridtypemenu)))),
GINT_TO_POINTER (GRID_TYPE_MENU));
#ifdef DEBUG
printf ("Gridtype set in options to ");
if (current_obj->opts.gridtype == RECT_GRID)
......@@ -1413,6 +1398,7 @@ load_options (GFigObj *gfig,
}
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
#ifdef DEBUG
printf ("opt line '%s'\n", load_buf);
#endif /* DEBUG */
......@@ -1437,13 +1423,13 @@ gfig_obj_counts (DAllObjs *objs)
static void
gfig_save_callbk (void)
{
FILE *fp;
DAllObjs * objs;
gint count = 0;
gchar *savename;
gchar *message;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
gchar conv_buf[MAX_LOAD_LINE*3 +1];
FILE *fp;
DAllObjs *objs;
gint count = 0;
gchar *savename;
gchar *message;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
gchar conv_buf[MAX_LOAD_LINE*3 +1];
savename = current_obj->filename;
......@@ -1508,10 +1494,11 @@ file_selection_ok (GtkWidget *w,
gpointer data)
{
const gchar *filenamebuf;
GFigObj *obj = (GFigObj *)gtk_object_get_user_data (GTK_OBJECT (fs));
GFigObj *real_current;
GFigObj *obj = g_object_get_data (G_OBJECT (fs), "user_data");
GFigObj *real_current;
filenamebuf = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
#ifdef DEBUG
g_print ("name selected '%s'\n", filenamebuf);
#endif /* DEBUG */
......@@ -1555,7 +1542,7 @@ create_file_selection (GFigObj *obj,
G_CALLBACK (gtk_widget_destroyed),
&window);
gtk_object_set_user_data (GTK_OBJECT (window), obj);
g_object_set_data (G_OBJECT (window), "user_data", obj);
g_signal_connect (GTK_FILE_SELECTION (window)->ok_button, "clicked",
G_CALLBACK (file_selection_ok),
window);
......@@ -1615,11 +1602,11 @@ void * yyy;
static void
cache_preview (void)
{
GimpPixelRgn src_rgn;
int y, x;
guchar *src_rows;
guchar *p;
int isgrey = 0;
GimpPixelRgn src_rgn;
gint y, x;
guchar *src_rows;
guchar *p;
gint isgrey = 0;
gimp_pixel_rgn_init (&src_rgn, gfig_select_drawable,
sel_x1, sel_y1, sel_width, sel_height, FALSE, FALSE);
......@@ -1659,27 +1646,29 @@ cache_preview (void)
sel_y1 + (y*sel_height)/preview_height,
sel_width);
for (x = 0; x < (preview_width); x ++)
{
/* Get the pixels of each col */
int i;
for (i = 0 ; i < 3; i++)
p[x*img_bpp+i] =
src_rows[((x*sel_width)/preview_width)*src_rgn.bpp +((isgrey)?0:i)];
if (has_alpha)
p[x*img_bpp+3] =
src_rows[((x*sel_width)/preview_width)*src_rgn.bpp + ((isgrey)?1:3)];
}
p += (preview_width*img_bpp);
for (x = 0; x < (preview_width); x ++)
{
/* Get the pixels of each col */
gint i;
for (i = 0 ; i < 3; i++)
p[x*img_bpp+i] =
src_rows[((x*sel_width)/preview_width)*src_rgn.bpp +((isgrey)?0:i)];
if (has_alpha)
p[x*img_bpp+3] =
src_rows[((x*sel_width)/preview_width)*src_rgn.bpp + ((isgrey)?1:3)];
}
p += (preview_width*img_bpp);
}
g_free (src_rows);
}
static void
refill_cache (void)
{
GdkCursorType ctype1 = GDK_WATCH;
GdkCursorType ctype2 = GDK_TOP_LEFT_ARROW;
GdkCursorType ctype1 = GDK_WATCH;
GdkCursorType ctype2 = GDK_TOP_LEFT_ARROW;
static GdkCursor *preview_cursor1;
static GdkCursor *preview_cursor2;
......@@ -1755,9 +1744,9 @@ select_button_press (GtkWidget *widget,
GdkEventButton *event,
gpointer data)
{
gint type = GPOINTER_TO_INT (data);
gint count = 0;
DAllObjs * objs;
gint type = GPOINTER_TO_INT (data);
gint count = 0;
DAllObjs *objs;
if (current_obj)
{
......@@ -1777,14 +1766,17 @@ select_button_press (GtkWidget *widget,
if (obj_show_single < 0)
obj_show_single = count - 1;
break;
case OBJ_SELECT_GT:
obj_show_single++;
if (obj_show_single >= count)
obj_show_single = 0;
break;
case OBJ_SELECT_EQ:
obj_show_single = -1; /* Reset to show all */
break;
default:
break;
}
......@@ -1847,7 +1839,7 @@ but_with_pix (gchar **pixdata,
GINT_TO_POINTER (baction));
gtk_widget_show (button);
*group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
*group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_add (GTK_CONTAINER (button), alignment);
......@@ -1867,7 +1859,7 @@ small_preview (GtkWidget *list)
GtkWidget *frame;
GtkWidget *button;
GtkWidget *vbox;
gint y;
gint y;
vbox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox);
......@@ -2217,13 +2209,13 @@ gfig_brush_preview_events (GtkWidget *widget,
point.x = bevent->x;
point.y = bevent->y;
have_start = 1;
break;
case GDK_BUTTON_RELEASE:
bevent = (GdkEventButton *) event;
have_start = 0;
break;
case GDK_MOTION_NOTIFY:
mevent = (GdkEventMotion *) event;
......@@ -2237,9 +2229,11 @@ gfig_brush_preview_events (GtkWidget *widget,
point.x = mevent->x;
point.y = mevent->y;
break;
default:
break;
}
return FALSE;
}
......@@ -2252,7 +2246,7 @@ gfig_brush_update_preview (GtkWidget *widget,
/* Must update the dialog area */
/* Use the same brush as already set in the dialog */
bdesc = gtk_object_get_user_data (GTK_OBJECT (pw));
bdesc = g_object_get_data (G_OBJECT (pw), "user_data");
brush_list_button_callback (NULL, bdesc);
}
......@@ -2270,24 +2264,28 @@ gfig_brush_menu_callback (GtkWidget *widget,
gtk_widget_show (fade_out_hbox);
gtk_widget_show (gradient_hbox);
break;
case BRUSH_PENCIL_TYPE:
gtk_widget_hide (fade_out_hbox);
gtk_widget_hide (gradient_hbox);
gtk_widget_hide (pressure_hbox);
gtk_widget_show (pencil_hbox);
break;
case BRUSH_AIRBRUSH_TYPE:
gtk_widget_hide (fade_out_hbox);
gtk_widget_hide (gradient_hbox);
gtk_widget_hide (pencil_hbox);
gtk_widget_show (pressure_hbox);
break;
case BRUSH_PATTERN_TYPE:
gtk_widget_hide (fade_out_hbox);
gtk_widget_hide (gradient_hbox);