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