1 /* graphene-size.h: Size
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Copyright 2014  Emmanuele Bassi
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  */
25 
26 #pragma once
27 
28 #if !defined(GRAPHENE_H_INSIDE) && !defined(GRAPHENE_COMPILATION)
29 #error "Only graphene.h can be included directly."
30 #endif
31 
32 #include "graphene-types.h"
33 
34 GRAPHENE_BEGIN_DECLS
35 
36 /**
37  * GRAPHENE_SIZE_INIT:
38  * @_w: the width
39  * @_h: the height
40  *
41  * Initializes a #graphene_size_t with the given sizes when
42  * declaring it, e.g.:
43  *
44  * |[<!-- language="C" -->
45  *   graphene_size_t size = GRAPHENE_SIZE_INIT (100.f, 100.f);
46  * ]|
47  *
48  * Since: 1.0
49  */
50 #define GRAPHENE_SIZE_INIT(_w,_h)       (graphene_size_t) { .width = (_w), .height = (_h) }
51 
52 /**
53  * GRAPHENE_SIZE_INIT_ZERO:
54  *
55  * Initializes a #graphene_size_t to (0, 0) when declaring it.
56  *
57  * Since: 1.0
58  */
59 #define GRAPHENE_SIZE_INIT_ZERO         GRAPHENE_SIZE_INIT (0.f, 0.f)
60 
61 /**
62  * graphene_size_t:
63  * @width: the width
64  * @height: the height
65  *
66  * A size.
67  *
68  * Since: 1.0
69  */
70 struct _graphene_size_t
71 {
72   float width;
73   float height;
74 };
75 
76 GRAPHENE_AVAILABLE_IN_1_0
77 graphene_size_t *               graphene_size_alloc             (void);
78 GRAPHENE_AVAILABLE_IN_1_0
79 void                            graphene_size_free              (graphene_size_t        *s);
80 GRAPHENE_AVAILABLE_IN_1_0
81 graphene_size_t *               graphene_size_init              (graphene_size_t        *s,
82                                                                  float                   width,
83                                                                  float                   height);
84 GRAPHENE_AVAILABLE_IN_1_0
85 graphene_size_t *               graphene_size_init_from_size    (graphene_size_t        *s,
86                                                                  const graphene_size_t  *src);
87 GRAPHENE_AVAILABLE_IN_1_0
88 bool                            graphene_size_equal             (const graphene_size_t  *a,
89                                                                  const graphene_size_t  *b);
90 
91 GRAPHENE_AVAILABLE_IN_1_0
92 void                            graphene_size_scale             (const graphene_size_t  *s,
93                                                                  float                   factor,
94                                                                  graphene_size_t        *res);
95 GRAPHENE_AVAILABLE_IN_1_0
96 void                            graphene_size_interpolate       (const graphene_size_t  *a,
97                                                                  const graphene_size_t  *b,
98                                                                  double                  factor,
99                                                                  graphene_size_t        *res);
100 
101 GRAPHENE_AVAILABLE_IN_1_0
102 const graphene_size_t *         graphene_size_zero              (void);
103 
104 GRAPHENE_END_DECLS
105