About windows and replicant menu options

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.
This commit is contained in:
Jaidyn Ann 2022-06-05 15:14:32 -05:00
parent bf02ce442e
commit 00f9ecb0cb
10 changed files with 103 additions and 4 deletions

View File

@ -38,6 +38,7 @@ SRCS = src/App.cpp \
src/MediaPlayer.cpp \ src/MediaPlayer.cpp \
src/ReplicantView.cpp \ src/ReplicantView.cpp \
src/Song.cpp \ src/Song.cpp \
src/Util.cpp \
src/VolumeView.cpp \ src/VolumeView.cpp \
src/thirdparty/PlayPauseButton.cpp \ src/thirdparty/PlayPauseButton.cpp \
src/thirdparty/SymbolButton.cpp \ src/thirdparty/SymbolButton.cpp \
@ -79,7 +80,8 @@ LIBPATHS =
# Additional paths to look for system headers. These use the form # Additional paths to look for system headers. These use the form
# "#include <header>". Directories that contain the files in SRCS are # "#include <header>". Directories that contain the files in SRCS are
# NOT auto-included here. # 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 # Additional paths paths to look for local headers. These use the form
# #include "header". Directories that contain the files in SRCS are # #include "header". Directories that contain the files in SRCS are

View File

@ -5,7 +5,10 @@
#include "App.h" #include "App.h"
#include <AboutWindow.h>
#include "MainWindow.h" #include "MainWindow.h"
#include "Util.h"
App::App() App::App()
@ -13,11 +16,18 @@ App::App()
BApplication(APP_SIGNATURE) BApplication(APP_SIGNATURE)
{ {
MainWindow* win = new MainWindow(); MainWindow* win = new MainWindow();
win->SetPulseRate(2500000); win->SetPulseRate(1250000);
win->Show(); win->Show();
} }
void
App::AboutRequested()
{
show_about_window(NULL);
}
int int
main(int argc, char** argv) main(int argc, char** argv)
{ {

View File

@ -11,7 +11,9 @@
class App: public BApplication class App: public BApplication
{ {
public: public:
App(); App();
virtual void AboutRequested();
}; };

View File

@ -14,12 +14,15 @@
const uint32 COVER_MAKE_SQUARE = 'cvsq'; 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) CoverView::CoverView(BRect frame)
: :
ReplicantView(frame, "Cover", B_FOLLOW_RIGHT, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE) 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); SetViewColor(B_TRANSPARENT_COLOR);
fCover = NULL; fCover = NULL;
Pulse(); Pulse();
@ -30,6 +33,8 @@ CoverView::CoverView(BMessage* data)
: :
ReplicantView(data) ReplicantView(data)
{ {
fDescription.SetTo(kCoverDesc);
SetViewColor(B_TRANSPARENT_COLOR); SetViewColor(B_TRANSPARENT_COLOR);
fCover = NULL; fCover = NULL;
Pulse(); Pulse();

View File

@ -13,6 +13,9 @@
#include "MediaPlayer.h" #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, LyricsTextView::LyricsTextView(BRect frame, const char* name, BRect textFrame,
uint32 resize, uint32 flags) uint32 resize, uint32 flags)
: :
@ -65,6 +68,8 @@ LyricsView::LyricsView(BRect frame)
: :
ReplicantView(frame, "Lyrics", B_FOLLOW_LEFT) ReplicantView(frame, "Lyrics", B_FOLLOW_LEFT)
{ {
fDescription.SetTo(kLyricsDesc);
BRect textRect(0, 0, Bounds().Width(), Bounds().Height() - 10); BRect textRect(0, 0, Bounds().Width(), Bounds().Height() - 10);
fTextView = new LyricsTextView(textRect, "lyricsText", textRect, fTextView = new LyricsTextView(textRect, "lyricsText", textRect,
B_FOLLOW_ALL, B_WILL_DRAW); B_FOLLOW_ALL, B_WILL_DRAW);
@ -89,6 +94,7 @@ LyricsView::LyricsView(BMessage* data)
: :
ReplicantView(data) ReplicantView(data)
{ {
fDescription.SetTo(kLyricsDesc);
fAutoScroll = false; fAutoScroll = false;
fFgColor = ui_color(B_PANEL_TEXT_COLOR); fFgColor = ui_color(B_PANEL_TEXT_COLOR);

View File

@ -11,6 +11,7 @@
#include <Window.h> #include <Window.h>
#include "MediaPlayer.h" #include "MediaPlayer.h"
#include "Util.h"
ReplicantView::ReplicantView(BRect frame, const char* name, uint32 draggerPlacement, uint32 resize, 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); fDragger->SetViewColor(B_TRANSPARENT_COLOR);
AddChild(fDragger); AddChild(fDragger);
fInactive = true;
fReplicated = false;
fTransparentInactivity = false; fTransparentInactivity = false;
fTransparentDragger = false; fTransparentDragger = false;
fInactive = true;
fMediaPlayer = new MediaPlayer(0); fMediaPlayer = new MediaPlayer(0);
} }
@ -49,7 +52,9 @@ ReplicantView::ReplicantView(BMessage* data)
fTransparentInactivity = data->GetBool("transparent_inactivity", true); fTransparentInactivity = data->GetBool("transparent_inactivity", true);
fTransparentDragger = data->GetBool("transparent_dragger", false); fTransparentDragger = data->GetBool("transparent_dragger", false);
fInactive = true; fInactive = true;
fReplicated = true;
} }
@ -93,6 +98,9 @@ ReplicantView::MessageReceived(BMessage* msg)
SetInactive(fInactive); SetInactive(fInactive);
break; break;
} }
case B_ABOUT_REQUESTED:
show_about_window(fDescription.String());
break;
default: default:
BView::MessageReceived(msg); BView::MessageReceived(msg);
break; break;
@ -140,6 +148,20 @@ ReplicantView::RightClickPopUp(BPopUpMenu* menu)
hideDragger->SetTarget(this); hideDragger->SetTarget(this);
hideMenu->AddItem(hideDragger); 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; return menu;
} }

View File

@ -53,10 +53,15 @@ public:
// Set inactivity state, re-render accordingly // Set inactivity state, re-render accordingly
virtual void SetInactive(bool inactive); virtual void SetInactive(bool inactive);
protected:
MediaPlayer* fMediaPlayer; MediaPlayer* fMediaPlayer;
BDragger* fDragger; BDragger* fDragger;
BString fDescription;
bool fReplicated;
bool fInactive; bool fInactive;
bool fTransparentInactivity; bool fTransparentInactivity;
bool fTransparentDragger; bool fTransparentDragger;
}; };

28
src/Util.cpp Normal file
View File

@ -0,0 +1,28 @@
/*
* Copyright 2022, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "Util.h"
#include <AboutWindow.h>
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();
}

12
src/Util.h Normal file
View File

@ -0,0 +1,12 @@
/*
* Copyright 2022, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef UTIL_H
#define UTIL_H
#include <SupportDefs.h>
void show_about_window(const char* description);
#endif // UTIL_H

View File

@ -12,6 +12,9 @@
#include "MediaPlayer.h" #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 // The same color MediaPlayer uses, interface/VolumeSlider
static const rgb_color kVolumeGreen = (rgb_color){ 116, 224, 0, 255 }; 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) ReplicantView(frame, "Volume", B_FOLLOW_RIGHT, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS)
{ {
fDescription.SetTo(kVolumeDesc);
_InitInterface(); _InitInterface();
Pulse(); Pulse();
} }
@ -31,6 +36,8 @@ VolumeView::VolumeView(BMessage* data)
: :
ReplicantView(data) ReplicantView(data)
{ {
fDescription.SetTo(kVolumeDesc);
// For some reason, the BSlider gets archived with a wacko frame― better to just nuke it. // For some reason, the BSlider gets archived with a wacko frame― better to just nuke it.
fSlider = dynamic_cast<BSlider*>(FindView("volumeSlider")); fSlider = dynamic_cast<BSlider*>(FindView("volumeSlider"));
delete fSlider; delete fSlider;