From c38c84b296f13f528efa4bf99d3081d8608c3df3 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sun, 5 Jun 2022 12:00:50 -0500 Subject: [PATCH] =?UTF-8?q?Import=20A=C3=9Fmus'=20PlayPauseButton=20from?= =?UTF-8?q?=20MediaPlayer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … along with its parent SymbolButton. Also moves imports into a new src/thirdparty/ directory. --- Makefile | 6 +- src/Song.cpp | 2 +- src/thirdparty/PlayPauseButton.cpp | 191 +++++++++++++++++++++++++++++ src/thirdparty/PlayPauseButton.h | 51 ++++++++ src/thirdparty/SymbolButton.cpp | 120 ++++++++++++++++++ src/thirdparty/SymbolButton.h | 39 ++++++ src/{ => thirdparty}/TextFile.cpp | 2 +- src/{ => thirdparty}/TextFile.h | 0 8 files changed, 407 insertions(+), 4 deletions(-) create mode 100644 src/thirdparty/PlayPauseButton.cpp create mode 100644 src/thirdparty/PlayPauseButton.h create mode 100644 src/thirdparty/SymbolButton.cpp create mode 100644 src/thirdparty/SymbolButton.h rename src/{ => thirdparty}/TextFile.cpp (98%) rename src/{ => thirdparty}/TextFile.h (100%) diff --git a/Makefile b/Makefile index f18fe49..465969d 100644 --- a/Makefile +++ b/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. diff --git a/src/Song.cpp b/src/Song.cpp index 75a7fee..5a62c59 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -10,7 +10,7 @@ #include #include -#include "TextFile.h" +#include "thirdparty/TextFile.h" Song::Song() diff --git a/src/thirdparty/PlayPauseButton.cpp b/src/thirdparty/PlayPauseButton.cpp new file mode 100644 index 0000000..59f468e --- /dev/null +++ b/src/thirdparty/PlayPauseButton.cpp @@ -0,0 +1,191 @@ +/* + * Copyright 2010, Stephan Aßmus . + * Distributed under the terms of the MIT License. + */ + + +#include "thirdparty/PlayPauseButton.h" + +#include +#include +#include + + +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(); +} diff --git a/src/thirdparty/PlayPauseButton.h b/src/thirdparty/PlayPauseButton.h new file mode 100644 index 0000000..a86010e --- /dev/null +++ b/src/thirdparty/PlayPauseButton.h @@ -0,0 +1,51 @@ +/* + * Copyright 2010, Stephan Aßmus . + * 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 diff --git a/src/thirdparty/SymbolButton.cpp b/src/thirdparty/SymbolButton.cpp new file mode 100644 index 0000000..fdf9f68 --- /dev/null +++ b/src/thirdparty/SymbolButton.cpp @@ -0,0 +1,120 @@ +/* + * Copyright 2010, Stephan Aßmus . + * Distributed under the terms of the MIT License. + */ + + +#include "thirdparty/SymbolButton.h" + +#include +#include +#include + + +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(); +} + diff --git a/src/thirdparty/SymbolButton.h b/src/thirdparty/SymbolButton.h new file mode 100644 index 0000000..35aa35f --- /dev/null +++ b/src/thirdparty/SymbolButton.h @@ -0,0 +1,39 @@ +/* + * Copyright 2010, Stephan Aßmus . + * Distributed under the terms of the MIT License. + */ +#ifndef SYMBOL_BUTTON_H +#define SYMBOL_BUTTON_H + + +#include +#include + +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 diff --git a/src/TextFile.cpp b/src/thirdparty/TextFile.cpp similarity index 98% rename from src/TextFile.cpp rename to src/thirdparty/TextFile.cpp index ca4ef0e..1ed8b39 100644 --- a/src/TextFile.cpp +++ b/src/thirdparty/TextFile.cpp @@ -3,7 +3,7 @@ Written by DarkWyrm, Copyright 2007 Released under the MIT license. */ -#include "TextFile.h" +#include "thirdparty/TextFile.h" #include #include #include diff --git a/src/TextFile.h b/src/thirdparty/TextFile.h similarity index 100% rename from src/TextFile.h rename to src/thirdparty/TextFile.h