1 /* 2 * Copyright 2005-2013 Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _COLOR_CONTROL_H 6 #define _COLOR_CONTROL_H 7 8 9 #include <Control.h> 10 11 12 enum color_control_layout { 13 B_CELLS_4x64 = 4, 14 B_CELLS_8x32 = 8, 15 B_CELLS_16x16 = 16, 16 B_CELLS_32x8 = 32, 17 B_CELLS_64x4 = 64, 18 }; 19 20 21 class BBitmap; 22 class BTextControl; 23 24 25 class BColorControl : public BControl { 26 public: 27 BColorControl(BPoint start, 28 color_control_layout layout, 29 float cellSize, const char* name, 30 BMessage* message = NULL, 31 bool useOffscreen = false); 32 BColorControl(BMessage* archive); 33 virtual ~BColorControl(); 34 35 static BArchivable* Instantiate(BMessage* archive); 36 virtual status_t Archive(BMessage* archive, 37 bool deep = true) const; 38 39 virtual void SetLayout(BLayout* layout); 40 41 virtual void SetValue(int32 color_value); 42 void SetValue(rgb_color color); 43 rgb_color ValueAsColor(); 44 45 virtual void SetEnabled(bool state); 46 47 virtual void AttachedToWindow(); 48 virtual void MessageReceived(BMessage* message); 49 virtual void Draw(BRect updateRect); 50 virtual void MouseDown(BPoint where); 51 virtual void KeyDown(const char* bytes, int32 numBytes); 52 53 virtual void SetCellSize(float size); 54 float CellSize() const; 55 virtual void SetLayout(color_control_layout layout); 56 color_control_layout Layout() const; 57 58 virtual void WindowActivated(bool state); 59 virtual void MouseUp(BPoint point); 60 virtual void MouseMoved(BPoint point, uint32 code, 61 const BMessage* dragMessage); 62 virtual void DetachedFromWindow(); 63 virtual void GetPreferredSize(float* _width, 64 float* _height); 65 virtual void ResizeToPreferred(); 66 virtual status_t Invoke(BMessage* message = NULL); 67 virtual void FrameMoved(BPoint newPosition); 68 virtual void FrameResized(float newWidth, float newHeight); 69 70 virtual BHandler* ResolveSpecifier(BMessage* message, 71 int32 index, BMessage* specifier, 72 int32 what, const char* property); 73 virtual status_t GetSupportedSuites(BMessage* data); 74 75 virtual void MakeFocus(bool focused = true); 76 virtual void AllAttached(); 77 virtual void AllDetached(); 78 79 private: 80 virtual status_t Perform(perform_code d, void *arg); 81 // this can be made public again if needed 82 83 virtual void _ReservedColorControl1(); 84 virtual void _ReservedColorControl2(); 85 virtual void _ReservedColorControl3(); 86 virtual void _ReservedColorControl4(); 87 88 BColorControl& operator=(const BColorControl &other); 89 90 void _InitData(color_control_layout layout, 91 float size, bool useOffscreen, 92 BMessage* archive = NULL); 93 void _LayoutView(); 94 void _InitOffscreen(); 95 void _InvalidateSelector(int16 ramp, 96 rgb_color color, bool focused); 97 void _DrawColorArea(BView* target, BRect update); 98 void _DrawSelectors(BView* target); 99 void _DrawColorRamp(BRect rect, BView* target, 100 rgb_color baseColor, rgb_color compColor, 101 int16 flag, bool focused, 102 BRect updateRect); 103 BPoint _SelectorPosition(const BRect& rampRect, 104 uint8 shade) const; 105 BRect _PaletteFrame() const; 106 BRect _PaletteSelectorFrame(uint8 colorIndex) const; 107 BRect _RampFrame(uint8 rampIndex) const; 108 void _SetCellSize(float size); 109 float _TextRectOffset(); 110 111 private: 112 BRect fPaletteFrame; 113 int16 fSelectedPaletteColorIndex; 114 int16 fPreviousSelectedPaletteColorIndex; 115 116 float fCellSize; 117 int32 fRows; 118 int32 fColumns; 119 bool fPaletteMode; 120 bool _unused[3]; 121 122 BTextControl* fRedText; 123 BTextControl* fGreenText; 124 BTextControl* fBlueText; 125 126 BBitmap* fBitmap; 127 BView* fOffscreenView; 128 129 int16 fFocusedRamp; 130 int16 fClickedRamp; 131 uint32 _reserved[2]; 132 }; 133 134 inline void 135 BColorControl::SetValue(rgb_color color) 136 { 137 int32 c = (color.red << 24) + (color.green << 16) + (color.blue << 8); 138 SetValue(c); 139 } 140 141 #endif // _COLOR_CONTROL_H 142