2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include "gsteditor.h"
27 static void gst_editor_pad_class_init(GstEditorPadClass *klass);
28 static void gst_editor_pad_init(GstEditorPad *pad);
29 static void gst_editor_pad_set_arg(GtkObject *object,GtkArg *arg,guint id);
30 static void gst_editor_pad_get_arg(GtkObject *object,GtkArg *arg,guint id);
31 static void gst_editor_pad_realize(GstEditorPad *pad);
33 static void gst_editor_pad_position_changed(GstEditorPad *pad, GstEditorElement *element);
35 /* class implementation functions */
36 //static void gst_editor_pad_update(GnomeCanvasItem *item,double *affine,
37 // ArtSVP *clip_path,int flags);
38 //static gint gst_editor_pad_event(GnomeCanvasItem *item,GdkEvent *event);
40 /* events fired by items within self */
41 static gint gst_editor_pad_padbox_event(GnomeCanvasItem *item,
45 /* utility functions */
46 static void gst_editor_pad_resize(GstEditorPad *pad);
62 static GtkObjectClass *parent_class;
63 //static guint gst_editor_pad_signals[LAST_SIGNAL] = { 0 };
66 gst_editor_pad_get_type (void)
68 static GtkType pad_type = 0;
71 static const GtkTypeInfo pad_info = {
74 sizeof(GstEditorPadClass),
75 (GtkClassInitFunc)gst_editor_pad_class_init,
76 (GtkObjectInitFunc)gst_editor_pad_init,
79 (GtkClassInitFunc)NULL,
81 pad_type = gtk_type_unique(gtk_object_get_type(),&pad_info);
87 gst_editor_pad_class_init (GstEditorPadClass *klass)
89 GtkObjectClass *object_class;
91 object_class = (GtkObjectClass*)klass;
93 parent_class = gtk_type_class(gtk_object_get_type());
95 gtk_object_add_arg_type("GstEditorPad::x",GTK_TYPE_DOUBLE,
96 GTK_ARG_READWRITE,ARG_X);
97 gtk_object_add_arg_type("GstEditorPad::y",GTK_TYPE_DOUBLE,
98 GTK_ARG_READWRITE,ARG_Y);
99 gtk_object_add_arg_type("GstEditorPad::width",GTK_TYPE_DOUBLE,
100 GTK_ARG_READWRITE,ARG_WIDTH);
101 gtk_object_add_arg_type("GstEditorPad::height",GTK_TYPE_DOUBLE,
102 GTK_ARG_READWRITE,ARG_HEIGHT);
103 gtk_object_add_arg_type("GstEditorPad::pad",GTK_TYPE_POINTER,
104 GTK_ARG_READWRITE,ARG_PAD);
106 klass->realize = gst_editor_pad_realize;
108 object_class->set_arg = gst_editor_pad_set_arg;
109 object_class->get_arg = gst_editor_pad_get_arg;
113 gst_editor_pad_init(GstEditorPad *pad)
118 gst_editor_pad_new(GstEditorElement *parent,GstPad *pad,
119 const gchar *first_arg_name, ...)
121 GstEditorPad *editorpad;
124 g_return_val_if_fail(parent != NULL, NULL);
125 g_return_val_if_fail(GST_IS_EDITOR_ELEMENT(parent), NULL);
126 g_return_val_if_fail(pad != NULL, NULL);
127 g_return_val_if_fail(GST_IS_PAD(pad), NULL);
129 editorpad = GST_EDITOR_PAD(gtk_type_new(GST_TYPE_EDITOR_PAD));
130 editorpad->pad = pad;
131 GST_EDITOR_SET_OBJECT(pad, editorpad);
133 va_start(args,first_arg_name);
134 gst_editor_pad_construct(editorpad,parent,first_arg_name,args);
137 if (GST_PAD_CONNECTED (pad)) {
139 GstEditorPad *peereditorpad;
141 // FIXME does this need to check for ghost/real?
142 peerpad = GST_PAD_PEER(pad);
144 peereditorpad = GST_EDITOR_GET_OBJECT (peerpad);
147 GstEditorConnection *connection;
149 connection = gst_editor_connection_new (parent, editorpad);
150 gst_editor_connection_set_endpad (connection, peereditorpad);
154 gtk_signal_connect_object (GTK_OBJECT (parent), "position_changed",
155 gst_editor_pad_position_changed, editorpad);
161 gst_editor_pad_construct(GstEditorPad *pad,
162 GstEditorElement *parent,
163 const gchar *first_arg_name,va_list args)
165 GtkObject *obj = GTK_OBJECT(pad);
166 GSList *arg_list = NULL, *info_list = NULL;
168 GstEditorPadClass *padclass;
170 // g_print("in gst_editor_pad_construct()\n");
172 error = gtk_object_args_collect(GTK_OBJECT_TYPE(obj),&arg_list,
173 &info_list,first_arg_name,args);
175 g_warning("gst_editor_pad_construct(): %s",error);
179 // g_print("setting all the arguments on the pad\n");
180 for (arg=arg_list,info=info_list;arg;arg=arg->next,info=info->next)
181 gtk_object_arg_set(obj,arg->data,info->data);
182 gtk_args_collect_cleanup(arg_list,info_list);
185 pad->parent = parent;
187 padclass = GST_EDITOR_PAD_CLASS(GTK_OBJECT(pad)->klass);
189 (padclass->realize)(pad);
193 gst_editor_pad_set_arg (GtkObject *object,GtkArg *arg,guint id)
197 /* get the major types of this object */
198 pad = GST_EDITOR_PAD(object);
202 pad->x = GTK_VALUE_DOUBLE(*arg);
205 pad->y = GTK_VALUE_DOUBLE(*arg);
208 pad->width = GTK_VALUE_DOUBLE(*arg);
212 pad->height = GTK_VALUE_DOUBLE(*arg);
216 /* FIXME: this is very brute force */
217 pad->pad = GTK_VALUE_POINTER(*arg);
220 g_warning("gsteditorpad: unknown arg!");
226 gst_editor_pad_get_arg (GtkObject *object,GtkArg *arg,guint id)
230 /* get the major types of this object */
231 pad = GST_EDITOR_PAD(object);
235 GTK_VALUE_INT(*arg) = pad->x;
238 GTK_VALUE_INT(*arg) = pad->y;
241 GTK_VALUE_INT(*arg) = pad->width;
244 GTK_VALUE_INT(*arg) = pad->height;
247 arg->type = GTK_TYPE_INVALID;
253 gst_editor_pad_realize (GstEditorPad *pad)
255 // g_print("realizing editor pad %p\n",pad);
257 /* we must be attached to an element */
258 g_return_if_fail(pad->parent != NULL);
260 /* create the group and bounding box */
261 pad->group = GNOME_CANVAS_GROUP(gnome_canvas_item_new(pad->parent->group,
262 gnome_canvas_group_get_type(),"x",pad->x,"y",pad->y,NULL));
263 g_return_if_fail(pad->group != NULL);
264 GST_EDITOR_SET_OBJECT(pad->group,pad);
266 pad->border = gnome_canvas_item_new(pad->group,
267 gnome_canvas_rect_get_type(),
268 "width_units",1.0,"fill_color_rgba", 0xCCFFCC00,"outline_color","black",
269 "x1",0.0,"y1",0.0,"x2",pad->width,"y2",pad->height,NULL);
270 g_return_if_fail(pad->border != NULL);
271 GST_EDITOR_SET_OBJECT(pad->border,pad);
273 /* create the pad box on the correct side */
274 // FIXME does this need to check for ghost/real?
275 pad->issrc = (GST_PAD_DIRECTION(pad->pad) == GST_PAD_SRC);
277 pad->padbox = gnome_canvas_item_new(pad->group,
278 gnome_canvas_rect_get_type(),
279 "width_units",1.0,"fill_color","white","outline_color","black",
280 "x1",pad->x-4.0,"y1",2.0,"x2",pad->x,"y2",pad->height-2.0,NULL);
282 pad->padbox = gnome_canvas_item_new(pad->group,
283 gnome_canvas_rect_get_type(),
284 "width_units",1.0,"fill_color","white","outline_color","black",
285 "x1",0.0,"y1",2.0,"x2",4.0,"y2",pad->height-2.0,NULL);
286 g_return_if_fail(pad->padbox != NULL);
287 GST_EDITOR_SET_OBJECT(pad->padbox,pad);
289 gtk_signal_connect(GTK_OBJECT(pad->group),"event",
290 GTK_SIGNAL_FUNC(gst_editor_pad_padbox_event),pad);
292 pad->title = gnome_canvas_item_new(pad->group,
293 gnome_canvas_text_get_type(),
294 "text",gst_pad_get_name(pad->pad),
295 "x",0.0,"y",0.0,"anchor",GTK_ANCHOR_NORTH_WEST,
296 "font_gdk",gtk_widget_get_default_style()->font,
298 g_return_if_fail(pad->title != NULL);
299 GST_EDITOR_SET_OBJECT(pad->title,pad);
301 pad->realized = TRUE;
303 gst_editor_pad_repack(pad);
308 gst_editor_pad_resize (GstEditorPad *pad)
310 gdouble minwidth,minheight;
312 // g_print("resizing pad\n");
314 minwidth = 0;minheight = 0;
316 /* get the text size and add it into minsize */
317 minwidth = gst_util_get_double_arg(GTK_OBJECT(pad->title),
319 minheight = gst_util_get_double_arg(GTK_OBJECT(pad->title),
322 /* calculate the size of the padbox */
323 pad->boxheight = minheight - 4.0;
324 pad->boxwidth = pad->boxheight / 2.0;
325 minwidth += pad->boxwidth;
327 /* force the thing to grow if necessary */
328 pad->width = MAX(pad->width,minwidth);
329 pad->height = MAX(pad->height,minheight);
331 /* update the connection if there is one */
332 // g_print("connection is %p\n",pad->connection);
333 if (pad->connection != NULL)
334 gst_editor_connection_resize(pad->connection);
338 gst_editor_pad_repack (GstEditorPad *pad)
342 if (!pad->realized) return;
344 gst_editor_pad_resize(pad);
347 x2 = x1 + pad->width;y2 = y1 + pad->height;
348 // g_print("repacking pad at %.2fx%.2f - %.2fx%.2f\n",x1,y1,x2,y2);
351 gtk_object_set(GTK_OBJECT(pad->group),"x",pad->x,"y",pad->y,NULL);
353 /* start by resizing the bordering box */
354 gtk_object_set(GTK_OBJECT(pad->border),
355 "x1",x1,"y1",y1,"x2",x2,"y2",y2,NULL);
357 /* if we're a left-jusified sink */
359 /* and move the pad box */
360 gtk_object_set(GTK_OBJECT(pad->padbox),
361 "x1",x2-pad->boxwidth,"y1",y1+2.0,
362 "x2",x2,"y2",y2-2.0,NULL);
363 /* then move the text to the right place */
364 gtk_object_set(GTK_OBJECT(pad->title),
365 "x",x2-pad->boxwidth-1.0,"y",y1,
366 "anchor",GTK_ANCHOR_NORTH_EAST,
369 /* and move the pad box */
370 gtk_object_set(GTK_OBJECT(pad->padbox),
372 "x2",x1+pad->boxwidth,"y2",y2-2.0,NULL);
373 /* then move the text to the right place */
374 gtk_object_set(GTK_OBJECT(pad->title),
375 "x",x1+pad->boxwidth+1.0,"y",y1,
376 "anchor",GTK_ANCHOR_NORTH_WEST,
380 if (pad->connection != NULL) {
381 pad->connection->resize = TRUE;
382 gst_editor_connection_resize(pad->connection);
390 static gint gst_editor_pad_event(GnomeCanvasItem *item,GdkEvent *event) {
391 GstEditorPad *pad = GST_EDITOR_PAD(item);
392 gdouble item_x,item_y;
396 item_x = event->button.x;
397 item_y = event->button.y;
398 gnome_canvas_item_w2i(item->parent,&item_x,&item_y);
400 switch(event->type) {
401 case GDK_ENTER_NOTIFY:
402 // g_print("entered pad\n");
404 case GDK_LEAVE_NOTIFY:
405 // g_print("left pad\n");
414 /* FIXME FIXME FIXME */
416 gst_editor_pad_padbox_event(GnomeCanvasItem *item,
420 GstEditorElement *element;
423 // g_print("padbox has event %d\n",event->type);
424 g_return_val_if_fail(GST_IS_EDITOR_PAD(pad), FALSE);
426 element = pad->parent;
427 bin = element->parent;
429 switch(event->type) {
430 case GDK_ENTER_NOTIFY:
431 gtk_object_set(GTK_OBJECT(pad->border),
432 "fill_color_rgba", 0xBBDDBB00, NULL);
434 case GDK_LEAVE_NOTIFY:
435 gtk_object_set(GTK_OBJECT(pad->border),
436 "fill_color_rgba", 0xCCFFCC00, NULL);
438 case GDK_BUTTON_PRESS:
439 // g_print("have button press in pad '%s'\n",
440 // gst_pad_get_name(pad->pad));
441 gst_editor_bin_start_banding(bin,pad);
444 case GDK_MOTION_NOTIFY:
445 // g_print("have motion in pad\n");
454 gst_editor_pad_position_changed(GstEditorPad *pad,
455 GstEditorElement *element)
459 if (pad->connection) {
460 // g_print("updating pad's connection\n");
461 pad->connection->resize = TRUE;
462 gst_editor_connection_resize(pad->connection);