shumate/vector/shumate-vector-background-layer.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (C) 2021 James Westman <james@jwestman.net> | ||
| 3 | * | ||
| 4 | * This library is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This library is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with this library; if not, see <https://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <gtk/gtk.h> | ||
| 19 | #include "shumate-vector-background-layer-private.h" | ||
| 20 | #include "shumate-vector-expression-private.h" | ||
| 21 | #include "shumate-vector-utils-private.h" | ||
| 22 | |||
| 23 | struct _ShumateVectorBackgroundLayer | ||
| 24 | { | ||
| 25 | ShumateVectorLayer parent_instance; | ||
| 26 | |||
| 27 | ShumateVectorExpression *color; | ||
| 28 | ShumateVectorExpression *opacity; | ||
| 29 | }; | ||
| 30 | |||
| 31 |
4/6shumate_vector_background_layer_class_intern_init:
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 4 times.
shumate_vector_background_layer_get_type:
✓ Branch 2 → 3 taken 4 times.
✓ Branch 2 → 7 taken 2 times.
✓ Branch 4 → 5 taken 4 times.
✗ Branch 4 → 7 not taken.
|
14 | G_DEFINE_TYPE (ShumateVectorBackgroundLayer, shumate_vector_background_layer, SHUMATE_TYPE_VECTOR_LAYER) |
| 32 | |||
| 33 | |||
| 34 | ShumateVectorLayer * | ||
| 35 | 6 | shumate_vector_background_layer_create_from_json (JsonObject *object, GError **error) | |
| 36 | { | ||
| 37 | 6 | ShumateVectorBackgroundLayer *layer = g_object_new (SHUMATE_TYPE_VECTOR_BACKGROUND_LAYER, NULL); | |
| 38 | 6 | JsonNode *paint_node; | |
| 39 | |||
| 40 |
1/2✓ Branch 5 → 6 taken 6 times.
✗ Branch 5 → 16 not taken.
|
6 | if ((paint_node = json_object_get_member (object, "paint"))) |
| 41 | { | ||
| 42 | 6 | JsonObject *paint; | |
| 43 | |||
| 44 |
1/2✓ Branch 7 → 8 taken 6 times.
✗ Branch 7 → 15 not taken.
|
6 | if (!shumate_vector_json_get_object (paint_node, &paint, error)) |
| 45 | ✗ | return NULL; | |
| 46 | |||
| 47 |
1/2✓ Branch 10 → 11 taken 6 times.
✗ Branch 10 → 15 not taken.
|
6 | if (!(layer->color = shumate_vector_expression_from_json (json_object_get_member (paint, "background-color"), error))) |
| 48 | return NULL; | ||
| 49 | |||
| 50 |
1/2✓ Branch 13 → 14 taken 6 times.
✗ Branch 13 → 15 not taken.
|
6 | if (!(layer->opacity = shumate_vector_expression_from_json (json_object_get_member (paint, "background-opacity"), error))) |
| 51 | return NULL; | ||
| 52 | } | ||
| 53 | |||
| 54 | return (ShumateVectorLayer *)layer; | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | static void | ||
| 59 | 6 | shumate_vector_background_layer_finalize (GObject *object) | |
| 60 | { | ||
| 61 | 6 | ShumateVectorBackgroundLayer *self = SHUMATE_VECTOR_BACKGROUND_LAYER (object); | |
| 62 | |||
| 63 |
1/2✓ Branch 2 → 3 taken 6 times.
✗ Branch 2 → 4 not taken.
|
6 | g_clear_object (&self->color); |
| 64 |
1/2✓ Branch 4 → 5 taken 6 times.
✗ Branch 4 → 6 not taken.
|
6 | g_clear_object (&self->opacity); |
| 65 | |||
| 66 | 6 | G_OBJECT_CLASS (shumate_vector_background_layer_parent_class)->finalize (object); | |
| 67 | 6 | } | |
| 68 | |||
| 69 | |||
| 70 | static void | ||
| 71 | 2 | shumate_vector_background_layer_render (ShumateVectorLayer *layer, ShumateVectorRenderScope *scope) | |
| 72 | { | ||
| 73 | 2 | ShumateVectorBackgroundLayer *self = SHUMATE_VECTOR_BACKGROUND_LAYER (layer); | |
| 74 | 2 | GdkRGBA color = SHUMATE_VECTOR_COLOR_BLACK; | |
| 75 | 2 | double opacity; | |
| 76 | |||
| 77 | 2 | shumate_vector_expression_eval_color (self->color, scope, &color); | |
| 78 | 2 | opacity = shumate_vector_expression_eval_number (self->opacity, scope, 1.0); | |
| 79 | |||
| 80 | 2 | cairo_set_source_rgba (scope->cr, color.red, color.green, color.blue, color.alpha * opacity); | |
| 81 | 2 | cairo_paint (scope->cr); | |
| 82 | 2 | } | |
| 83 | |||
| 84 | |||
| 85 | static void | ||
| 86 | 4 | shumate_vector_background_layer_class_init (ShumateVectorBackgroundLayerClass *klass) | |
| 87 | { | ||
| 88 | 4 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
| 89 | 4 | ShumateVectorLayerClass *layer_class = SHUMATE_VECTOR_LAYER_CLASS (klass); | |
| 90 | |||
| 91 | 4 | object_class->finalize = shumate_vector_background_layer_finalize; | |
| 92 | 4 | layer_class->render = shumate_vector_background_layer_render; | |
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | static void | ||
| 97 | 6 | shumate_vector_background_layer_init (ShumateVectorBackgroundLayer *self) | |
| 98 | { | ||
| 99 | 6 | } | |
| 100 |