From 8f5fd23f6012a9852853f83b61d9236184b8f412 Mon Sep 17 00:00:00 2001 From: Ryan Leavengood Date: Mon, 29 Jan 2007 20:29:16 +0000 Subject: [PATCH] The size of the selection rectangle is now shown in the status bar. Useful for cropping an image to a certain size or taking similar sized croppings from various images (as I need to do.) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20012 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/showimage/ShowImageView.cpp | 30 ++++++++++++++++++++++---- src/apps/showimage/ShowImageView.h | 1 + src/apps/showimage/ShowImageWindow.cpp | 22 ++++++++++++++----- src/apps/showimage/ShowImageWindow.h | 1 + 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index 8390c04a91..161e625f4d 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -402,6 +402,25 @@ ShowImageView::Notify() } +void +ShowImageView::UpdateStatusText() +{ + BMessage msg(MSG_UPDATE_STATUS_TEXT); + BString status_to_send = fImageType; + + if (fHasSelection) { + char size[50]; + sprintf(size, " (%.0fx%.0f)", + fSelectionRect.Width()+1.0, + fSelectionRect.Height()+1.0); + status_to_send << size; + } + + msg.AddString("status", status_to_send.String()); + SendMessageToWindow(&msg); +} + + void ShowImageView::AddToRecentDocuments() { @@ -1480,7 +1499,8 @@ ShowImageView::UpdateSelectionRect(BPoint point, bool final) // selection must be at least 2 pixels wide or 2 pixels tall if (fCopyFromRect.Width() < 1.0 && fCopyFromRect.Height() < 1.0) SetHasSelection(false); - } + } else + UpdateStatusText(); if (oldSelection != fCopyFromRect || !HasSelection()) { BRect updateRect; @@ -1866,9 +1886,9 @@ ShowImageView::Undo() if (!undoSelection) SetHasSelection(false); else { - SetHasSelection(true); fCopyFromRect = BRect(); fSelectionRect = fUndo.GetRect(); + SetHasSelection(true); fSelBitmap = undoSelection; } @@ -1952,10 +1972,10 @@ ShowImageView::PasteBitmap(BBitmap *bitmap, BPoint point) if (bitmap && bitmap->IsValid()) { MergeSelection(); - SetHasSelection(true); - fSelBitmap = bitmap; fCopyFromRect = BRect(); fSelectionRect = bitmap->Bounds(); + SetHasSelection(true); + fSelBitmap = bitmap; BRect offsetRect = fSelectionRect; offsetRect.OffsetBy(point); @@ -2016,6 +2036,8 @@ ShowImageView::SetHasSelection(bool bHasSelection) { DeleteSelBitmap(); fHasSelection = bHasSelection; + + UpdateStatusText(); BMessage msg(MSG_SELECTION); msg.AddBool("has_selection", fHasSelection); diff --git a/src/apps/showimage/ShowImageView.h b/src/apps/showimage/ShowImageView.h index bb9c87e1d1..db5b88198e 100644 --- a/src/apps/showimage/ShowImageView.h +++ b/src/apps/showimage/ShowImageView.h @@ -136,6 +136,7 @@ class ShowImageView : public BView { void SendMessageToWindow(BMessage *message); void SendMessageToWindow(uint32 code); void Notify(); + void UpdateStatusText(); void AddToRecentDocuments(); void AddWhiteRect(BRect &rect); void GetMergeRects(BBitmap *merge, BRect selection, BRect &srcBits, BRect &destRect); diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index db9bf7b229..46383129c8 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -97,6 +97,7 @@ ShowImageWindow::ShowImageWindow(const entry_ref *ref, fImageView = NULL; fSlideShowDelay = NULL; fResizerWindowMessenger = NULL; + fHeight = fWidth = 0; LoadSettings(); @@ -591,10 +592,9 @@ ShowImageWindow::MessageReceived(BMessage *message) BString status; bool messageProvidesSize = false; - int32 width, height; - if (message->FindInt32("width", &width) >= B_OK - && message->FindInt32("height", &height) >= B_OK) { - status << width << "x" << height; + if (message->FindInt32("width", &fWidth) >= B_OK + && message->FindInt32("height", &fHeight) >= B_OK) { + status << fWidth << "x" << fHeight; messageProvidesSize = true; } @@ -606,7 +606,7 @@ ShowImageWindow::MessageReceived(BMessage *message) } if (messageProvidesSize) { - UpdateResizerWindow(width, height); + UpdateResizerWindow(fWidth, fHeight); } fStatusView->SetText(status); @@ -615,6 +615,18 @@ ShowImageWindow::MessageReceived(BMessage *message) break; } + case MSG_UPDATE_STATUS_TEXT: + { + BString status; + status << fWidth << "x" << fHeight; + BString str; + if (message->FindString("status", &str) == B_OK && str.Length() > 0) { + status << ", " << str; + fStatusView->SetText(status); + } + break; + } + case MSG_SELECTION: { // The view sends this message when a selection is diff --git a/src/apps/showimage/ShowImageWindow.h b/src/apps/showimage/ShowImageWindow.h index 0e0e8ad0fb..ae17bae432 100644 --- a/src/apps/showimage/ShowImageWindow.h +++ b/src/apps/showimage/ShowImageWindow.h @@ -98,6 +98,7 @@ class ShowImageWindow : public BWindow { BMessage *fPrintSettings; PrintOptions fPrintOptions; BMessenger* fResizerWindowMessenger; + int32 fHeight, fWidth; }; #endif // SHOW_IMAGE_WINDOW_H