vfs: check userland buffers before reading them.
[haiku.git] / src / apps / soundrecorder / DrawButton.cpp
blob5103d0fc8886ebfabbaa3757eca8f77b5172d526
1 /*
2 * Copyright 2005, Jérôme Duval. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Reworked from DarkWyrm version in CDPlayer
6 */
8 #include "DrawButton.h"
9 #include "DrawingTidbits.h"
11 DrawButton::DrawButton(BRect frame, const char *name, const unsigned char *on,
12 const unsigned char *off, BMessage *msg, int32 resize, int32 flags)
13 : BControl(frame, name, "", msg, resize, flags | B_WILL_DRAW),
14 fOn(frame, B_CMAP8),
15 fOff(frame, B_CMAP8),
16 fButtonState(false)
18 fOff.SetBits(off, (frame.Width() + 1) * (frame.Height() + 1), 0, B_CMAP8);
19 fOn.SetBits(on, (frame.Width() + 1) * (frame.Height() + 1), 0, B_CMAP8);
23 DrawButton::~DrawButton(void)
28 void
29 DrawButton::AttachedToWindow()
31 SetViewColor(B_TRANSPARENT_COLOR);
32 ReplaceTransparentColor(&fOn, Parent()->ViewColor());
33 ReplaceTransparentColor(&fOff, Parent()->ViewColor());
37 void
38 DrawButton::MouseUp(BPoint pt)
40 fButtonState = fButtonState ? false : true;
41 Invalidate();
42 Invoke();
46 void
47 DrawButton::Draw(BRect update)
49 if (fButtonState) {
50 DrawBitmap(&fOn, BPoint(0,0));
51 } else {
52 DrawBitmap(&fOff, BPoint(0,0));