[libchamplain: 24/45] Make path layer anchor aware.



commit 95f57bee46eaf124a9634a0faea7153d900153c4
Author: Marius Stanciu <stanciumarius94 gmail com>
Date:   Sun Jul 17 16:49:42 2016 +0300

    Make path layer anchor aware.

 champlain/champlain-path-layer.c |   15 ++++++++++-----
 champlain/champlain-view.c       |   22 ++++++++++++++++++++++
 champlain/champlain-view.h       |    3 +++
 3 files changed, 35 insertions(+), 5 deletions(-)
---
diff --git a/champlain/champlain-path-layer.c b/champlain/champlain-path-layer.c
index 0471454..89a0db9 100644
--- a/champlain/champlain-path-layer.c
+++ b/champlain/champlain-path-layer.c
@@ -515,6 +515,7 @@ invalidate_canvas (ChamplainPathLayer *layer)
   gfloat view_width, view_height;
   gint map_width, map_height;
   gint viewport_x, viewport_y;
+  gint anchor_x, anchor_y;
   gfloat right_actor_width, right_actor_height;
   gfloat left_actor_width, left_actor_height;
 
@@ -530,9 +531,11 @@ invalidate_canvas (ChamplainPathLayer *layer)
       get_map_size (priv->view, &map_width, &map_height);
       clutter_actor_get_size (CLUTTER_ACTOR (priv->view), &view_width, &view_height);
       champlain_view_get_viewport_origin (priv->view, &viewport_x, &viewport_y);
-      right_actor_width = MIN (map_width - viewport_x, view_width);
-      right_actor_height = MIN (map_height - viewport_y, view_height);
-      left_actor_width = view_width - right_actor_width;
+      champlain_view_get_viewport_anchor (priv->view, &anchor_x, &anchor_y);
+
+      right_actor_width = MIN (map_width - (viewport_x + anchor_x), (gint)view_width);
+      right_actor_height = MIN (map_height - (viewport_y + anchor_y), (gint)view_height);
+      left_actor_width = MIN (view_width - right_actor_width, map_width - right_actor_width);
       left_actor_height = right_actor_height;
     }
 
@@ -743,6 +746,7 @@ redraw_path (ClutterCanvas *canvas,
   GList *elem;
   ChamplainView *view = priv->view;
   gint  viewport_x, viewport_y;
+  gint anchor_x, anchor_y;
   
   /* layer not yet added to the view */
   if (view == NULL)
@@ -752,11 +756,12 @@ redraw_path (ClutterCanvas *canvas,
     return FALSE;
 
   champlain_view_get_viewport_origin (priv->view, &viewport_x, &viewport_y);
+  champlain_view_get_viewport_anchor (priv->view, &anchor_x, &anchor_y);
 
   if (canvas == CLUTTER_CANVAS (priv->right_canvas))
       clutter_actor_set_position (priv->right_actor, viewport_x, viewport_y);
   else
-      clutter_actor_set_position (priv->left_actor, 0, viewport_y);
+      clutter_actor_set_position (priv->left_actor, -anchor_x, viewport_y);
 
   /* Clear the drawing area */
   cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
@@ -776,7 +781,7 @@ redraw_path (ClutterCanvas *canvas,
       if (canvas == CLUTTER_CANVAS (priv->right_canvas))
         cairo_line_to (cr, x, y);
       else
-        cairo_line_to (cr, x + viewport_x, y);
+        cairo_line_to (cr, x + (viewport_x + anchor_x), y);
     }
 
   if (priv->closed_path)
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index 7b096eb..a55cec1 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -2510,6 +2510,28 @@ champlain_view_latitude_to_y (ChamplainView *view,
   return y - priv->viewport_y;
 }
 
+/**
+ * champlain_view_get_viewport_anchor:
+ * @view: a #ChamplainView
+ * @anchor_x: (out): the x coordinate of the viewport anchor
+ * @anchor_y: (out): the y coordinate of the viewport anchor
+ *
+ * Gets the x and y coordinate of the viewport anchor in respect to the layer origin.
+ *
+ * Since: 0.12.14
+ */
+void
+champlain_view_get_viewport_anchor (ChamplainView *view,
+    gint *anchor_x,
+    gint *anchor_y)
+{
+    DEBUG_LOG ()
+
+  g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
+  ChamplainViewPrivate *priv = view->priv;
+
+  champlain_viewport_get_anchor (CHAMPLAIN_VIEWPORT (priv->viewport), anchor_x, anchor_y);
+}
 
 /**
  * champlain_view_get_viewport_origin:
diff --git a/champlain/champlain-view.h b/champlain/champlain-view.h
index 9c8c057..675606d 100644
--- a/champlain/champlain-view.h
+++ b/champlain/champlain-view.h
@@ -162,6 +162,9 @@ gdouble champlain_view_longitude_to_x (ChamplainView *view,
 gdouble champlain_view_latitude_to_y (ChamplainView *view,
     gdouble latitude);
 
+void champlain_view_get_viewport_anchor (ChamplainView *view,
+    gint *anchor_x,
+    gint *anchor_y);
 void champlain_view_get_viewport_origin (ChamplainView *view,
     gint *x,
     gint *y);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]