Import Aßmus' PlayPauseButton from MediaPlayer
… along with its parent SymbolButton. Also moves imports into a new src/thirdparty/ directory.
This commit is contained in:
parent
a0897d1401
commit
c38c84b296
6
Makefile
6
Makefile
|
@ -38,8 +38,10 @@ SRCS = src/App.cpp \
|
|||
src/MediaPlayer.cpp \
|
||||
src/ReplicantView.cpp \
|
||||
src/Song.cpp \
|
||||
src/TextFile.cpp \
|
||||
src/VolumeView.cpp
|
||||
src/VolumeView.cpp \
|
||||
src/thirdparty/PlayPauseButton.cpp \
|
||||
src/thirdparty/SymbolButton.cpp \
|
||||
src/thirdparty/TextFile.cpp
|
||||
|
||||
# Specify the resource definition files to use. Full or relative paths can be
|
||||
# used.
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <String.h>
|
||||
#include <TranslationUtils.h>
|
||||
|
||||
#include "TextFile.h"
|
||||
#include "thirdparty/TextFile.h"
|
||||
|
||||
|
||||
Song::Song()
|
||||
|
|
|
@ -0,0 +1,191 @@
|
|||
/*
|
||||
* Copyright 2010, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "thirdparty/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)
|
||||
{
|
||||
BSize oldSize = MinSize();
|
||||
|
||||
delete fPlaySymbol;
|
||||
fPlaySymbol = playSymbolShape;
|
||||
delete fPauseSymbol;
|
||||
fPauseSymbol = pauseSymbolShape;
|
||||
|
||||
if (MinSize() != oldSize)
|
||||
InvalidateLayout();
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayPauseButton::_SetPlaybackState(uint32 state)
|
||||
{
|
||||
if (fPlaybackState == state)
|
||||
return;
|
||||
fPlaybackState = state;
|
||||
Invalidate();
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright 2010, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* 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,120 @@
|
|||
/*
|
||||
* Copyright 2010, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "thirdparty/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);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
float scale = fBorders != 0 ? 2.5f : 1.0f;
|
||||
|
||||
BSize size;
|
||||
size.width = ceilf(fSymbol->Bounds().Width() * scale);
|
||||
size.height = ceilf(fSymbol->Bounds().Height() * scale);
|
||||
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
|
||||
}
|
||||
|
||||
|
||||
BSize
|
||||
SymbolButton::MaxSize()
|
||||
{
|
||||
BSize size(MinSize());
|
||||
if (fBorders != 0)
|
||||
size.width = ceilf(size.width * 1.5f);
|
||||
return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SymbolButton::SetSymbol(BShape* symbolShape)
|
||||
{
|
||||
BSize oldSize = MinSize();
|
||||
|
||||
delete fSymbol;
|
||||
fSymbol = symbolShape;
|
||||
|
||||
if (MinSize() != oldSize)
|
||||
InvalidateLayout();
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2010, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* 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
|
|
@ -3,7 +3,7 @@
|
|||
Written by DarkWyrm, Copyright 2007
|
||||
Released under the MIT license.
|
||||
*/
|
||||
#include "TextFile.h"
|
||||
#include "thirdparty/TextFile.h"
|
||||
#include <stdio.h>
|
||||
#include <OS.h>
|
||||
#include <string.h>
|
Ŝarĝante…
Reference in New Issue