diff --git a/mtk/mtk/meson.build b/mtk/mtk/meson.build index 2de4d2c34..d7ae49d28 100644 --- a/mtk/mtk/meson.build +++ b/mtk/mtk/meson.build @@ -3,9 +3,11 @@ mtk_mtk_includesubdir = mtk_includesubdir / 'mtk' mtk_headers = [ 'mtk.h', 'mtk-macros.h', + 'mtk-rectangle.h', ] mtk_sources = [ + 'mtk-rectangle.c', ] mtk_private_headers = [ diff --git a/mtk/mtk/mtk-rectangle.c b/mtk/mtk/mtk-rectangle.c new file mode 100644 index 000000000..861bf0ac2 --- /dev/null +++ b/mtk/mtk/mtk-rectangle.c @@ -0,0 +1,38 @@ +/* + * Mtk + * + * A low-level base library. + * + * Copyright (C) 2023 Red Hat + * + * 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 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 . + */ + +#include "mtk/mtk-rectangle.h" + + +MtkRectangle * +mtk_rectangle_copy (const MtkRectangle *rect) +{ + return g_memdup2 (rect, sizeof (MtkRectangle)); +} + +void +mtk_rectangle_free (MtkRectangle *rect) +{ + g_free (rect); +} + +G_DEFINE_BOXED_TYPE (MtkRectangle, mtk_rectangle, + mtk_rectangle_copy, mtk_rectangle_free); diff --git a/mtk/mtk/mtk-rectangle.h b/mtk/mtk/mtk-rectangle.h new file mode 100644 index 000000000..92150a620 --- /dev/null +++ b/mtk/mtk/mtk-rectangle.h @@ -0,0 +1,66 @@ +/* + * Mtk + * + * A low-level base library. + * + * Copyright (C) 2023 Red Hat + * + * 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 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 . + */ + +#pragma once + +#include +#include + +#include "mtk/mtk-macros.h" + +#define MTK_TYPE_RECTANGLE (mtk_rectangle_get_type ()) + +/** + * MtkRectangle: + * @x: X coordinate of the top-left corner + * @y: Y coordinate of the top-left corner + * @width: Width of the rectangle + * @height: Height of the rectangle + */ +#ifdef __GI_SCANNER__ +/* The introspection scanner is currently unable to lookup how + * cairo_rectangle_int_t is actually defined. This prevents + * introspection data for the GdkRectangle type to include fields + * descriptions. To workaround this issue, we define it with the same + * content as cairo_rectangle_int_t, but only under the introspection + * define. + */ +struct _MtkRectangle +{ + int x; + int y; + int width; + int height; +}; +typedef struct _MtkRectangle MtkRectangle; +#else +typedef cairo_rectangle_int_t MtkRectangle; +#endif + +MTK_EXPORT +GType mtk_rectangle_get_type (void); + +MTK_EXPORT +MtkRectangle * mtk_rectangle_copy (const MtkRectangle *rect); + +MTK_EXPORT +void mtk_rectangle_free (MtkRectangle *rect); + diff --git a/mtk/mtk/mtk.h b/mtk/mtk/mtk.h index 31a9de196..7645e3841 100644 --- a/mtk/mtk/mtk.h +++ b/mtk/mtk/mtk.h @@ -23,6 +23,7 @@ #define __MTK_H_INSIDE__ +#include "mtk/mtk-rectangle.h" #include "mtk/mtk-macros.h" #undef __MTK_H_INSIDE__