File: callbacks_img.c

package info (click to toggle)
xmorph 1%3A20071230.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 11,392 kB
  • ctags: 2,253
  • sloc: ansic: 25,069; sh: 9,691; cpp: 1,231; makefile: 856; sed: 16
file content (258 lines) | stat: -rw-r--r-- 5,985 bytes parent folder | download | duplicates (9)
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
#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>

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

#include "string.h" //memcpy

#include "gtk-meta.h"

#include "gtktopdata.h"
#include "gtk_subimagesel.h"

#include "main.h"
#include "utils.h"
#include "colors.h"
#include "mesh-gtk.h"




/********************************************************************
 *
 * input image window, drawingarea
 *

 note: many callbacks are shared with the "resulting image window"

 ******************************************************************
**/




/***************************************************************

 *		drawing area callbacks

 ***********************************************************
*/ 



void
on_drawingarea_realize                 (GtkWidget       *widget,
				     gpointer         user_data)
{
  int i=
    GPOINTER_TO_UINT(gtk_widget_get_data_top(widget,"imagenum")); 
  /* the drawing area widget will be accessible tru this */

  g_return_if_fail(sp->im_drawingarea_widget[i] == widget);//also done in create_and_show_image_win()
  
  render_pixmap(i, PIXSUBIMAGE);
}





/* gboolean */
/* on_drawingarea_configure_event         (GtkWidget       *widget, */
/*                                         GdkEventConfigure *event, */
/*                                         gpointer         user_data) */
/* { */
/*   int i=    GPOINTER_TO_UINT(gtk_widget_get_data_top(widget,"imagenum"));  */
/*   g_debug(" configure drawingarea %d",i); */
/*   // this loops */
/*   //`drawingarea_configure(i); */
/*   return FALSE; */
/* } */



double transl[6]={1,0,PIXEDITBORDER,0,1,PIXEDITBORDER},
  ident[6]={1,0,0,0,1,0};
double loaded[6];
double * matrix_for_image(int i) 
{
  double *a=ident;
  if( sp->im_editview[i]==EDITVIEW_EYES )
    {
      a=loaded;
      memcpy(a,&sp->transforms[i].subimage2loaded,6*sizeof(double));
      a[2]+=PIXLOADEDBORDER;
      a[5]+=PIXLOADEDBORDER;
    }
  if( sp->im_editview[i]==EDITVIEW_EDIT)
    a=transl;
  return a;
}

gboolean
on_expose_event                        (GtkWidget       *widget,
                                        GdkEventExpose  *event,
                                        gpointer         user_data)
{
  int i=
    GPOINTER_TO_UINT(gtk_widget_get_data_top(widget,"imagenum")); 
  GdkPixmap *pixmap ,
    **pixmap_p=which_pixmap_is_visible(i);

  g_assert(i > 0);
  g_assert(pixmap_p);
  pixmap=*pixmap_p;
  
  if(pixmap == NULL) 
    return FALSE;
  //g_critical("THERE IS NO PIXMAP of type %d  for image %d",
  //       sp->which_pix[i],i);
  //  if ( ! mpl_gc)     allocate_colors( widget );
  if ( ! mpl_gc)    {
    g_critical("colors unavaible: can't draw meshes!");
    return FALSE; 
  }
  /* the gtk+ manual (see "drawing area" section)
     says we have to:*/
  gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
			     &event->area);

  // this one flashes too much
  //gdk_window_clear_area (widget->window,
  //                        event->area.x, event->area.y,
  //                        event->area.width, event->area.height);

  /* then we draw...*/ 
  
  gdk_draw_pixmap(widget->window,
		    widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
		    pixmap,
		    event->area.x, event->area.y,
		    event->area.x, event->area.y,
		    event->area.width, event->area.height);
 {
   double *a=matrix_for_image(i);
   if(i!=MAIN_WIN)
     gdk_draw_mesh(widget->window,
		   image_settings_get_value("view original mesh",i),
		   mpl_gc ,
		   (image_settings_get_value("view original points",i))?
		   features_max_n:0,
		   features_gc,
		   0,//image_settings_get_value("view original features",i),
		   &(sp->im_mesh[i]),// MeshT *mesh, 
		   //sp->resulting_height,
		   //sp->resulting_width,
		   a
		   );
   gdk_draw_mesh(widget->window,
		   image_settings_get_value("view warped mesh",i),
		   widget->style->white_gc ,
		   (image_settings_get_value("view warped points",i))?
		   features_max_n:0,
		   features_gc,
		   0,//image_settings_get_value("view warped features",i),
		   &(sp->im_mesh[MAIN_WIN]),// MeshT *mesh,
		   //sp->resulting_height,
		   //sp->resulting_width,
		   a);       
   if( sp->im_mesh_diff[i]) 
     gdk_draw_mesh_as_arrows( widget->window, widget->style->white_gc ,
			      sp->im_mesh_diff[i],
			      &(sp->im_mesh[i]),
			      sp->im_mesh_diff_is_difference_mesh[i],
			      a);
   }
  if(image_settings_get_value("view eyes",i)) {
    gdk_subimagesel_draw( widget->window, &(sp->subimasel[i]), mps_gc);
  }
/*    if( sp->im_editview[i]==EDITVIEW_EYES || */
/*        sp->im_editview[i]==EDITVIEW_EDIT) */
/*      { */
/*        a[2]-=PIXLOADEDBORDER; */
/*        a[5]-=PIXLOADEDBORDER; */
/*      } */
/*    if( sp->im_editview[i]==EDITVIEW_EYES || */
/*        sp->im_editview[i]==EDITVIEW_EDIT) */
/*      { */
/*        a[2]-=PIXLOADEDBORDER; */
/*        a[5]-=PIXLOADEDBORDER; */
/*      } */
 /* after that, we  */
 gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
			    NULL);
 return TRUE;
}







/*****************************************************************************/








void
on_settings_clicked                    (GtkButton       *button,
                                        gpointer         user_data)
{  
  int i=
    GPOINTER_TO_UINT(gtk_widget_get_data_top(GTK_WIDGET(button),"imagenum")); 
  GtkWidget* m=sp->im_menu_settings[i];
  
  gtk_menu_popup (GTK_MENU(m),//GtkMenu *menu,
		  NULL,//GtkWidget *parent_menu_shell,
		  NULL,//GtkWidget *parent_menu_item,
		  NULL,//GtkMenuPositionFunc func,
		  NULL,//gpointer data,
		  1,//guint button,
		  0);//guint32 activate_time);
}






void
on_do_warp_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{
  int i=
    GPOINTER_TO_UINT(gtk_widget_get_data_top(GTK_WIDGET(button),"imagenum")); 
 
  /* geometry of the resulting image */
  
  do_warp_an_image(i);
}