-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvenOddIterator.cpp
146 lines (123 loc) · 2.72 KB
/
EvenOddIterator.cpp
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
#include "EvenOddIterator.h"
#include <Point.h>
#include <View.h>
#include <Bitmap.h>
#include <Polygon.h>
#include <StopWatch.h>
#include <stdio.h>
#include <string.h>
bigtime_t creationtime = 0;
EvenOddIterator::EvenOddIterator(BRect frame)
: fBitmap(NULL),
fView(NULL),
fOutput(NULL),
fLocation(0, 0),
fStart(0, 0),
fOffset(0, 0)
{
frame.right++;
frame.bottom++;
fBitmap = new BBitmap(frame, B_GRAY1, true);
fView = new BView(frame, "bitmapdrawer", 0, 0);
fBitmap->AddChild(fView);
}
EvenOddIterator::~EvenOddIterator()
{
if (fBitmap)
fBitmap->Lock();
if (fView)
fView->RemoveSelf();
delete fBitmap;
delete fView;
fBitmap = NULL;
fView = NULL;
}
void
EvenOddIterator::SetOutput(BView *output)
{
fOutput = output;
}
void
EvenOddIterator::SetOffset(float x, float y)
{
fOffset.Set(x, y);
}
BRect
EvenOddIterator::Bounds()
{
return (fBitmap ? fBitmap->Bounds() : BRect(0, 0, 0, 0));
}
status_t
EvenOddIterator::IterateMoveTo(BPoint *point)
{
fLocation = *point;
fStart = fLocation;
return B_OK;
}
status_t
EvenOddIterator::IterateLineTo(int32 count, BPoint *pts)
{
for (int i = 0; i < count; i++) {
BShape shape;
shape.MoveTo(fLocation);
shape.LineTo(BPoint(0, fLocation.y)); // TODO: find out why 0 works
shape.LineTo(BPoint(0, pts[i].y)); // actually, does it?
shape.LineTo(pts[i]);
fView->FillShape(&shape);
fLocation = pts[i];
}
return B_OK;
}
status_t
EvenOddIterator::IterateBezierTo(int32 count, BPoint *pts)
{
for (int i = 0; i < count; i++) {
BShape shape;
shape.MoveTo(fLocation);
shape.BezierTo(&pts[i * 3]);
fView->FillShape(&shape);
IterateLineTo(1, &pts[i * 3 + 2]);
}
return B_OK;
}
status_t
EvenOddIterator::IterateClose()
{
IterateLineTo(1, &fStart);
return B_OK;
}
status_t
EvenOddIterator::Iterate(BShape *shape)
{
BRect frame = shape->Bounds();
fLocation.Set(0, 0);
fStart.Set(0, 0);
fBitmap->Lock();
fView->SetHighColor(255, 255, 255);
fView->SetLowColor(0, 0, 0);
fView->SetDrawingMode(B_OP_COPY);
fView->FillRect(frame, B_SOLID_LOW);
fView->SetDrawingMode(B_OP_INVERT);
BShapeIterator::Iterate(shape);
fView->Sync();
fBitmap->Unlock();
uint32 c = B_TRANSPARENT_MAGIC_RGBA32;
rgb_color transparent;
transparent.alpha = (c >> 24) & 0xff;
transparent.red = (c >> 16) & 0xff;
transparent.green = (c >> 8) & 0xff;
transparent.blue = (c >> 0) & 0xff;
if (fOutput->LockLooper()) {
drawing_mode mode = fOutput->DrawingMode();
BPoint origin = fOutput->Origin();
fOutput->SetLowColor(transparent);
fOutput->SetHighColor(0, 0, 0, 255);
fOutput->SetDrawingMode(B_OP_ERASE);
fOutput->SetOrigin(fOffset);
fOutput->DrawBitmap(fBitmap);
fOutput->SetDrawingMode(mode);
fOutput->SetOrigin(origin);
fOutput->UnlockLooper();
}
return B_OK;
}