headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / servers / app / shape_test / main.cpp
blobc5f2548ae7e28c46ab9e5bfe04ccf6a3c0318cee
1 #include <stdio.h>
2 #include <string.h>
4 #include <Application.h>
5 #include <Message.h>
6 #include <Shape.h>
7 #include <View.h>
8 #include <Window.h>
11 static const char* kAppSignature = "application/x.vnd-Haiku.ShapeTest";
14 class TestView : public BView {
15 public:
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,
24 uint32 flags)
26 BView(frame, name, resizeFlags, flags)
31 void
32 TestView::Draw(BRect updateRect)
34 BRect r(Bounds());
36 SetDrawingMode(B_OP_ALPHA);
37 SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
38 SetHighColor(0, 0, 0, 240);
40 class TranslateIterator : public BShapeIterator {
41 public:
42 TranslateIterator()
44 fOffsetX(0),
45 fOffsetY(0)
49 TranslateIterator(float offsetX, float offsetY)
51 fOffsetX(offsetX),
52 fOffsetY(offsetY)
56 void SetOffset(float offsetX, float offsetY)
58 fOffsetX = offsetX;
59 fOffsetY = offsetY;
62 virtual status_t IterateMoveTo(BPoint* point)
64 point->x += fOffsetX;
65 point->y += fOffsetY;
66 return B_OK;
69 virtual status_t IterateLineTo(int32 lineCount, BPoint* linePts)
71 while (lineCount--) {
72 linePts->x += fOffsetX;
73 linePts->y += fOffsetY;
74 linePts++;
76 return B_OK;
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;
88 bezierPts += 3;
90 return B_OK;
93 virtual status_t IterateArcTo(float& rx, float& ry, float& angle,
94 bool largeArc, bool counterClockWise, BPoint& point)
96 point.x += fOffsetX;
97 point.y += fOffsetY;
98 return B_OK;
101 private:
102 float fOffsetX;
103 float fOffsetY;
104 } translator;
106 MovePenTo(B_ORIGIN);
108 const float arcRX = 50;
109 const float arcRY = 80;
111 BShape shape;
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));
116 shape.Close();
118 StrokeShape(&shape);
120 shape.Clear();
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));
125 shape.Close();
127 translator.SetOffset(10, 10);
128 translator.Iterate(&shape);
130 SetHighColor(140, 30, 50, 255);
131 StrokeShape(&shape);
133 shape.Clear();
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));
138 shape.Close();
140 translator.SetOffset(20, 20);
141 translator.Iterate(&shape);
143 SetHighColor(140, 130, 50, 255);
144 StrokeShape(&shape);
146 shape.Clear();
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));
151 shape.Close();
153 translator.SetOffset(30, 30);
154 translator.Iterate(&shape);
156 SetHighColor(40, 130, 150, 255);
157 StrokeShape(&shape);
161 // #pragma mark -
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,
174 B_WILL_DRAW);
175 window->AddChild(view);
177 window->Show();
179 app.Run();
180 return 0;