Doh... should have been part of my last commit. Sorry!
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38586 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,184 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Stephan Aßmus <[email protected]>.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "PlayPauseButton.h"
|
||||||
|
|
||||||
|
#include <GradientLinear.h>
|
||||||
|
#include <LayoutUtils.h>
|
||||||
|
#include <Shape.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const rgb_color kGreen = (rgb_color){ 116, 224, 0, 255 };
|
||||||
|
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PlayPauseButton::PlayPauseButton(const char* name,
|
||||||
|
BShape* playSymbolShape, BShape* pauseSymbolShape, BMessage* message,
|
||||||
|
uint32 borders)
|
||||||
|
:
|
||||||
|
SymbolButton(name, NULL, message, borders),
|
||||||
|
fPlaySymbol(playSymbolShape),
|
||||||
|
fPauseSymbol(pauseSymbolShape),
|
||||||
|
fPlaybackState(kStopped)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PlayPauseButton::~PlayPauseButton()
|
||||||
|
{
|
||||||
|
delete fPlaySymbol;
|
||||||
|
delete fPauseSymbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayPauseButton::Draw(BRect updateRect)
|
||||||
|
{
|
||||||
|
SymbolButton::Draw(updateRect);
|
||||||
|
|
||||||
|
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||||
|
rgb_color active = (rgb_color){ 116, 224, 0, 255 };
|
||||||
|
|
||||||
|
if (IsEnabled()) {
|
||||||
|
if (Value() == B_CONTROL_ON)
|
||||||
|
base = tint_color(base, (B_DARKEN_4_TINT + B_DARKEN_MAX_TINT) / 2);
|
||||||
|
else
|
||||||
|
base = tint_color(base, B_DARKEN_4_TINT);
|
||||||
|
} else {
|
||||||
|
if (Value() == B_CONTROL_ON)
|
||||||
|
base = tint_color(base, B_DARKEN_2_TINT);
|
||||||
|
else
|
||||||
|
base = tint_color(base, B_DARKEN_1_TINT);
|
||||||
|
}
|
||||||
|
BRect bounds(Bounds());
|
||||||
|
BRect pauseBounds = fPauseSymbol->Bounds();
|
||||||
|
BRect playBounds = fPlaySymbol->Bounds();
|
||||||
|
|
||||||
|
BPoint offset;
|
||||||
|
float spacing = pauseBounds.Height() / 4;
|
||||||
|
offset.x = (bounds.left + bounds.right) / 2;
|
||||||
|
offset.y = (bounds.top + bounds.bottom) / 2;
|
||||||
|
offset.x -= (pauseBounds.Width() + playBounds.Width() + spacing) / 2;
|
||||||
|
offset.y -= pauseBounds.Height() / 2;
|
||||||
|
offset.x = floorf(offset.x - playBounds.left + 0.5);
|
||||||
|
offset.y = ceilf(offset.y - pauseBounds.top);
|
||||||
|
if (Value() == B_CONTROL_ON) {
|
||||||
|
offset.x += 1;
|
||||||
|
offset.y += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool playActive = IsEnabled()
|
||||||
|
&& ((fPlaybackState == kPlaying && Value() == B_CONTROL_OFF)
|
||||||
|
|| (fPlaybackState == kPaused && Value() == B_CONTROL_ON));
|
||||||
|
bool pauseActive = IsEnabled()
|
||||||
|
&& ((fPlaybackState == kPaused && Value() == B_CONTROL_OFF)
|
||||||
|
|| (fPlaybackState == kPlaying && Value() == B_CONTROL_ON));
|
||||||
|
|
||||||
|
MovePenTo(offset);
|
||||||
|
BGradientLinear gradient;
|
||||||
|
if (playActive) {
|
||||||
|
gradient.AddColor(active, 0);
|
||||||
|
gradient.AddColor(tint_color(active, B_LIGHTEN_1_TINT), 255);
|
||||||
|
} else {
|
||||||
|
gradient.AddColor(tint_color(base, B_DARKEN_1_TINT), 0);
|
||||||
|
gradient.AddColor(base, 255);
|
||||||
|
}
|
||||||
|
gradient.SetStart(offset);
|
||||||
|
offset.y += playBounds.Height();
|
||||||
|
gradient.SetEnd(offset);
|
||||||
|
FillShape(fPlaySymbol, gradient);
|
||||||
|
if (playActive) {
|
||||||
|
SetHighColor(tint_color(active, B_DARKEN_3_TINT));
|
||||||
|
MovePenBy(0.5, 0.5);
|
||||||
|
StrokeShape(fPlaySymbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
offset.y -= playBounds.Height();
|
||||||
|
offset.x += ceilf(playBounds.Width() + spacing);
|
||||||
|
MovePenTo(offset);
|
||||||
|
gradient.MakeEmpty();
|
||||||
|
if (pauseActive) {
|
||||||
|
gradient.AddColor(active, 0);
|
||||||
|
gradient.AddColor(tint_color(active, B_LIGHTEN_1_TINT), 255);
|
||||||
|
} else {
|
||||||
|
gradient.AddColor(tint_color(base, B_DARKEN_1_TINT), 0);
|
||||||
|
gradient.AddColor(base, 255);
|
||||||
|
}
|
||||||
|
gradient.SetStart(offset);
|
||||||
|
offset.y += playBounds.Height();
|
||||||
|
gradient.SetEnd(offset);
|
||||||
|
FillShape(fPauseSymbol, gradient);
|
||||||
|
if (pauseActive) {
|
||||||
|
SetHighColor(tint_color(active, B_DARKEN_3_TINT));
|
||||||
|
MovePenBy(0.5, 0.5);
|
||||||
|
StrokeShape(fPauseSymbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
PlayPauseButton::MinSize()
|
||||||
|
{
|
||||||
|
if (fPauseSymbol == NULL || fPlaySymbol == NULL)
|
||||||
|
return BButton::MinSize();
|
||||||
|
|
||||||
|
BSize size;
|
||||||
|
size.width = ceilf(
|
||||||
|
(fPlaySymbol->Bounds().Width() + fPauseSymbol->Bounds().Width())
|
||||||
|
* 2.5f);
|
||||||
|
size.height = ceilf(fPauseSymbol->Bounds().Height() * 2.5f);
|
||||||
|
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
PlayPauseButton::MaxSize()
|
||||||
|
{
|
||||||
|
BSize size(MinSize());
|
||||||
|
size.width = ceilf(size.width * 1.5f);
|
||||||
|
return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayPauseButton::SetPlaying()
|
||||||
|
{
|
||||||
|
_SetPlaybackState(kPlaying);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayPauseButton::SetPaused()
|
||||||
|
{
|
||||||
|
_SetPlaybackState(kPaused);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayPauseButton::SetStopped()
|
||||||
|
{
|
||||||
|
_SetPlaybackState(kStopped);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayPauseButton::SetSymbols(BShape* playSymbolShape, BShape* pauseSymbolShape)
|
||||||
|
{
|
||||||
|
delete fPlaySymbol;
|
||||||
|
fPlaySymbol = playSymbolShape;
|
||||||
|
delete fPauseSymbol;
|
||||||
|
fPauseSymbol = pauseSymbolShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayPauseButton::_SetPlaybackState(uint32 state)
|
||||||
|
{
|
||||||
|
if (fPlaybackState == state)
|
||||||
|
return;
|
||||||
|
fPlaybackState = state;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Stephan Aßmus <[email protected]>.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef PLAY_PAUSE_BUTTON_H
|
||||||
|
#define PLAY_PAUSE_BUTTON_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "SymbolButton.h"
|
||||||
|
|
||||||
|
|
||||||
|
class PlayPauseButton : public SymbolButton {
|
||||||
|
public:
|
||||||
|
PlayPauseButton(const char* name,
|
||||||
|
BShape* playSymbolShape,
|
||||||
|
BShape* pauseSymbolShape,
|
||||||
|
BMessage* message = NULL,
|
||||||
|
uint32 borders
|
||||||
|
= BControlLook::B_ALL_BORDERS);
|
||||||
|
|
||||||
|
virtual ~PlayPauseButton();
|
||||||
|
|
||||||
|
// BButton interface
|
||||||
|
virtual void Draw(BRect updateRect);
|
||||||
|
virtual BSize MinSize();
|
||||||
|
virtual BSize MaxSize();
|
||||||
|
|
||||||
|
// PlayPauseButton
|
||||||
|
void SetPlaying();
|
||||||
|
void SetPaused();
|
||||||
|
void SetStopped();
|
||||||
|
|
||||||
|
void SetSymbols(BShape* playSymbolShape,
|
||||||
|
BShape* pauseSymbolShape);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _SetPlaybackState(uint32 state);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BShape* fPlaySymbol;
|
||||||
|
BShape* fPauseSymbol;
|
||||||
|
enum {
|
||||||
|
kStopped = 0,
|
||||||
|
kPaused,
|
||||||
|
kPlaying
|
||||||
|
};
|
||||||
|
uint32 fPlaybackState;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // PLAY_PAUSE_BUTTON_H
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Stephan Aßmus <[email protected]>.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "SymbolButton.h"
|
||||||
|
|
||||||
|
#include <GradientLinear.h>
|
||||||
|
#include <LayoutUtils.h>
|
||||||
|
#include <Shape.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const rgb_color kGreen = (rgb_color){ 116, 224, 0, 255 };
|
||||||
|
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
SymbolButton::SymbolButton(const char* name, BShape* symbolShape,
|
||||||
|
BMessage* message, uint32 borders)
|
||||||
|
:
|
||||||
|
BButton(name, NULL, message),
|
||||||
|
fSymbol(symbolShape),
|
||||||
|
fBorders(borders)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SymbolButton::~SymbolButton()
|
||||||
|
{
|
||||||
|
delete fSymbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SymbolButton::Draw(BRect updateRect)
|
||||||
|
{
|
||||||
|
uint32 flags = be_control_look->Flags(this);
|
||||||
|
rgb_color base = LowColor();
|
||||||
|
BRect bounds(Bounds());
|
||||||
|
|
||||||
|
if (fBorders != 0) {
|
||||||
|
be_control_look->DrawButtonFrame(this, bounds, updateRect, base,
|
||||||
|
base, flags & ~BControlLook::B_DISABLED, fBorders);
|
||||||
|
be_control_look->DrawButtonBackground(this, bounds, updateRect, base,
|
||||||
|
flags);
|
||||||
|
} else
|
||||||
|
FillRect(updateRect, B_SOLID_LOW);
|
||||||
|
|
||||||
|
if (fSymbol == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (IsEnabled()) {
|
||||||
|
if (Value() == B_CONTROL_ON)
|
||||||
|
base = tint_color(base, (B_DARKEN_4_TINT + B_DARKEN_MAX_TINT) / 2);
|
||||||
|
else
|
||||||
|
base = tint_color(base, B_DARKEN_4_TINT);
|
||||||
|
} else {
|
||||||
|
if (Value() == B_CONTROL_ON)
|
||||||
|
base = tint_color(base, B_DARKEN_2_TINT);
|
||||||
|
else
|
||||||
|
base = tint_color(base, B_DARKEN_1_TINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
BPoint offset;
|
||||||
|
offset.x = (bounds.left + bounds.right) / 2;
|
||||||
|
offset.y = (bounds.top + bounds.bottom) / 2;
|
||||||
|
offset.x -= fSymbol->Bounds().Width() / 2;
|
||||||
|
offset.y -= fSymbol->Bounds().Height() / 2;
|
||||||
|
offset.x = floorf(offset.x - fSymbol->Bounds().left);
|
||||||
|
offset.y = ceilf(offset.y - fSymbol->Bounds().top);
|
||||||
|
|
||||||
|
MovePenTo(offset);
|
||||||
|
BGradientLinear gradient;
|
||||||
|
gradient.AddColor(tint_color(base, B_DARKEN_1_TINT), 0);
|
||||||
|
gradient.AddColor(base, 255);
|
||||||
|
gradient.SetStart(offset);
|
||||||
|
offset.y += fSymbol->Bounds().Height();
|
||||||
|
gradient.SetEnd(offset);
|
||||||
|
FillShape(fSymbol, gradient);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
SymbolButton::MinSize()
|
||||||
|
{
|
||||||
|
if (fSymbol == NULL)
|
||||||
|
return BButton::MinSize();
|
||||||
|
|
||||||
|
BSize size;
|
||||||
|
size.width = ceilf(fSymbol->Bounds().Width() * 2.5f);
|
||||||
|
size.height = ceilf(fSymbol->Bounds().Height() * 2.5f);
|
||||||
|
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
SymbolButton::MaxSize()
|
||||||
|
{
|
||||||
|
BSize size(MinSize());
|
||||||
|
size.width = ceilf(size.width * 1.5f);
|
||||||
|
return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SymbolButton::SetSymbol(BShape* symbolShape)
|
||||||
|
{
|
||||||
|
delete fSymbol;
|
||||||
|
fSymbol = symbolShape;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Stephan Aßmus <[email protected]>.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef SYMBOL_BUTTON_H
|
||||||
|
#define SYMBOL_BUTTON_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <Button.h>
|
||||||
|
#include <ControlLook.h>
|
||||||
|
|
||||||
|
class BShape;
|
||||||
|
|
||||||
|
|
||||||
|
class SymbolButton : public BButton {
|
||||||
|
public:
|
||||||
|
SymbolButton(const char* name,
|
||||||
|
BShape* symbolShape,
|
||||||
|
BMessage* message = NULL,
|
||||||
|
uint32 borders
|
||||||
|
= BControlLook::B_ALL_BORDERS);
|
||||||
|
|
||||||
|
virtual ~SymbolButton();
|
||||||
|
|
||||||
|
// BButton interface
|
||||||
|
virtual void Draw(BRect updateRect);
|
||||||
|
virtual BSize MinSize();
|
||||||
|
virtual BSize MaxSize();
|
||||||
|
|
||||||
|
// SymbolButton
|
||||||
|
void SetSymbol(BShape* symbolShape);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BShape* fSymbol;
|
||||||
|
uint32 fBorders;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SYMBOL_BUTTON_H
|
||||||
Reference in New Issue
Block a user