[libshumate] viewport: Add shumate_viewport_copy()



commit d4f2642813396960da475dcde92c1495e1804278
Author: James Westman <james jwestman net>
Date:   Mon Apr 25 13:28:05 2022 -0500

    viewport: Add shumate_viewport_copy()

 shumate/meson.build                |  1 +
 shumate/shumate-map.c              |  2 +-
 shumate/shumate-viewport-private.h | 23 +++++++++++++++++++++++
 shumate/shumate-viewport.c         | 35 ++++++++++++++++++++++++++++++-----
 4 files changed, 55 insertions(+), 6 deletions(-)
---
diff --git a/shumate/meson.build b/shumate/meson.build
index b432f64..5ee22be 100644
--- a/shumate/meson.build
+++ b/shumate/meson.build
@@ -29,6 +29,7 @@ libshumate_public_h = [
 libshumate_private_h = [
   'shumate-kinetic-scrolling-private.h',
   'shumate-marker-private.h',
+  'shumate-viewport-private.h',
 
   'vector/shumate-vector-background-layer-private.h',
   'vector/shumate-vector-expression-private.h',
diff --git a/shumate/shumate-map.c b/shumate/shumate-map.c
index 48c7d12..63977b3 100644
--- a/shumate/shumate-map.c
+++ b/shumate/shumate-map.c
@@ -51,7 +51,7 @@
 #include "shumate-tile.h"
 #include "shumate-license.h"
 #include "shumate-location.h"
-#include "shumate-viewport.h"
+#include "shumate-viewport-private.h"
 
 #include <glib.h>
 #include <glib-object.h>
diff --git a/shumate/shumate-viewport-private.h b/shumate/shumate-viewport-private.h
new file mode 100644
index 0000000..825819d
--- /dev/null
+++ b/shumate/shumate-viewport-private.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2022 James Westman <james jwestman net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "shumate-viewport.h"
+
+ShumateViewport *shumate_viewport_copy (ShumateViewport *self);
+
diff --git a/shumate/shumate-viewport.c b/shumate/shumate-viewport.c
index 540371f..ce8a06f 100644
--- a/shumate/shumate-viewport.c
+++ b/shumate/shumate-viewport.c
@@ -56,6 +56,7 @@ static void shumate_viewport_shumate_location_interface_init (ShumateLocationInt
 G_DEFINE_TYPE_WITH_CODE (ShumateViewport, shumate_viewport, G_TYPE_OBJECT,
     G_IMPLEMENT_INTERFACE (SHUMATE_TYPE_LOCATION, shumate_viewport_shumate_location_interface_init));
 
+/* Remember to update shumate_viewport_copy() when adding properties */
 enum
 {
   PROP_ZOOM_LEVEL = 1,
@@ -274,7 +275,7 @@ shumate_viewport_class_init (ShumateViewportClass *klass)
                          "The rotation of the map view in radians",
                          0, G_PI * 2.0, 0,
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
-  
+
   g_object_class_install_properties (object_class,
                                      N_PROPERTIES,
                                      obj_properties);
@@ -341,7 +342,7 @@ shumate_viewport_set_zoom_level (ShumateViewport *self,
  * @self: a #ShumateViewport
  *
  * Get the current zoom level
- * 
+ *
  * Returns: the current zoom level
  */
 double
@@ -381,7 +382,7 @@ shumate_viewport_set_max_zoom_level (ShumateViewport *self,
  * @self: a #ShumateViewport
  *
  * Get the maximal zoom level
- * 
+ *
  * Returns: the maximal zoom level
  */
 guint
@@ -421,7 +422,7 @@ shumate_viewport_set_min_zoom_level (ShumateViewport *self,
  * @self: a #ShumateViewport
  *
  * Get the minimal zoom level
- * 
+ *
  * Returns: the minimal zoom level
  */
 guint
@@ -492,7 +493,7 @@ shumate_viewport_set_reference_map_source (ShumateViewport  *self,
  * @self: a #ShumateViewport
  *
  * Get the reference map source
- * 
+ *
  * Returns: (transfer none) (nullable): the reference #ShumateMapSource or %NULL
  * when none has been set.
  */
@@ -662,3 +663,27 @@ shumate_viewport_location_to_widget_coords (ShumateViewport *self,
 
   rotate_around_center (x, y, width, height, self->rotation);
 }
+
+/**
+ * shumate_viewport_copy:
+ * @self: a [class@Viewport]
+ *
+ * Creates a copy of the viewport.
+ *
+ * Returns: (transfer full): a [class@Viewport] with the same values as @self
+ */
+ShumateViewport *
+shumate_viewport_copy (ShumateViewport *self)
+{
+  g_return_val_if_fail (SHUMATE_IS_VIEWPORT (self), NULL);
+
+  return g_object_new (SHUMATE_TYPE_VIEWPORT,
+                       "latitude", self->lat,
+                       "longitude", self->lon,
+                       "min-zoom-level", self->min_zoom_level,
+                       "max-zoom-level", self->max_zoom_level,
+                       "rotation", self->rotation,
+                       "reference-map-source", self->ref_map_source,
+                       "zoom-level", self->zoom_level,
+                       NULL);
+}


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