1/*
2 * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Mattias Sundblad
7 *		Andrew Bachmann
8 */
9
10#include "ColorMenuItem.h"
11
12#include <Message.h>
13#include <Rect.h>
14
15
16ColorMenuItem::ColorMenuItem(const char* label, rgb_color color,
17	BMessage *message)
18	:
19	BMenuItem(label, message, 0, 0),
20	fItemColor(color)
21{
22	message->AddData("color", B_RGB_COLOR_TYPE, &color, sizeof(rgb_color));
23}
24
25
26void
27ColorMenuItem::DrawContent()
28{
29	BMenu* menu = Menu();
30	if (menu) {
31		rgb_color menuColor = menu->HighColor();
32		BRect colorSquare(Frame());
33
34		if (colorSquare.Width() > colorSquare.Height()) {
35			// large button
36			colorSquare.left += 8;
37			colorSquare.top += 2;
38			colorSquare.bottom -= 2;
39		}
40		colorSquare.right = colorSquare.left + colorSquare.Height();
41		if (IsMarked()) {
42			menu->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
43			menu->StrokeRect(colorSquare);
44		}
45		colorSquare.InsetBy(1, 1);
46		menu->SetHighColor(fItemColor);
47		menu->FillRect(colorSquare);
48		menu->SetHighColor(menuColor);
49		menu->MovePenBy(colorSquare.right + 5.0f, 4.0f);
50		BMenuItem::DrawContent();
51	}
52}
53