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_SLIDER_H 10 #define COLOR_SLIDER_H 11 12 #include <Control.h> 13 14 #include "SelectedColorMode.h" 15 16 #define MSG_COLOR_SLIDER 'ColS' 17 18 class BBitmap; 19 20 class ColorSlider : public BControl { 21 public: 22 ColorSlider(SelectedColorMode mode, 23 float value1, float value2, 24 orientation dir = B_VERTICAL, 25 border_style border = B_FANCY_BORDER); 26 ColorSlider(BPoint offsetPoint, 27 SelectedColorMode mode, 28 float value1, float value2, 29 orientation dir = B_VERTICAL, 30 border_style border = B_FANCY_BORDER); 31 virtual ~ColorSlider(); 32 33 // BControl 34 virtual BSize MinSize(); 35 virtual BSize PreferredSize(); 36 virtual BSize MaxSize(); 37 38 virtual void AttachedToWindow(); 39 40 virtual status_t Invoke(BMessage* message = NULL); 41 42 virtual void Draw(BRect updateRect); 43 virtual void FrameResized(float width, float height); 44 45 virtual void MouseDown(BPoint where); 46 virtual void MouseUp(BPoint where); 47 virtual void MouseMoved(BPoint where, uint32 code, 48 const BMessage* dragMessage); 49 50 virtual void SetValue(int32 value); 51 52 // ColorSlider IsTracking()53 bool IsTracking() const 54 { return fMouseDown; } 55 56 void SetModeAndValues(SelectedColorMode mode, 57 float value1, float value2); 58 void SetOtherValues(float value1, float value2); 59 void GetOtherValues(float* value1, 60 float* value2) const; 61 62 void SetMarkerToColor(rgb_color color); 63 64 private: 65 void _Init(SelectedColorMode mode, 66 float value1, float value2, 67 orientation dir, border_style border); 68 69 void _AllocBitmap(int32 width, int32 height); 70 void _Update(); 71 BRect _BitmapRect() const; 72 void _FillBitmap(BBitmap* bitmap, 73 SelectedColorMode mode, 74 float fixedValue1, float fixedValue2, 75 orientation orient) const; 76 77 static inline void _DrawColorLineY(uint8* bits, int width, 78 int r, int g, int b); 79 static inline void _DrawColorLineX(uint8* bits, int height, 80 int bpr, int r, int g, int b); 81 void _DrawTriangle(BPoint point1, BPoint point2, 82 BPoint point3); 83 84 void _TrackMouse(BPoint where); 85 86 private: 87 SelectedColorMode fMode; 88 float fFixedValue1; 89 float fFixedValue2; 90 91 bool fMouseDown; 92 93 BBitmap* fBitmap; 94 bool fBitmapDirty; 95 96 orientation fOrientation; 97 border_style fBorderStyle; 98 }; 99 100 #endif // COLOR_SLIDER_H 101