1948356deSJérôme Duval/*
2948356deSJérôme Duval * Copyright 2005, J��r��me Duval. All rights reserved.
3948356deSJérôme Duval * Distributed under the terms of the MIT License.
4948356deSJérôme Duval *
5948356deSJérôme Duval * Reworked from DarkWyrm version in CDPlayer
6948356deSJérôme Duval */
7948356deSJérôme Duval
8948356deSJérôme Duval#include "DrawButton.h"
9948356deSJérôme Duval#include "DrawingTidbits.h"
10948356deSJérôme Duval
113ee96407SJérôme DuvalDrawButton::DrawButton(BRect frame, const char *name, const unsigned char *on,
123ee96407SJérôme Duval	const unsigned char *off, BMessage *msg, int32 resize, int32 flags)
13948356deSJérôme Duval	: BControl(frame, name, "", msg, resize, flags | B_WILL_DRAW),
14c228b168SJérôme Duval		fOn(frame, B_CMAP8),
15c228b168SJérôme Duval		fOff(frame, B_CMAP8),
16948356deSJérôme Duval		fButtonState(false)
17948356deSJérôme Duval{
18c228b168SJérôme Duval	fOff.SetBits(off, (frame.Width() + 1) * (frame.Height() + 1), 0, B_CMAP8);
19c228b168SJérôme Duval	fOn.SetBits(on, (frame.Width() + 1) * (frame.Height() + 1), 0, B_CMAP8);
20948356deSJérôme Duval}
21948356deSJérôme Duval
22948356deSJérôme Duval
23948356deSJérôme DuvalDrawButton::~DrawButton(void)
24948356deSJérôme Duval{
25948356deSJérôme Duval}
26948356deSJérôme Duval
27948356deSJérôme Duval
28948356deSJérôme Duvalvoid
29948356deSJérôme DuvalDrawButton::AttachedToWindow()
30948356deSJérôme Duval{
3142f70a5dSJérôme Duval	SetViewColor(B_TRANSPARENT_COLOR);
32948356deSJérôme Duval	ReplaceTransparentColor(&fOn, Parent()->ViewColor());
33948356deSJérôme Duval	ReplaceTransparentColor(&fOff, Parent()->ViewColor());
34948356deSJérôme Duval}
35948356deSJérôme Duval
36948356deSJérôme Duval
37948356deSJérôme Duvalvoid
38948356deSJérôme DuvalDrawButton::MouseUp(BPoint pt)
39948356deSJérôme Duval{
40948356deSJérôme Duval	fButtonState = fButtonState ? false : true;
41948356deSJérôme Duval	Invalidate();
42948356deSJérôme Duval	Invoke();
43948356deSJérôme Duval}
44948356deSJérôme Duval
45948356deSJérôme Duval
46948356deSJérôme Duvalvoid
47948356deSJérôme DuvalDrawButton::Draw(BRect update)
48948356deSJérôme Duval{
49948356deSJérôme Duval	if (fButtonState) {
50948356deSJérôme Duval		DrawBitmap(&fOn, BPoint(0,0));
51948356deSJérôme Duval	} else {
52948356deSJérôme Duval		DrawBitmap(&fOff, BPoint(0,0));
53948356deSJérôme Duval	}
54948356deSJérôme Duval}
55