]> err.no Git - libchamplain/commitdiff
Clean up
authorPierre-Luc Beaudoin <pierre-luc@squidy.info>
Sat, 16 Aug 2008 15:15:34 +0000 (11:15 -0400)
committerPierre-Luc Beaudoin <pierre-luc@squidy.info>
Sat, 16 Aug 2008 15:15:34 +0000 (11:15 -0400)
src/champlain_map.c
src/champlain_map.h
src/champlain_map_zoom_level.c
src/champlain_map_zoom_level.h
src/champlain_private.h
src/champlain_widget.c
src/launcher.c

index 7d2ddc05d65d7629365e0a28f3c9417f2b8ac982..bf1f189183a47fa58e1a6610541c1f68a3290bcb 100644 (file)
  * Boston, MA 02110-1301, USA.
  */
  
- #include <champlain_map.h>
+#include <champlain_map.h>
  
 ChamplainMap* 
 champlain_map_new (ChamplainMapSource source)
 {
        ChamplainMap* map = g_new0(ChamplainMap, 1);
-       map->name = "OpenStreetMap";
+       map->name = "Debug";
        map->zoom_levels = 1;
        return map;
 }
@@ -31,6 +31,7 @@ champlain_map_new (ChamplainMapSource source)
 void 
 champlain_map_load(ChamplainMap* map, gint zoom_level)
 {
-               map->current_level = champlain_map_zoom_level_new(zoom_level, 5, 4, 200);
+               map->current_level = champlain_map_zoom_level_new(zoom_level, 15, 15, 100);
                champlain_map_zoom_level_create(map->current_level, zoom_level);
 }
+
index a84ea638abd88cf5c45831d77a0b3ebfb4bb4f7a..f5303c67f18752839d30995acd2219e89882c56b 100644 (file)
@@ -27,6 +27,7 @@
 
 typedef enum
 {
+  CHAMPLAIN_MAP_SOURCE_DEBUG,
   CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP,
   CHAMPLAIN_MAP_SOURCE_GOOGLE
 } ChamplainMapSource;
index b0519c6d04cb4ba6506c9ca73dbd36ce65cd8921..581990ecc3db04c3d8eccc9b9a055a0cba0e80d5 100644 (file)
@@ -55,8 +55,20 @@ champlain_map_zoom_level_create(ChamplainMapZoomLevel* level, gint zoom_level)
                                        
                                        ChamplainMapTile* tile = champlain_map_tile_new(x, y, level->tile_size);
                                        
-                                       //clutter_container_add (CLUTTER_CONTAINER (level->group), tile->actor, NULL);
+                                       clutter_container_add (CLUTTER_CONTAINER (level->group), tile->actor, NULL);
                                        g_ptr_array_add (level->tiles, tile);
                                }
                }
 }
+
+guint
+champlain_map_zoom_level_get_width(ChamplainMapZoomLevel* level)
+{
+               return (level->column_count + 1) * level->tile_size;
+}
+
+guint
+champlain_map_zoom_level_get_height(ChamplainMapZoomLevel* level)
+{
+               return (level->row_count + 1)  * level->tile_size;
+}
index e9194df8ee690851e854fe489d103e6291ec9438..e67b86c0dbd89fb5363d338bae91de83a24effa9 100644 (file)
@@ -35,4 +35,9 @@ typedef struct
   
 } ChamplainMapZoomLevel;
 
+guint champlain_map_zoom_level_get_width(ChamplainMapZoomLevel* level);
+
+guint champlain_map_zoom_level_get_height(ChamplainMapZoomLevel* level);
+
+
 #endif
index 6bf6132288f2e15375b6f1f27b6df1c835dc4b67..e52b0e63412cc8c6f6e3baa2fa747acbd5792cc4 100644 (file)
@@ -32,4 +32,10 @@ ChamplainMapZoomLevel* champlain_map_zoom_level_new(gint zoom_level, gint row, g
 
 ChamplainMapTile* champlain_map_tile_new(gint x, gint y, gint tile_size);
 
+#define CHAMPLAIN_MIN_LAT -90
+#define CHAMPLAIN_MAX_LAT 90
+#define CHAMPLAIN_MIN_LONG -180
+#define CHAMPLAIN_MAX_LONG 180
+
+
 #endif
index c6eff33132e01feafba68c96362b48e48d492edb..5ae875bfcbb06022ec5767a2b7fc3c5e843e6ee6 100644 (file)
@@ -45,7 +45,6 @@ enum
 enum
 {
   PROP_0,
-
   PROP_TBD
 };
 
@@ -64,12 +63,10 @@ struct _ChamplainWidgetPrivate
 {
   GtkWidget *clutterEmbed;
   ClutterActor *viewport;
-
-  // Scrolling  
-  ChamplainPoint position;
-  ChamplainPoint hitPoint;
+  ChamplainPoint viewportSize;
+  ClutterActor *fingerScroll;
   
-  ChamplainMapmap;
+  ChamplainMap *map;
 };
 
 
@@ -87,7 +84,7 @@ champlain_widget_finalize (GObject * object)
 }
 
 static void
-champlain_widget_class_init (ChamplainWidgetClass * champlainWidgetClass)
+champlain_widget_class_init (ChamplainWidgetClass *champlainWidgetClass)
 {
   g_type_class_add_private (champlainWidgetClass, sizeof (ChamplainWidgetPrivate));
 
@@ -96,268 +93,78 @@ champlain_widget_class_init (ChamplainWidgetClass * champlainWidgetClass)
 }
 
 static void
-champlain_widget_init (ChamplainWidget * champlainWidget)
-{
-  ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget);
-}
-
-static gboolean
-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));
-
-       //FIXME: doesn't work when the viewport's size is larger than the stage (?)
-  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\t h: %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),
-              CLUTTER_UNITS_TO_INT (priv->hitPoint.x), 
-              CLUTTER_UNITS_TO_INT (priv->hitPoint.y));*/
-
-      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);
-      
-    } else g_print("Couldn't convert point");
-
-  return TRUE;
-}
-
-static gboolean
-viewport_button_release_event_cb (ClutterActor * actor, ClutterButtonEvent * event, ChamplainWidget * champlainWidget)
-{
-  ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget);
-  
-  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);
-
-  clutter_ungrab_pointer ();
-
-  /* Pass through events to children.
-   * FIXME: this probably breaks click-count.
-   */
-  clutter_event_put ((ClutterEvent *) event);
-
-  return TRUE;
-}
-
-static gboolean
-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);
-  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);
-    }
-
-  return FALSE;
-}
-
-static gboolean
-viewport_captured_event_cb (ClutterActor * actor, ClutterEvent * event, ChamplainWidget * champlainWidget)
+champlain_widget_init (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;
-                               g_print ("d: %d, %d \n", 
-                                       bevent->x, 
-                                       bevent->y);
-      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 \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),
-                                       bevent->x, 
-                                       bevent->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);
-                       }
-                       else g_print("Couldn't convert point");
-    }
-
-  return FALSE;
 }
 
 static void
-champlain_widget_load_map (ChamplainWidget * champlainWidget)
-{
+widget_size_allocated_cb (GtkWidget *widget, GtkAllocation *allocation, ChamplainWidget *champlainWidget) 
+{                
+  gdouble lower, upper;
+  TidyAdjustment *hadjust, *vadjust;
+  
   ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget);
-
-       priv->map = champlain_map_new(CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP);
-       
-       champlain_map_load(priv->map, 1);
-       
-  clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map->current_level->group);
-       
-}
-static void
-add_rects (ClutterGroup* stage) 
-{
-       ClutterColor white;
-       clutter_color_parse("white", &white);
-       ClutterColor blue;
-       clutter_color_parse("blue", &blue);
-
-       ClutterActor * rect = clutter_rectangle_new_with_color(&blue);
-       clutter_container_add(CLUTTER_CONTAINER(stage), rect, NULL);
-       clutter_actor_set_position (rect, 100, 100);
-       clutter_actor_set_size (rect, 100, 100);
-       clutter_actor_show(rect);
-
-       rect = clutter_rectangle_new_with_color(&white);
-       clutter_container_add(CLUTTER_CONTAINER(stage), rect, NULL);
-       clutter_actor_set_position (rect, 100, 200);
-       clutter_actor_set_size (rect, 100, 100);
-       clutter_actor_show(rect);
-
-       rect = clutter_rectangle_new_with_color(&blue);
-       clutter_container_add(CLUTTER_CONTAINER(stage), rect, NULL);
-       clutter_actor_set_position (rect, 200, 200);
-       clutter_actor_set_size (rect, 100, 100);
-       clutter_actor_show(rect);
-
-       rect = clutter_rectangle_new_with_color(&white);
-       clutter_container_add(CLUTTER_CONTAINER(stage), rect, NULL);
-       clutter_actor_set_position (rect, 200, 100);
-       clutter_actor_set_size (rect, 100, 100);
-       clutter_actor_show(rect);
-
-}
-
-#define RECT_W 300
-#define RECT_H 300
-#define RECT_N 200
-#define RECT_GAP 50
-static void
-viewport_x_origin_notify_cb (TidyViewport *viewport,
-                             GParamSpec *args1,
-                             ClutterActor *group)
-{
-  GList *children, *c;
-  gint origin_x, width;
+  priv->viewportSize.x = allocation->width;
+  priv->viewportSize.y = allocation->height;
+  clutter_actor_set_size (priv->fingerScroll, priv->viewportSize.x, priv->viewportSize.y);
+  
+  g_object_set (G_OBJECT (priv->viewport), "sync-adjustments", FALSE, NULL);
   
-  tidy_viewport_get_origin (viewport, &origin_x, NULL, NULL);
-  width = clutter_actor_get_width (
-            clutter_actor_get_parent (CLUTTER_ACTOR (viewport)));
+  tidy_scrollable_get_adjustments (TIDY_SCROLLABLE (priv->viewport), &hadjust, &vadjust);
   
-  children = clutter_container_get_children (CLUTTER_CONTAINER (group));
-  for (c = children; c; c = c->next)
-    {
-      gint x;
-      gdouble pos;
-      ClutterActor *actor;
-      
-      actor = (ClutterActor *)c->data;
-      
-      /* Get actor position with respect to viewport origin */
-      x = clutter_actor_get_x (actor) - origin_x;
-      pos = (((gdouble)x / (gdouble)(width-RECT_W)) - 0.5) * 2.0;
-      
-      /* Apply a function that transforms the actor depending on its 
-       * viewport position.
-       */
-      //pos = CLAMP(pos * 3.0, -0.5, 0.5);
-      clutter_actor_set_position (actor, pos, pos);
-    }
-  g_list_free (children);
+  tidy_adjustment_get_values (hadjust, NULL, &lower, &upper, NULL, NULL, NULL);
+  lower = 0;
+  upper = champlain_map_zoom_level_get_width(priv->map->current_level) - priv->viewportSize.x; // Map's width - Viewport width
+  g_object_set (hadjust, "lower", lower, "upper", upper,
+                "step-increment", 1.0, "elastic", TRUE, NULL);
+                
+  tidy_adjustment_get_values (vadjust, NULL, &lower, &upper, NULL, NULL, NULL);
+  lower = 0;
+  upper = champlain_map_zoom_level_get_height(priv->map->current_level) - priv->viewportSize.y;
+  g_object_set (vadjust, "lower", lower, "upper", upper,
+                "step-increment", 1.0, "elastic", TRUE, NULL);
 }
-
+                          
 GtkWidget *
 champlain_widget_new ()
 {
-  ChamplainWidget *widget = CHAMPLAIN_WIDGET (g_object_new (CHAMPLAIN_TYPE_WIDGET, NULL));
+  ClutterColor stage_color = { 0x34, 0x39, 0x39, 0xff };
+  ChamplainWidget *widget, *stage; 
+  
+  widget = CHAMPLAIN_WIDGET (g_object_new (CHAMPLAIN_TYPE_WIDGET, NULL));
   ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (widget);
-
+  
+  priv->viewportSize.x = 640;
+  priv->viewportSize.y = 480;
+       
   priv->clutterEmbed = gtk_clutter_embed_new ();
+  g_signal_connect (priv->clutterEmbed,
+                    "size-allocate",
+                    G_CALLBACK (widget_size_allocated_cb),
+                    widget);
 
-       /* Setup stage */
-  ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutterEmbed));
+       // Setup stage
+  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);
+  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
   gtk_container_add (GTK_CONTAINER (widget), priv->clutterEmbed);
   
   // Setup viewport
-  ClutterActor* viewport = tidy_viewport_new ();
-  clutter_actor_set_clip (viewport, 0, 0, 640, 480);
+  priv->viewport = tidy_viewport_new ();
   ClutterActor* group = clutter_group_new();
-  add_rects (group);
-       clutter_actor_show_all(group);
-  clutter_container_add_actor (CLUTTER_CONTAINER (viewport), group);
-  g_signal_connect (viewport, "notify::x-origin",
-                    G_CALLBACK (viewport_x_origin_notify_cb), group);
-  
-  gdouble lower, upper;
-  TidyAdjustment *hadjust, *vadjust;
-  g_object_set (G_OBJECT (viewport), "sync-adjustments", FALSE, NULL);
-  tidy_scrollable_get_adjustments (TIDY_SCROLLABLE (viewport), &hadjust, &vadjust);
-  tidy_adjustment_get_values (hadjust, NULL, &lower, &upper, NULL, NULL, NULL);
-  lower -= RECT_W - RECT_GAP;
-  upper += RECT_W - RECT_GAP;
-  g_object_set (hadjust, "lower", lower, "upper", upper,
-                "step-increment", (gdouble)RECT_GAP, "elastic", TRUE, NULL);
-  tidy_adjustment_get_values (vadjust, NULL, &lower, &upper, NULL, NULL, NULL);
-  lower -= RECT_W - RECT_GAP;
-  upper += RECT_W - RECT_GAP;
-  g_object_set (vadjust, "lower", lower, "upper", upper,
-                "step-increment", (gdouble)RECT_GAP, "elastic", TRUE, NULL);
+  clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), group);
                 
-  // Setup fingerscroll
-  ClutterActor* finger_scroll = tidy_finger_scroll_new(TIDY_FINGER_SCROLL_MODE_PUSH);
-  g_object_set (finger_scroll, "decel-rate", 1.03, NULL);
-  clutter_container_add_actor (CLUTTER_CONTAINER (finger_scroll), viewport);
-  clutter_container_add_actor (CLUTTER_CONTAINER (stage), finger_scroll);
-  clutter_actor_set_size (finger_scroll, 640, 480); // FIXME make as wide as the stage always
+  // Setup finger scroll
+  priv->fingerScroll = tidy_finger_scroll_new(TIDY_FINGER_SCROLL_MODE_KINETIC);
+  g_object_set (priv->fingerScroll, "decel-rate", 1.25, NULL);
+  clutter_container_add_actor (CLUTTER_CONTAINER (priv->fingerScroll), priv->viewport);
+  clutter_container_add_actor (CLUTTER_CONTAINER (stage), priv->fingerScroll);
+  
+  
+       priv->map = champlain_map_new(CHAMPLAIN_MAP_SOURCE_DEBUG);
+       champlain_map_load(priv->map, 1);
+  clutter_container_add_actor (CLUTTER_CONTAINER (group), priv->map->current_level->group);
   
   return GTK_WIDGET (widget);
 }
index f2cdb9b905bef808a4c929a0e7442435f7927c89..a150b497eacfc891d4037dbe98b7931b2aebaef2 100644 (file)
@@ -51,7 +51,7 @@ main (int argc, char *argv[])
   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);
+  gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
 
 
   /* Connect the destroy event of the window with our on_destroy function