1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* A simple surface for debugging the canvas. Shows how tiles are drawn.
*
* Author:
* Tavmjong Bah <tavmjong@free.fr>
*
* Copyright (C) 2017 Tavmjong Bah
*
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include "canvas-debug.h"
#include "sp-canvas.h"
#include "cairo-utils.h"
#include "ui/event-debug.h"
namespace {
static void sp_canvas_debug_destroy(SPCanvasItem *item);
static void sp_canvas_debug_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned int flags);
static void sp_canvas_debug_render (SPCanvasItem *item, SPCanvasBuf *buf);
static int sp_canvas_debug_event (SPCanvasItem *item, GdkEvent *event);
} // namespace
G_DEFINE_TYPE(SPCanvasDebug, sp_canvas_debug, SP_TYPE_CANVAS_ITEM);
static void sp_canvas_debug_class_init (SPCanvasDebugClass *klass)
{
klass->destroy = sp_canvas_debug_destroy;
klass->update = sp_canvas_debug_update;
klass->render = sp_canvas_debug_render;
klass->event = sp_canvas_debug_event;
}
static void sp_canvas_debug_init (SPCanvasDebug *debug)
{
debug->pickable = true; // So we can receive events.
}
namespace {
static void sp_canvas_debug_destroy (SPCanvasItem *object)
{
g_return_if_fail (object != nullptr);
g_return_if_fail (SP_IS_CANVAS_DEBUG (object));
if (SP_CANVAS_ITEM_CLASS(sp_canvas_debug_parent_class)->destroy) {
SP_CANVAS_ITEM_CLASS(sp_canvas_debug_parent_class)->destroy(object);
}
}
static void sp_canvas_debug_update( SPCanvasItem *item, Geom::Affine const &/*affine*/, unsigned int /*flags*/ )
{
// We cover the entire canvas
item->x1 = -G_MAXINT;
item->y1 = -G_MAXINT;
item->x2 = G_MAXINT;
item->y2 = G_MAXINT;
}
static void sp_canvas_debug_render( SPCanvasItem *item, SPCanvasBuf *buf)
{
if (!buf->ct) {
return;
}
cairo_set_line_width (buf->ct, 2);
// Draw box around buffer (for debugging)
cairo_new_path (buf->ct);
cairo_move_to (buf->ct, 0, 0);
cairo_line_to (buf->ct, buf->rect.width(), 0);
cairo_line_to (buf->ct, buf->rect.width(), buf->rect.height());
cairo_line_to (buf->ct, 0, buf->rect.height());
cairo_close_path (buf->ct);
ink_cairo_set_source_rgba32 (buf->ct, 0xff7f7f7f);
cairo_stroke (buf->ct);
}
static int sp_canvas_debug_event (SPCanvasItem *item, GdkEvent *event)
{
ui_dump_event (event, Glib::ustring("sp_canvas_debug_event"));
return false; // We don't use any events...
}
} // namespace
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
|