Add "square-resize" menu option for CoverView

This commit is contained in:
Jaidyn Ann 2022-06-04 12:18:52 -05:00
parent d249b25df1
commit 347a5fe6be
6 changed files with 79 additions and 19 deletions

View File

@ -6,15 +6,19 @@
#include "CoverView.h" #include "CoverView.h"
#include <Bitmap.h> #include <Bitmap.h>
#include <Dragger.h> #include <MenuItem.h>
#include <Messenger.h> #include <PopUpMenu.h>
#include <Window.h>
#include "MediaPlayer.h" #include "MediaPlayer.h"
const uint32 COVER_MAKE_SQUARE = 'cvsq';
CoverView::CoverView(BRect frame) 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); SetViewColor(B_TRANSPARENT_COLOR);
fCover = NULL; 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 void
CoverView::Pulse() 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 void
CoverView::Draw(BRect updateRect) CoverView::Draw(BRect updateRect)
{ {
@ -84,3 +116,30 @@ CoverView::Draw(BRect updateRect)
if (fCover != NULL && fCover->IsValid()) if (fCover != NULL && fCover->IsValid())
DrawBitmap(fCover, Bounds()); 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());
}
}

View File

@ -8,24 +8,26 @@
#include "ReplicantView.h" #include "ReplicantView.h"
#include "Song.h" #include "Song.h"
class BDragger;
class MediaPlayer;
class CoverView : public ReplicantView { class CoverView : public ReplicantView {
public: public:
CoverView(BRect frame); CoverView(BRect frame);
CoverView(BMessage* archive); CoverView(BMessage* archive);
virtual status_t Archive(BMessage* data, bool deep = true) const; virtual status_t Archive(BMessage* data, bool deep = true) const;
static CoverView* Instantiate(BMessage* data); 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: private:
void _Init(BRect frame); bool _IsSquare();
void _MakeSquare();
Song fCurrentSong; Song fCurrentSong;
BBitmap* fCover; BBitmap* fCover;

View File

@ -63,7 +63,7 @@ LyricsTextView::MouseDown(BPoint where)
LyricsView::LyricsView(BRect frame) 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); BRect textRect(0, 0, Bounds().Width(), Bounds().Height() - 10);
fTextView = new LyricsTextView(textRect, "lyricsText", textRect, fTextView = new LyricsTextView(textRect, "lyricsText", textRect,

View File

@ -10,10 +10,8 @@
#include "ReplicantView.h" #include "ReplicantView.h"
#include "Song.h" #include "Song.h"
class BDragger;
class BPopUpMenu; class BPopUpMenu;
class BScrollView; class BScrollView;
class MediaPlayer;
enum { enum {

View File

@ -13,9 +13,9 @@
#include "MediaPlayer.h" #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()); BRect dragRect(frame.Width() - 10, 0, frame.Width(), frame.Height());
uint32 dragFollow = B_FOLLOW_RIGHT; uint32 dragFollow = B_FOLLOW_RIGHT;

View File

@ -32,7 +32,8 @@ enum {
- MediaPlayer object */ - MediaPlayer object */
class ReplicantView : public BView { class ReplicantView : public BView {
public: public:
ReplicantView(BRect frame, const char* name, uint32 draggerPlacement); ReplicantView(BRect frame, const char* name, uint32 flags,
uint32 draggerPlacement);
ReplicantView(BMessage* archive); ReplicantView(BMessage* archive);
virtual status_t Archive(BMessage* data, bool deep = true) const; virtual status_t Archive(BMessage* data, bool deep = true) const;