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