diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index 1f16035..680f2cd 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -286,6 +286,7 @@ ConversationView::_InitInterface() fIcon->SetExplicitMinSize(BSize(50, 50)); fIcon->SetExplicitPreferredSize(BSize(50, 50)); fIcon->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE)); + fIcon->SetSquare(true); fProtocolView = new BitmapView("protocolView"); diff --git a/libs/libinterface/BitmapView.cpp b/libs/libinterface/BitmapView.cpp index 793635d..2f463d9 100644 --- a/libs/libinterface/BitmapView.cpp +++ b/libs/libinterface/BitmapView.cpp @@ -22,6 +22,7 @@ BitmapView::BitmapView(const char* name, uint32 flags) : BView(name, flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE), fBitmap(NULL), + fIsSquare(false), fWidth(kMinWidth), fHeight(kMinHeight) { @@ -97,6 +98,13 @@ BitmapView::SetBitmap(const BBitmap* bitmap) } +void +BitmapView::SetSquare(bool isSquare) +{ + fIsSquare = isSquare; +} + + BSize BitmapView::MinSize() { @@ -131,5 +139,30 @@ BitmapView::Draw(BRect frame) SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); DrawBitmap(fBitmap, fBitmap->Bounds(), - Bounds(), B_FILTER_BITMAP_BILINEAR); + _ViewBounds(), B_FILTER_BITMAP_BILINEAR); +} + + +BRect +BitmapView::_ViewBounds() +{ + BRect bounds = Bounds(); + if (fIsSquare == false || bounds.Height() == bounds.Width()) + return bounds; + + BPoint lt = bounds.LeftTop(); + BPoint rb = bounds.RightBottom(); + float diff = 0.0; + + if (bounds.Height() > bounds.Width()) { + diff = bounds.Height() - bounds.Width(); + lt -= BPoint(0.0, diff / 2); + rb += BPoint(0.0, diff / 2); + } + else if (bounds.Width() > bounds.Height()) { + diff = bounds.Height() - bounds.Width(); + lt -= BPoint(diff / 2, 0.0); + rb += BPoint(diff / 2, 0.0); + } + return BRect(lt, rb); } diff --git a/libs/libinterface/BitmapView.h b/libs/libinterface/BitmapView.h index afb2746..29451d3 100644 --- a/libs/libinterface/BitmapView.h +++ b/libs/libinterface/BitmapView.h @@ -23,6 +23,7 @@ public: status_t SetBitmap(const char* filename); status_t SetBitmap(const BBitmap* bitmap); + void SetSquare(bool isSquare); virtual BSize MinSize(); virtual BSize MaxSize(); @@ -31,7 +32,10 @@ public: virtual void Draw(BRect frame); private: + BRect _ViewBounds(); + BBitmap* fBitmap; + bool fIsSquare; float fWidth; float fHeight; };