1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "surfacepaintable.hxx"
12 struct _SurfacePaintable
14 GObject parent_instance
;
17 cairo_surface_t
* surface
;
22 struct _SurfacePaintableClass
: public GObjectClass
27 static void surface_paintable_snapshot(GdkPaintable
* paintable
, GdkSnapshot
* snapshot
, double width
,
31 = GRAPHENE_RECT_INIT(0.0f
, 0.0f
, static_cast<float>(width
), static_cast<float>(height
));
32 SurfacePaintable
* self
= SURFACE_PAINTABLE(paintable
);
33 cairo_t
* cr
= gtk_snapshot_append_cairo(GTK_SNAPSHOT(snapshot
), &rect
);
34 cairo_set_source_surface(cr
, self
->surface
, 0, 0);
39 static GdkPaintableFlags
surface_paintable_get_flags(GdkPaintable
* /*paintable*/)
41 return static_cast<GdkPaintableFlags
>(GDK_PAINTABLE_STATIC_SIZE
42 | GDK_PAINTABLE_STATIC_CONTENTS
);
45 static int surface_paintable_get_intrinsic_width(GdkPaintable
* paintable
)
47 SurfacePaintable
* self
= SURFACE_PAINTABLE(paintable
);
51 static int surface_paintable_get_intrinsic_height(GdkPaintable
* paintable
)
53 SurfacePaintable
* self
= SURFACE_PAINTABLE(paintable
);
57 static void surface_paintable_init_interface(GdkPaintableInterface
* iface
)
59 iface
->snapshot
= surface_paintable_snapshot
;
60 iface
->get_flags
= surface_paintable_get_flags
;
61 iface
->get_intrinsic_width
= surface_paintable_get_intrinsic_width
;
62 iface
->get_intrinsic_height
= surface_paintable_get_intrinsic_height
;
65 G_DEFINE_TYPE_WITH_CODE(SurfacePaintable
, surface_paintable
, G_TYPE_OBJECT
,
66 G_IMPLEMENT_INTERFACE(GDK_TYPE_PAINTABLE
,
67 surface_paintable_init_interface
));
69 static void surface_paintable_init(SurfacePaintable
* self
)
73 self
->surface
= nullptr;
75 // prevent loplugin:unreffun firing on macro generated function
76 (void)surface_paintable_get_instance_private(self
);
79 static void surface_paintable_dispose(GObject
* object
)
81 SurfacePaintable
* self
= SURFACE_PAINTABLE(object
);
82 cairo_surface_destroy(self
->surface
);
83 G_OBJECT_CLASS(surface_paintable_parent_class
)->dispose(object
);
86 static void surface_paintable_class_init(SurfacePaintableClass
* klass
)
88 GObjectClass
* object_class
= G_OBJECT_CLASS(klass
);
89 object_class
->dispose
= surface_paintable_dispose
;
92 void surface_paintable_set_source(SurfacePaintable
* pPaintable
, cairo_surface_t
* pSource
,
93 int nWidth
, int nHeight
)
95 pPaintable
->surface
= pSource
;
96 pPaintable
->width
= nWidth
;
97 pPaintable
->height
= nHeight
;
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */