1/*
2 * Copyright 2001 Werner Freytag - please read to the LICENSE file
3 *
4 * Copyright 2002-2006, Stephan Aßmus <superstippi@gmx.de>
5 * All rights reserved.
6 *
7 */
8
9#ifndef COLOR_FIELD_H
10#define COLOR_FIELD_H
11
12#include <Control.h>
13
14#include "SelectedColorMode.h"
15
16enum {
17	MSG_COLOR_FIELD		= 'ColF',
18};
19
20class BBitmap;
21
22class ColorField : public BControl {
23public:
24								ColorField(BPoint offset_point,
25									SelectedColorMode mode, float fixedValue,
26									orientation orient = B_VERTICAL,
27									border_style border = B_FANCY_BORDER);
28
29								ColorField(SelectedColorMode mode,
30									float fixedValue,
31									orientation orient = B_VERTICAL,
32									border_style border = B_FANCY_BORDER);
33
34	virtual						~ColorField();
35
36	// BControl interface
37	virtual	BSize				MinSize();
38	virtual	BSize				PreferredSize();
39	virtual	BSize				MaxSize();
40
41	virtual	status_t			Invoke(BMessage* message = NULL);
42
43	virtual	void				AttachedToWindow();
44	virtual	void				Draw(BRect updateRect);
45	virtual	void				FrameResized(float width, float height);
46
47	virtual	void				MouseDown(BPoint where);
48	virtual	void				MouseUp(BPoint where);
49	virtual	void				MouseMoved(BPoint where, uint32 code,
50									const BMessage* dragMessage);
51
52	// ColorField
53			void				SetModeAndValue(SelectedColorMode mode,
54									float fixedValue);
55			void				SetFixedValue(float fixedValue);
56			float				FixedValue() const
57									{ return fFixedValue; }
58
59			void				SetMarkerToColor(rgb_color color);
60			void				PositionMarkerAt(BPoint where);
61
62			float				Width() const;
63			float				Height() const;
64			bool				IsTracking() const
65									{ return fMouseDown; }
66
67private:
68			void				_Init(SelectedColorMode mode,
69									float fixedValue, orientation orient,
70									border_style border);
71
72			void				_AllocBitmap(int32 width, int32 height);
73			void				_Update();
74			BRect				_BitmapRect() const;
75			void				_FillBitmap(BBitmap* bitmap,
76									SelectedColorMode mode,
77									float fixedValue, orientation orient) const;
78
79private:
80	SelectedColorMode			fMode;
81	float						fFixedValue;
82	orientation					fOrientation;
83	border_style				fBorderStyle;
84
85	BPoint						fMarkerPosition;
86	BPoint						fLastMarkerPosition;
87	bool						fMouseDown;
88
89	BBitmap*					fBitmap;
90	bool						fBitmapDirty;
91};
92
93#endif // COLOR_FIELD_H
94