1/*
2 * Copyright 2017 Julian Harnath <julian.harnath@rwth-aachen.de>
3 * All rights reserved. Distributed under the terms of the MIT license.
4 */
5#ifndef BARBER_POLE_H
6#define BARBER_POLE_H
7
8
9#include <View.h>
10
11#include <Polygon.h>
12
13
14class BMessageRunner;
15
16
17/*! Spinning barber pole progress indicator. Number and colors of the
18    color stripes are configurable. By default, it will be 2 colors,
19    chosen from the system color palette.
20*/
21class BarberPole : public BView {
22public:
23	enum {
24		// Message codes
25		kRefreshMessage = 0x1001
26	};
27
28public:
29								BarberPole(const char* name);
30								~BarberPole();
31
32	virtual	void				MessageReceived(BMessage* message);
33	virtual void				Draw(BRect updateRect);
34	virtual	void				FrameResized(float width, float height);
35
36	virtual	BSize				MinSize();
37
38			void				Start();
39			void				Stop();
40
41			void				SetSpinSpeed(float speed);
42			void				SetColors(const rgb_color* colors,
43									uint32 numColors);
44
45private:
46			void				_Spin();
47			void				_DrawSpin(BRect updateRect);
48			void				_DrawNonSpin(BRect updateRect);
49private:
50			bool				fIsSpinning;
51			float				fSpinSpeed;
52			const rgb_color*	fColors;
53			uint32				fNumColors;
54
55			float				fScrollOffset;
56			BPolygon			fStripe;
57			float				fStripeWidth;
58			uint32				fNumStripes;
59};
60
61
62#endif // BARBER_POLE_H
63