xref: /haiku/src/apps/icon-o-matic/gui/GradientControl.h (revision 22440f4105cafc95cc1d49f9bc65bb395c527d86)
1 /*
2  * Copyright 2006-2007, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 #ifndef GRADIENT_CONTROL_H
9 #define GRADIENT_CONTROL_H
10 
11 
12 #include <View.h>
13 
14 #if LIB_LAYOUT
15 #	include <layout.h>
16 #endif
17 
18 #include "IconBuild.h"
19 
20 
21 _BEGIN_ICON_NAMESPACE
22 	class Gradient;
23 _END_ICON_NAMESPACE
24 
25 
26 enum {
27 	MSG_GRADIENT_CONTROL_FOCUS_CHANGED	= 'gcfc',
28 };
29 
30 class GradientControl :
31 						#if LIB_LAYOUT
32 						public MView,
33 						#endif
34 						public BView {
35 
36  public:
37 								GradientControl(BMessage* message = NULL,
38 												BHandler* target = NULL);
39 	virtual						~GradientControl();
40 
41 								// MView
42 	#if LIB_LAYOUT
43 	virtual	minimax				layoutprefs();
44 	virtual	BRect				layout(BRect frame);
45 	#endif
46 
47 								// BView
48 	virtual	void				WindowActivated(bool active);
49 	virtual	void				MakeFocus(bool focus);
50 
51 	virtual	void				MouseDown(BPoint where);
52 	virtual	void				MouseUp(BPoint where);
53 	virtual	void				MouseMoved(BPoint where, uint32 transit,
54 										   const BMessage* dragMessage);
55 
56 	virtual	void				MessageReceived(BMessage* message);
57 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
58 
59 	virtual	void				Draw(BRect updateRect);
60 	virtual	void				FrameResized(float width, float height);
61 
62 								// GradientControl
63 			void				SetGradient(const _ICON_NAMESPACE Gradient*
64 											gradient);
65 			_ICON_NAMESPACE Gradient* Gradient() const
66 									{ return fGradient; }
67 
68 			void				SetCurrentStop(const rgb_color& color);
69 			bool				GetCurrentStop(rgb_color* color) const;
70 
71 			void				SetEnabled(bool enabled);
72 			bool				IsEnabled() const
73 									{ return fEnabled; }
74 
75  private:
76 			void				_UpdateColors();
77 			void				_AllocBitmap(int32 width, int32 height);
78 			BRect				_GradientBitmapRect() const;
79 			int32				_StepIndexFor(BPoint where) const;
80 			float				_OffsetFor(BPoint where) const;
81 			void				_UpdateCurrentColor() const;
82 
83  			_ICON_NAMESPACE Gradient* fGradient;
84 			BBitmap*			fGradientBitmap;
85 			int32				fDraggingStepIndex;
86 			int32				fCurrentStepIndex;
87 
88 			float				fDropOffset;
89 			int32				fDropIndex;
90 
91 			bool				fEnabled;
92 
93 			BMessage*			fMessage;
94 			BHandler*			fTarget;
95 };
96 
97 #endif // GRADIENT_CONTROL_H
98