~ubuntu-branches/ubuntu/utopic/glame/utopic

« back to all changes in this revision

Viewing changes to src/gui/edit_filter/canvaspipe.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-09 17:14:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020409171412-jzpnov7mbz2w6zsr
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * canvaspipe.c
 
3
 *
 
4
 * $Id: canvaspipe.c,v 1.22.2.1 2002/01/16 21:08:02 richi Exp $
 
5
 *
 
6
 * Copyright (C) 2001 Johannes Hirche
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 *
 
22
 *
 
23
 */
 
24
 
 
25
 
 
26
#include <sys/param.h>
 
27
#include <stdio.h>
 
28
#include <math.h>
 
29
#include <gnome.h>
 
30
#include "glamecanvas.h"
 
31
#include "canvasitem.h"
 
32
#include "util/glame_gui_utils.h"
 
33
#include "hash.h"
 
34
 
 
35
 
 
36
extern long bMac;
 
37
extern long nPopupTimeout;
 
38
 
 
39
HASH(gcpipe, GlameCanvasPipe, 8,
 
40
        (gcpipe->pipe == key ),
 
41
        ((long)key/4),
 
42
        ((long)gcpipe->pipe/4),
 
43
        filter_pipe_t * key)
 
44
 
 
45
     
 
46
     /* GlameCanvasFilter* hash_find_GCfilter(filter_t*);
 
47
        void hash_add_GCFilter(GlameCanvasFilter*);
 
48
     */
 
49
 
 
50
 
 
51
     /*  Forward decls */
 
52
 
 
53
 
 
54
 
 
55
/*Yukky gtk class stuff    
 
56
 * Ignore these
 
57
 */
 
58
 
 
59
 
 
60
enum {
 
61
        DELETED,
 
62
        LAST_SIGNAL
 
63
};
 
64
static guint pipe_signals[LAST_SIGNAL] = { 0 };
 
65
 
 
66
 
 
67
 
 
68
static void
 
69
glame_canvas_pipe_destroy (GtkObject *object)
 
70
{
 
71
        GnomeCanvasGroupClass* parent_class;
 
72
        hash_remove_gcpipe(GLAME_CANVAS_PIPE(object));
 
73
        parent_class = gtk_type_class (GNOME_TYPE_CANVAS_GROUP);
 
74
        GTK_OBJECT_CLASS (parent_class)->destroy (object);
 
75
}
 
76
 
 
77
 
 
78
static void
 
79
glame_canvas_pipe_class_init(GlameCanvasPipeClass* class)
 
80
{
 
81
        
 
82
        GtkObjectClass *object_class;
 
83
        object_class = GTK_OBJECT_CLASS(class);
 
84
        object_class->destroy = glame_canvas_pipe_destroy;
 
85
 
 
86
        pipe_signals[DELETED] = gtk_signal_new("deleted",
 
87
                                               GTK_RUN_LAST,
 
88
                                               object_class->type,
 
89
                                               GTK_SIGNAL_OFFSET(GlameCanvasPipeClass,deleted),
 
90
                                               gtk_marshal_NONE__NONE,
 
91
                                               GTK_TYPE_NONE,
 
92
                                               0);
 
93
        gtk_object_class_add_signals(object_class,pipe_signals,LAST_SIGNAL);
 
94
        class->deleted = NULL;
 
95
}
 
96
 
 
97
static void
 
98
glame_canvas_pipe_init(GlameCanvasPipe *p)
 
99
{
 
100
        p->pipe = NULL;
 
101
        p->property_texts = NULL;
 
102
        p->points = NULL;
 
103
        p->line = NULL;
 
104
        p->circle = NULL;
 
105
        p->sourceId = 0;
 
106
        p->destId = 0;
 
107
        p->dy = 0.0;
 
108
        hash_init_gcpipe(p);
 
109
}
 
110
 
 
111
GtkType
 
112
glame_canvas_pipe_get_type(void)
 
113
{
 
114
        static GtkType canvas_pipe_type = 0;
 
115
        
 
116
        if(!canvas_pipe_type){
 
117
                GtkTypeInfo canvas_pipe_info={
 
118
                        "GlameCanvasPipe",
 
119
                        sizeof(GlameCanvasPipe),
 
120
                        sizeof(GlameCanvasPipeClass),
 
121
                        (GtkClassInitFunc) glame_canvas_pipe_class_init,
 
122
                        (GtkObjectInitFunc) glame_canvas_pipe_init,
 
123
                        NULL,NULL,(GtkClassInitFunc)NULL,};
 
124
                canvas_pipe_type = gtk_type_unique(GNOME_TYPE_CANVAS_GROUP,
 
125
                                                   &canvas_pipe_info);
 
126
                gtk_type_set_chunk_alloc(canvas_pipe_type,8);
 
127
        }
 
128
        
 
129
        return canvas_pipe_type;
 
130
}
 
131
 
 
132
 
 
133
GlameCanvasPipe* 
 
134
glame_canvas_find_pipe(filter_pipe_t *p)
 
135
{
 
136
        return hash_find_gcpipe(p);
 
137
}
 
138
 
 
139
static void
 
140
glame_canvas_pipe_reroute(GlameCanvasPipe *p)
 
141
{
 
142
        /* draw connection depending on start and end coords  */
 
143
        double xs, ys, xd,yd;
 
144
        double xOffset, dist;
 
145
        double dy = p->dy;
 
146
        xs = p->points->coords[0];
 
147
        ys = p->points->coords[1];
 
148
        xd = p->points->coords[10];
 
149
        yd = p->points->coords[11];
 
150
        
 
151
 
 
152
        dist = xd-xs;
 
153
        if(dist<50.0)
 
154
                xOffset = dist/2.0;
 
155
        xOffset=(xOffset<5.0)?5.0:xOffset;
 
156
        
 
157
        
 
158
        p->points->coords[2]=xs+xOffset+(p->sourceId*4);
 
159
        p->points->coords[3]=ys;
 
160
        
 
161
        p->points->coords[4]=xs+xOffset+(p->sourceId*4);
 
162
        p->points->coords[5]=(ys+yd)/2.0 + dy;
 
163
        
 
164
        p->points->coords[6]=xd-25.0-(p->destId*4);
 
165
        p->points->coords[7]=(ys+yd)/2.0+dy;
 
166
        
 
167
        p->points->coords[8]=xd-25.0-(p->destId*4);
 
168
        p->points->coords[9]=yd;
 
169
        
 
170
        gnome_canvas_item_set(GNOME_CANVAS_ITEM(p->line),
 
171
                              "points",p->points,
 
172
                              NULL);
 
173
        
 
174
        gnome_canvas_item_set(GNOME_CANVAS_ITEM(p->circle),
 
175
                              "x1",((xs+xd)/2.0)-6.0,
 
176
                              "x2",((xs+xd)/2.0)+6.0,
 
177
                              "y1",((ys+yd)/2.0+dy)-6.0,
 
178
                              "y2",((ys+yd)/2.0+dy)+6.0,
 
179
                              NULL);
 
180
}
 
181
        
 
182
 
 
183
void
 
184
glame_canvas_pipe_redraw(GlameCanvasPipe *p)
 
185
{
 
186
        double sourcex,sourcey,destx,desty;
 
187
        GlameCanvasPort *port;
 
188
        int pipes;
 
189
 
 
190
        /* find coords */
 
191
        
 
192
        port = glame_canvas_find_port(filterpipe_connection_source(p->pipe));
 
193
        pipes = filterport_nrpipes(filterpipe_source(p->pipe));
 
194
        
 
195
        if(!port){
 
196
                DPRINTF("canvasport not found\n");
 
197
                return;
 
198
        }
 
199
        sourcex = GNOME_CANVAS_RE(port)->x1 + 16.0;
 
200
        sourcey = GNOME_CANVAS_RE(port)->y1 + ((GNOME_CANVAS_RE(port)->y2 - GNOME_CANVAS_RE(port)->y1)/(float)(pipes+1))*p->sourceId;
 
201
        gnome_canvas_item_i2w(GNOME_CANVAS_ITEM(port),&sourcex,&sourcey);
 
202
        
 
203
        port = glame_canvas_find_port(filterpipe_connection_dest(p->pipe));
 
204
        pipes = filterport_nrpipes(filterpipe_dest(p->pipe));
 
205
 
 
206
        destx = GNOME_CANVAS_RE(port)->x1;
 
207
        
 
208
        desty = GNOME_CANVAS_RE(port)->y1 + ((GNOME_CANVAS_RE(port)->y2 - GNOME_CANVAS_RE(port)->y1)/(float)(pipes+1))*p->destId;
 
209
        gnome_canvas_item_i2w(GNOME_CANVAS_ITEM(port),&destx,&desty);
 
210
        
 
211
        p->points->coords[0] = sourcex;
 
212
        p->points->coords[1] = sourcey;
 
213
        p->points->coords[10] = destx;
 
214
        p->points->coords[11] = desty;
 
215
        glame_canvas_pipe_reroute(p);
 
216
}
 
217
 
 
218
 
 
219
static void
 
220
glame_canvas_pipe_end_moved_cb(GlameCanvasPort* p,double dx, double dy, GlameCanvasPipe* pipe)
 
221
{
 
222
        pipe->points->coords[10] += dx;
 
223
        pipe->points->coords[11] += dy;
 
224
        glame_canvas_pipe_reroute(pipe);
 
225
}
 
226
 
 
227
static gboolean
 
228
glame_canvas_pipe_begin_moved_cb(GlameCanvasPort* p,double dx, double dy, GlameCanvasPipe* pipe)
 
229
{
 
230
        pipe->points->coords[0] += dx;
 
231
        pipe->points->coords[1] += dy;
 
232
        glame_canvas_pipe_reroute(pipe);
 
233
        return FALSE;
 
234
}
 
235
 
 
236
static void
 
237
glame_canvas_pipe_port_changed_cb(GlameCanvasPort* p, GlameCanvasPipe* pipe)
 
238
{
 
239
        glame_canvas_pipe_redraw(pipe);
 
240
}
 
241
 
 
242
static void
 
243
glame_canvas_pipe_deleted_cb(glsig_handler_t *handler,long sig,va_list va)
 
244
{
 
245
        GlameCanvasPipe* gPipe;
 
246
        filter_pipe_t *pipe;
 
247
 
 
248
        /* Ignore not existing pipes (and delete handler) */
 
249
        GLSIGH_GETARGS1(va, pipe);
 
250
        if (!hash_find_gcpipe(pipe)) {
 
251
                glsig_delete_handler(handler);
 
252
                return;
 
253
        }
 
254
 
 
255
        gPipe = GLAME_CANVAS_PIPE(glsig_handler_private(handler));
 
256
        gtk_signal_emit_by_name(GTK_OBJECT(gPipe),"deleted");
 
257
        gtk_object_destroy(GTK_OBJECT(gPipe));
 
258
}
 
259
        
 
260
 
 
261
static gboolean
 
262
glame_canvas_pipe_event_cb(GnomeCanvasItem* i, GdkEvent* event, GlameCanvasPipe* p);
 
263
 
 
264
 
 
265
 
 
266
/****************
 
267
 * menu stuff
 
268
 ****************/
 
269
 
 
270
static void canvas_pipe_source_properties_cb(GtkObject *foo,
 
271
                                             filter_pipe_t *pipe)
 
272
{
 
273
        GtkWidget *p;
 
274
        p = glame_gui_filter_properties(filterpipe_sourceparamdb(pipe),
 
275
                                        filterport_label(filterpipe_connection_source(pipe)), NULL);
 
276
        gtk_widget_show(p);
 
277
}
 
278
static void canvas_pipe_dest_properties_cb(GtkObject *foo, filter_pipe_t *pipe)
 
279
{
 
280
        GtkWidget *p;
 
281
        p = glame_gui_filter_properties(filterpipe_destparamdb(pipe),
 
282
                                        filterport_label(filterpipe_connection_dest(pipe)), NULL);
 
283
        gtk_widget_show(p);
 
284
}
 
285
static void canvas_pipe_delete_cb(GtkObject* foo, filter_pipe_t* pipe)
 
286
{
 
287
        filterpipe_delete(pipe);
 
288
}
 
289
 
 
290
static GnomeUIInfo pipe_menu[]=
 
291
{
 
292
        GNOMEUIINFO_ITEM(N_("_Source properties..."), NULL, canvas_pipe_source_properties_cb, NULL),
 
293
        GNOMEUIINFO_ITEM(N_("D_estination properties..."), NULL, canvas_pipe_dest_properties_cb, NULL),
 
294
        GNOMEUIINFO_SEPARATOR,
 
295
        GNOMEUIINFO_ITEM(N_("_Delete"), NULL, canvas_pipe_delete_cb,NULL),
 
296
        GNOMEUIINFO_END
 
297
};
 
298
 
 
299
 
 
300
 
 
301
static gboolean
 
302
glame_canvas_pipe_grabbing_cb(GnomeCanvasItem* i, GdkEvent* event, GlameCanvasPipe* p)
 
303
{
 
304
        GtkWidget* menu;
 
305
        switch(event->type){
 
306
        case GDK_MOTION_NOTIFY:
 
307
                /* do something here */
 
308
                p->dy -= p->last_y - event->button.y;
 
309
                p->last_y = event->button.y;
 
310
                glame_canvas_pipe_reroute(p);
 
311
                return TRUE;
 
312
                break;
 
313
        case GDK_BUTTON_RELEASE:
 
314
                gnome_canvas_item_ungrab(i,event->button.time);
 
315
                gtk_signal_disconnect_by_func(GTO(i),GTK_SIGNAL_FUNC(glame_canvas_pipe_grabbing_cb),p);
 
316
                gtk_signal_handler_unblock_by_func(GTO(i),GTK_SIGNAL_FUNC(glame_canvas_pipe_event_cb),p);
 
317
                return TRUE;
 
318
        case GDK_2BUTTON_PRESS:
 
319
                switch(event->button.button){
 
320
                case 1:
 
321
                        if(bMac){
 
322
                                menu = gnome_popup_menu_new(pipe_menu);
 
323
                                gnome_popup_menu_do_popup(menu,NULL,NULL,&event->button,p->pipe);
 
324
                        }
 
325
                        break;
 
326
                }
 
327
                gnome_canvas_item_ungrab(i,event->button.time);
 
328
                gtk_signal_disconnect_by_func(GTO(i),GTK_SIGNAL_FUNC(glame_canvas_pipe_grabbing_cb),p);
 
329
                gtk_signal_handler_unblock_by_func(GTO(i),GTK_SIGNAL_FUNC(glame_canvas_pipe_event_cb),p);
 
330
                return TRUE;
 
331
                break;
 
332
 
 
333
        default:
 
334
                return FALSE;
 
335
        }
 
336
}
 
337
 
 
338
 
 
339
gboolean 
 
340
glame_canvas_pipe_show_properties(GlameCanvasPipe* pipe)
 
341
{
 
342
 
 
343
        filter_param_t* param;
 
344
        GnomeCanvasText * text;
 
345
        GnomeCanvasGroup *group;
 
346
        GnomeCanvasRect* rect;
 
347
        char buffer[256];
 
348
        const char* font = glame_gui_get_font(GLAME_CANVAS(GNOME_CANVAS_ITEM(pipe)->canvas));
 
349
        float y;
 
350
        double xOffset,yOffset;
 
351
        double bmaxx,bminx,bminy,bmaxy, recx1,recx2,recy1,recy2;
 
352
        gboolean params = FALSE;
 
353
        if(pipe->timeout_id){
 
354
                gtk_timeout_remove(pipe->timeout_id);
 
355
                pipe->timeout_id = 0;
 
356
        }
 
357
        
 
358
        bmaxx=-999999999.0;
 
359
        bminx=9999999999.0;
 
360
        bmaxy=-999999999.0;
 
361
        bminy=999999999.0;
 
362
 
 
363
 
 
364
        xOffset = (GNOME_CANVAS_RE(pipe->circle)->x1+GNOME_CANVAS_RE(pipe->circle)->x2)/2.0;
 
365
        yOffset = GNOME_CANVAS_RE(pipe->circle)->y2;
 
366
 
 
367
        y = 10.0 + yOffset;
 
368
        
 
369
        DPRINTF("foo\n");
 
370
        group = GNOME_CANVAS_GROUP(CANVAS_ITEM_ROOT(pipe));
 
371
        group = GNOME_CANVAS_GROUP(gnome_canvas_item_new(group,
 
372
                                      gnome_canvas_group_get_type(),
 
373
                                      NULL));
 
374
        gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(group));
 
375
        params = TRUE;
 
376
        snprintf(buffer,255,_("Samplerate: %d"),filterpipe_sample_rate(pipe->pipe));
 
377
        text = GNOME_CANVAS_TEXT(gnome_canvas_item_new(group,
 
378
                                                       gnome_canvas_text_get_type(),
 
379
                                                       "x",xOffset,
 
380
                                                       "y",y,
 
381
                                                       "text",buffer,
 
382
                                                       "font",font,
 
383
                                                       "clip_width",94.0,
 
384
                                                       "clip_height",16.0,
 
385
                                                       "fill_color","blue",
 
386
                                                       "anchor",GTK_ANCHOR_WEST,
 
387
                                                       "justification",GTK_JUSTIFY_LEFT, 
 
388
                                                       "clip",0,
 
389
                                                       NULL));
 
390
        gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(text));
 
391
        
 
392
        gnome_canvas_item_get_bounds(GCI(text),&recx1,&recy1,&recx2,&recy2);
 
393
        bmaxx = bmaxx<recx2?recx2:bmaxx;
 
394
        bmaxy = bmaxy<recy2?recy2:bmaxy;
 
395
        bminx = bminx>recx1?recx1:bminx;
 
396
        bminy = bminy>recy1?recy1:bminy;
 
397
        
 
398
        y +=16.0;
 
399
        snprintf(buffer,255,_("Hangle: %f"),filterpipe_sample_hangle(pipe->pipe));
 
400
        text = GNOME_CANVAS_TEXT(gnome_canvas_item_new(group,
 
401
                                                       gnome_canvas_text_get_type(),
 
402
                                                       "x",xOffset,
 
403
                                                       "y",y,
 
404
                                                       "text",buffer,
 
405
                                                       "font",font,
 
406
                                                       "clip_width",94.0,
 
407
                                                       "clip_height",16.0,
 
408
                                                       "fill_color","blue",
 
409
                                                       "anchor",GTK_ANCHOR_WEST,
 
410
                                                       "justification",GTK_JUSTIFY_LEFT, 
 
411
                                                       "clip",0,
 
412
                                                       NULL));
 
413
        gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(text));
 
414
        
 
415
        gnome_canvas_item_get_bounds(GCI(text),&recx1,&recy1,&recx2,&recy2);
 
416
        bmaxx = bmaxx<recx2?recx2:bmaxx;
 
417
        bmaxy = bmaxy<recy2?recy2:bmaxy;
 
418
        bminx = bminx>recx1?recx1:bminx;
 
419
        bminy = bminy>recy1?recy1:bminy;
 
420
        
 
421
        y +=16.0;
 
422
        
 
423
        if(filterparamdb_nrparams(filterpipe_sourceparamdb(pipe->pipe))){
 
424
                params = TRUE;
 
425
                snprintf(buffer,255, _("Source params:"));
 
426
                text = GNOME_CANVAS_TEXT(gnome_canvas_item_new(group,
 
427
                                                               gnome_canvas_text_get_type(),
 
428
                                                               "x",xOffset,
 
429
                                                               "y",y,
 
430
                                                               "text",buffer,
 
431
                                                               "font",font,
 
432
                                                               "clip_width",94.0,
 
433
                                                               "clip_height",16.0,
 
434
                                                               "fill_color","blue",
 
435
                                                               "anchor",GTK_ANCHOR_WEST,
 
436
                                                               "justification",GTK_JUSTIFY_LEFT, 
 
437
                                                               "clip",0,
 
438
                                                               NULL));
 
439
                gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(text));
 
440
                
 
441
                gnome_canvas_item_get_bounds(GCI(text),&recx1,&recy1,&recx2,&recy2);
 
442
                bmaxx = bmaxx<recx2?recx2:bmaxx;
 
443
                bmaxy = bmaxy<recy2?recy2:bmaxy;
 
444
                bminx = bminx>recx1?recx1:bminx;
 
445
                bminy = bminy>recy1?recy1:bminy;
 
446
                
 
447
                y +=16.0;
 
448
                
 
449
                filterparamdb_foreach_param(filterpipe_sourceparamdb(pipe->pipe),param){
 
450
                        char *str;
 
451
                        str = filterparam_to_string(param);
 
452
                        snprintf(buffer, 255, "%s: %s", filterparam_label(param), str);
 
453
                        free(str);
 
454
                        text = GNOME_CANVAS_TEXT(gnome_canvas_item_new(group,
 
455
                                                                       gnome_canvas_text_get_type(),
 
456
                                                                       "x",xOffset,
 
457
                                             "y",y,
 
458
                                                                       "text",buffer,
 
459
                                                                       "font",font,
 
460
                                                                       "clip_width",94.0,
 
461
                                                                       "clip_height",16.0,
 
462
                                                                       "fill_color","black",
 
463
                                                                       "anchor",GTK_ANCHOR_WEST,
 
464
                                                                       "justification",GTK_JUSTIFY_LEFT, 
 
465
                                                                       "clip",0,
 
466
                                                                       NULL));
 
467
                        gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(text));
 
468
                        
 
469
                        gnome_canvas_item_get_bounds(GCI(text),&recx1,&recy1,&recx2,&recy2);
 
470
                        bmaxx = bmaxx<recx2?recx2:bmaxx;
 
471
                        bmaxy = bmaxy<recy2?recy2:bmaxy;
 
472
                        bminx = bminx>recx1?recx1:bminx;
 
473
                        bminy = bminy>recy1?recy1:bminy;
 
474
                        
 
475
                        y+=16.0;
 
476
                }
 
477
        }
 
478
        if(filterparamdb_nrparams(filterpipe_destparamdb(pipe->pipe))){
 
479
                params = TRUE;
 
480
                snprintf(buffer,255, _("Dest params:"));
 
481
                text = GNOME_CANVAS_TEXT(gnome_canvas_item_new(group,
 
482
                                                               gnome_canvas_text_get_type(),
 
483
                                                               "x",xOffset,
 
484
                                                               "y",y,
 
485
                                                               "text",buffer,
 
486
                                                               "font",font,                    
 
487
                                                               "clip_width",94.0,
 
488
                                                               "clip_height",16.0,
 
489
                                                               "fill_color","red",
 
490
                                                               "anchor",GTK_ANCHOR_WEST,
 
491
                                                               "justification",GTK_JUSTIFY_LEFT, 
 
492
                                                               "clip",0,
 
493
                                                               NULL));
 
494
                gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(text));
 
495
        
 
496
                gnome_canvas_item_get_bounds(GCI(text),&recx1,&recy1,&recx2,&recy2);
 
497
                bmaxx = bmaxx<recx2?recx2:bmaxx;
 
498
                bmaxy = bmaxy<recy2?recy2:bmaxy;
 
499
                bminx = bminx>recx1?recx1:bminx;
 
500
                bminy = bminy>recy1?recy1:bminy;
 
501
                
 
502
                y +=16.0;
 
503
                
 
504
                filterparamdb_foreach_param(filterpipe_destparamdb(pipe->pipe),param){
 
505
                        char *str;
 
506
                        str = filterparam_to_string(param);
 
507
                        snprintf(buffer, 255, "%s: %s", filterparam_label(param), str);
 
508
                        free(str);
 
509
                        text = GNOME_CANVAS_TEXT(gnome_canvas_item_new(group,
 
510
                                                                       gnome_canvas_text_get_type(),
 
511
                                                                       "x",xOffset,
 
512
                                                                       "y",y,
 
513
                                                                       "text",buffer,
 
514
                                                                       "font",font,
 
515
                                                                       "clip_width",94.0,
 
516
                                                                       "clip_height",16.0,
 
517
                                                                       "fill_color","black",
 
518
                                                                       "anchor",GTK_ANCHOR_WEST,
 
519
                                                                       "justification",GTK_JUSTIFY_LEFT, 
 
520
                                                                       "clip",0,
 
521
                                                                       NULL));
 
522
                        gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(text));
 
523
                        
 
524
                        gnome_canvas_item_get_bounds(GCI(text),&recx1,&recy1,&recx2,&recy2);
 
525
                        bmaxx = bmaxx<recx2?recx2:bmaxx;
 
526
                        bmaxy = bmaxy<recy2?recy2:bmaxy;
 
527
                        bminx = bminx>recx1?recx1:bminx;
 
528
                        bminy = bminy>recy1?recy1:bminy;
 
529
                        
 
530
                        y+=16.0;
 
531
                }
 
532
        }
 
533
        if(params){
 
534
        rect = GNOME_CANVAS_RECT(gnome_canvas_item_new(group,
 
535
                                     gnome_canvas_rect_get_type(),
 
536
                                     "x1",bminx -5.0,
 
537
                                     "y1",bminy -5.0,
 
538
                                     "x2",bmaxx+5.0,
 
539
                                     "y2",bmaxy+5.0,
 
540
                                     "outline_color","black",
 
541
                                     "width_units",1.0,
 
542
                                     "fill_color_rgba",0xd0d0ff00,
 
543
                                     NULL));
 
544
        gnome_canvas_item_lower_to_bottom(GNOME_CANVAS_ITEM(rect));
 
545
        }
 
546
        pipe->popupGroup = group;
 
547
        return FALSE;
 
548
}
 
549
 
 
550
void
 
551
glame_canvas_pipe_hide_properties(GlameCanvasPipe *pipe)
 
552
{
 
553
        if(!pipe->popupGroup){
 
554
                return;
 
555
        }
 
556
        gtk_object_destroy(GTO(pipe->popupGroup));
 
557
        pipe->popupGroup = NULL;
 
558
 
 
559
}
 
560
 
 
561
 
 
562
static void
 
563
glame_canvas_pipe_register_popup(GlameCanvasPipe* pipe)
 
564
{
 
565
        if(pipe->timeout_id){
 
566
                gtk_timeout_remove(pipe->timeout_id);
 
567
        }
 
568
        pipe->timeout_id = gtk_timeout_add(nPopupTimeout,(GtkFunction)glame_canvas_pipe_show_properties,pipe);
 
569
}
 
570
static void
 
571
glame_canvas_pipe_deregister_popup(GlameCanvasPipe* pipe)
 
572
{
 
573
        if(pipe->timeout_id){
 
574
                gtk_timeout_remove(pipe->timeout_id);
 
575
                pipe->timeout_id = 0;
 
576
        }else{
 
577
                glame_canvas_pipe_hide_properties(pipe);
 
578
        }
 
579
}
 
580
 
 
581
static gboolean
 
582
glame_canvas_pipe_event_cb(GnomeCanvasItem* i, GdkEvent* event, GlameCanvasPipe* p)
 
583
{
 
584
        GdkCursor * fleur;
 
585
        GtkWidget* menu;
 
586
        switch(event->type){
 
587
        case GDK_BUTTON_PRESS:
 
588
                switch(event->button.button){
 
589
                case 1:
 
590
                        p->last_y = event->button.y;
 
591
                        fleur = gdk_cursor_new(GDK_FLEUR);
 
592
                        /* block other handlers (this one ;-) */
 
593
                        gtk_signal_handler_block_by_func(GTK_OBJECT(i),GTK_SIGNAL_FUNC(glame_canvas_pipe_event_cb),p);
 
594
                        gtk_signal_connect(GTK_OBJECT(i),"event", GTK_SIGNAL_FUNC(glame_canvas_pipe_grabbing_cb), p);
 
595
                        gnome_canvas_item_grab(GNOME_CANVAS_ITEM(i),GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK|GDK_BUTTON_PRESS_MASK,fleur,
 
596
                                               event->button.time);
 
597
                        gdk_cursor_destroy(fleur);
 
598
                        return TRUE;
 
599
                        break;
 
600
                case 3:
 
601
                                /* popup menu */
 
602
                        menu = gnome_popup_menu_new(pipe_menu);
 
603
                        gnome_popup_menu_do_popup(menu,NULL,NULL,&event->button,p->pipe);
 
604
 
 
605
                        break;
 
606
                default:
 
607
                        return FALSE;
 
608
                        break;
 
609
                }
 
610
        case GDK_2BUTTON_PRESS:
 
611
                switch(event->button.button){
 
612
                case 1:
 
613
                        if(bMac){
 
614
                                menu = gnome_popup_menu_new(pipe_menu);
 
615
                                gnome_popup_menu_do_popup(menu,NULL,NULL,&event->button,p->pipe);
 
616
                        }
 
617
                        break;
 
618
                }
 
619
                break;
 
620
        case GDK_ENTER_NOTIFY:
 
621
                glame_canvas_pipe_register_popup(p);
 
622
                break;
 
623
        case GDK_LEAVE_NOTIFY:
 
624
                glame_canvas_pipe_deregister_popup(p);
 
625
                break;
 
626
        default:
 
627
                return FALSE;
 
628
                break;
 
629
        }
 
630
        return FALSE;
 
631
}
 
632
 
 
633
GlameCanvasPipe* glame_canvas_pipe_new(GnomeCanvasGroup *group, filter_pipe_t * pipe)
 
634
{
 
635
        GlameCanvasPipe* gPipe;
 
636
        GnomeCanvasGroup * gGroup;
 
637
        GlameCanvasPort *gSource, *gDest;
 
638
        int i;
 
639
        
 
640
        if(glame_canvas_find_pipe(pipe)){
 
641
                DPRINTF("Trying to add duplicate pipe!\n");
 
642
                return glame_canvas_find_pipe(pipe);
 
643
        }
 
644
        gPipe = GLAME_CANVAS_PIPE(gnome_canvas_item_new(group, 
 
645
                                                        glame_canvas_pipe_get_type(),
 
646
                                                        NULL));
 
647
        gGroup = GNOME_CANVAS_GROUP(gPipe);
 
648
        
 
649
        /* create and clear line coords */
 
650
        gPipe->points = gnome_canvas_points_new(6);
 
651
        for(i=0;i<12;i++)
 
652
                gPipe->points->coords[i] = 0.0;
 
653
        
 
654
        gPipe->line = GNOME_CANVAS_LINE(gnome_canvas_item_new(gGroup,
 
655
                                                              gnome_canvas_line_get_type(),
 
656
                                                              "points",gPipe->points,
 
657
                                                              "fill_color","black",
 
658
                                                              "width_units",2.0,
 
659
                                                              "arrow_shape_a",18.0,
 
660
                                                              "arrow_shape_b",20.0,
 
661
                                                              "arrow_shape_c",5.0,
 
662
                                                              "smooth",TRUE,
 
663
                                                              "spline_steps",100,
 
664
                                                              "last_arrowhead",TRUE,
 
665
                                                              NULL));
 
666
        gPipe->circle = GNOME_CANVAS_ELLIPSE(gnome_canvas_item_new(gGroup,
 
667
                                                                   gnome_canvas_ellipse_get_type(),
 
668
                                                                   "x1",0.0,
 
669
                                                                   "x2",0.0,
 
670
                                                                   "y1",0.0,
 
671
                                                                   "y2",0.0,
 
672
                                                                   "fill_color","black",
 
673
                                                                   "width_pixels",5,
 
674
                                                                   NULL));
 
675
        gPipe->pipe = pipe;
 
676
 
 
677
        /* connect to backend destroy sig */
 
678
        glsig_add_handler(filterpipe_emitter(pipe),GLSIG_PIPE_DELETED,glame_canvas_pipe_deleted_cb,gPipe);
 
679
        
 
680
        hash_add_gcpipe(gPipe);
 
681
        
 
682
        gtk_signal_connect_after(GTK_OBJECT(gPipe->circle),
 
683
                                 "event",
 
684
                                 GTK_SIGNAL_FUNC(glame_canvas_pipe_event_cb),
 
685
                                 gPipe);
 
686
        
 
687
        gSource = glame_canvas_find_port(filterpipe_connection_source(pipe));
 
688
        gDest = glame_canvas_find_port(filterpipe_connection_dest(pipe));
 
689
 
 
690
        /* connect to movement of ports */
 
691
        gtk_signal_connect(GTK_OBJECT(gDest),
 
692
                           "moved",
 
693
                           GTK_SIGNAL_FUNC(glame_canvas_pipe_end_moved_cb),
 
694
                           gPipe);
 
695
        
 
696
        gtk_signal_connect(GTK_OBJECT(gSource),
 
697
                           "moved",
 
698
                           GTK_SIGNAL_FUNC(glame_canvas_pipe_begin_moved_cb),
 
699
                           gPipe);
 
700
 
 
701
        /* connect to reordering of connections at port */
 
702
        gtk_signal_connect(GTK_OBJECT(gDest),
 
703
                           "connections_changed",
 
704
                           GTK_SIGNAL_FUNC(glame_canvas_pipe_port_changed_cb),
 
705
                           gPipe);
 
706
        
 
707
        gtk_signal_connect(GTK_OBJECT(gSource),
 
708
                           "connections_changed",
 
709
                           GTK_SIGNAL_FUNC(glame_canvas_pipe_port_changed_cb),
 
710
                           gPipe);
 
711
 
 
712
        gtk_signal_connect(GTK_OBJECT(gPipe),"deleted",
 
713
                           GTK_SIGNAL_FUNC(glame_canvas_port_pipe_deleted_cb),
 
714
                           gSource);
 
715
 
 
716
        gtk_signal_connect(GTK_OBJECT(gPipe),"deleted",
 
717
                           GTK_SIGNAL_FUNC(glame_canvas_port_pipe_deleted_cb),
 
718
                           gDest);
 
719
 
 
720
 
 
721
        /* reorder all pipes */
 
722
        gtk_signal_emit_by_name(GTK_OBJECT(glame_canvas_find_port(filterpipe_connection_dest(pipe))),
 
723
                                "connections_changed");
 
724
        gtk_signal_emit_by_name(GTK_OBJECT(glame_canvas_find_port(filterpipe_connection_source(pipe))),
 
725
                                "connections_changed");
 
726
        
 
727
        return gPipe;
 
728
}
 
729
 
 
730
 
 
731
 
 
732
/* destroy all pipes in a canvas */
 
733
void glame_canvas_pipe_destroy_all(GnomeCanvas* canvas)
 
734
{
 
735
        GlameCanvasPipe * gcp;
 
736
        
 
737
        int i;
 
738
        for(i=0;i<(1<<8);i++){
 
739
                gcp = hash_getslot_gcpipe(i);
 
740
                
 
741
                while(gcp){
 
742
                        if(CANVAS_ITEM_CANVAS(gcp) == canvas){
 
743
                                /* FIXME doesnt take other windows into account! */
 
744
                                gtk_object_destroy(GTO(gcp));
 
745
                        }
 
746
                        gcp = hash_next_gcpipe(gcp);
 
747
                }
 
748
        }
 
749
}