File: Brush.cpp

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 (135 lines) | stat: -rw-r--r-- 3,459 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
125
126
127
128
129
130
131
132
133
134
135
#include "stdafx.h"
#include "Brush.h"
#include "Painter.h"
#include "Bitmap.h"
#include "GraphicsMgr.h"

namespace gui {

	Brush::Brush() {}

	SolidBrush::SolidBrush(Color c) : myOpacity(1.0f), myColor(c) {}

	void SolidBrush::create(GraphicsMgrRaw *g, void *&result, Cleanup &update) {
		g->create(this, result, update);
	}
	void SolidBrush::update(GraphicsMgrRaw *g, void *resource) {
		g->update(this, resource);
	}


	BitmapBrush::BitmapBrush(Bitmap *bitmap) : myBitmap(bitmap), myTfm(new (engine()) Transform()), myOpacity(1.0f) {}

	BitmapBrush::BitmapBrush(Bitmap *bitmap, Transform *tfm) : myBitmap(bitmap), myTfm(tfm), myOpacity(1.0f) {}

	void BitmapBrush::transform(Transform *tfm) {
		myTfm = tfm;
		needUpdate();
	}

	void BitmapBrush::create(GraphicsMgrRaw *g, void *&result, Cleanup &update) {
		g->create(this, result, update);
	}
	void BitmapBrush::update(GraphicsMgrRaw *g, void *resource) {
		g->update(this, resource);
	}


	GradientStop::GradientStop(Float position, Color color) : pos(position), color(color) {}

	wostream &operator <<(wostream &to, const GradientStop &s) {
		return to << s.color << L"@" << s.pos;
	}

	void GradientStop::toS(StrBuf *to) const {
		*to << color << S("@") << pos;
	}


	Gradient::Gradient() : myStops(null) {}

	Gradient::Gradient(Array<GradientStop> *stops) : myStops(stops) {}

	Array<GradientStop> *Gradient::stops() const {
		return new (this) Array<GradientStop>(*myStops);
	}

	void Gradient::stops(Array<GradientStop> *stops) {
		myStops = new (this) Array<GradientStop>(*stops);

		// We need to re-create the backend-specific things.
		recreate();
	}


	LinearGradient::LinearGradient(Array<GradientStop> *stops, Point start, Point end) :
		Gradient(stops), myStart(start), myEnd(end) {}

	LinearGradient::LinearGradient(Color c1, Color c2, Point start, Point end) :
		Gradient(), myStart(start), myEnd(end) {

		Array<GradientStop> *s = new (this) Array<GradientStop>();
		s->push(GradientStop(0, c1));
		s->push(GradientStop(1, c2));
		stops(s);
	}

	void LinearGradient::start(Point p) {
		myStart = p;
		needUpdate();
	}

	void LinearGradient::end(Point p) {
		myEnd = p;
		needUpdate();
	}

	void LinearGradient::points(Point start, Point end) {
		myStart = start;
		myEnd = end;
		needUpdate();
	}

	void LinearGradient::create(GraphicsMgrRaw *g, void *&result, Cleanup &update) {
		g->create(this, result, update);
	}
	void LinearGradient::update(GraphicsMgrRaw *g, void *resource) {
		g->update(this, resource);
	}


	RadialGradient::RadialGradient(Array<GradientStop> *stops, Point center, Float radius) :
		Gradient(stops), myCenter(center), myRadius(radius), myTransform(new (engine()) Transform()) {}

	RadialGradient::RadialGradient(Color c1, Color c2, Point center, Float radius) :
		Gradient(), myCenter(center), myRadius(radius), myTransform(new (engine()) Transform()) {

		Array<GradientStop> *s = new (this) Array<GradientStop>();
		s->push(GradientStop(0, c1));
		s->push(GradientStop(1, c2));
		stops(s);
	}

	void RadialGradient::center(Point p) {
		myCenter = p;
		needUpdate();
	}

	void RadialGradient::radius(Float v) {
		myRadius = v;
		needUpdate();
	}

	void RadialGradient::transform(Transform *tfm) {
		myTransform = tfm;
		needUpdate();
	}

	void RadialGradient::create(GraphicsMgrRaw *g, void *&result, Cleanup &update) {
		g->create(this, result, update);
	}
	void RadialGradient::update(GraphicsMgrRaw *g, void *resource) {
		g->update(this, resource);
	}

}