1 /* 2 * Copyright 2005, Jérôme Duval. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Reworked from DarkWyrm version in CDPlayer 6 */ 7 8 #include "DrawButton.h" 9 #include "DrawingTidbits.h" 10 11 DrawButton::DrawButton(BRect frame, const char *name, const unsigned char *on, const unsigned char *off, 12 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) 17 { 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); 20 } 21 22 23 DrawButton::~DrawButton(void) 24 { 25 } 26 27 28 void 29 DrawButton::AttachedToWindow() 30 { 31 ReplaceTransparentColor(&fOn, Parent()->ViewColor()); 32 ReplaceTransparentColor(&fOff, Parent()->ViewColor()); 33 } 34 35 36 void 37 DrawButton::MouseUp(BPoint pt) 38 { 39 fButtonState = fButtonState ? false : true; 40 Invalidate(); 41 Invoke(); 42 } 43 44 45 void 46 DrawButton::Draw(BRect update) 47 { 48 if (fButtonState) { 49 DrawBitmap(&fOn, BPoint(0,0)); 50 } else { 51 DrawBitmap(&fOff, BPoint(0,0)); 52 } 53 } 54