19a1d68e4SAxel Dörfler /*
20289f920SJohn Scipione * Copyright 2005-2013 Haiku, Inc. All Rights Reserved.
39a1d68e4SAxel Dörfler * Distributed under the terms of the MIT License.
49a1d68e4SAxel Dörfler */
5d734a8ceSbeveloper #ifndef _COLOR_CONTROL_H
6d734a8ceSbeveloper #define _COLOR_CONTROL_H
7d734a8ceSbeveloper
89a1d68e4SAxel Dörfler
9d734a8ceSbeveloper #include <Control.h>
10d734a8ceSbeveloper
11d734a8ceSbeveloper
12d734a8ceSbeveloper enum color_control_layout {
13d734a8ceSbeveloper B_CELLS_4x64 = 4,
14d734a8ceSbeveloper B_CELLS_8x32 = 8,
15d734a8ceSbeveloper B_CELLS_16x16 = 16,
16d734a8ceSbeveloper B_CELLS_32x8 = 32,
179a1d68e4SAxel Dörfler B_CELLS_64x4 = 64,
18d734a8ceSbeveloper };
19d734a8ceSbeveloper
200289f920SJohn Scipione
210289f920SJohn Scipione class BBitmap;
22d734a8ceSbeveloper class BTextControl;
23d734a8ceSbeveloper
24d734a8ceSbeveloper
25d734a8ceSbeveloper class BColorControl : public BControl {
26d734a8ceSbeveloper public:
27295f3d13SStephan Aßmus BColorControl(BPoint start,
28295f3d13SStephan Aßmus color_control_layout layout,
299a1d68e4SAxel Dörfler float cellSize, const char* name,
30295f3d13SStephan Aßmus BMessage* message = NULL,
31295f3d13SStephan Aßmus bool useOffscreen = false);
321f424632SJohn Scipione BColorControl(BMessage* data);
33d734a8ceSbeveloper virtual ~BColorControl();
34d734a8ceSbeveloper
351f424632SJohn Scipione static BArchivable* Instantiate(BMessage* data);
361f424632SJohn Scipione virtual status_t Archive(BMessage* data,
37295f3d13SStephan Aßmus bool deep = true) const;
38d734a8ceSbeveloper
399ecf9d1cSIngo Weinhold virtual void SetLayout(BLayout* layout);
409ecf9d1cSIngo Weinhold
41d734a8ceSbeveloper virtual void SetValue(int32 color_value);
42d734a8ceSbeveloper void SetValue(rgb_color color);
43d734a8ceSbeveloper rgb_color ValueAsColor();
44d734a8ceSbeveloper
45d734a8ceSbeveloper virtual void SetEnabled(bool state);
46d734a8ceSbeveloper
47d734a8ceSbeveloper virtual void AttachedToWindow();
489a1d68e4SAxel Dörfler virtual void MessageReceived(BMessage* message);
49d734a8ceSbeveloper virtual void Draw(BRect updateRect);
50d734a8ceSbeveloper virtual void MouseDown(BPoint where);
51d734a8ceSbeveloper virtual void KeyDown(const char* bytes, int32 numBytes);
52d734a8ceSbeveloper
53d734a8ceSbeveloper virtual void SetCellSize(float size);
54d734a8ceSbeveloper float CellSize() const;
55d734a8ceSbeveloper virtual void SetLayout(color_control_layout layout);
56d734a8ceSbeveloper color_control_layout Layout() const;
57d734a8ceSbeveloper
58d734a8ceSbeveloper virtual void WindowActivated(bool state);
599a1d68e4SAxel Dörfler virtual void MouseUp(BPoint point);
609a1d68e4SAxel Dörfler virtual void MouseMoved(BPoint point, uint32 code,
619a1d68e4SAxel Dörfler const BMessage* dragMessage);
62d734a8ceSbeveloper virtual void DetachedFromWindow();
6387ba0eaaSStephan Aßmus virtual void GetPreferredSize(float* _width,
6487ba0eaaSStephan Aßmus float* _height);
65d734a8ceSbeveloper virtual void ResizeToPreferred();
669a1d68e4SAxel Dörfler virtual status_t Invoke(BMessage* message = NULL);
679a1d68e4SAxel Dörfler virtual void FrameMoved(BPoint newPosition);
689a1d68e4SAxel Dörfler virtual void FrameResized(float newWidth, float newHeight);
69d734a8ceSbeveloper
7087ba0eaaSStephan Aßmus virtual BHandler* ResolveSpecifier(BMessage* message,
7187ba0eaaSStephan Aßmus int32 index, BMessage* specifier,
7287ba0eaaSStephan Aßmus int32 what, const char* property);
73d734a8ceSbeveloper virtual status_t GetSupportedSuites(BMessage* data);
74d734a8ceSbeveloper
7574577830SJohn Scipione virtual void MakeFocus(bool focused = true);
76d734a8ceSbeveloper virtual void AllAttached();
77d734a8ceSbeveloper virtual void AllDetached();
78d734a8ceSbeveloper
79be436742SIngo Weinhold virtual status_t SetIcon(const BBitmap* icon, uint32 flags = 0);
80be436742SIngo Weinhold
81d734a8ceSbeveloper private:
829a1d68e4SAxel Dörfler virtual status_t Perform(perform_code d, void *arg);
839a1d68e4SAxel Dörfler // this can be made public again if needed
84d734a8ceSbeveloper
85d734a8ceSbeveloper virtual void _ReservedColorControl1();
86d734a8ceSbeveloper virtual void _ReservedColorControl2();
87d734a8ceSbeveloper virtual void _ReservedColorControl3();
88d734a8ceSbeveloper virtual void _ReservedColorControl4();
89d734a8ceSbeveloper
909a1d68e4SAxel Dörfler BColorControl& operator=(const BColorControl &other);
91d734a8ceSbeveloper
929a1d68e4SAxel Dörfler void _InitData(color_control_layout layout,
939a1d68e4SAxel Dörfler float size, bool useOffscreen,
941f424632SJohn Scipione BMessage* data = NULL);
959a1d68e4SAxel Dörfler void _LayoutView();
969c76ea4cSStefano Ceccherini void _InitOffscreen();
9774577830SJohn Scipione void _InvalidateSelector(int16 ramp,
9874577830SJohn Scipione rgb_color color, bool focused);
999a1d68e4SAxel Dörfler void _DrawColorArea(BView* target, BRect update);
1009c76ea4cSStefano Ceccherini void _DrawSelectors(BView* target);
1010289f920SJohn Scipione void _DrawColorRamp(BRect rect, BView* target,
102d2184e65SJérôme Duval rgb_color baseColor, rgb_color compColor,
1030289f920SJohn Scipione int16 flag, bool focused,
1040289f920SJohn Scipione BRect updateRect);
105295f3d13SStephan Aßmus BPoint _SelectorPosition(const BRect& rampRect,
106295f3d13SStephan Aßmus uint8 shade) const;
1078b3b14fdSJohn Scipione BRect _PaletteFrame() const;
1089c76ea4cSStefano Ceccherini BRect _PaletteSelectorFrame(uint8 colorIndex) const;
1099c76ea4cSStefano Ceccherini BRect _RampFrame(uint8 rampIndex) const;
1101186916fSJohn Scipione void _SetCellSize(float size);
11162fec205SJohn Scipione float _TextRectOffset();
112d734a8ceSbeveloper
1139a1d68e4SAxel Dörfler private:
1149c76ea4cSStefano Ceccherini BRect fPaletteFrame;
1159c76ea4cSStefano Ceccherini int16 fSelectedPaletteColorIndex;
1169c76ea4cSStefano Ceccherini int16 fPreviousSelectedPaletteColorIndex;
1179c76ea4cSStefano Ceccherini
118d734a8ceSbeveloper float fCellSize;
119d734a8ceSbeveloper int32 fRows;
120d734a8ceSbeveloper int32 fColumns;
1219c76ea4cSStefano Ceccherini bool fPaletteMode;
1229c76ea4cSStefano Ceccherini bool _unused[3];
123d734a8ceSbeveloper
124d734a8ceSbeveloper BTextControl* fRedText;
125d734a8ceSbeveloper BTextControl* fGreenText;
126d734a8ceSbeveloper BTextControl* fBlueText;
1279a1d68e4SAxel Dörfler
128*53f75ce5SJohn Scipione BBitmap* fOffscreenBitmap;
1299a1d68e4SAxel Dörfler
13074577830SJohn Scipione int16 fFocusedRamp;
13174577830SJohn Scipione int16 fClickedRamp;
132*53f75ce5SJohn Scipione uint32 _reserved[3];
133d734a8ceSbeveloper };
134d734a8ceSbeveloper
1359a1d68e4SAxel Dörfler inline void
SetValue(rgb_color color)1369a1d68e4SAxel Dörfler BColorControl::SetValue(rgb_color color)
137d734a8ceSbeveloper {
138d734a8ceSbeveloper int32 c = (color.red << 24) + (color.green << 16) + (color.blue << 8);
139d734a8ceSbeveloper SetValue(c);
140d734a8ceSbeveloper }
141d734a8ceSbeveloper
14287ba0eaaSStephan Aßmus #endif // _COLOR_CONTROL_H
143