xref: /haiku/src/tests/kits/interface/SetDiskModeTest.cpp (revision 10d8f3749ec989200635939f010b68b91dde7446)
1 #include <Application.h>
2 #include <Box.h>
3 #include <Picture.h>
4 #include <Region.h>
5 #include <Shape.h>
6 #include <View.h>
7 #include <Window.h>
8 
9 
10 
11 class PictureView : public BBox {
12 public:
13 	PictureView(BRect frame);
14 	~PictureView();
15 
16 	virtual void Draw(BRect update);
17 	virtual void AllAttached();
18 
19 private:
20 	BPicture *fPicture;
21 };
22 
23 
24 static void
DrawStuff(BView * view)25 DrawStuff(BView *view)
26 {
27 	// StrokeShape
28 	BShape shape;
29 	BPoint bezier[3] = {BPoint(100,0), BPoint(100, 100), BPoint(25, 50)};
30 	shape.MoveTo(BPoint(150,0));
31 	shape.LineTo(BPoint(200,100));
32 	shape.BezierTo(bezier);
33 	shape.Close();
34 	view->StrokeShape(&shape);
35 
36 	// Stroke/FillRect, Push/PopState, SetHighColor, SetLineMode, SetPenSize
37 	view->PushState();
38 	const rgb_color blue = { 0, 0, 240, 0 };
39 	view->SetHighColor(blue);
40 	view->SetLineMode(B_BUTT_CAP, B_BEVEL_JOIN);
41 	view->SetPenSize(7);
42 	view->StrokeRect(BRect(10, 220, 50, 260));
43 	view->FillRect(BRect(65, 245, 120, 300));
44 	view->PopState();
45 
46 	// Stroke/FillEllipse
47 	view->StrokeEllipse(BPoint(50, 150), 50, 50);
48 	view->FillEllipse(BPoint(100, 120), 50, 50);
49 
50 	// Stroke/FillArc
51 	view->StrokeArc(BRect(0, 200, 50, 250), 180, 180);
52 	view->FillArc(BPoint(150, 250), 50, 50, 0, 125);
53 
54 	// DrawString, SetHighColor, SetFontSize
55 	const rgb_color red = { 240, 0, 0, 0 };
56 	view->SetHighColor(red);
57 	view->SetFontSize(20);
58 	view->DrawString("BPicture test", BPoint(30, 20));
59 
60 	BRegion region;
61 	region.Include(BRect(10, 10, 40, 40));
62 	region.Include(BRect(30, 30, 100, 50));
63 	view->ConstrainClippingRegion(&region);
64 }
65 
66 
67 
68 
69 // PictureView
PictureView(BRect frame)70 PictureView::PictureView(BRect frame)
71 	:	BBox(frame, "pict_view", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
72 		fPicture(NULL)
73 {
74 }
75 
76 
~PictureView()77 PictureView::~PictureView()
78 {
79 	delete fPicture;
80 }
81 
82 
83 void
AllAttached()84 PictureView::AllAttached()
85 {
86 	SetDiskMode("picture", 0);
87 
88 	DrawStuff(this);
89 
90 	BPicture *picture = EndPicture();
91 	if (picture == NULL)
92 		return;
93 
94 }
95 
96 void
Draw(BRect update)97 PictureView::Draw(BRect update)
98 {
99 	DrawPicture("picture", 0, B_ORIGIN);
100 }
101 
102 
103 // main
104 int
main()105 main()
106 {
107 	BApplication pictureApp("application/x-vnd.SetDiskModeTest");
108 	BWindow *pictureWindow = new BWindow(BRect(100, 100, 500, 400),
109 				"SetDiskMode test", B_TITLED_WINDOW,
110 				B_NOT_RESIZABLE|B_NOT_ZOOMABLE|B_QUIT_ON_WINDOW_CLOSE);
111 
112 
113 	BRect rect(pictureWindow->Bounds());
114 
115 	PictureView *pictureView = new PictureView(rect);
116 
117 	pictureWindow->AddChild(pictureView);
118 	pictureWindow->Show();
119 
120 	pictureApp.Run();
121 
122 	return 0;
123 }
124 
125