LCOV - code coverage report
Current view: top level - shumate - shumate-layer.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 39 56 69.6 %
Date: 2024-05-11 21:41:31 Functions: 9 11 81.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 14 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2011-2013 Jiri Techet <techet@gmail.com>
       3                 :            :  * Copyright (C) 2019 Marcus Lundblad <ml@update.uu.se>
       4                 :            :  *
       5                 :            :  * This library is free software; you can redistribute it and/or
       6                 :            :  * modify it under the terms of the GNU Lesser General Public
       7                 :            :  * License as published by the Free Software Foundation; either
       8                 :            :  * version 2.1 of the License, or (at your option) any later version.
       9                 :            :  *
      10                 :            :  * This library is distributed in the hope that it will be useful,
      11                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13                 :            :  * Lesser General Public License for more details.
      14                 :            :  *
      15                 :            :  * You should have received a copy of the GNU Lesser General Public
      16                 :            :  * License along with this library; if not, write to the Free Software
      17                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      18                 :            :  */
      19                 :            : 
      20                 :            : /**
      21                 :            :  * ShumateLayer:
      22                 :            :  *
      23                 :            :  * Every layer (overlay that moves together with the map) has to inherit this
      24                 :            :  * class and implement its virtual methods.
      25                 :            :  *
      26                 :            :  * You can use the same layer to display many types of maps.  In Shumate they
      27                 :            :  * are called map sources.  You can change the [property@MapLayer:map-source]
      28                 :            :  * property at any time to replace the current displayed map.
      29                 :            :  */
      30                 :            : 
      31                 :            : #include "shumate-layer.h"
      32                 :            : 
      33                 :            : enum
      34                 :            : {
      35                 :            :   PROP_VIEWPORT = 1,
      36                 :            :   N_PROPERTIES
      37                 :            : };
      38                 :            : 
      39                 :            : static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
      40                 :            : 
      41                 :            : typedef struct {
      42                 :            :   ShumateViewport *viewport;
      43                 :            : } ShumateLayerPrivate;
      44                 :            : 
      45   [ +  +  +  - ]:        576 : G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ShumateLayer, shumate_layer, GTK_TYPE_WIDGET)
      46                 :            : 
      47                 :            : static void
      48                 :         22 : shumate_layer_set_property (GObject      *object,
      49                 :            :                             guint         property_id,
      50                 :            :                             const GValue *value,
      51                 :            :                             GParamSpec   *pspec)
      52                 :            : {
      53                 :         22 :   ShumateLayer *self = SHUMATE_LAYER (object);
      54                 :         22 :   ShumateLayerPrivate *priv = shumate_layer_get_instance_private (self);
      55                 :            : 
      56         [ +  - ]:         22 :   switch (property_id)
      57                 :            :     {
      58                 :         22 :     case PROP_VIEWPORT:
      59                 :         22 :       priv->viewport = g_value_dup_object (value);
      60                 :         22 :       break;
      61                 :            : 
      62                 :          0 :     default:
      63                 :          0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      64                 :          0 :       break;
      65                 :            :     }
      66                 :         22 : }
      67                 :            : 
      68                 :            : static void
      69                 :          0 : shumate_layer_get_property (GObject    *object,
      70                 :            :                             guint       property_id,
      71                 :            :                             GValue     *value,
      72                 :            :                             GParamSpec *pspec)
      73                 :            : {
      74                 :          0 :   ShumateLayer *self = SHUMATE_LAYER (object);
      75                 :          0 :   ShumateLayerPrivate *priv = shumate_layer_get_instance_private (self);
      76                 :            : 
      77         [ #  # ]:          0 :   switch (property_id)
      78                 :            :     {
      79                 :          0 :     case PROP_VIEWPORT:
      80                 :          0 :       g_value_set_object (value, priv->viewport);
      81                 :          0 :       break;
      82                 :            : 
      83                 :          0 :     default:
      84                 :          0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      85                 :          0 :       break;
      86                 :            :     }
      87                 :          0 : }
      88                 :            : 
      89                 :            : static void
      90                 :         10 : shumate_layer_dispose (GObject *object)
      91                 :            : {
      92                 :         10 :   ShumateLayerPrivate *priv = shumate_layer_get_instance_private (SHUMATE_LAYER (object));
      93                 :            : 
      94         [ +  - ]:         10 :   g_clear_object (&priv->viewport);
      95                 :            : 
      96                 :         10 :   G_OBJECT_CLASS (shumate_layer_parent_class)->dispose (object);
      97                 :         10 : }
      98                 :            : 
      99                 :            : static void
     100                 :         22 : shumate_layer_constructed (GObject *object)
     101                 :            : {
     102                 :         22 :   ShumateLayerPrivate *priv = shumate_layer_get_instance_private (SHUMATE_LAYER (object));
     103                 :            : 
     104         [ -  + ]:         22 :   if (!priv->viewport)
     105                 :          0 :     priv->viewport = shumate_viewport_new ();
     106                 :            : 
     107                 :         22 :   G_OBJECT_CLASS (shumate_layer_parent_class)->constructed (object);
     108                 :         22 : }
     109                 :            : 
     110                 :            : static gboolean
     111                 :          0 : shumate_layer_contains (GtkWidget *widget,
     112                 :            :                         double     x,
     113                 :            :                         double     y)
     114                 :            : {
     115                 :            :   /* This allows mouse events on the empty space between markers in this layer
     116                 :            :    * to fall through to lower layers. */
     117                 :          0 :   return FALSE;
     118                 :            : }
     119                 :            : 
     120                 :            : static void
     121                 :          5 : shumate_layer_class_init (ShumateLayerClass *klass)
     122                 :            : {
     123                 :          5 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
     124                 :          5 :   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
     125                 :            : 
     126                 :          5 :   object_class->set_property = shumate_layer_set_property;
     127                 :          5 :   object_class->get_property = shumate_layer_get_property;
     128                 :          5 :   object_class->dispose = shumate_layer_dispose;
     129                 :          5 :   object_class->constructed = shumate_layer_constructed;
     130                 :            : 
     131                 :          5 :   widget_class->contains = shumate_layer_contains;
     132                 :            : 
     133                 :         10 :   obj_properties[PROP_VIEWPORT] =
     134                 :          5 :     g_param_spec_object ("viewport",
     135                 :            :                          "Viewport",
     136                 :            :                          "The viewport used to display the layer",
     137                 :            :                          SHUMATE_TYPE_VIEWPORT,
     138                 :            :                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
     139                 :            : 
     140                 :          5 :   g_object_class_install_properties (object_class,
     141                 :            :                                      N_PROPERTIES,
     142                 :            :                                      obj_properties);
     143                 :            : 
     144                 :          5 :   gtk_widget_class_set_css_name (widget_class, "map-layer");
     145                 :          5 : }
     146                 :            : 
     147                 :            : static void
     148                 :         22 : shumate_layer_init (ShumateLayer *self)
     149                 :            : {
     150                 :         22 :   g_object_set (G_OBJECT (self),
     151                 :            :                 "hexpand", TRUE,
     152                 :            :                 "vexpand", TRUE,
     153                 :            :                 NULL);
     154                 :         22 : }
     155                 :            : 
     156                 :            : /**
     157                 :            :  * shumate_layer_get_viewport:
     158                 :            :  * @self: a #ShumateLayer
     159                 :            :  *
     160                 :            :  * Gets the #ShumateViewport used by this layer.
     161                 :            :  *
     162                 :            :  * Returns: (transfer none): The #ShumateViewport.
     163                 :            :  */
     164                 :            : ShumateViewport *
     165                 :        240 : shumate_layer_get_viewport (ShumateLayer *self)
     166                 :            : {
     167                 :        240 :   ShumateLayerPrivate *priv = shumate_layer_get_instance_private (self);
     168                 :            : 
     169         [ +  - ]:        240 :   g_return_val_if_fail (SHUMATE_IS_LAYER (self), NULL);
     170                 :            : 
     171                 :        240 :   return priv->viewport;
     172                 :            : }

Generated by: LCOV version 1.14