Removed the gimp_1.0.2 dir since CVS didn't get the links anyway and the

files were doubled.

Made the source use g_malloc/g_new/g_free/g_getenv and nothinh else.

Changed the README to reflect that GAP is now part of The GIMP.


--Sven
This commit is contained in:
Sven Neumann 1999-03-28 21:56:05 +00:00
parent a129fc0d20
commit 99cfe6f5b4
18 changed files with 70 additions and 1002 deletions

View File

@ -4,7 +4,7 @@ pluginlibdir = $(gimpplugindir)/plug-ins
scriptdatadir = $(gimpdatadir)/scripts
SUBDIRS = gimp_1.0.2_src iter_ALT
SUBDIRS = iter_ALT
scriptdata_DATA = sel-to-anim-img.scm

View File

@ -447,7 +447,7 @@ radio_create_value(char *title, GtkTable *table, int row, t_arr_arg *arr_ptr)
for(l_idy=0; l_idy < arr_ptr->radio_argc; l_idy++)
{
radio_ptr = calloc(1, sizeof(t_radio_arg));
radio_ptr = g_malloc0(sizeof(t_radio_arg));
radio_ptr->arr_ptr = arr_ptr;
radio_ptr->radio_index = l_idy;
@ -553,7 +553,7 @@ optionmenu_create_value(char *title, GtkTable *table, int row, t_arr_arg *arr_pt
if (arr_ptr->radio_argv[l_idy] != NULL)
l_radio_txt = arr_ptr->radio_argv[l_idy];
}
l_menu_ptr = calloc(1, sizeof(t_radio_arg));
l_menu_ptr = g_malloc0(sizeof(t_radio_arg));
l_menu_ptr->radio_index = l_idy;
l_menu_ptr->arr_ptr = arr_ptr;

View File

@ -68,7 +68,7 @@ gap_db_browser_dialog(char *title_txt,
gtk_init (&l_argsc, &l_argsv);
}
dbbrowser = (gpointer)malloc(sizeof(dbbrowser_t));
dbbrowser = (gpointer)g_malloc(sizeof(dbbrowser_t));
/* store pointers to gap constraint procedures */
dbbrowser->constraint_func = constraint_func;

View File

@ -515,7 +515,7 @@ int p_foreach_multilayer(GRunModeType run_mode, gint32 image_id,
}
if(l_plugin_iterator != NULL) free(l_plugin_iterator);
if(l_plugin_iterator != NULL) g_free(l_plugin_iterator);
return l_rc;
} /* end p_foreach_multilayer */

View File

@ -137,7 +137,7 @@ run (char *name,
*return_vals = values;
l_rc = 0;
l_env = getenv("GAP_DEBUG");
l_env = g_getenv("GAP_DEBUG");
if(l_env != NULL)
{
if((*l_env != 'n') && (*l_env != 'N')) gap_debug = 1;

View File

@ -376,7 +376,7 @@ char * p_get_iterator_proc(char *plugin_name)
char *l_plugin_iterator;
/* check for matching Iterator PluginProcedures */
l_plugin_iterator = malloc(strlen(plugin_name) + strlen("_Iterator_ALT") +2);
l_plugin_iterator = g_malloc(strlen(plugin_name) + strlen("_Iterator_ALT") +2);
if(l_plugin_iterator != NULL)
{
sprintf(l_plugin_iterator, "%s_Iterator", plugin_name);
@ -395,7 +395,7 @@ char * p_get_iterator_proc(char *plugin_name)
if(p_procedure_available(l_plugin_iterator, PTYP_ITERATOR) < 0)
{
/* both iterator names are not available */
free(l_plugin_iterator);
g_free(l_plugin_iterator);
l_plugin_iterator = NULL;
}
}
@ -452,7 +452,7 @@ int p_constraint_proc_sel2(gchar *proc_name)
l_plugin_iterator = p_get_iterator_proc(proc_name);
if(l_plugin_iterator != NULL)
{
free(l_plugin_iterator);
g_free(l_plugin_iterator);
return 1; /* 1 .. set "Apply Varying" Button sensitive */
}
}

View File

@ -165,7 +165,7 @@ int p_file_copy(char *fname, char *fname_copy)
l_len = (long)l_stat_buf.st_size;
/* Buffer allocate */
l_buffer=(char *)calloc(1, (size_t)l_len+1);
l_buffer=(char *)g_malloc0((size_t)l_len+1);
if(l_buffer == NULL)
{
fprintf(stderr, "file_copy: calloc error (%ld Bytes not available)\n", l_len);
@ -177,7 +177,7 @@ int p_file_copy(char *fname, char *fname_copy)
if(l_fp == NULL)
{
fprintf (stderr, "open(read) error on '%s'\n", fname);
free(l_buffer);
g_free(l_buffer);
return -1;
}
fread(l_buffer, 1, (size_t)l_len, l_fp);
@ -187,7 +187,7 @@ int p_file_copy(char *fname, char *fname_copy)
if(l_fp == NULL)
{
fprintf (stderr, "file_copy: open(write) error on '%s' \n", fname_copy);
free(l_buffer);
g_free(l_buffer);
return -1;
}
@ -197,7 +197,7 @@ int p_file_copy(char *fname, char *fname_copy)
}
fclose(l_fp);
free(l_buffer);
g_free(l_buffer);
return 0; /* all done OK */
} /* end p_file_copy */
@ -217,7 +217,7 @@ int p_delete_frame(t_anim_info *ainfo_ptr, long nr)
if(gap_debug) fprintf(stderr, "\nDEBUG p_delete_frame: %s\n", l_fname);
l_rc = remove(l_fname);
free(l_fname);
g_free(l_fname);
return(l_rc);
@ -237,14 +237,14 @@ int p_rename_frame(t_anim_info *ainfo_ptr, long from_nr, long to_nr)
if(l_from_fname == NULL) { return(1); }
l_to_fname = p_alloc_fname(ainfo_ptr->basename, to_nr, ainfo_ptr->extension);
if(l_to_fname == NULL) { free(l_from_fname); return(1); }
if(l_to_fname == NULL) { g_free(l_from_fname); return(1); }
if(gap_debug) fprintf(stderr, "\nDEBUG p_rename_frame: %s ..to.. %s\n", l_from_fname, l_to_fname);
l_rc = rename(l_from_fname, l_to_fname);
free(l_from_fname);
free(l_to_fname);
g_free(l_from_fname);
g_free(l_to_fname);
return(l_rc);
@ -269,7 +269,7 @@ char* p_alloc_basename(char *imagename, long *number)
*number = 0;
if(imagename == NULL) return (NULL);
l_fname = (char *)malloc(strlen(imagename) + 1);
l_fname = (char *)g_malloc(strlen(imagename) + 1);
if(l_fname == NULL) return (NULL);
/* copy from imagename */
@ -342,7 +342,7 @@ char* p_alloc_extension(char *imagename)
l_ptr--;
}
l_ext = calloc(1, (size_t)(l_exlen + 1));
l_ext = g_malloc0((size_t)(l_exlen + 1));
if(l_ext == NULL)
return (NULL);
@ -366,7 +366,7 @@ char* p_alloc_fname(char *basename, long nr, char *extension)
char *l_fname;
if(basename == NULL) return (NULL);
l_fname = (char *)malloc(strlen(basename) + strlen(extension) + 8);
l_fname = (char *)g_malloc(strlen(basename) + strlen(extension) + 8);
if(l_fname != NULL)
{
sprintf(l_fname, "%s_%04ld%s", basename, nr, extension);
@ -387,7 +387,7 @@ t_anim_info *p_alloc_ainfo(gint32 image_id, GRunModeType run_mode)
{
t_anim_info *l_ainfo_ptr;
l_ainfo_ptr = (t_anim_info*)malloc(sizeof(t_anim_info));
l_ainfo_ptr = (t_anim_info*)g_malloc(sizeof(t_anim_info));
if(l_ainfo_ptr == NULL) return(NULL);
l_ainfo_ptr->basename = NULL;
@ -399,7 +399,7 @@ t_anim_info *p_alloc_ainfo(gint32 image_id, GRunModeType run_mode)
l_ainfo_ptr->old_filename = gimp_image_get_filename(image_id);
if(l_ainfo_ptr->old_filename == NULL)
{
l_ainfo_ptr->old_filename = malloc(30);
l_ainfo_ptr->old_filename = g_malloc(30);
sprintf(l_ainfo_ptr->old_filename, "frame_0001.xcf"); /* assign a defaultname */
gimp_image_set_filename (image_id, l_ainfo_ptr->old_filename);
}
@ -452,7 +452,7 @@ int p_dir_ainfo(t_anim_info *ainfo_ptr)
short l_dirflag;
char dirname_buff[1024];
l_dirname = malloc(strlen(ainfo_ptr->basename) +1);
l_dirname = g_malloc(strlen(ainfo_ptr->basename) +1);
if(l_dirname == NULL)
return -1;
@ -546,7 +546,7 @@ int p_dir_ainfo(t_anim_info *ainfo_ptr)
l_minnr = l_nr;
}
free(l_dummy);
g_free(l_dummy);
}
}
}
@ -554,7 +554,7 @@ int p_dir_ainfo(t_anim_info *ainfo_ptr)
closedir( l_dirp );
}
free(l_dirname);
g_free(l_dirname);
/* set first_frame_nr and last_frame_nr (found as "_0099" in diskfile namepart) */
ainfo_ptr->last_frame_nr = l_maxnr;
@ -579,18 +579,18 @@ void p_free_ainfo(t_anim_info **ainfo)
return;
if(aptr->basename)
free(aptr->basename);
g_free(aptr->basename);
if(aptr->extension)
free(aptr->extension);
g_free(aptr->extension);
if(aptr->new_filename)
free(aptr->new_filename);
g_free(aptr->new_filename);
if(aptr->old_filename)
free(aptr->old_filename);
g_free(aptr->old_filename);
free(aptr);
g_free(aptr);
}
@ -668,7 +668,7 @@ char * p_gzip (char *orig_name, char *new_name, char *zip)
l_cmd = NULL;
l_tmpname = new_name;
l_cmd = calloc(1, (strlen(l_tmpname) + strlen(orig_name) + 20));
l_cmd = g_malloc((strlen(l_tmpname) + strlen(orig_name) + 20));
if(l_cmd == NULL)
{
return NULL;
@ -702,7 +702,7 @@ char * p_gzip (char *orig_name, char *new_name, char *zip)
fprintf(stderr, "ERROR system: %s\nreturncodes %d %d", l_cmd, l_rc, l_rc2);
l_tmpname = NULL;
}
free(l_cmd);
g_free(l_cmd);
return l_tmpname;
} /* end p_gzip */
@ -873,7 +873,7 @@ int p_save_named_frame(gint32 image_id, char *sav_name)
* that resides on the same filesystem as sav_name
* and has the same extension as the original sav_name
*/
l_tmpname = (char *)malloc(strlen(sav_name) + strlen(".gtmp") + strlen(l_ext) +2);
l_tmpname = (char *)g_malloc(strlen(sav_name) + strlen(".gtmp") + strlen(l_ext) +2);
if(l_tmpname == NULL)
{
return -1;
@ -895,16 +895,16 @@ int p_save_named_frame(gint32 image_id, char *sav_name)
g_free(l_params);
}
free(l_ext);
g_free(l_ext);
if(gap_debug)
{
l_ext = getenv("GAP_NO_SAVE");
l_ext = g_getenv("GAP_NO_SAVE");
if(l_ext != NULL)
{
fprintf(stderr, "DEBUG: GAP_NO_SAVE is set: save is skipped: '%s'\n", l_tmpname);
free(l_tmpname); /* free if it was a temporary name */
g_free(l_tmpname); /* free if it was a temporary name */
return 0;
}
}
@ -953,7 +953,7 @@ int p_save_named_frame(gint32 image_id, char *sav_name)
if(l_rc < 0)
{
remove(l_tmpname);
free(l_tmpname); /* free temporary name */
g_free(l_tmpname); /* free temporary name */
return l_rc;
}
@ -989,7 +989,7 @@ int p_save_named_frame(gint32 image_id, char *sav_name)
}
}
free(l_tmpname); /* free temporary name */
g_free(l_tmpname); /* free temporary name */
return l_rc;
@ -1057,7 +1057,7 @@ gint32 p_load_image (char *lod_name)
g_free(l_params);
}
else l_tmpname = lod_name;
free(l_ext);
g_free(l_ext);
}
if(l_tmpname == NULL)
@ -1143,7 +1143,7 @@ int p_load_named_frame (gint32 image_id, char *lod_name)
*/
int p_replace_image(t_anim_info *ainfo_ptr)
{
if(ainfo_ptr->new_filename != NULL) free(ainfo_ptr->new_filename);
if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename);
ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename,
ainfo_ptr->frame_nr,
ainfo_ptr->extension);
@ -1235,7 +1235,7 @@ int p_del(t_anim_info *ainfo_ptr, long cnt)
}
/* make filename, then load the new current frame */
if(ainfo_ptr->new_filename != NULL) free(ainfo_ptr->new_filename);
if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename);
ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename,
ainfo_ptr->frame_nr,
ainfo_ptr->extension);
@ -1275,7 +1275,7 @@ int p_dup(t_anim_info *ainfo_ptr, long cnt, long range_from, long range_to)
/* use a new name (_0001.xcf Konvention) */
gimp_image_set_filename (ainfo_ptr->image_id, l_curr_name);
free(l_curr_name);
g_free(l_curr_name);
if((range_from <0 ) && (range_to < 0 ))
@ -1352,8 +1352,8 @@ int p_dup(t_anim_info *ainfo_ptr, long cnt, long range_from, long range_to)
if((l_dup_name != NULL) && (l_curr_name != NULL))
{
p_file_copy(l_curr_name, l_dup_name);
free(l_dup_name);
free(l_curr_name);
g_free(l_dup_name);
g_free(l_curr_name);
}
if(ainfo_ptr->run_mode == RUN_INTERACTIVE)
{
@ -1374,7 +1374,7 @@ int p_dup(t_anim_info *ainfo_ptr, long cnt, long range_from, long range_to)
ainfo_ptr->last_frame_nr = ainfo_ptr->first_frame_nr + ainfo_ptr->frame_cnt -1;
/* load from the "new" current frame */
if(ainfo_ptr->new_filename != NULL) free(ainfo_ptr->new_filename);
if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename);
ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename,
ainfo_ptr->curr_frame_nr,
ainfo_ptr->extension);
@ -1422,7 +1422,7 @@ int p_exchg(t_anim_info *ainfo_ptr, long dest)
}
/* load from the "new" current frame */
if(ainfo_ptr->new_filename != NULL) free(ainfo_ptr->new_filename);
if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename);
ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename,
ainfo_ptr->curr_frame_nr,
ainfo_ptr->extension);
@ -1479,7 +1479,7 @@ p_shift(t_anim_info *ainfo_ptr, long cnt, long range_from, long range_to)
l_curr_name = p_alloc_fname(ainfo_ptr->basename, ainfo_ptr->curr_frame_nr, ainfo_ptr->extension);
/* save current frame */
p_save_named_frame(ainfo_ptr->image_id, l_curr_name);
free(l_curr_name);
g_free(l_curr_name);
l_percentage = 0.0;
if(ainfo_ptr->run_mode == RUN_INTERACTIVE)
@ -1532,7 +1532,7 @@ p_shift(t_anim_info *ainfo_ptr, long cnt, long range_from, long range_to)
/* load from the "new" current frame */
if(ainfo_ptr->new_filename != NULL) free(ainfo_ptr->new_filename);
if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename);
ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename,
ainfo_ptr->curr_frame_nr,
ainfo_ptr->extension);

View File

@ -622,7 +622,7 @@ run (char *name,
l_rc = 0;
l_env = getenv("GAP_DEBUG");
l_env = g_getenv("GAP_DEBUG");
if(l_env != NULL)
{
if((*l_env != 'n') && (*l_env != 'N')) gap_debug = 1;

View File

@ -256,7 +256,7 @@ p_pitstop_dialog(gint text_flag, char *filter_procname)
l_argc = 0;
/* optional dialog between both calls (to see the effect of 1.call) */
l_env = getenv("GAP_FILTER_PITSTOP");
l_env = g_getenv("GAP_FILTER_PITSTOP");
if(l_env != NULL)
{
if((*l_env == 'N') || (*l_env == 'n'))
@ -331,7 +331,7 @@ p_alloc_layli(gint32 image_id, gint32 *l_sel_cnt, gint *nlayers,
return(NULL);
}
l_layli_ptr = calloc((*nlayers), sizeof(t_LayliElem));
l_layli_ptr = g_new0(t_LayliElem, (*nlayers));
if(l_layli_ptr == NULL)
{
g_free (l_layers_list);
@ -812,7 +812,7 @@ p_do_2nd_filter_dialogs(char *filter_procname,
cleanup:
if(l_dpy_id >= 0) gimp_display_delete(l_dpy_id);
if(l_last_image_id >= 0) gimp_image_delete(l_last_image_id);
if(l_layli_ptr != NULL) free(l_layli_ptr);
if(l_layli_ptr != NULL) g_free(l_layli_ptr);
return (l_rc);
@ -922,7 +922,7 @@ p_frames_modify(t_anim_info *ainfo_ptr,
if(gap_debug) fprintf(stderr, "p_frames_modify While l_cur_frame_nr = %d\n", (int)l_cur_frame_nr);
/* build the frame name */
if(ainfo_ptr->new_filename != NULL) free(ainfo_ptr->new_filename);
if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename);
ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename,
l_cur_frame_nr,
ainfo_ptr->extension);
@ -987,7 +987,7 @@ p_frames_modify(t_anim_info *ainfo_ptr,
);
}
free(l_last_frame_filename);
g_free(l_last_frame_filename);
l_last_frame_filename = NULL;
}
@ -1032,7 +1032,7 @@ p_frames_modify(t_anim_info *ainfo_ptr,
/* free layli info table for the current frame */
if(l_layli_ptr != NULL)
{
free(l_layli_ptr);
g_free(l_layli_ptr);
l_layli_ptr = NULL;
}
@ -1116,8 +1116,8 @@ error:
l_dpy_id = -1;
}
if(l_tmp_image_id >= 0) gimp_image_delete(l_tmp_image_id);
if(l_layli_ptr != NULL) free(l_layli_ptr);
if(l_plugin_iterator != NULL) free(l_plugin_iterator);
if(l_layli_ptr != NULL) g_free(l_layli_ptr);
if(l_plugin_iterator != NULL) g_free(l_plugin_iterator);
return -1;
} /* end p_frames_modify */
@ -1201,3 +1201,4 @@ gint gap_mod_layer(GRunModeType run_mode, gint32 image_id,
return(l_rc);
}

View File

@ -693,7 +693,7 @@ mov_upvw_callback (GtkWidget *widget,
{
/* replace the temporary image */
l_new_tmp_image_id = p_load_image(l_filename);
free(l_filename);
g_free(l_filename);
if (l_new_tmp_image_id >= 0)
{
/* use the new loaded temporary image */

View File

@ -70,7 +70,7 @@ int p_mov_call_render(t_mov_data *mov_ptr, t_mov_current *cur_ptr)
ainfo_ptr = mov_ptr->dst_ainfo_ptr;
if(ainfo_ptr->new_filename != NULL) free(ainfo_ptr->new_filename);
if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename);
ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename,
cur_ptr->dst_frame_nr,
ainfo_ptr->extension);
@ -409,7 +409,7 @@ int gap_move(GRunModeType run_mode, gint32 image_id)
ainfo_ptr = p_alloc_ainfo(image_id, run_mode);
if(ainfo_ptr != NULL)
{
l_mov_data.val_ptr = malloc(sizeof(t_mov_values));
l_mov_data.val_ptr = g_malloc(sizeof(t_mov_values));
if(NULL != l_mov_data.val_ptr)
{
if (0 == p_dir_ainfo(ainfo_ptr))
@ -442,7 +442,7 @@ int gap_move(GRunModeType run_mode, gint32 image_id)
}
}
}
free(l_mov_data.val_ptr);
g_free(l_mov_data.val_ptr);
}
p_free_ainfo(&ainfo_ptr);

View File

@ -614,7 +614,7 @@ p_frames_to_multilayer(t_anim_info *ainfo_ptr,
while(1)
{
/* build the frame name */
if(ainfo_ptr->new_filename != NULL) free(ainfo_ptr->new_filename);
if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename);
ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename,
l_cur_frame_nr,
ainfo_ptr->extension);
@ -651,7 +651,7 @@ p_frames_to_multilayer(t_anim_info *ainfo_ptr,
}
}
free(l_layli_ptr);
g_free(l_layli_ptr);
if((flatten_mode >= FLAM_MERG_EXPAND) && (flatten_mode <= FLAM_MERG_CLIP_BG))
{
@ -950,7 +950,7 @@ p_frames_convert(t_anim_info *ainfo_ptr,
while(l_rc >= 0)
{
/* build the frame name */
if(ainfo_ptr->new_filename != NULL) free(ainfo_ptr->new_filename);
if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename);
ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename,
l_cur_frame_nr,
ainfo_ptr->extension);
@ -1029,7 +1029,7 @@ p_frames_convert(t_anim_info *ainfo_ptr,
l_run_mode = RUN_NONINTERACTIVE; /* for all further calls */
free(l_sav_name);
g_free(l_sav_name);
}
}
@ -1157,7 +1157,7 @@ gint32 p_anim_sizechange(t_anim_info *ainfo_ptr,
while(1)
{
/* build the frame name */
if(ainfo_ptr->new_filename != NULL) free(ainfo_ptr->new_filename);
if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename);
ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename,
l_cur_frame_nr,
ainfo_ptr->extension);
@ -1315,7 +1315,7 @@ p_frames_layer_del(t_anim_info *ainfo_ptr,
while(1)
{
/* build the frame name */
if(ainfo_ptr->new_filename != NULL) free(ainfo_ptr->new_filename);
if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename);
ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename,
l_cur_frame_nr,
ainfo_ptr->extension);
@ -1513,7 +1513,7 @@ gint32 gap_range_conv(GRunModeType run_mode, gint32 image_id,
l_dest_type,
l_dest_colors,
l_dest_dither);
free(l_basename_ptr);
g_free(l_basename_ptr);
}
}
}

View File

@ -173,7 +173,7 @@ p_split_image(t_anim_info *ainfo_ptr,
/* prepare return value */
l_rc = l_new_image_id;
free(l_sav_name);
g_free(l_sav_name);
}
/* save as frame */

View File

@ -1,2 +0,0 @@
Makefile
Makefile.in

View File

@ -1,12 +0,0 @@
## Process this file with automake to produce Makefile.in
EXTRA_DIST = \
appenv.h \
resize.c \
resize.c
files:
@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
echo $$p; \
done

View File

@ -1,46 +0,0 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __APPENV_H__
#define __APPENV_H__
#include "gdk/gdkx.h"
#include "gtk/gtk.h"
#define DISPLAY ((Display *) GDK_DISPLAY())
/* important macros */
#define BOUNDS(a,x,y) ((a < x) ? x : ((a > y) ? y : a))
#define MINIMUM(x,y) ((x < y) ? x : y)
#define MAXIMUM(x,y) ((x > y) ? x : y)
typedef enum {
MESSAGE_BOX,
CONSOLE
} MessageHandlerType;
extern int no_interface;
extern int no_splash;
extern int no_splash_image;
extern int no_data;
extern int be_verbose;
extern int use_debug_handler;
extern int console_messages;
extern MessageHandlerType message_handler;
#endif /* APPENV_H */

View File

@ -1,822 +0,0 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "appenv.h"
#include "resize.h"
#define EVENT_MASK GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK
#define DRAWING_AREA_SIZE 200
#define TEXT_WIDTH 35
typedef struct _ResizePrivate ResizePrivate;
struct _ResizePrivate
{
GtkWidget *width_text;
GtkWidget *height_text;
GtkWidget *ratio_x_text;
GtkWidget *ratio_y_text;
GtkWidget *off_x_text;
GtkWidget *off_y_text;
GtkWidget *drawing_area;
double ratio;
int constrain;
int old_width, old_height;
int area_width, area_height;
int start_x, start_y;
int orig_x, orig_y;
};
static void resize_draw (Resize *);
static int resize_bound_off_x (Resize *, int);
static int resize_bound_off_y (Resize *, int);
static void off_x_update (GtkWidget *w, gpointer data);
static void off_y_update (GtkWidget *w, gpointer data);
static void width_update (GtkWidget *w, gpointer data);
static void height_update (GtkWidget *w, gpointer data);
static void ratio_x_update (GtkWidget *w, gpointer data);
static void ratio_y_update (GtkWidget *w, gpointer data);
static void constrain_update (GtkWidget *w, gpointer data);
static gint resize_events (GtkWidget *area, GdkEvent *event);
Resize *
resize_widget_new (ResizeType type,
int width,
int height)
{
Resize *resize;
ResizePrivate *private;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *frame;
GtkWidget *constrain;
GtkWidget *table;
char size[12];
char ratio_text[12];
table = NULL;
resize = g_new (Resize, 1);
private = g_new (ResizePrivate, 1);
resize->type = type;
resize->private_part = private;
resize->width = width;
resize->height = height;
resize->ratio_x = 1.0;
resize->ratio_y = 1.0;
resize->off_x = 0;
resize->off_y = 0;
private->old_width = width;
private->old_height = height;
private->constrain = TRUE;
/* Get the image width and height variables, based on the gimage */
if (width > height)
private->ratio = (double) DRAWING_AREA_SIZE / (double) width;
else
private->ratio = (double) DRAWING_AREA_SIZE / (double) height;
private->area_width = (int) (private->ratio * width);
private->area_height = (int) (private->ratio * height);
switch (type)
{
case ScaleWidget:
resize->resize_widget = gtk_frame_new ("Scale");
table = gtk_table_new (4, 2, TRUE);
break;
case ResizeWidget:
resize->resize_widget = gtk_frame_new ("Resize");
table = gtk_table_new (6, 2, TRUE);
break;
}
gtk_frame_set_shadow_type (GTK_FRAME (resize->resize_widget), GTK_SHADOW_ETCHED_IN);
/* the main vbox */
vbox = gtk_vbox_new (FALSE, 1);
gtk_container_border_width (GTK_CONTAINER (vbox), 5);
gtk_container_add (GTK_CONTAINER (resize->resize_widget), vbox);
gtk_container_border_width (GTK_CONTAINER (table), 2);
gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
/* the width label and entry */
sprintf (size, "%d", width);
label = gtk_label_new ("New width:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->width_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->width_text, 1, 2, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->width_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->width_text), size);
gtk_signal_connect (GTK_OBJECT (private->width_text), "changed",
(GtkSignalFunc) width_update,
resize);
gtk_widget_show (private->width_text);
/* the height label and entry */
sprintf (size, "%d", height);
label = gtk_label_new ("New height:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->height_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->height_text, 1, 2, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->height_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->height_text), size);
gtk_signal_connect (GTK_OBJECT (private->height_text), "changed",
(GtkSignalFunc) height_update,
resize);
gtk_widget_show (private->height_text);
/* the x scale ratio label and entry */
sprintf (ratio_text, "%0.4f", resize->ratio_x);
label = gtk_label_new ("X ratio:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->ratio_x_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->ratio_x_text, 1, 2, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->ratio_x_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->ratio_x_text), ratio_text);
gtk_signal_connect (GTK_OBJECT (private->ratio_x_text), "changed",
(GtkSignalFunc) ratio_x_update,
resize);
gtk_widget_show (private->ratio_x_text);
/* the y scale ratio label and entry */
sprintf (ratio_text, "%0.4f", resize->ratio_y);
label = gtk_label_new ("Y ratio:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->ratio_y_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->ratio_y_text, 1, 2, 3, 4,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->ratio_y_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->ratio_y_text), ratio_text);
gtk_signal_connect (GTK_OBJECT (private->ratio_y_text), "changed",
(GtkSignalFunc) ratio_y_update,
resize);
gtk_widget_show (private->ratio_y_text);
if (type == ResizeWidget)
{
/* the off_x label and entry */
sprintf (size, "%d", 0);
label = gtk_label_new ("X Offset:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->off_x_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->off_x_text, 1, 2, 4, 5,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->off_x_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->off_x_text), size);
gtk_signal_connect (GTK_OBJECT (private->off_x_text), "changed",
(GtkSignalFunc) off_x_update,
resize);
gtk_widget_show (private->off_x_text);
/* the off_y label and entry */
sprintf (size, "%d", 0);
label = gtk_label_new ("Y Offset:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 5, 6,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->off_y_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->off_y_text, 1, 2, 5, 6,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->off_y_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->off_y_text), size);
gtk_signal_connect (GTK_OBJECT (private->off_y_text), "changed",
(GtkSignalFunc) off_y_update,
resize);
gtk_widget_show (private->off_y_text);
}
/* the constrain toggle button */
constrain = gtk_check_button_new_with_label ("Constrain Ratio");
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (constrain), private->constrain);
gtk_box_pack_start (GTK_BOX (vbox), constrain, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (constrain), "toggled",
(GtkSignalFunc) constrain_update,
resize);
gtk_widget_show (constrain);
if (type == ResizeWidget)
{
/* frame to hold drawing area */
hbox = gtk_hbox_new (FALSE, 1);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_border_width (GTK_CONTAINER (frame), 2);
gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, FALSE, 0);
private->drawing_area = gtk_drawing_area_new ();
gtk_drawing_area_size (GTK_DRAWING_AREA (private->drawing_area),
private->area_width, private->area_height);
gtk_widget_set_events (private->drawing_area, EVENT_MASK);
gtk_signal_connect (GTK_OBJECT (private->drawing_area), "event",
(GtkSignalFunc) resize_events,
NULL);
gtk_object_set_user_data (GTK_OBJECT (private->drawing_area), resize);
gtk_container_add (GTK_CONTAINER (frame), private->drawing_area);
gtk_widget_show (private->drawing_area);
gtk_widget_show (frame);
gtk_widget_show (hbox);
}
gtk_widget_show (table);
gtk_widget_show (vbox);
return resize;
}
void
resize_widget_free (Resize *resize)
{
g_free (resize->private_part);
g_free (resize);
}
static void
resize_draw (Resize *resize)
{
GtkWidget *widget;
ResizePrivate *private;
int aw, ah;
int x, y;
int w, h;
/* Only need to draw if it's a resize widget */
if (resize->type != ResizeWidget)
return;
private = (ResizePrivate *) resize->private_part;
widget = private->drawing_area;
/* If we're making the size larger */
if (private->old_width <= resize->width)
w = resize->width;
/* otherwise, if we're making the size smaller */
else
w = private->old_width * 2 - resize->width;
/* If we're making the size larger */
if (private->old_height <= resize->height)
h = resize->height;
/* otherwise, if we're making the size smaller */
else
h = private->old_height * 2 - resize->height;
if (w > h)
private->ratio = (double) DRAWING_AREA_SIZE / (double) w;
else
private->ratio = (double) DRAWING_AREA_SIZE / (double) h;
aw = (int) (private->ratio * w);
ah = (int) (private->ratio * h);
if (aw != private->area_width || ah != private->area_height)
{
private->area_width = aw;
private->area_height = ah;
gtk_widget_set_usize (private->drawing_area, aw, ah);
}
if (private->old_width <= resize->width)
x = private->ratio * resize->off_x;
else
x = private->ratio * (resize->off_x + private->old_width - resize->width);
if (private->old_height <= resize->height)
y = private->ratio * resize->off_y;
else
y = private->ratio * (resize->off_y + private->old_height - resize->height);
w = private->ratio * private->old_width;
h = private->ratio * private->old_height;
gdk_window_clear (private->drawing_area->window);
gtk_draw_shadow (widget->style, widget->window,
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
x, y, w, h);
/* If we're making the size smaller */
if (private->old_width > resize->width ||
private->old_height > resize->height)
{
if (private->old_width > resize->width)
{
x = private->ratio * (private->old_width - resize->width);
w = private->ratio * resize->width;
}
else
{
x = -1;
w = aw + 2;
}
if (private->old_height > resize->height)
{
y = private->ratio * (private->old_height - resize->height);
h = private->ratio * resize->height;
}
else
{
y = -1;
h = ah + 2;
}
gdk_draw_rectangle (private->drawing_area->window,
widget->style->black_gc, 0,
x, y, w, h);
}
}
static int
resize_bound_off_x (Resize *resize,
int off_x)
{
ResizePrivate *private;
private = (ResizePrivate *) resize->private_part;
if (private->old_width <= resize->width)
off_x = BOUNDS (off_x, 0, (resize->width - private->old_width));
else
off_x = BOUNDS (off_x, (resize->width - private->old_width), 0);
return off_x;
}
static int
resize_bound_off_y (Resize *resize,
int off_y)
{
ResizePrivate *private;
private = (ResizePrivate *) resize->private_part;
if (private->old_height <= resize->height)
off_y = BOUNDS (off_y, 0, (resize->height - private->old_height));
else
off_y = BOUNDS (off_y, (resize->height - private->old_height), 0);
return off_y;
}
static void
constrain_update (GtkWidget *w,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
if (GTK_TOGGLE_BUTTON (w)->active)
private->constrain = TRUE;
else
private->constrain = FALSE;
}
static void
off_x_update (GtkWidget *w,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
char *str;
int offset;
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
str = gtk_entry_get_text (GTK_ENTRY (w));
offset = atoi (str);
offset = resize_bound_off_x (resize, offset);
if (offset != resize->off_x)
{
resize->off_x = offset;
resize_draw (resize);
}
}
static void
off_y_update (GtkWidget *w,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
char *str;
int offset;
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
str = gtk_entry_get_text (GTK_ENTRY (w));
offset = atoi (str);
offset = resize_bound_off_y (resize, offset);
if (offset != resize->off_y)
{
resize->off_y = offset;
resize_draw (resize);
}
}
static void
width_update (GtkWidget *w,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
char *str;
double ratio;
int new_height;
char size[12];
char ratio_text[12];
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
str = gtk_entry_get_text (GTK_ENTRY (w));
resize->width = atoi (str);
ratio = (double) resize->width / (double) private->old_width;
resize->ratio_x = ratio;
sprintf (ratio_text, "%0.4f", ratio);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_x_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_x_text), data);
if (resize->type == ResizeWidget)
{
resize->off_x = resize_bound_off_x (resize, (resize->width - private->old_width) / 2);
sprintf (size, "%d", resize->off_x);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_x_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_x_text), data);
}
if (private->constrain && resize->width != 0)
{
private->constrain = FALSE;
new_height = (int) (private->old_height * ratio);
if (new_height == 0) new_height = 1;
if (new_height != resize->height)
{
resize->height = new_height;
sprintf (size, "%d", resize->height);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->height_text), data);
gtk_entry_set_text (GTK_ENTRY (private->height_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->height_text), data);
resize->ratio_y = ratio;
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_y_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_y_text), data);
if (resize->type == ResizeWidget)
{
resize->off_y = resize_bound_off_y (resize, (resize->height - private->old_height) / 2);
sprintf (size, "%d", resize->off_y);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_y_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_y_text), data);
}
}
private->constrain = TRUE;
}
resize_draw (resize);
}
static void
height_update (GtkWidget *w,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
char *str;
double ratio;
int new_width;
char size[12];
char ratio_text[12];
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
str = gtk_entry_get_text (GTK_ENTRY (w));
resize->height = atoi (str);
ratio = (double) resize->height / (double) private->old_height;
resize->ratio_y = ratio;
sprintf (ratio_text, "%0.4f", ratio);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_y_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_y_text), data);
if (resize->type == ResizeWidget)
{
resize->off_y = resize_bound_off_y (resize, (resize->height - private->old_height) / 2);
sprintf (size, "%d", resize->off_y);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_y_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_y_text), data);
}
if (private->constrain && resize->height != 0)
{
private->constrain = FALSE;
ratio = (double) resize->height / (double) private->old_height;
new_width = (int) (private->old_width * ratio);
if (new_width == 0) new_width = 1;
if (new_width != resize->width)
{
resize->width = new_width;
sprintf (size, "%d", resize->width);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->width_text), data);
gtk_entry_set_text (GTK_ENTRY (private->width_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->width_text), data);
resize->ratio_x = ratio;
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_x_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_x_text), data);
if (resize->type == ResizeWidget)
{
resize->off_x = resize_bound_off_x (resize, (resize->width - private->old_width) / 2);
sprintf (size, "%d", resize->off_x);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_x_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_x_text), data);
}
}
private->constrain = TRUE;
}
resize_draw (resize);
}
static void
ratio_x_update (GtkWidget *w,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
char *str;
int new_width;
int new_height;
char size[12];
char ratio_text[12];
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
str = gtk_entry_get_text (GTK_ENTRY (w));
resize->ratio_x = atof (str);
new_width = (int) ((double) private->old_width * resize->ratio_x);
if (new_width != resize->width)
{
resize->width = new_width;
sprintf (size, "%d", new_width);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->width_text), data);
gtk_entry_set_text (GTK_ENTRY (private->width_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->width_text), data);
if (resize->type == ResizeWidget)
{
resize->off_x = resize_bound_off_x (resize, (resize->width - private->old_width) / 2);
sprintf (size, "%d", resize->off_x);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_x_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_x_text), data);
}
}
if (private->constrain && resize->width != 0)
{
private->constrain = FALSE;
resize->ratio_y = resize->ratio_x;
new_height = (int) (private->old_height * resize->ratio_y);
if (new_height == 0) new_height = 1;
if (new_height != resize->height)
{
resize->height = new_height;
sprintf (size, "%d", resize->height);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->height_text), data);
gtk_entry_set_text (GTK_ENTRY (private->height_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->height_text), data);
sprintf (ratio_text, "%0.4f", resize->ratio_y);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_y_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_y_text), data);
if (resize->type == ResizeWidget)
{
resize->off_y = resize_bound_off_y (resize, (resize->height - private->old_height) / 2);
sprintf (size, "%d", resize->off_y);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_y_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_y_text), data);
}
}
private->constrain = TRUE;
}
resize_draw (resize);
}
static void
ratio_y_update (GtkWidget *w,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
char *str;
int new_width;
int new_height;
char size[12];
char ratio_text[12];
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
str = gtk_entry_get_text (GTK_ENTRY (w));
resize->ratio_y = atof (str);
new_height = (int) ((double) private->old_height * resize->ratio_y);
if (new_height != resize->height)
{
resize->height = new_height;
sprintf (size, "%d", new_height);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->height_text), data);
gtk_entry_set_text (GTK_ENTRY (private->height_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->height_text), data);
if (resize->type == ResizeWidget)
{
resize->off_y = resize_bound_off_y (resize, (resize->height - private->old_height) / 2);
sprintf (size, "%d", resize->off_y);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_y_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_y_text), data);
}
}
if (private->constrain && resize->height != 0)
{
private->constrain = FALSE;
resize->ratio_x = resize->ratio_y;
new_width = (int) (private->old_width * resize->ratio_x);
if (new_width == 0) new_width = 1;
if (new_width != resize->width)
{
resize->width = new_width;
sprintf (size, "%d", resize->width);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->width_text), data);
gtk_entry_set_text (GTK_ENTRY (private->width_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->width_text), data);
sprintf (ratio_text, "%0.4f", resize->ratio_x);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_x_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_x_text), data);
if (resize->type == ResizeWidget)
{
resize->off_x = resize_bound_off_x (resize, (resize->width - private->old_width) / 2);
sprintf (size, "%d", resize->off_x);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_x_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_x_text), data);
}
}
private->constrain = TRUE;
}
resize_draw (resize);
}
static gint
resize_events (GtkWidget *widget,
GdkEvent *event)
{
Resize *resize;
ResizePrivate *private;
int dx, dy;
int off_x, off_y;
char size[12];
resize = (Resize *) gtk_object_get_user_data (GTK_OBJECT (widget));
private = (ResizePrivate *) resize->private_part;
switch (event->type)
{
case GDK_EXPOSE:
resize_draw (resize);
break;
case GDK_BUTTON_PRESS:
gdk_pointer_grab (private->drawing_area->window, FALSE,
(GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, event->button.time);
private->orig_x = resize->off_x;
private->orig_y = resize->off_y;
private->start_x = event->button.x;
private->start_y = event->button.y;
break;
case GDK_MOTION_NOTIFY:
/* X offset */
dx = event->motion.x - private->start_x;
off_x = private->orig_x + dx / private->ratio;
off_x = resize_bound_off_x (resize, off_x);
sprintf (size, "%d", off_x);
gtk_entry_set_text (GTK_ENTRY (private->off_x_text), size);
/* Y offset */
dy = event->motion.y - private->start_y;
off_y = private->orig_y + dy / private->ratio;
off_y = resize_bound_off_y (resize, off_y);
sprintf (size, "%d", off_y);
gtk_entry_set_text (GTK_ENTRY (private->off_y_text), size);
break;
case GDK_BUTTON_RELEASE:
gdk_pointer_ungrab (event->button.time);
break;
default:
break;
}
return FALSE;
}

View File

@ -1,51 +0,0 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __RESIZE_H__
#define __RESIZE_H__
typedef enum
{
ScaleWidget,
ResizeWidget
} ResizeType;
typedef struct _Resize Resize;
struct _Resize
{
/* The calling procedure is respondible for showing this widget */
GtkWidget *resize_widget;
ResizeType type;
int width;
int height;
double ratio_x;
double ratio_y;
int off_x;
int off_y;
/* Don't touch this :) */
void * private_part;
};
Resize * resize_widget_new (ResizeType type,
int width,
int height);
void resize_widget_free (Resize * resize);
#endif /* __RESIZE_H__ */