File: Path.h

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (124 lines) | stat: -rw-r--r-- 2,405 bytes parent folder | download | duplicates (2)
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
#pragma once
#include "Core/Array.h"
#include "Resource.h"

namespace gui {

	// Element type.
	enum PathPointType {
		tClose,
		tStart,
		tLine,
		tBezier2,
		tBezier3,
	};

	// Different element types.
	struct Start {
		Point pt;
	};

	struct Line {
		Point to;
	};

	struct Bezier2 {
		Point c1;
		Point to;
	};

	struct Bezier3 {
		Point c1;
		Point c2;
		Point to;
	};

	// Element. One of five different types.
	class PathPoint {
		STORM_VALUE;
	public:
		STORM_CTOR PathPoint(PathPointType type) {
			t = type;
		}

		PathPointType t;
		Point p0;
		Point p1;
		Point p2;

		// Convert to other types for convenient access.
		inline Start *start() {
			return (Start *)&p0;
		}
		inline Line *line() {
			return (Line *)&p0;
		}
		inline Bezier2 *bezier2() {
			return (Bezier2 *)&p0;
		}
		inline Bezier3 *bezier3() {
			return (Bezier3 *)&p0;
		}
	};



	/**
	 * A point-by-point path to draw.
	 *
	 * Paths can be either open or closed when they are drawn as an outline. When filling, it is
	 * assumed that all paths are closed with a line from the last point to the first point.
	 */
	class Path : public Resource {
		STORM_CLASS;
	public:
		// Create.
		STORM_CTOR Path();

		// Clear this path.
		void STORM_FN clear();

		// Start a new segment.
		void STORM_FN start(Point pt);

		// Add a line from the current point to `to`.
		void STORM_FN line(Point to);

		// Add a point. If the path is not started, this point will start it. Aside from that, works like `line`.
		void STORM_FN point(Point to);

		// Add a bezier segment with one control point and an endpoint.
		void STORM_FN bezier(Point c1, Point to);

		// Add a bezier segment with two control points and an endpoint.
		void STORM_FN bezier(Point c1, Point c2, Point to);

		// Close the previous path, adding a line segment to the start of the path.
		void STORM_FN close();

		// Get the bounding box of this path.
		inline Rect STORM_FN bound() { return b; }

		// Get the actual path.
		Array<PathPoint> *STORM_FN data();

		// Peek at the actual object to avoid copying.
		Array<PathPoint> *peekData() { return elements; }

	protected:
		// Create and update.
		virtual void create(GraphicsMgrRaw *g, void *&result, Cleanup &cleanup);
		virtual void update(GraphicsMgrRaw *g, void *resource);

	private:
		// All elements.
		Array<PathPoint> *elements;

		// Any path started?
		Bool started;

		// Bound.
		Rect b;
	};

}