1 #include <Application.h>
2 #include <View.h>
3 #include <Window.h>
4
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 static void
ChangeColor(rgb_color & color)9 ChangeColor(rgb_color &color)
10 {
11 color.red = rand() % 255;
12 color.green = rand() % 255;
13 }
14
15
16 class PulseView : public BView {
17 public:
PulseView(BRect rect,const char * name,uint32 resizeMode,uint32 flags)18 PulseView(BRect rect, const char *name, uint32 resizeMode, uint32 flags)
19 : BView(rect, name, resizeMode, flags)
20 {
21 fLeft = Bounds().OffsetToCopy(B_ORIGIN);
22 fLeft.right -= Bounds().Width() / 2;
23 fRight = fLeft.OffsetByCopy(fLeft.Width(), 0);
24 fColor.red = 255;
25 fColor.green = 255;
26 fColor.blue = 255;
27 }
28
Pulse()29 virtual void Pulse()
30 {
31 SetHighColor(fColor);
32 BRect rect = fRight;
33
34 if (fLeftTurn)
35 rect = fLeft;
36
37 FillRect(rect, B_SOLID_HIGH);
38
39 fLeftTurn = !fLeftTurn;
40
41 ChangeColor(fColor);
42 }
43
44 BRect fLeft;
45 BRect fRight;
46
47 bool fLeftTurn;
48 rgb_color fColor;
49 };
50
51 void
show_window(BWindow * window)52 show_window(BWindow *window)
53 {
54 BView *view = new PulseView(window->Bounds(), "pulse view", B_FOLLOW_ALL, B_PULSE_NEEDED|B_WILL_DRAW);
55 window->SetPulseRate(500000);
56 window->AddChild(view);
57 window->Show();
58 }
59
60
main()61 int main()
62 {
63 srand(time(NULL));
64 BApplication app("application/x-vnd.pulse_test");
65 BWindow *window = new BWindow(BRect(100, 100, 400, 300), "pulse test",
66 B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE | B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE);
67 show_window(window);
68 app.Run();
69 }
70