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 15 #if LIB_LAYOUT 16 # include <layout.h> 17 #endif 18 19 namespace BPrivate { 20 namespace Icon { 21 22 class Gradient; 23 24 } // namespace Icon 25 } // namespace BPrivate 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 // GradientControl 64 void SetGradient(const BPrivate::Icon::Gradient* 65 gradient); 66 BPrivate::Icon::Gradient* Gradient() const 67 { return fGradient; } 68 69 void SetCurrentStop(const rgb_color& color); 70 bool GetCurrentStop(rgb_color* color) const; 71 72 void SetEnabled(bool enabled); 73 bool IsEnabled() const 74 { return fEnabled; } 75 76 private: 77 void _UpdateColors(); 78 void _AllocBitmap(int32 width, int32 height); 79 BRect _GradientBitmapRect() const; 80 int32 _StepIndexFor(BPoint where) const; 81 float _OffsetFor(BPoint where) const; 82 void _UpdateCurrentColor() const; 83 84 BPrivate::Icon::Gradient* fGradient; 85 BBitmap* fGradientBitmap; 86 int32 fDraggingStepIndex; 87 int32 fCurrentStepIndex; 88 89 float fDropOffset; 90 int32 fDropIndex; 91 92 bool fEnabled; 93 94 BMessage* fMessage; 95 BHandler* fTarget; 96 }; 97 98 #endif // GRADIENT_CONTROL_H 99