From 347a5fe6be4868e9017b4418be67f1e45e830187 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sat, 4 Jun 2022 12:18:52 -0500 Subject: [PATCH] Add "square-resize" menu option for CoverView --- src/CoverView.cpp | 65 +++++++++++++++++++++++++++++++++++++++++-- src/CoverView.h | 22 ++++++++------- src/LyricsView.cpp | 2 +- src/LyricsView.h | 2 -- src/ReplicantView.cpp | 4 +-- src/ReplicantView.h | 3 +- 6 files changed, 79 insertions(+), 19 deletions(-) diff --git a/src/CoverView.cpp b/src/CoverView.cpp index 12b1114..dbf8049 100644 --- a/src/CoverView.cpp +++ b/src/CoverView.cpp @@ -6,15 +6,19 @@ #include "CoverView.h" #include -#include -#include +#include +#include +#include #include "MediaPlayer.h" +const uint32 COVER_MAKE_SQUARE = 'cvsq'; + + CoverView::CoverView(BRect frame) : - ReplicantView(frame, "Cover", B_FOLLOW_LEFT) + ReplicantView(frame, "Cover", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE, B_FOLLOW_RIGHT) { SetViewColor(B_TRANSPARENT_COLOR); fCover = NULL; @@ -52,6 +56,16 @@ CoverView::Instantiate(BMessage* data) } +void +CoverView::MessageReceived(BMessage* msg) +{ + if (msg->what == COVER_MAKE_SQUARE) + _MakeSquare(); + else + ReplicantView::MessageReceived(msg); +} + + void CoverView::Pulse() { @@ -77,6 +91,24 @@ CoverView::Pulse() } +BPopUpMenu* +CoverView::RightClickPopUp(BPopUpMenu* menu) +{ + BPopUpMenu* newMenu = ReplicantView::RightClickPopUp(menu); + newMenu->ItemAt(0)->SetEnabled(false); + newMenu->ItemAt(0)->SetMarked(false); + + BMenuItem* square = new BMenuItem("Resize to square", + new BMessage(COVER_MAKE_SQUARE)); + square->SetMarked(_IsSquare()); + square->SetEnabled(!_IsSquare()); + square->SetTarget(this); + newMenu->AddItem(square, 0); + + return newMenu; +} + + void CoverView::Draw(BRect updateRect) { @@ -84,3 +116,30 @@ CoverView::Draw(BRect updateRect) if (fCover != NULL && fCover->IsValid()) DrawBitmap(fCover, Bounds()); } + + +bool +CoverView::_IsSquare() +{ + return floorf(Frame().Width()) == floorf(Frame().Height()); +} + + +void +CoverView::_MakeSquare() +{ + if (_IsSquare()) + return; + + ResizeTo(Frame().Height(), Frame().Height()); + + // If in MediaMonitor's window, resize the window too. + // (We don't want to resize Tracker, or other shelves!) + if (Parent() != NULL && Parent()->Parent() != NULL) { + BRect pRect = Parent()->Parent()->Frame(); + if (strcmp(Parent()->Parent()->Name(), "appletTabView") == 0 + && pRect.Width() < Frame().Width() || pRect.Height() < Frame().Height()) + Window()->ResizeBy(Frame().Width() - pRect.Width(), + Frame().Height() - pRect.Height()); + } +} diff --git a/src/CoverView.h b/src/CoverView.h index c39f9a0..9579eb0 100644 --- a/src/CoverView.h +++ b/src/CoverView.h @@ -8,24 +8,26 @@ #include "ReplicantView.h" #include "Song.h" -class BDragger; -class MediaPlayer; - class CoverView : public ReplicantView { public: - CoverView(BRect frame); - CoverView(BMessage* archive); + CoverView(BRect frame); + CoverView(BMessage* archive); - virtual status_t Archive(BMessage* data, bool deep = true) const; - static CoverView* Instantiate(BMessage* data); + virtual status_t Archive(BMessage* data, bool deep = true) const; + static CoverView* Instantiate(BMessage* data); - virtual void Pulse(); + virtual void MessageReceived(BMessage* msg); - virtual void Draw(BRect updateRect); + virtual void Pulse(); + + virtual BPopUpMenu* RightClickPopUp(BPopUpMenu* menu = NULL); + + virtual void Draw(BRect updateRect); private: - void _Init(BRect frame); + bool _IsSquare(); + void _MakeSquare(); Song fCurrentSong; BBitmap* fCover; diff --git a/src/LyricsView.cpp b/src/LyricsView.cpp index 6bb680d..4c2fa09 100644 --- a/src/LyricsView.cpp +++ b/src/LyricsView.cpp @@ -63,7 +63,7 @@ LyricsTextView::MouseDown(BPoint where) LyricsView::LyricsView(BRect frame) : - ReplicantView(frame, "Lyrics", B_FOLLOW_LEFT) + ReplicantView(frame, "Lyrics", 0, B_FOLLOW_LEFT) { BRect textRect(0, 0, Bounds().Width(), Bounds().Height() - 10); fTextView = new LyricsTextView(textRect, "lyricsText", textRect, diff --git a/src/LyricsView.h b/src/LyricsView.h index 8af07d9..fe55274 100644 --- a/src/LyricsView.h +++ b/src/LyricsView.h @@ -10,10 +10,8 @@ #include "ReplicantView.h" #include "Song.h" -class BDragger; class BPopUpMenu; class BScrollView; -class MediaPlayer; enum { diff --git a/src/ReplicantView.cpp b/src/ReplicantView.cpp index e4894e5..396ec19 100644 --- a/src/ReplicantView.cpp +++ b/src/ReplicantView.cpp @@ -13,9 +13,9 @@ #include "MediaPlayer.h" -ReplicantView::ReplicantView(BRect frame, const char* name, uint32 draggerPlacement) +ReplicantView::ReplicantView(BRect frame, const char* name, uint32 flags, uint32 draggerPlacement) : - BView(frame, name, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_TRANSPARENT_BACKGROUND | B_PULSE_NEEDED) + BView(frame, name, B_FOLLOW_ALL_SIDES, B_TRANSPARENT_BACKGROUND | B_PULSE_NEEDED | flags) { BRect dragRect(frame.Width() - 10, 0, frame.Width(), frame.Height()); uint32 dragFollow = B_FOLLOW_RIGHT; diff --git a/src/ReplicantView.h b/src/ReplicantView.h index ee9715e..ff3fe09 100644 --- a/src/ReplicantView.h +++ b/src/ReplicantView.h @@ -32,7 +32,8 @@ enum { - MediaPlayer object */ class ReplicantView : public BView { public: - ReplicantView(BRect frame, const char* name, uint32 draggerPlacement); + ReplicantView(BRect frame, const char* name, uint32 flags, + uint32 draggerPlacement); ReplicantView(BMessage* archive); virtual status_t Archive(BMessage* data, bool deep = true) const;