2 * Copyright 2005, Jérôme Duval. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers
8 #include "UpDownButton.h"
9 #include "icon_button.h"
11 UpDownButton::UpDownButton(BRect _rect
, BMessage
*msg
, uint32 resizeFlags
)
12 : BControl(_rect
, "button", NULL
, msg
, resizeFlags
, B_WILL_DRAW
),
13 fLastValue(B_CONTROL_ON
)
15 BRect rect
= BRect(0, 0, kUpDownButtonWidth
- 1, kUpDownButtonHeight
- 1);
16 fBitmapUp
= new BBitmap(rect
, B_CMAP8
);
17 fBitmapUp
->SetBits(kButtonUpBits
, kUpDownButtonWidth
* kUpDownButtonHeight
,
19 fBitmapDown
= new BBitmap(rect
, B_CMAP8
);
20 fBitmapDown
->SetBits(kButtonDownBits
, kUpDownButtonWidth
21 * kUpDownButtonHeight
, 0, B_CMAP8
);
22 fBitmapMiddle
= new BBitmap(rect
, B_CMAP8
);
23 fBitmapMiddle
->SetBits(kButtonMiddleBits
, kUpDownButtonWidth
24 * kUpDownButtonHeight
, 0, B_CMAP8
);
28 UpDownButton::~UpDownButton()
37 UpDownButton::Draw(BRect updateRect
)
39 SetDrawingMode(B_OP_OVER
);
42 if((Bounds().top
+ Bounds().Height()/2) > (fTrackingY
+ 3))
43 DrawBitmap(fBitmapUp
);
44 else if((Bounds().top
+ Bounds().Height()/2) < (fTrackingY
- 3))
45 DrawBitmap(fBitmapDown
);
47 DrawBitmap(fBitmapMiddle
);
49 if(Value()==B_CONTROL_OFF
)
50 DrawBitmap(fBitmapUp
);
52 DrawBitmap(fBitmapDown
);
55 SetDrawingMode(B_OP_COPY
);
60 UpDownButton::MouseDown(BPoint point
)
66 fTrackingY
= (Bounds().top
+ Bounds().Height()/2);
69 SetMouseEventMask(B_POINTER_EVENTS
, B_LOCK_WINDOW_FOCUS
);
71 SetValue(Value() == B_CONTROL_ON
? B_CONTROL_OFF
: B_CONTROL_ON
);
76 UpDownButton::MouseMoved(BPoint point
, uint32 transit
, const BMessage
*message
)
88 UpDownButton::MouseUp(BPoint point
)
93 if((Bounds().top
+ Bounds().Height()/2) > (fTrackingY
+ 3))
94 SetValue(B_CONTROL_ON
);
95 else if((Bounds().top
+ Bounds().Height()/2) < (fTrackingY
- 3))
96 SetValue(B_CONTROL_OFF
);
98 if(Value()!=fLastValue
)
103 fLastValue
= Value();