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 <Bitmap.h>
#include <Dragger.h>
#include <Messenger.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <Window.h>
#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());
}
}

View File

@ -8,9 +8,6 @@
#include "ReplicantView.h"
#include "Song.h"
class BDragger;
class MediaPlayer;
class CoverView : public ReplicantView {
public:
@ -20,12 +17,17 @@ public:
virtual status_t Archive(BMessage* data, bool deep = true) const;
static CoverView* Instantiate(BMessage* data);
virtual void MessageReceived(BMessage* msg);
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;

View File

@ -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,

View File

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

View File

@ -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;

View File

@ -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;