inspector: Handle background rendering in snapshots
This commit is contained in:
@@ -10,6 +10,7 @@ inspector_c_sources = \
|
||||
inspector/gestures.c \
|
||||
inspector/graphdata.c \
|
||||
inspector/gtkrenderoperation.c \
|
||||
inspector/gtkrenderoperationbackground.c \
|
||||
inspector/gtkrenderoperationcairo.c \
|
||||
inspector/gtkrenderoperationwidget.c \
|
||||
inspector/gtktreemodelcssnode.c \
|
||||
@@ -46,6 +47,7 @@ inspector_h_sources = \
|
||||
inspector/gestures.h \
|
||||
inspector/graphdata.h \
|
||||
inspector/gtkrenderoperation.h \
|
||||
inspector/gtkrenderoperationbackground.h \
|
||||
inspector/gtkrenderoperationcairo.h \
|
||||
inspector/gtkrenderoperationwidget.h \
|
||||
inspector/gtktreemodelcssnode.h \
|
||||
|
||||
130
gtk/inspector/gtkrenderoperationbackground.c
Normal file
130
gtk/inspector/gtkrenderoperationbackground.c
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright © 2015 Benjamin Otte <otte@gnome.org>
|
||||
*
|
||||
* 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.1 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkrenderoperationbackground.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "gtkcssstyleprivate.h"
|
||||
#include "gtkcssshadowsvalueprivate.h"
|
||||
#include "gtkrenderbackgroundprivate.h"
|
||||
|
||||
G_DEFINE_TYPE (GtkRenderOperationBackground, gtk_render_operation_background, GTK_TYPE_RENDER_OPERATION)
|
||||
|
||||
static void
|
||||
gtk_render_operation_background_get_clip (GtkRenderOperation *operation,
|
||||
cairo_rectangle_int_t *clip)
|
||||
{
|
||||
GtkRenderOperationBackground *oper = GTK_RENDER_OPERATION_BACKGROUND (operation);
|
||||
GtkBorder extents;
|
||||
|
||||
_gtk_css_shadows_value_get_extents (gtk_css_style_get_value (oper->style,
|
||||
GTK_CSS_PROPERTY_BOX_SHADOW),
|
||||
&extents);
|
||||
|
||||
clip->x = -extents.left;
|
||||
clip->y = -extents.right;
|
||||
clip->width = ceil (oper->width) + extents.left + extents.right;
|
||||
clip->height = ceil (oper->height) + extents.top + extents.bottom;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_render_operation_background_get_matrix (GtkRenderOperation *operation,
|
||||
cairo_matrix_t *matrix)
|
||||
{
|
||||
GtkRenderOperationBackground *oper = GTK_RENDER_OPERATION_BACKGROUND (operation);
|
||||
|
||||
cairo_matrix_init_translate (matrix, oper->x, oper->y);
|
||||
}
|
||||
|
||||
static char *
|
||||
gtk_render_operation_background_describe (GtkRenderOperation *operation)
|
||||
{
|
||||
return g_strdup ("CSS background");
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_render_operation_background_draw (GtkRenderOperation *operation,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GtkRenderOperationBackground *oper = GTK_RENDER_OPERATION_BACKGROUND (operation);
|
||||
|
||||
gtk_css_style_render_background (oper->style,
|
||||
cr,
|
||||
0, 0,
|
||||
oper->width,
|
||||
oper->height,
|
||||
oper->junction);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_render_operation_background_finalize (GObject *object)
|
||||
{
|
||||
GtkRenderOperationBackground *oper = GTK_RENDER_OPERATION_BACKGROUND (object);
|
||||
|
||||
g_object_unref (oper->style);
|
||||
|
||||
G_OBJECT_CLASS (gtk_render_operation_background_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_render_operation_background_class_init (GtkRenderOperationBackgroundClass *klass)
|
||||
{
|
||||
GtkRenderOperationClass *operation_class = GTK_RENDER_OPERATION_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = gtk_render_operation_background_finalize;
|
||||
|
||||
operation_class->get_clip = gtk_render_operation_background_get_clip;
|
||||
operation_class->get_matrix = gtk_render_operation_background_get_matrix;
|
||||
operation_class->describe = gtk_render_operation_background_describe;
|
||||
operation_class->draw = gtk_render_operation_background_draw;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_render_operation_background_init (GtkRenderOperationBackground *image)
|
||||
{
|
||||
}
|
||||
|
||||
GtkRenderOperation *
|
||||
gtk_render_operation_background_new (GtkCssStyle *style,
|
||||
double x,
|
||||
double y,
|
||||
double width,
|
||||
double height,
|
||||
GtkJunctionSides junction)
|
||||
{
|
||||
GtkRenderOperationBackground *result;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_CSS_STYLE (style), NULL);
|
||||
|
||||
result = g_object_new (GTK_TYPE_RENDER_OPERATION_BACKGROUND, NULL);
|
||||
|
||||
result->style = g_object_ref (style);
|
||||
result->x = x;
|
||||
result->y = y;
|
||||
result->width = width;
|
||||
result->height = height;
|
||||
result->junction = junction;
|
||||
|
||||
return GTK_RENDER_OPERATION (result);
|
||||
}
|
||||
|
||||
67
gtk/inspector/gtkrenderoperationbackground.h
Normal file
67
gtk/inspector/gtkrenderoperationbackground.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright © 2015 Red Hat Inc.
|
||||
*
|
||||
* 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.1 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_RENDER_OPERATION_BACKGROUND_PRIVATE_H__
|
||||
#define __GTK_RENDER_OPERATION_BACKGROUND_PRIVATE_H__
|
||||
|
||||
#include "gtkrenderoperation.h"
|
||||
|
||||
#include "gtkcsstypesprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_RENDER_OPERATION_BACKGROUND (gtk_render_operation_background_get_type ())
|
||||
#define GTK_RENDER_OPERATION_BACKGROUND(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_RENDER_OPERATION_BACKGROUND, GtkRenderOperationBackground))
|
||||
#define GTK_RENDER_OPERATION_BACKGROUND_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_RENDER_OPERATION_BACKGROUND, GtkRenderOperationBackgroundClass))
|
||||
#define GTK_IS_RENDER_OPERATION_BACKGROUND(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_RENDER_OPERATION_BACKGROUND))
|
||||
#define GTK_IS_RENDER_OPERATION_BACKGROUND_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_RENDER_OPERATION_BACKGROUND))
|
||||
#define GTK_RENDER_OPERATION_BACKGROUND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RENDER_OPERATION_BACKGROUND, GtkRenderOperationBackgroundClass))
|
||||
|
||||
typedef struct _GtkRenderOperationBackground GtkRenderOperationBackground;
|
||||
typedef struct _GtkRenderOperationBackgroundClass GtkRenderOperationBackgroundClass;
|
||||
|
||||
struct _GtkRenderOperationBackground
|
||||
{
|
||||
GtkRenderOperation parent;
|
||||
|
||||
GtkCssStyle *style;
|
||||
double x;
|
||||
double y;
|
||||
double width;
|
||||
double height;
|
||||
GtkJunctionSides junction;
|
||||
};
|
||||
|
||||
struct _GtkRenderOperationBackgroundClass
|
||||
{
|
||||
GtkRenderOperationClass parent_class;
|
||||
};
|
||||
|
||||
GType gtk_render_operation_background_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkRenderOperation * gtk_render_operation_background_new (GtkCssStyle *style,
|
||||
double x,
|
||||
double y,
|
||||
double width,
|
||||
double height,
|
||||
GtkJunctionSides junction);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_RENDER_OPERATION_BACKGROUND_PRIVATE_H__ */
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "recordingrenderops.h"
|
||||
|
||||
#include "gtkrenderoperationbackground.h"
|
||||
#include "gtkrenderoperationcairo.h"
|
||||
#include "gtkrenderoperationwidget.h"
|
||||
#include "gtkwidget.h"
|
||||
@@ -99,6 +100,26 @@ gtk_recording_render_ops_save_snapshot (GtkRecordingRenderOps *record,
|
||||
cairo_restore (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_recording_render_ops_draw_background (GtkRenderOps *ops,
|
||||
GtkCssStyle *style,
|
||||
cairo_t *cr,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gdouble width,
|
||||
gdouble height,
|
||||
GtkJunctionSides junction)
|
||||
{
|
||||
GtkRecordingRenderOps *record = GTK_RECORDING_RENDER_OPS (ops);
|
||||
GtkRenderOperation *oper;
|
||||
|
||||
gtk_recording_render_ops_save_snapshot (record, cr);
|
||||
|
||||
oper = gtk_render_operation_background_new (style, x, y, width, height, junction);
|
||||
gtk_render_operation_widget_add_operation (record->widgets->data, oper);
|
||||
g_object_unref (oper);
|
||||
}
|
||||
|
||||
static cairo_t *
|
||||
gtk_recording_render_ops_begin_draw_widget (GtkRenderOps *ops,
|
||||
GtkWidget *widget,
|
||||
@@ -151,6 +172,7 @@ gtk_recording_render_ops_class_init (GtkRecordingRenderOpsClass *klass)
|
||||
|
||||
ops_class->begin_draw_widget = gtk_recording_render_ops_begin_draw_widget;
|
||||
ops_class->end_draw_widget = gtk_recording_render_ops_end_draw_widget;
|
||||
ops_class->draw_background = gtk_recording_render_ops_draw_background;
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user