4 #include <Application.h>
11 static const char* kAppSignature
= "application/x.vnd-Haiku.ShapeTest";
14 class TestView
: public BView
{
16 TestView(BRect frame
, const char* name
,
17 uint32 resizeFlags
, uint32 flags
);
19 virtual void Draw(BRect updateRect
);
23 TestView::TestView(BRect frame
, const char* name
, uint32 resizeFlags
,
26 BView(frame
, name
, resizeFlags
, flags
)
32 TestView::Draw(BRect updateRect
)
36 SetDrawingMode(B_OP_ALPHA
);
37 SetBlendingMode(B_PIXEL_ALPHA
, B_ALPHA_OVERLAY
);
38 SetHighColor(0, 0, 0, 240);
40 class TranslateIterator
: public BShapeIterator
{
49 TranslateIterator(float offsetX
, float offsetY
)
56 void SetOffset(float offsetX
, float offsetY
)
62 virtual status_t
IterateMoveTo(BPoint
* point
)
69 virtual status_t
IterateLineTo(int32 lineCount
, BPoint
* linePts
)
72 linePts
->x
+= fOffsetX
;
73 linePts
->y
+= fOffsetY
;
79 virtual status_t
IterateBezierTo(int32 bezierCount
, BPoint
* bezierPts
)
81 while (bezierCount
--) {
82 bezierPts
[0].x
+= fOffsetX
;
83 bezierPts
[0].y
+= fOffsetY
;
84 bezierPts
[1].x
+= fOffsetX
;
85 bezierPts
[1].y
+= fOffsetY
;
86 bezierPts
[2].x
+= fOffsetX
;
87 bezierPts
[2].y
+= fOffsetY
;
93 virtual status_t
IterateArcTo(float& rx
, float& ry
, float& angle
,
94 bool largeArc
, bool counterClockWise
, BPoint
& point
)
108 const float arcRX
= 50;
109 const float arcRY
= 80;
112 shape
.MoveTo(BPoint(20, 10));
113 shape
.LineTo(BPoint(10, 90));
114 shape
.LineTo(BPoint(90, 100));
115 shape
.ArcTo(arcRX
, arcRY
, 45, true, true, BPoint(100, 20));
121 shape
.MoveTo(BPoint(20, 10));
122 shape
.LineTo(BPoint(10, 90));
123 shape
.LineTo(BPoint(90, 100));
124 shape
.ArcTo(arcRX
, arcRY
, 45, false, true, BPoint(100, 20));
127 translator
.SetOffset(10, 10);
128 translator
.Iterate(&shape
);
130 SetHighColor(140, 30, 50, 255);
134 shape
.MoveTo(BPoint(20, 10));
135 shape
.LineTo(BPoint(10, 90));
136 shape
.LineTo(BPoint(90, 100));
137 shape
.ArcTo(arcRX
, arcRY
, 45, true, false, BPoint(100, 20));
140 translator
.SetOffset(20, 20);
141 translator
.Iterate(&shape
);
143 SetHighColor(140, 130, 50, 255);
147 shape
.MoveTo(BPoint(20, 10));
148 shape
.LineTo(BPoint(10, 90));
149 shape
.LineTo(BPoint(90, 100));
150 shape
.ArcTo(arcRX
, arcRY
, 45, false, false, BPoint(100, 20));
153 translator
.SetOffset(30, 30);
154 translator
.Iterate(&shape
);
156 SetHighColor(40, 130, 150, 255);
165 main(int argc
, char** argv
)
167 BApplication
app(kAppSignature
);
169 BWindow
* window
= new BWindow(BRect(50.0, 50.0, 300.0, 250.0),
170 "BShape Test", B_TITLED_WINDOW
,
171 B_ASYNCHRONOUS_CONTROLS
| B_QUIT_ON_WINDOW_CLOSE
);
173 BView
* view
= new TestView(window
->Bounds(), "test", B_FOLLOW_ALL
,
175 window
->AddChild(view
);