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 11DrawButton::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) 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 23DrawButton::~DrawButton(void) 24{ 25} 26 27 28void 29DrawButton::AttachedToWindow() 30{ 31 SetViewColor(B_TRANSPARENT_COLOR); 32 ReplaceTransparentColor(&fOn, Parent()->ViewColor()); 33 ReplaceTransparentColor(&fOff, Parent()->ViewColor()); 34} 35 36 37void 38DrawButton::MouseUp(BPoint pt) 39{ 40 fButtonState = fButtonState ? false : true; 41 Invalidate(); 42 Invoke(); 43} 44 45 46void 47DrawButton::Draw(BRect update) 48{ 49 if (fButtonState) { 50 DrawBitmap(&fOn, BPoint(0,0)); 51 } else { 52 DrawBitmap(&fOff, BPoint(0,0)); 53 } 54} 55