File: settings.c

package info (click to toggle)
xmorph 1%3A20060817
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 5,688 kB
  • ctags: 2,022
  • sloc: ansic: 19,988; sh: 9,418; cpp: 1,230; makefile: 560; sed: 16
file content (442 lines) | stat: -rw-r--r-- 12,941 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>

#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include "gtk-meta.h"

#ifdef USE_IMLIB
#include <gdk_imlib.h>
#else
#include <gdk-pixbuf/gdk-pixbuf.h>
#endif

#include "gtktopdata.h"
#include "gtksettings.h"

#include "settings.h"

//#include "callbacks.h"
//#include "interface.h"
#include "support.h"
#include "main.h"
#include "utils.h"



void
gtkmorph_settings_callback(GtkWidget* thismenu, gpointer userdata)
{
#if HAVE_WAILI
  extern int wavelet_depth;
  extern double wavelet_equalization_factor;
  wavelet_equalization_factor
    =0.5 * settings_get_value("wavelet equalization");
  wavelet_depth=settings_get_value("wavelet depth")+1;
#endif

/* if the meshes do not have the same sizes, something will crash */
  if (settings_get_value("mesh auto sync"))
    promote_meshes();
#ifndef IS_PLYMORPH
  smooth_idle_stop();
  if (settings_get_value("preserve border")){
    int lp=MAX_WINS; for(; lp>=0; lp--) 
      if(sp->im_widget[lp] != NULL && sp->im_mesh[lp].x != NULL) {
	meshFunctionalize(&sp->im_mesh[lp],
			  sp->resulting_width,sp->resulting_height);
/* 	meshSet(&sp->im_mesh[lp],0,0,0,0); */
/* 	meshSet(&sp->im_mesh[lp],sp->im_mesh[lp].nx-1,sp->im_mesh[lp].ny-1, */
/* 		sp->resulting_width,sp->resulting_height); */
      }}
#endif

  set_state();
}

/* trick, so these get in the po files */
#ifdef ENABLE_NLS
#undef _
#define _(S) (S)
#endif


extern char * resample_array_inv_names[] ;
extern char * smooth_mesh_energy_names[] ;
extern char * wavelet_depths[] ;
extern char * wavelet_equalization[] ;

//char * wavelet_stat_origin[]=;


gpointer *gtkmorph_settings=NULL,
  gtkmorph_template[] =
{ 
  //gtkmorph_settings_callback,

  /****** next*******/
  _("no warnings"), //name
  NULL,//integer value, stored in pointer
  NULL,//accels
  _("dont warn, just beep; warnings may be read with 'why the beep' in the 'help' menu"),
  NULL, 

  /****** next*******/
  _("edit features"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels
  _("permits to add and delete mesh lines, edit features"),
  NULL, //magic pointer

  /****** next *****/
  _("preserve border"), //name
  GUINT_TO_POINTER(0),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("border points of the mesh are forced to stay on the border of the image"), //tooltip (they are translated below)
  NULL, //magic pointer

  /****** next*******/
  _("hide unusable"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels
  _("hide unusable widgets, instead of deactivating them"),
  NULL, //magic pointer

  /****** next*******/
  _("cursor jump"), //name
  GUINT_TO_POINTER(0),//integer value, stored in pointer
  NULL,//accels
  _("moves the image to recenter the last edited point"),
  NULL, //magic pointer

  /****** next *****/
  _("mesh cant overlap"), //name
  GUINT_TO_POINTER(0),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("a mesh point cannot enter in a neighbouring cell (this is currently not very well enforced)"), //tooltip (they are translated below)
  NULL, //magic pointer

  /****** next *****/
  _("use antialiasing warping"), //name
  GUINT_TO_POINTER(2),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("choose antialiasing method that is used when warping: the lanczos kernels are slower, but are necessary if the images have fine or grained textures and/or for animations"), //tooltip (they are translated below)
  resample_array_inv_names, //magic pointer

#if HAVE_WAILI
  /****** next *****/
  _("wavelet equalization"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("the averaging of images will lose details; you may enable an enhancing algorithm (based on wavelets)"), //tooltip (they are translated below)
  wavelet_equalization, //magic pointer

  /****** next *****/
  _("wavelet depth"), //name
  GUINT_TO_POINTER(2),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("this is the depth of the wavelets"), //tooltip (they are translated below)
  wavelet_depths, //magic pointer
#endif

  /****** next *****/
  _("energy for mesh smoothing"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("type of energy that is minimized to decide the position of the non-selected mesh points: thin plate energy is better but slower, to speed up use elastic energy when editing meshes"), //tooltip (they are translated below)
  smooth_mesh_energy_names, //magic pointer

  /****** next *****/
  _("auto point adjust"), //name
  GUINT_TO_POINTER(0),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("adjust the position of a mesh point by comparing this image with the previous one and doing a best match. Achieves sub-pixel precision but may move your point around erratically."),
  NULL, //magic pointer

 /****** next *****/
  _("mesh factors sum to 1"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("always force the mesh factors so that they sum to 1;\n(if not, they are internally renormalized before using)"), //tooltip 
  NULL, //magic pointer

 /****** next *****/
  _("image factors sum to 1"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("always force the image factors so that they sum to 1;\n(if not, they are internally renormalized before using)"), //tooltip 
  NULL, //magic pointer

 /****** next *****/
  _("automatic mesh interpolation"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("automatically interpolates the resulting mesh when morphing (note that in this case you cannot edit it)" ) , //tooltip 
  NULL, //magic pointer 

 /****** next *****/
  _("automatic blending"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("automatically blends the images when the image blending factors are changed" ) , //tooltip 
  NULL, //magic pointer 

 /****** next *****/ 
  _("mesh auto sync"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("any change (add/del, label/unlabel) to a mesh is replicated"), //tooltip 
  NULL, //magic pointer

  /****** next *****/
  _("warped image in other win"), //name
  GUINT_TO_POINTER(0),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("put warped images in another window"), //tooltip (they are translated below)
  NULL, //magic pointer

  /****** next*******/
  /*      what is shown after a "warp" or "mix" or "morph"
     button is hit ?*/
  _("show warp after warp"),
  GUINT_TO_POINTER(EDITVIEW_SHOW),
  NULL,
  _("switch the input window(s) to the warped image after a warp (overridden by the above)"), //name
  NULL,

  /****** next*******/
  NULL};


GtkWidget*
create_gtkmorph_menuSettings ()
{

  g_assert(gtkmorph_settings==NULL);
  gtkmorph_settings=gtk_settings_alloc(gtkmorph_template);
  g_assert(gtkmorph_settings);
  return   gtk_settings_create(gtkmorph_template, gtkmorph_settings,
			       gtkmorph_settings_callback,NULL);
}



int
settings_get_value(char *name)
{
  return gtk_settings_get_value(name, gtkmorph_settings);
}


int
settings_set_value(char *name, int val)
{
  return gtk_settings_set_value(name, gtkmorph_settings, val);
}






/***************************** image pane settings ******************/



void
gtkmorph_image_settings_callback(GtkWidget* thismenu, gpointer userdata)
{
  int i=
    GPOINTER_TO_UINT(userdata);
  //userdata==gtk_widget_get_data_top(thismenu,"userdata"));
  g_assert(i>0);
  if (sp->im_widget[i] && GTK_WIDGET_DRAWABLE(sp->im_widget[i]))
    {
      render_pixmap(i, PIXSUBIMAGE);
      render_pixmap(i, PIXLOADED);
    }
  MY_GTK_DRAW(sp->im_widget[i]);
}


gpointer image_settings_template[] =
{ 
  //gtkmorph_image_settings_callback,

  /****** next *****/
  _("preserve aspect ratio"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  _("when loading an image, preserve aspect ratio"), //tooltip (they are translated below)
  NULL, //magic pointer

  /****** next*******/
  _("dim image"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels
  "",
  NULL, //magic pointer

  /****** next*******/
  _("view original mesh"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels
  "",
  NULL, //magic pointer

  /****** next *****/
  _("view original points"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  "",
  NULL, //magic pointer

  /****** next *****/
/*   _("view original features"), //name */
/*   GUINT_TO_POINTER(1),//integer value, stored in pointer */
/*   NULL,//accels NOW IGNORED */
/*   "", */
/*   NULL, //magic pointer */

  /****** next*******/
  _("view warped mesh"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels
  "",
  NULL, //magic pointer

  /****** next *****/
  _("view warped points"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  "",
  NULL, //magic pointer

  /****** next *****/
/*   _("view warped features"), //name */
/*   GUINT_TO_POINTER(1),//integer value, stored in pointer */
/*   NULL,//accels NOW IGNORED */
/*   "", */
/*   NULL, //magic pointer */

  /****** next *****/
  _("view eyes"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  "",
  NULL, //magic pointer

  //  /****** next *****/ /* HACK FIXME : NOW IGNORED */
  //  "view .../loaded image/subimage/warped image/", //name
  //GUINT_TO_POINTER(1),//integer value, stored in pointer
  //NULL,//accels NOW IGNORED
  //"view warped image instead of original image",
  //NULL, //magic pointer

  /****** next *****/
  _("mesh is readonly"), //name
  GUINT_TO_POINTER(1),//integer value, stored in pointer
  NULL,//accels NOW IGNORED
  "",
  NULL, //magic pointer

  /****** next*******/
  NULL};

static void
show_diff_set_it    (GtkMenuItem     *menuitem,
			 gpointer         data)
{
  unsigned int d=GPOINTER_TO_INT(data);
  unsigned int from=d/256, to=d&255;
  if(sp->im_mesh_diff[from]) meshUnref(sp->im_mesh_diff[from]);
  //GtkWidget *b=lookup_widget(sp->im_widget[from],"save_diff");
  if(to>0) {
    g_return_if_fail(meshAllocated ( &( sp->im_mesh[to]  )));
    sp->im_mesh_diff[from] = &( sp->im_mesh[to]  ); 
    meshRef(sp->im_mesh_diff[from]);
    sp->im_mesh_diff_is_difference_mesh[from] =
      sp->im_widget_is_difference_mesh[to];
    //gtk_widget_show(b);
  } else {
    sp->im_mesh_diff[from] = NULL;
    //gtk_widget_hide(b);
  }
  MY_GTK_DRAW(sp->im_drawingarea_widget[from]);
} 

static void
show_diff_show (GtkMenuItem     *menuitem,
			gpointer         data)
{
  unsigned int to , from = GPOINTER_TO_INT(data);
  GtkWidget *m=create_menu_of_images(from,show_diff_set_it,FALSE);  
  {
    GtkWidget *i = gtk_separator_menu_item_new     ();
    gtk_widget_show(i);gtk_container_add (GTK_CONTAINER (m), i);
    i =gtk_menu_item_new_with_label ( _("disable"));
    gtk_widget_show(i);gtk_container_add (GTK_CONTAINER (m), i);
    gtk_signal_connect (GTK_OBJECT (i), "activate",
			GTK_SIGNAL_FUNC (show_diff_set_it ),
			GINT_TO_POINTER( 256 * from) );
  }
  gtk_menu_popup(m,//GtkMenu *menu,
		 NULL,//GtkWidget *parent_menu_shell,
		 NULL,//GtkWidget *parent_menu_item,
		 NULL,//GtkMenuPositionFunc func,
		 NULL,//gpointer data,
		 0,//guint button,
		 gtk_get_current_event_time());//guint32 activate_time);
}

GtkWidget*
create_image_menu_settings (int i)
{

  sp->im_settings[i] = gtk_settings_alloc(image_settings_template);

  g_assert(sp->im_settings[i]);
  sp->im_menu_settings[i]=
    gtk_settings_create(image_settings_template,
			sp->im_settings[i],
			gtkmorph_image_settings_callback,GINT_TO_POINTER(i));
  g_assert(sp->im_menu_settings[i]);

  {
    GtkWidget *menuSettings=sp->im_menu_settings[i];
    GtkWidget *item;
    GtkTooltips *tooltips;
    tooltips = gtk_tooltips_new ();
    item = gtk_menu_item_new_with_label ( _("show mesh difference to..."));
    //gtk_widget_set_name (item,name);
    gtk_tooltips_set_tip (tooltips, item, _("show difference between this mesh and another mesh, as white arrows") , NULL);
    //gtk_widget_ref (item );
    gtk_widget_show (item);
    gtk_container_add (GTK_CONTAINER (menuSettings), item);
    gtk_signal_connect (GTK_OBJECT (item), "activate",
			GTK_SIGNAL_FUNC(show_diff_show ),
			GINT_TO_POINTER(i));
      }

  return sp->im_menu_settings[i];
}



int
image_settings_get_value(char *name, int i)
{
  return gtk_settings_get_value(name, sp->im_settings[i]);
}

int
image_settings_set_value(char *name, int i, int value)
{
  return gtk_settings_set_value(name,sp->im_settings[i],value);
}