summaryrefslogtreecommitdiffstats
path: root/ksvg/core/CanvasItem.h
blob: 0288400fcfebc160e5c67f492027079eacb9dbca (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
/*
    Copyright (C) 2003 KSVG Team
    This file is part of the KDE project

    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
    aint with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef CANVASITEM_H
#define CANVASITEM_H

#include <tqrect.h>
#include <tqpoint.h>
#include <tqvaluelist.h>

#define CHUNK_SIZE_HORIZONTAL 32
#define CHUNK_SIZE_VERTICAL   32

namespace KSVG
{

class SVGElementImpl;

enum RenderContext
{
	/* NONE = for initializing */
	NONE = 0,
	/* NORMAL = use baseVal()'s for calculation, and fillRule */
	NORMAL = 1,
	/* CLIPPING = use baseVal()'s for calculation, and clipRule */
	CLIPPING = 2,
	/* ANIMATION = use animVal()'s for calculation, and fillRule */
	ANIMATION = 4
};

enum CanvasItemUpdate
{
	UPDATE_STYLE,
	UPDATE_LINEWIDTH,
	UPDATE_TRANSFORM,
	UPDATE_ZOOM,
	UPDATE_PAN
};

class CanvasItem
{
public:
	CanvasItem() { m_zIndex = 0; m_referenced = false; }
	virtual ~CanvasItem() { }

	virtual TQRect bbox() const = 0;
	virtual bool fillContains(const TQPoint &) = 0;
	virtual bool strokeContains(const TQPoint &) = 0;
	virtual void update(CanvasItemUpdate reason, int param1 = 0, int param2 = 0) = 0;
	virtual void draw() = 0;
	virtual bool isVisible() = 0;

	void setZIndex(unsigned int zIndex) { m_zIndex = zIndex; }
	unsigned int zIndex() const { return m_zIndex; }

	void setReferenced(bool referenced) { m_referenced = referenced; }
	bool referenced() const { return m_referenced; }

	virtual SVGElementImpl *element() const { return 0; }

protected:
	unsigned int m_zIndex;
	bool m_referenced;
};

class CanvasItemPtr
{
public:
	CanvasItemPtr() : ptr(0) { }
	CanvasItemPtr(CanvasItem *p) : ptr(p) { }

	bool operator<=(const CanvasItemPtr& that) const
	{
		// Order same-z objects by identity.
		if(that.ptr->zIndex() == ptr->zIndex())
			return that.ptr >= ptr;
		return that.ptr->zIndex() >= ptr->zIndex();
	}
	bool operator<(const CanvasItemPtr& that) const
	{
		// Order same-z objects by identity.
		if(that.ptr->zIndex() == ptr->zIndex())
			return that.ptr > ptr;
		return that.ptr->zIndex() > ptr->zIndex();
	}
	bool operator>(const CanvasItemPtr& that) const
	{
		// Order same-z objects by identity.
		if(that.ptr->zIndex() == ptr->zIndex())
			return that.ptr < ptr;
		return that.ptr->zIndex() < ptr->zIndex();
	}
	bool operator==(const CanvasItemPtr& that) const { return that.ptr == ptr; }
	operator CanvasItem *() const { return ptr; }

private:
	CanvasItem *ptr;
};

class CanvasItemList : public TQValueList<CanvasItem *>
{
public:
	void sort() { qHeapSort(*((TQValueList<CanvasItemPtr> *) this)); }
};

class CanvasChunk
{
public:
	CanvasChunk(short x, short y) : m_x(x), m_y(y), m_dirty(false) { }

	void sort() { m_list.sort(); }
	const CanvasItemList &list() const { return m_list; }

	void add(CanvasItem *item) { m_list.prepend(item); m_dirty = true; }
	void remove(CanvasItem *item) { m_list.remove(item); m_dirty = true; }

	void setDirty() { m_dirty = true; }
	bool unsetDirty() { bool y = m_dirty; m_dirty = false; return y; }
	bool isDirty() const { return m_dirty; }

	short x() const { return m_x; }
	short y() const { return m_y; }

	TQRect bbox() const { return TQRect(m_x * CHUNK_SIZE_HORIZONTAL, m_y * CHUNK_SIZE_VERTICAL, CHUNK_SIZE_HORIZONTAL, CHUNK_SIZE_VERTICAL); }

private:
	CanvasItemList m_list;
	short m_x;
	short m_y;
	bool m_dirty : 1;
};

}

#endif