From: Pierre-Luc Beaudoin Date: Thu, 14 Aug 2008 22:12:23 +0000 (-0400) Subject: Fix indent X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c40f27f1c78d2146c9b9bfdaf39367baa23af1b;p=libchamplain Fix indent --- diff --git a/src/champlain.h b/src/champlain.h index dcda655..5551c75 100644 --- a/src/champlain.h +++ b/src/champlain.h @@ -23,4 +23,3 @@ #include "champlain_widget.h" #endif - diff --git a/src/champlain_defines.h b/src/champlain_defines.h index 7ff4216..c59e8b2 100644 --- a/src/champlain_defines.h +++ b/src/champlain_defines.h @@ -16,10 +16,10 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + #ifndef CHAMPLAIN_DEFINES_H #define CHAMPLAIN_DEFINES_H - + #define CHAMPLAIN_API __attribute__((visibility("default"))) #define CHAMPLAIN_OBSOLETE_API CHAMPLAIN_API __attribute__((deprecated)) diff --git a/src/champlain_widget.c b/src/champlain_widget.c index ee2530a..589db74 100644 --- a/src/champlain_widget.c +++ b/src/champlain_widget.c @@ -29,347 +29,339 @@ #include #include -enum { - /* normal signals */ - TBD, - LAST_SIGNAL +enum +{ + /* normal signals */ + TBD, + LAST_SIGNAL }; -enum { - PROP_0, +enum +{ + PROP_0, - PROP_TBD + PROP_TBD }; static guint champlain_widget_signals[LAST_SIGNAL] = { 0, }; #define CHAMPLAIN_WIDGET_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), CHAMPLAIN_TYPE_WIDGET, ChamplainWidgetPrivate)) -typedef struct { - /* Units to store the origin of a click when scrolling */ - ClutterUnit x; - ClutterUnit y; +typedef struct +{ + /* Units to store the origin of a click when scrolling */ + ClutterUnit x; + ClutterUnit y; } ScrollMotion; -struct _ChamplainWidgetPrivate { - GtkWidget* clutterEmbed; - GtkAdjustment* horizontalAdjustment; - GtkAdjustment* verticalAdjustment; - ClutterActor* viewport; - - // Scrolling - ScrollMotion position; - ScrollMotion hitPoint; +struct _ChamplainWidgetPrivate +{ + GtkWidget *clutterEmbed; + GtkAdjustment *horizontalAdjustment; + GtkAdjustment *verticalAdjustment; + ClutterActor *viewport; + + // Scrolling + ScrollMotion position; + ScrollMotion hitPoint; }; -G_DEFINE_TYPE(ChamplainWidget, champlain_widget, GTK_TYPE_ALIGNMENT) - +G_DEFINE_TYPE (ChamplainWidget, champlain_widget, GTK_TYPE_ALIGNMENT); + static void -adjustement_changed_cb (GtkAdjustment* adjustment, - ChamplainWidgetPrivate* champlainWidget) +adjustement_changed_cb (GtkAdjustment * adjustment, ChamplainWidgetPrivate * champlainWidget) { - ChamplainWidgetPrivate* priv = CHAMPLAIN_WIDGET_GET_PRIVATE(champlainWidget); - /* - if (adjustment == priv->horizontalAdjustment) - priv->scrollOffset.x = (int)gtk_adjustment_get_value(adjustment); - else if (adjustment == priv->verticalAdjustment) - priv->scrollOffset.y = (int)gtk_adjustment_get_value(adjustment); - */ - // Check if the offset is empty - -} - -static void -champlain_widget_set_scroll_adjustments (ChamplainWidget *champlainWidget, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment) + ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget); + /* + if (adjustment == priv->horizontalAdjustment) + priv->scrollOffset.x = (int)gtk_adjustment_get_value(adjustment); + else if (adjustment == priv->verticalAdjustment) + priv->scrollOffset.y = (int)gtk_adjustment_get_value(adjustment); + */ + // Check if the offset is empty + +} + +static void +champlain_widget_set_scroll_adjustments (ChamplainWidget * champlainWidget, + GtkAdjustment * hadjustment, GtkAdjustment * vadjustment) { - ChamplainWidgetPrivate* priv = CHAMPLAIN_WIDGET_GET_PRIVATE(champlainWidget); - - if (priv->horizontalAdjustment) { - g_signal_handlers_disconnect_by_func(G_OBJECT(priv->horizontalAdjustment), (gpointer) adjustement_changed_cb, champlainWidget); - g_signal_handlers_disconnect_by_func(G_OBJECT(priv->verticalAdjustment), (gpointer) adjustement_changed_cb, champlainWidget); - - g_object_unref(priv->horizontalAdjustment); - g_object_unref(priv->verticalAdjustment); - } - - priv->horizontalAdjustment = hadjustment; - priv->verticalAdjustment = vadjustment; - - if (hadjustment) { - g_object_ref_sink(priv->horizontalAdjustment); - g_object_ref_sink(priv->verticalAdjustment); - - gdouble val = gtk_adjustment_get_value(hadjustment); - val = gtk_adjustment_get_value(vadjustment); - // Connect the signals - - g_object_set(G_OBJECT(priv->horizontalAdjustment), "lower", -180.0, NULL); - g_object_set(G_OBJECT(priv->horizontalAdjustment), "upper", 180.0, NULL); - g_object_set(G_OBJECT(priv->horizontalAdjustment), "page-size", 20.0, NULL); - g_object_set(G_OBJECT(priv->horizontalAdjustment), "step-increment", 5.0, NULL); - g_object_set(G_OBJECT(priv->horizontalAdjustment), "page-increment", 15.0, NULL); - - g_object_set(G_OBJECT(priv->verticalAdjustment), "lower", -90.0, NULL); - g_object_set(G_OBJECT(priv->verticalAdjustment), "upper", 90.0, NULL); - g_object_set(G_OBJECT(priv->verticalAdjustment), "page-size", 20.0, NULL); - g_object_set(G_OBJECT(priv->verticalAdjustment), "step-increment", 5.0, NULL); - g_object_set(G_OBJECT(priv->verticalAdjustment), "page-increment", 15.0, NULL); - - //g_signal_connect(G_OBJECT(priv->horizontalAdjustment), "value-changed", (gpointer)adjustement_changed_cb, champlainWidget); - //g_signal_connect(G_OBJECT(priv->verticalAdjustment), "value-changed", (gpointer)adjustement_changed_cb, champlainWidget); - } -} - -static void champlain_widget_finalize(GObject* object) + ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget); + + if (priv->horizontalAdjustment) + { + g_signal_handlers_disconnect_by_func (G_OBJECT + (priv->horizontalAdjustment), + (gpointer) adjustement_changed_cb, champlainWidget); + g_signal_handlers_disconnect_by_func (G_OBJECT + (priv->verticalAdjustment), + (gpointer) adjustement_changed_cb, champlainWidget); + + g_object_unref (priv->horizontalAdjustment); + g_object_unref (priv->verticalAdjustment); + } + + priv->horizontalAdjustment = hadjustment; + priv->verticalAdjustment = vadjustment; + + if (hadjustment) + { + g_object_ref_sink (priv->horizontalAdjustment); + g_object_ref_sink (priv->verticalAdjustment); + + gdouble val = gtk_adjustment_get_value (hadjustment); + val = gtk_adjustment_get_value (vadjustment); + // Connect the signals + + g_object_set (G_OBJECT (priv->horizontalAdjustment), "lower", -180.0, NULL); + g_object_set (G_OBJECT (priv->horizontalAdjustment), "upper", 180.0, NULL); + g_object_set (G_OBJECT (priv->horizontalAdjustment), "page-size", 20.0, NULL); + g_object_set (G_OBJECT (priv->horizontalAdjustment), "step-increment", 5.0, NULL); + g_object_set (G_OBJECT (priv->horizontalAdjustment), "page-increment", 15.0, NULL); + + g_object_set (G_OBJECT (priv->verticalAdjustment), "lower", -90.0, NULL); + g_object_set (G_OBJECT (priv->verticalAdjustment), "upper", 90.0, NULL); + g_object_set (G_OBJECT (priv->verticalAdjustment), "page-size", 20.0, NULL); + g_object_set (G_OBJECT (priv->verticalAdjustment), "step-increment", 5.0, NULL); + g_object_set (G_OBJECT (priv->verticalAdjustment), "page-increment", 15.0, NULL); + + //g_signal_connect(G_OBJECT(priv->horizontalAdjustment), "value-changed", (gpointer)adjustement_changed_cb, champlainWidget); + //g_signal_connect(G_OBJECT(priv->verticalAdjustment), "value-changed", (gpointer)adjustement_changed_cb, champlainWidget); + } +} + +static void +champlain_widget_finalize (GObject * object) { - ChamplainWidget* widget = CHAMPLAIN_WIDGET(object); - ChamplainWidgetPrivate* priv = CHAMPLAIN_WIDGET_GET_PRIVATE(widget); - - if (priv->horizontalAdjustment) { - g_object_unref(priv->horizontalAdjustment); - g_signal_handlers_disconnect_by_func(G_OBJECT(priv->horizontalAdjustment), (gpointer)adjustement_changed_cb, widget); - } - - if (priv->verticalAdjustment) { - g_object_unref(priv->verticalAdjustment); - g_signal_handlers_disconnect_by_func(G_OBJECT(priv->verticalAdjustment), (gpointer)adjustement_changed_cb, widget); + ChamplainWidget *widget = CHAMPLAIN_WIDGET (object); + ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (widget); + + if (priv->horizontalAdjustment) + { + g_object_unref (priv->horizontalAdjustment); + g_signal_handlers_disconnect_by_func (G_OBJECT + (priv->horizontalAdjustment), (gpointer) adjustement_changed_cb, widget); + } + + if (priv->verticalAdjustment) + { + g_object_unref (priv->verticalAdjustment); + g_signal_handlers_disconnect_by_func (G_OBJECT + (priv->verticalAdjustment), (gpointer) adjustement_changed_cb, widget); } - G_OBJECT_CLASS(champlain_widget_parent_class)->finalize(object); + G_OBJECT_CLASS (champlain_widget_parent_class)->finalize (object); } - -static void -champlain_widget_class_init(ChamplainWidgetClass* champlainWidgetClass) + +static void +champlain_widget_class_init (ChamplainWidgetClass * champlainWidgetClass) { - g_type_class_add_private(champlainWidgetClass, sizeof(ChamplainWidgetPrivate)); - - /* - * make us scrollable (e.g. addable to a GtkScrolledWindow) - */ - champlainWidgetClass->set_scroll_adjustments = champlain_widget_set_scroll_adjustments; - GTK_WIDGET_CLASS(champlainWidgetClass)->set_scroll_adjustments_signal = g_signal_new("set-scroll-adjustments", - G_TYPE_FROM_CLASS(champlainWidgetClass), - (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), - G_STRUCT_OFFSET(ChamplainWidgetClass, set_scroll_adjustments), - NULL, NULL, - champlain_marshal_VOID__OBJECT_OBJECT, - G_TYPE_NONE, 2, - GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); - - GObjectClass* objectClass = G_OBJECT_CLASS(champlainWidgetClass); - objectClass->finalize = champlain_widget_finalize; + g_type_class_add_private (champlainWidgetClass, sizeof (ChamplainWidgetPrivate)); + + /* + * make us scrollable (e.g. addable to a GtkScrolledWindow) + */ + champlainWidgetClass->set_scroll_adjustments = champlain_widget_set_scroll_adjustments; + GTK_WIDGET_CLASS (champlainWidgetClass)->set_scroll_adjustments_signal = + g_signal_new ("set-scroll-adjustments", + G_TYPE_FROM_CLASS (champlainWidgetClass), + (GSignalFlags) (G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET (ChamplainWidgetClass, + set_scroll_adjustments), NULL, NULL, + champlain_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); + + GObjectClass *objectClass = G_OBJECT_CLASS (champlainWidgetClass); + objectClass->finalize = champlain_widget_finalize; } -static void champlain_widget_init(ChamplainWidget* champlainWidget) +static void +champlain_widget_init (ChamplainWidget * champlainWidget) { - ChamplainWidgetPrivate* priv = CHAMPLAIN_WIDGET_GET_PRIVATE(champlainWidget); - - priv->horizontalAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); - priv->verticalAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); - - g_object_ref_sink(priv->horizontalAdjustment); - g_object_ref_sink(priv->verticalAdjustment); - - + ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget); + + priv->horizontalAdjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); + priv->verticalAdjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); + + g_object_ref_sink (priv->horizontalAdjustment); + g_object_ref_sink (priv->verticalAdjustment); + + } static gboolean -viewport_motion_event_cb (ClutterActor *actor, - ClutterMotionEvent *event, - ChamplainWidget* champlainWidget) +viewport_motion_event_cb (ClutterActor * actor, ClutterMotionEvent * event, ChamplainWidget * champlainWidget) { - ChamplainWidgetPrivate* priv = CHAMPLAIN_WIDGET_GET_PRIVATE(champlainWidget); - ClutterActor* stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(priv->clutterEmbed)); - - ClutterUnit x, y; - if (clutter_actor_transform_stage_point (stage, - CLUTTER_UNITS_FROM_DEVICE(event->x), - CLUTTER_UNITS_FROM_DEVICE(event->y), - &x, &y)) - { - ClutterUnit dx, dy; - - dx = x - priv->position.x ; - dy = y - priv->position.y; - - g_print("Motion n: %d, %d\t c: %d, %d \t d: %d, %d\n", CLUTTER_UNITS_TO_INT(x), CLUTTER_UNITS_TO_INT(y), - CLUTTER_UNITS_TO_INT(priv->position.x), CLUTTER_UNITS_TO_INT(priv->position.y), - CLUTTER_UNITS_TO_INT(dx), CLUTTER_UNITS_TO_INT(dy)); - - priv->position.x += dx - priv->hitPoint.x; - priv->position.y += dy - priv->hitPoint.y; - - clutter_actor_set_positionu(priv->viewport, priv->position.x, priv->position.y ); - } - - return TRUE; + ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget); + ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutterEmbed)); + + ClutterUnit x, y; + if (clutter_actor_transform_stage_point (stage, + CLUTTER_UNITS_FROM_DEVICE (event-> + x), CLUTTER_UNITS_FROM_DEVICE (event->y), &x, &y)) + { + ClutterUnit dx, dy; + + dx = x - priv->position.x; + dy = y - priv->position.y; + + g_print ("Motion n: %d, %d\t c: %d, %d \t d: %d, %d\n", + CLUTTER_UNITS_TO_INT (x), CLUTTER_UNITS_TO_INT (y), + CLUTTER_UNITS_TO_INT (priv->position.x), + CLUTTER_UNITS_TO_INT (priv->position.y), CLUTTER_UNITS_TO_INT (dx), CLUTTER_UNITS_TO_INT (dy)); + + priv->position.x += dx - priv->hitPoint.x; + priv->position.y += dy - priv->hitPoint.y; + + clutter_actor_set_positionu (priv->viewport, priv->position.x, priv->position.y); + } + + return TRUE; } static gboolean -viewport_button_release_event_cb (ClutterActor *actor, - ClutterButtonEvent *event, - ChamplainWidget* champlainWidget) +viewport_button_release_event_cb (ClutterActor * actor, ClutterButtonEvent * event, ChamplainWidget * champlainWidget) { - ChamplainWidgetPrivate* priv = CHAMPLAIN_WIDGET_GET_PRIVATE(champlainWidget); - g_print("release\n"); - + ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget); + g_print ("release\n"); + ClutterActor *viewport = priv->viewport; if (event->button != 1) return FALSE; - - g_signal_handlers_disconnect_by_func (viewport, - viewport_motion_event_cb, - champlainWidget); - g_signal_handlers_disconnect_by_func (viewport, - viewport_button_release_event_cb, - champlainWidget); - + + g_signal_handlers_disconnect_by_func (viewport, viewport_motion_event_cb, champlainWidget); + g_signal_handlers_disconnect_by_func (viewport, viewport_button_release_event_cb, champlainWidget); + clutter_ungrab_pointer (); - + /* Pass through events to children. * FIXME: this probably breaks click-count. */ - clutter_event_put ((ClutterEvent *)event); - + clutter_event_put ((ClutterEvent *) event); + return TRUE; } + static gboolean -after_event_cb (ChamplainWidget* champlainWidget) +after_event_cb (ChamplainWidget * champlainWidget) { /* Check the pointer grab - if something else has grabbed it - for example, * a scroll-bar or some such, don't do our funky stuff. */ - ChamplainWidgetPrivate* priv = CHAMPLAIN_WIDGET_GET_PRIVATE(champlainWidget); + ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget); if (clutter_get_pointer_grab () != CLUTTER_ACTOR (priv->viewport)) { - g_signal_handlers_disconnect_by_func (priv->viewport, - viewport_motion_event_cb, - champlainWidget); - g_signal_handlers_disconnect_by_func (priv->viewport, - viewport_button_release_event_cb, - champlainWidget); + g_signal_handlers_disconnect_by_func (priv->viewport, viewport_motion_event_cb, champlainWidget); + g_signal_handlers_disconnect_by_func (priv->viewport, viewport_button_release_event_cb, champlainWidget); } - + return FALSE; } static gboolean -viewport_captured_event_cb (ClutterActor *actor, - ClutterEvent *event, - ChamplainWidget* champlainWidget) +viewport_captured_event_cb (ClutterActor * actor, ClutterEvent * event, ChamplainWidget * champlainWidget) { - - ChamplainWidgetPrivate* priv = CHAMPLAIN_WIDGET_GET_PRIVATE(champlainWidget); - ClutterActor* stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(priv->clutterEmbed)); - - if (event->type == CLUTTER_BUTTON_PRESS) - { - ClutterButtonEvent *bevent = (ClutterButtonEvent *)event; - ClutterUnit x, y; - if ((bevent->button == 1) && - (clutter_actor_transform_stage_point (stage, - CLUTTER_UNITS_FROM_DEVICE(bevent->x), - CLUTTER_UNITS_FROM_DEVICE(bevent->y), - &x, &y))) - { - - g_print("Hit h: %d, %d\t c: %d, %d \n", CLUTTER_UNITS_TO_INT(x), CLUTTER_UNITS_TO_INT(y), - CLUTTER_UNITS_TO_INT(priv->position.x), CLUTTER_UNITS_TO_INT(priv->position.y)); - priv->hitPoint.x = x - priv->position.x; - priv->hitPoint.y = y - priv->position.y; - - clutter_grab_pointer (actor); - - /* Add a high priority idle to check the grab after the event - * emission is finished. - */ - g_idle_add_full (G_PRIORITY_HIGH_IDLE, - (GSourceFunc)after_event_cb, - champlainWidget, - NULL); - - g_signal_connect (priv->viewport, - "motion-event", - G_CALLBACK (viewport_motion_event_cb), - champlainWidget); - g_signal_connect (priv->viewport, - "button-release-event", - G_CALLBACK (viewport_button_release_event_cb), - champlainWidget); - } - } - - return FALSE; + + ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget); + ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutterEmbed)); + + if (event->type == CLUTTER_BUTTON_PRESS) + { + ClutterButtonEvent *bevent = (ClutterButtonEvent *) event; + ClutterUnit x, y; + if ((bevent->button == 1) && + (clutter_actor_transform_stage_point (stage, + CLUTTER_UNITS_FROM_DEVICE + (bevent->x), CLUTTER_UNITS_FROM_DEVICE (bevent->y), &x, &y))) + { + + g_print ("Hit h: %d, %d\t c: %d, %d \n", CLUTTER_UNITS_TO_INT (x), + CLUTTER_UNITS_TO_INT (y), + CLUTTER_UNITS_TO_INT (priv->position.x), CLUTTER_UNITS_TO_INT (priv->position.y)); + priv->hitPoint.x = x - priv->position.x; + priv->hitPoint.y = y - priv->position.y; + + clutter_grab_pointer (actor); + + /* Add a high priority idle to check the grab after the event + * emission is finished. + */ + g_idle_add_full (G_PRIORITY_HIGH_IDLE, (GSourceFunc) after_event_cb, champlainWidget, NULL); + + g_signal_connect (priv->viewport, "motion-event", G_CALLBACK (viewport_motion_event_cb), champlainWidget); + g_signal_connect (priv->viewport, + "button-release-event", G_CALLBACK (viewport_button_release_event_cb), champlainWidget); + } + } + + return FALSE; } -static void champlain_widget_load_map(ChamplainWidget* champlainWidget) +static void +champlain_widget_load_map (ChamplainWidget * champlainWidget) { - ChamplainWidgetPrivate* priv = CHAMPLAIN_WIDGET_GET_PRIVATE(champlainWidget); - - ClutterActor* stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(priv->clutterEmbed)); - - ClutterActor* viewport = clutter_group_new(); - clutter_actor_set_reactive (CLUTTER_ACTOR (viewport), TRUE); - g_signal_connect (CLUTTER_ACTOR (viewport), - "captured-event", - G_CALLBACK (viewport_captured_event_cb), - champlainWidget); - - ClutterColor white; - clutter_color_parse("white", &white); - ClutterColor blue; - clutter_color_parse("blue", &blue); - ClutterActor* group = clutter_group_new(); - - ClutterActor* rect = clutter_rectangle_new_with_color(&blue); - clutter_actor_set_position (rect, 0, 0); - clutter_actor_set_size (rect, 100, 100); - clutter_actor_show(rect); - clutter_container_add(CLUTTER_CONTAINER(group), rect, NULL); - - rect = clutter_rectangle_new_with_color(&white); - clutter_actor_set_position (rect, 0, 100); - clutter_actor_set_size (rect, 100, 100); - clutter_actor_show(rect); - clutter_container_add(CLUTTER_CONTAINER(group), rect, NULL); - - rect = clutter_rectangle_new_with_color(&blue); - clutter_actor_set_position (rect, 100, 100); - clutter_actor_set_size (rect, 100, 100); - clutter_actor_show(rect); - clutter_container_add(CLUTTER_CONTAINER(group), rect, NULL); - - rect = clutter_rectangle_new_with_color(&white); - clutter_actor_set_position (rect, 100, 0); - clutter_actor_set_size (rect, 100, 100); - clutter_actor_show(rect); - clutter_container_add(CLUTTER_CONTAINER(group), rect, NULL); - - priv->viewport = viewport; - clutter_container_add(CLUTTER_CONTAINER(viewport), group, NULL); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), viewport); - + ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget); + + ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutterEmbed)); + + ClutterActor *viewport = clutter_group_new (); + clutter_actor_set_reactive (CLUTTER_ACTOR (viewport), TRUE); + g_signal_connect (CLUTTER_ACTOR (viewport), + "captured-event", G_CALLBACK (viewport_captured_event_cb), champlainWidget); + + ClutterColor white; + clutter_color_parse ("white", &white); + ClutterColor blue; + clutter_color_parse ("blue", &blue); + ClutterActor *group = clutter_group_new (); + + ClutterActor *rect = clutter_rectangle_new_with_color (&blue); + clutter_actor_set_position (rect, 0, 0); + clutter_actor_set_size (rect, 100, 100); + clutter_actor_show (rect); + clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL); + + rect = clutter_rectangle_new_with_color (&white); + clutter_actor_set_position (rect, 0, 100); + clutter_actor_set_size (rect, 100, 100); + clutter_actor_show (rect); + clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL); + + rect = clutter_rectangle_new_with_color (&blue); + clutter_actor_set_position (rect, 100, 100); + clutter_actor_set_size (rect, 100, 100); + clutter_actor_show (rect); + clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL); + + rect = clutter_rectangle_new_with_color (&white); + clutter_actor_set_position (rect, 100, 0); + clutter_actor_set_size (rect, 100, 100); + clutter_actor_show (rect); + clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL); + + priv->viewport = viewport; + clutter_container_add (CLUTTER_CONTAINER (viewport), group, NULL); + + clutter_container_add_actor (CLUTTER_CONTAINER (stage), viewport); + } -GtkWidget* champlain_widget_new() +GtkWidget * +champlain_widget_new () { - ChamplainWidget* widget = CHAMPLAIN_WIDGET(g_object_new(CHAMPLAIN_TYPE_WIDGET, NULL)); - ChamplainWidgetPrivate* priv = CHAMPLAIN_WIDGET_GET_PRIVATE(widget); - - priv->clutterEmbed = gtk_clutter_embed_new(); - ClutterActor* stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(priv->clutterEmbed)); - - ClutterColor black; - clutter_color_parse("black", &black); - clutter_stage_set_color(CLUTTER_STAGE(stage), &black); - gtk_container_add(GTK_CONTAINER(widget), priv->clutterEmbed); - - champlain_widget_load_map(widget); - - return GTK_WIDGET(widget); + ChamplainWidget *widget = CHAMPLAIN_WIDGET (g_object_new (CHAMPLAIN_TYPE_WIDGET, NULL)); + ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (widget); + + priv->clutterEmbed = gtk_clutter_embed_new (); + ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutterEmbed)); + + ClutterColor black; + clutter_color_parse ("black", &black); + clutter_stage_set_color (CLUTTER_STAGE (stage), &black); + gtk_container_add (GTK_CONTAINER (widget), priv->clutterEmbed); + + champlain_widget_load_map (widget); + + return GTK_WIDGET (widget); } diff --git a/src/champlain_widget.h b/src/champlain_widget.h index cf883ca..019b522 100644 --- a/src/champlain_widget.h +++ b/src/champlain_widget.h @@ -27,39 +27,34 @@ G_BEGIN_DECLS - #define CHAMPLAIN_TYPE_WIDGET (champlain_widget_get_type()) #define CHAMPLAIN_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CHAMPLAIN_TYPE_WIDGET, ChamplainWidget)) #define CHAMPLAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CHAMPLAIN_TYPE_WIDGET, ChamplainWidgetClass)) #define CHAMPLAIN_IS_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CHAMPLAIN_TYPE_WIDGET)) #define CHAMPLAIN_IS_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), CHAMPLAIN_TYPE_WIDGET)) #define CHAMPLAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CHAMPLAIN_TYPE_WIDGET, ChamplainWidgetClass)) - typedef struct _ChamplainWidgetPrivate ChamplainWidgetPrivate; -struct _ChamplainWidget { - GtkAlignment bin; +struct _ChamplainWidget +{ + GtkAlignment bin; - ChamplainWidgetPrivate *priv; + ChamplainWidgetPrivate *priv; }; -struct _ChamplainWidgetClass { - GtkBinClass parent_class; +struct _ChamplainWidgetClass +{ + GtkBinClass parent_class; - ChamplainWidget * (* create_widget) (ChamplainWidget* widget); + ChamplainWidget *(*create_widget) (ChamplainWidget * widget); - void (* set_scroll_adjustments) (ChamplainWidget *widget, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); + void (*set_scroll_adjustments) (ChamplainWidget * widget, GtkAdjustment * hadjustment, GtkAdjustment * vadjustment); }; -CHAMPLAIN_API GType -champlain_widget_get_type (void); +CHAMPLAIN_API GType champlain_widget_get_type (void); -CHAMPLAIN_API GtkWidget * -champlain_widget_new (void); +CHAMPLAIN_API GtkWidget *champlain_widget_new (void); #endif - diff --git a/src/launcher.c b/src/launcher.c index 7756935..f2cdb9b 100644 --- a/src/launcher.c +++ b/src/launcher.c @@ -29,49 +29,47 @@ static void on_destroy (GtkWidget * widget, gpointer data) { - gtk_main_quit (); + gtk_main_quit (); } int main (int argc, char *argv[]) { - GtkWidget *window; - GtkWidget *widget; - GtkWidget *scrolled; + GtkWidget *window; + GtkWidget *widget; + GtkWidget *scrolled; - gtk_clutter_init (&argc, &argv); + gtk_clutter_init (&argc, &argv); - /* create the main, top level, window */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + /* create the main, top level, window */ + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - /* give the window a 20px wide border */ - gtk_container_set_border_width (GTK_CONTAINER (window), 10); + /* give the window a 10px wide border */ + gtk_container_set_border_width (GTK_CONTAINER (window), 10); - /* give it the title */ - gtk_window_set_title (GTK_WINDOW (window), PACKAGE " " VERSION); + /* give it the title */ + gtk_window_set_title (GTK_WINDOW (window), PACKAGE " " VERSION); - /* open it a bit wider so that both the label and title show up */ - gtk_window_set_default_size (GTK_WINDOW (window), 500, 500); + /* open it a bit wider so that both the label and title show up */ + gtk_window_set_default_size (GTK_WINDOW (window), 500, 500); - /* Connect the destroy event of the window with our on_destroy function - * When the window is about to be destroyed we get a notificaiton and - * stop the main GTK loop - */ - g_signal_connect (G_OBJECT (window), "destroy", - G_CALLBACK (on_destroy), NULL); - - widget = champlain_widget_new (); + /* Connect the destroy event of the window with our on_destroy function + * When the window is about to be destroyed we get a notificaiton and + * stop the main GTK loop + */ + g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (on_destroy), NULL); - /* and insert it into the main window */ - gtk_container_add (GTK_CONTAINER (window), widget); + widget = champlain_widget_new (); - /* make sure that everything, window and label, are visible */ - gtk_widget_show_all (window); + /* and insert it into the main window */ + gtk_container_add (GTK_CONTAINER (window), widget); - /* start the main loop */ - gtk_main (); + /* make sure that everything, window and label, are visible */ + gtk_widget_show_all (window); - return 0; -} + /* start the main loop */ + gtk_main (); + return 0; +}