2018-04-11 22:16:43 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
*
|
|
|
|
* gdkcairocontext.c: Cairo wrappers
|
|
|
|
*
|
|
|
|
* Copyright © 2018 Benjamin Otte
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gdkcairocontext.h"
|
|
|
|
|
|
|
|
#include "gdkcairocontextprivate.h"
|
|
|
|
|
2018-04-11 22:32:53 +00:00
|
|
|
#include "gdkcairo.h"
|
2018-04-11 22:16:43 +00:00
|
|
|
#include "gdkinternals.h"
|
|
|
|
|
|
|
|
/**
|
2021-02-21 05:13:57 +00:00
|
|
|
* GdkCairoContext:
|
2018-04-11 22:16:43 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* `GdkCairoContext` is an object representing the platform-specific
|
2018-04-11 22:16:43 +00:00
|
|
|
* draw context.
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* `GdkCairoContext`s are created for a surface using
|
|
|
|
* [method@Gdk.Surface.create_cairo_context], and the context can then be used
|
|
|
|
* to draw on that surface.
|
2018-04-11 22:16:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct _GdkCairoContextPrivate GdkCairoContextPrivate;
|
|
|
|
|
|
|
|
struct _GdkCairoContextPrivate {
|
|
|
|
gpointer unused;
|
|
|
|
};
|
|
|
|
|
2018-04-12 14:48:31 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkCairoContext, gdk_cairo_context, GDK_TYPE_DRAW_CONTEXT,
|
|
|
|
G_ADD_PRIVATE (GdkCairoContext))
|
2018-04-11 22:16:43 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_cairo_context_class_init (GdkCairoContextClass *klass)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_cairo_context_init (GdkCairoContext *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-12 00:10:22 +00:00
|
|
|
/**
|
|
|
|
* gdk_cairo_context_cairo_create:
|
2018-05-01 10:35:32 +00:00
|
|
|
* @self: a #GdkCairoContext that is currently drawing
|
2018-04-12 00:10:22 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Retrieves a Cairo context to be used to draw on the `GdkSurface`
|
|
|
|
* of @context.
|
|
|
|
*
|
|
|
|
* A call to [method@Gdk.DrawContext.begin_frame] with this
|
2018-04-12 00:10:22 +00:00
|
|
|
* @context must have been done or this function will return %NULL.
|
|
|
|
*
|
|
|
|
* The returned context is guaranteed to be valid until
|
2021-02-21 05:13:57 +00:00
|
|
|
* [method@Gdk.DrawContext.end_frame] is called.
|
2018-04-12 00:10:22 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): a Cairo context to be used
|
2021-02-21 05:13:57 +00:00
|
|
|
* to draw the contents of the `GdkSurface`. %NULL is returned
|
2020-08-21 12:41:13 +00:00
|
|
|
* when @context is not drawing.
|
2018-04-12 00:10:22 +00:00
|
|
|
*/
|
|
|
|
cairo_t *
|
|
|
|
gdk_cairo_context_cairo_create (GdkCairoContext *self)
|
|
|
|
{
|
2018-04-23 16:42:36 +00:00
|
|
|
GdkDrawContext *draw_context;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_CAIRO_CONTEXT (self), NULL);
|
|
|
|
|
|
|
|
draw_context = GDK_DRAW_CONTEXT (self);
|
|
|
|
|
|
|
|
if (!gdk_draw_context_is_in_frame (draw_context))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cr = GDK_CAIRO_CONTEXT_GET_CLASS (self)->cairo_create (self);
|
|
|
|
|
|
|
|
gdk_cairo_region (cr, gdk_draw_context_get_frame_region (draw_context));
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
return cr;
|
2018-04-12 00:10:22 +00:00
|
|
|
}
|
|
|
|
|