summaryrefslogtreecommitdiffstats
path: root/src/display/nr-arena-group.cpp
blob: 64274202f4022c9a2ffa824dd5fd814ca1228933 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#define __NR_ARENA_GROUP_C__

/*
 * RGBA display list system for inkscape
 *
 * Author:
 *   Lauris Kaplinski <lauris@kaplinski.com>
 *
 * Copyright (C) 2001-2002 Lauris Kaplinski
 * Copyright (C) 2001 Ximian, Inc.
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#include "nr-arena-group.h"

static void nr_arena_group_class_init (NRArenaGroupClass *klass);
static void nr_arena_group_init (NRArenaGroup *group);

static NRArenaItem *nr_arena_group_children (NRArenaItem *item);
static NRArenaItem *nr_arena_group_last_child (NRArenaItem *item);
static void nr_arena_group_add_child (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref);
static void nr_arena_group_remove_child (NRArenaItem *item, NRArenaItem *child);
static void nr_arena_group_set_child_position (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref);

static unsigned int nr_arena_group_update (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int state, unsigned int reset);
static unsigned int nr_arena_group_render (NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags);
static unsigned int nr_arena_group_clip (NRArenaItem *item, NRRectL *area, NRPixBlock *pb);
static NRArenaItem *nr_arena_group_pick (NRArenaItem *item, NR::Point p, double delta, unsigned int sticky);

static NRArenaItemClass *parent_class;

NRType
nr_arena_group_get_type (void)
{
	static NRType type = 0;
	if (!type) {
		type = nr_object_register_type (NR_TYPE_ARENA_ITEM,
						"NRArenaGroup",
						sizeof (NRArenaGroupClass),
						sizeof (NRArenaGroup),
						(void (*) (NRObjectClass *)) nr_arena_group_class_init,
						(void (*) (NRObject *)) nr_arena_group_init);
	}
	return type;
}

static void
nr_arena_group_class_init (NRArenaGroupClass *klass)
{
	NRObjectClass *object_class;
	NRArenaItemClass *item_class;

	object_class = (NRObjectClass *) klass;
	item_class = (NRArenaItemClass *) klass;

	parent_class = (NRArenaItemClass *) ((NRObjectClass *) klass)->parent;

	object_class->cpp_ctor = NRObject::invoke_ctor<NRArenaGroup>;

	item_class->children = nr_arena_group_children;
	item_class->last_child = nr_arena_group_last_child;
	item_class->add_child = nr_arena_group_add_child;
	item_class->set_child_position = nr_arena_group_set_child_position;
	item_class->remove_child = nr_arena_group_remove_child;
	item_class->update = nr_arena_group_update;
	item_class->render = nr_arena_group_render;
	item_class->clip = nr_arena_group_clip;
	item_class->pick = nr_arena_group_pick;
}

static void
nr_arena_group_init (NRArenaGroup *group)
{
	group->transparent = FALSE;
	group->children = NULL;
	group->last = NULL;
	nr_matrix_set_identity (&group->child_transform);
  
#ifdef arena_item_tile_cache
  group->skipCaching=true;
#endif

}

static NRArenaItem *
nr_arena_group_children (NRArenaItem *item)
{
	NRArenaGroup *group = NR_ARENA_GROUP (item);

	return group->children;
}

static NRArenaItem *
nr_arena_group_last_child (NRArenaItem *item)
{
	NRArenaGroup *group = NR_ARENA_GROUP (item);

	return group->last;
}

static void
nr_arena_group_add_child (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref)
{
	NRArenaGroup *group = NR_ARENA_GROUP (item);

	if (!ref) {
		group->children = nr_arena_item_attach_ref (item, child, NULL, group->children);
	} else {
		ref->next = nr_arena_item_attach_ref (item, child, ref, ref->next);
	}

	if (ref == group->last) group->last = child;

	nr_arena_item_request_update (item, NR_ARENA_ITEM_STATE_ALL, FALSE);
}

static void
nr_arena_group_remove_child (NRArenaItem *item, NRArenaItem *child)
{
	NRArenaGroup *group = NR_ARENA_GROUP (item);

	if (child == group->last) group->last = child->prev;

	if (child->prev) {
		nr_arena_item_detach_unref (item, child);
	} else {
		group->children = nr_arena_item_detach_unref (item, child);
	}

	nr_arena_item_request_update (item, NR_ARENA_ITEM_STATE_ALL, FALSE);
}

static void
nr_arena_group_set_child_position (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref)
{
	NRArenaGroup *group = NR_ARENA_GROUP (item);

	if (child == group->last) group->last = child->prev;

	if (child->prev) {
		nr_arena_item_detach_unref (item, child);
	} else {
		group->children = nr_arena_item_detach_unref (item, child);
	}

	if (!ref) {
		group->children = nr_arena_item_attach_ref (item, child, NULL, group->children);
	} else {
		ref->next = nr_arena_item_attach_ref (item, child, ref, ref->next);
	}

	if (ref == group->last) group->last = child;

	nr_arena_item_request_render (child);
}

static unsigned int
nr_arena_group_update (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int state, unsigned int reset)
{
	unsigned int newstate;

	NRArenaGroup *group = NR_ARENA_GROUP (item);

	unsigned int beststate = NR_ARENA_ITEM_STATE_ALL;

	for (NRArenaItem *child = group->children; child != NULL; child = child->next) {
		NRGC cgc(gc);
		nr_matrix_multiply (&cgc.transform, &group->child_transform, &gc->transform);
		newstate = nr_arena_item_invoke_update (child, area, &cgc, state, reset);
		beststate = beststate & newstate;
	}

	if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
		nr_rect_l_set_empty (&item->bbox);
		for (NRArenaItem *child = group->children; child != NULL; child = child->next) {
			nr_rect_l_union (&item->bbox, &item->bbox, &child->bbox);
		}
	}

	return beststate;
}

static unsigned int
nr_arena_group_render (NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags)
{
	NRArenaGroup *group = NR_ARENA_GROUP (item);

	unsigned int ret = item->state;

	/* Just compose children into parent buffer */
	for (NRArenaItem *child = group->children; child != NULL; child = child->next) {
		ret = nr_arena_item_invoke_render (child, area, pb, flags);
		if (ret & NR_ARENA_ITEM_STATE_INVALID) break;
	}

	return ret;
}

static unsigned int
nr_arena_group_clip (NRArenaItem *item, NRRectL *area, NRPixBlock *pb)
{
	NRArenaGroup *group = NR_ARENA_GROUP (item);

	unsigned int ret = item->state;

	/* Just compose children into parent buffer */
	for (NRArenaItem *child = group->children; child != NULL; child = child->next) {
		ret = nr_arena_item_invoke_clip (child, area, pb);
		if (ret & NR_ARENA_ITEM_STATE_INVALID) break;
	}

	return ret;
}

static NRArenaItem *
nr_arena_group_pick (NRArenaItem *item, NR::Point p, double delta, unsigned int sticky)
{
	NRArenaGroup *group = NR_ARENA_GROUP (item);

	for (NRArenaItem *child = group->last; child != NULL; child = child->prev) {
		NRArenaItem *picked = nr_arena_item_invoke_pick (child, p, delta, sticky);
		if (picked)
			return (group->transparent) ? picked : item;
	}

	return NULL;
}

void
nr_arena_group_set_transparent (NRArenaGroup *group, unsigned int transparent)
{
	nr_return_if_fail (group != NULL);
	nr_return_if_fail (NR_IS_ARENA_GROUP (group));

	group->transparent = transparent;
}

void nr_arena_group_set_child_transform(NRArenaGroup *group, NR::Matrix const &t)
{
	NRMatrix nt(t);
	nr_arena_group_set_child_transform(group, &nt);
}

void nr_arena_group_set_child_transform(NRArenaGroup *group, NRMatrix const *t)
{
	if (!t) t = &NR_MATRIX_IDENTITY;

	if (!NR_MATRIX_DF_TEST_CLOSE (t, &group->child_transform, NR_EPSILON)) {
		nr_arena_item_request_render (NR_ARENA_ITEM (group));
		group->child_transform = *t;
		nr_arena_item_request_update (NR_ARENA_ITEM (group), NR_ARENA_ITEM_STATE_ALL, TRUE);
	}
}