From 00f9ecb0cb73ca0fbe366ed39330b50c14b5ae80 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sun, 5 Jun 2022 15:14:32 -0500 Subject: [PATCH] About windows and replicant menu options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gives the app and each replicant an "About" window. Also adds the "About…" and "Remove replicant" menu items from BDragger to the normal right-click menu. --- Makefile | 4 +++- src/App.cpp | 12 +++++++++++- src/App.h | 4 +++- src/CoverView.cpp | 5 +++++ src/LyricsView.cpp | 6 ++++++ src/ReplicantView.cpp | 24 +++++++++++++++++++++++- src/ReplicantView.h | 5 +++++ src/Util.cpp | 28 ++++++++++++++++++++++++++++ src/Util.h | 12 ++++++++++++ src/VolumeView.cpp | 7 +++++++ 10 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 src/Util.cpp create mode 100644 src/Util.h diff --git a/Makefile b/Makefile index 465969d..f356bff 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ SRCS = src/App.cpp \ src/MediaPlayer.cpp \ src/ReplicantView.cpp \ src/Song.cpp \ + src/Util.cpp \ src/VolumeView.cpp \ src/thirdparty/PlayPauseButton.cpp \ src/thirdparty/SymbolButton.cpp \ @@ -79,7 +80,8 @@ LIBPATHS = # Additional paths to look for system headers. These use the form # "#include
". Directories that contain the files in SRCS are # NOT auto-included here. -SYSTEM_INCLUDE_PATHS = +SYSTEM_INCLUDE_PATHS = \ + $(shell findpaths -e B_FIND_PATH_HEADERS_DIRECTORY private/interface) # Additional paths paths to look for local headers. These use the form # #include "header". Directories that contain the files in SRCS are diff --git a/src/App.cpp b/src/App.cpp index 13cc835..b39912d 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -5,7 +5,10 @@ #include "App.h" +#include + #include "MainWindow.h" +#include "Util.h" App::App() @@ -13,11 +16,18 @@ App::App() BApplication(APP_SIGNATURE) { MainWindow* win = new MainWindow(); - win->SetPulseRate(2500000); + win->SetPulseRate(1250000); win->Show(); } +void +App::AboutRequested() +{ + show_about_window(NULL); +} + + int main(int argc, char** argv) { diff --git a/src/App.h b/src/App.h index ace219d..92da380 100644 --- a/src/App.h +++ b/src/App.h @@ -11,7 +11,9 @@ class App: public BApplication { public: - App(); + App(); + + virtual void AboutRequested(); }; diff --git a/src/CoverView.cpp b/src/CoverView.cpp index 14b9f72..c87ba67 100644 --- a/src/CoverView.cpp +++ b/src/CoverView.cpp @@ -14,12 +14,15 @@ const uint32 COVER_MAKE_SQUARE = 'cvsq'; +const char* kCoverDesc = "CoverView is a replicant that shows a thumbnail for whatever is playing― often an album cover taken from a 'cover.jpg' or similar file."; CoverView::CoverView(BRect frame) : ReplicantView(frame, "Cover", B_FOLLOW_RIGHT, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE) { + fDescription.SetTo(kCoverDesc); + SetViewColor(B_TRANSPARENT_COLOR); fCover = NULL; Pulse(); @@ -30,6 +33,8 @@ CoverView::CoverView(BMessage* data) : ReplicantView(data) { + fDescription.SetTo(kCoverDesc); + SetViewColor(B_TRANSPARENT_COLOR); fCover = NULL; Pulse(); diff --git a/src/LyricsView.cpp b/src/LyricsView.cpp index 6bb680d..8d27d45 100644 --- a/src/LyricsView.cpp +++ b/src/LyricsView.cpp @@ -13,6 +13,9 @@ #include "MediaPlayer.h" +const char* kLyricsDesc = "LyricsView is a replicant that shows a transcription for the playing media. Usually this means lyrics to a song, stored in 'songFile.mp3.txt' or similar."; + + LyricsTextView::LyricsTextView(BRect frame, const char* name, BRect textFrame, uint32 resize, uint32 flags) : @@ -65,6 +68,8 @@ LyricsView::LyricsView(BRect frame) : ReplicantView(frame, "Lyrics", B_FOLLOW_LEFT) { + fDescription.SetTo(kLyricsDesc); + BRect textRect(0, 0, Bounds().Width(), Bounds().Height() - 10); fTextView = new LyricsTextView(textRect, "lyricsText", textRect, B_FOLLOW_ALL, B_WILL_DRAW); @@ -89,6 +94,7 @@ LyricsView::LyricsView(BMessage* data) : ReplicantView(data) { + fDescription.SetTo(kLyricsDesc); fAutoScroll = false; fFgColor = ui_color(B_PANEL_TEXT_COLOR); diff --git a/src/ReplicantView.cpp b/src/ReplicantView.cpp index 077eea4..7872656 100644 --- a/src/ReplicantView.cpp +++ b/src/ReplicantView.cpp @@ -11,6 +11,7 @@ #include #include "MediaPlayer.h" +#include "Util.h" ReplicantView::ReplicantView(BRect frame, const char* name, uint32 draggerPlacement, uint32 resize, @@ -29,9 +30,11 @@ ReplicantView::ReplicantView(BRect frame, const char* name, uint32 draggerPlacem fDragger->SetViewColor(B_TRANSPARENT_COLOR); AddChild(fDragger); + fInactive = true; + fReplicated = false; + fTransparentInactivity = false; fTransparentDragger = false; - fInactive = true; fMediaPlayer = new MediaPlayer(0); } @@ -49,7 +52,9 @@ ReplicantView::ReplicantView(BMessage* data) fTransparentInactivity = data->GetBool("transparent_inactivity", true); fTransparentDragger = data->GetBool("transparent_dragger", false); + fInactive = true; + fReplicated = true; } @@ -93,6 +98,9 @@ ReplicantView::MessageReceived(BMessage* msg) SetInactive(fInactive); break; } + case B_ABOUT_REQUESTED: + show_about_window(fDescription.String()); + break; default: BView::MessageReceived(msg); break; @@ -140,6 +148,20 @@ ReplicantView::RightClickPopUp(BPopUpMenu* menu) hideDragger->SetTarget(this); hideMenu->AddItem(hideDragger); + menu->AddSeparatorItem(); + + BString aboutLabel = "About %replicant" B_UTF8_ELLIPSIS; + aboutLabel.ReplaceAll("%replicant", Name()); + BMenuItem* aboutItem = new BMenuItem(aboutLabel, new BMessage(B_ABOUT_REQUESTED)); + aboutItem->SetTarget(this); + menu->AddItem(aboutItem); + + if (fReplicated) { + BMenuItem* removeItem = new BMenuItem("Remove replicant", new BMessage(B_TRASH_TARGET)); + removeItem->SetTarget(fDragger); + menu->AddItem(removeItem); + } + return menu; } diff --git a/src/ReplicantView.h b/src/ReplicantView.h index f833f42..e6d9708 100644 --- a/src/ReplicantView.h +++ b/src/ReplicantView.h @@ -53,10 +53,15 @@ public: // Set inactivity state, re-render accordingly virtual void SetInactive(bool inactive); +protected: MediaPlayer* fMediaPlayer; BDragger* fDragger; + BString fDescription; + + bool fReplicated; bool fInactive; + bool fTransparentInactivity; bool fTransparentDragger; }; diff --git a/src/Util.cpp b/src/Util.cpp new file mode 100644 index 0000000..8d84bef --- /dev/null +++ b/src/Util.cpp @@ -0,0 +1,28 @@ +/* + * Copyright 2022, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ + +#include "Util.h" + +#include + + +void +show_about_window(const char* description) +{ + const char* authors[] = { + "Stephan Aßmus", + "DarkWyrm", + "Jaidyn Levesque", + NULL + }; + + BAboutWindow* about = new BAboutWindow(APP_NAME, APP_SIGNATURE); + about->AddDescription("A collection of simple MediaPlayer replicants."); + if (description != NULL) + about->AddDescription(description); + about->AddAuthors(authors); + about->AddCopyright(2022, "Jaidyn Levesque"); + about->Show(); +} diff --git a/src/Util.h b/src/Util.h new file mode 100644 index 0000000..8188b60 --- /dev/null +++ b/src/Util.h @@ -0,0 +1,12 @@ +/* + * Copyright 2022, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ +#ifndef UTIL_H +#define UTIL_H + +#include + +void show_about_window(const char* description); + +#endif // UTIL_H diff --git a/src/VolumeView.cpp b/src/VolumeView.cpp index 856d19f..ae63a82 100644 --- a/src/VolumeView.cpp +++ b/src/VolumeView.cpp @@ -12,6 +12,9 @@ #include "MediaPlayer.h" +const char* kVolumeDesc = "VolumeView is a replicant that can monitor and change the volume of MediaPlayer."; + + // The same color MediaPlayer uses, interface/VolumeSlider static const rgb_color kVolumeGreen = (rgb_color){ 116, 224, 0, 255 }; @@ -22,6 +25,8 @@ VolumeView::VolumeView(BRect frame) : ReplicantView(frame, "Volume", B_FOLLOW_RIGHT, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS) { + fDescription.SetTo(kVolumeDesc); + _InitInterface(); Pulse(); } @@ -31,6 +36,8 @@ VolumeView::VolumeView(BMessage* data) : ReplicantView(data) { + fDescription.SetTo(kVolumeDesc); + // For some reason, the BSlider gets archived with a wacko frame― better to just nuke it. fSlider = dynamic_cast(FindView("volumeSlider")); delete fSlider;