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 #include "IconBuild.h" 16 17 18 _BEGIN_ICON_NAMESPACE 19 class Gradient; 20 _END_ICON_NAMESPACE 21 22 23 enum { 24 MSG_GRADIENT_CONTROL_FOCUS_CHANGED = 'gcfc', 25 }; 26 27 class GradientControl : public BView { 28 public: 29 GradientControl(BMessage* message = NULL, 30 BHandler* target = NULL); 31 virtual ~GradientControl(); 32 33 // MView 34 #if LIB_LAYOUT 35 virtual minimax layoutprefs(); 36 virtual BRect layout(BRect frame); 37 #endif 38 39 // BView 40 virtual void WindowActivated(bool active); 41 virtual void MakeFocus(bool focus); 42 43 virtual void MouseDown(BPoint where); 44 virtual void MouseUp(BPoint where); 45 virtual void MouseMoved(BPoint where, uint32 transit, 46 const BMessage* dragMessage); 47 48 virtual void MessageReceived(BMessage* message); 49 virtual void KeyDown(const char* bytes, int32 numBytes); 50 51 virtual void Draw(BRect updateRect); 52 virtual void FrameResized(float width, float height); 53 54 virtual void GetPreferredSize(float* width, float* height); 55 56 // GradientControl 57 void SetGradient(const _ICON_NAMESPACE Gradient* 58 gradient); 59 _ICON_NAMESPACE Gradient* Gradient() const 60 { return fGradient; } 61 62 void SetCurrentStop(const rgb_color& color); 63 bool GetCurrentStop(rgb_color* color) const; 64 65 void SetEnabled(bool enabled); 66 bool IsEnabled() const 67 { return fEnabled; } 68 69 private: 70 void _UpdateColors(); 71 void _AllocBitmap(int32 width, int32 height); 72 BRect _GradientBitmapRect() const; 73 int32 _StepIndexFor(BPoint where) const; 74 float _OffsetFor(BPoint where) const; 75 void _UpdateCurrentColor() const; 76 77 _ICON_NAMESPACE Gradient* fGradient; 78 BBitmap* fGradientBitmap; 79 int32 fDraggingStepIndex; 80 int32 fCurrentStepIndex; 81 82 float fDropOffset; 83 int32 fDropIndex; 84 85 bool fEnabled; 86 87 BMessage* fMessage; 88 BHandler* fTarget; 89 }; 90 91 #endif // GRADIENT_CONTROL_H 92