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
This commit is contained in:
Ryan Leavengood 2007-01-29 20:29:16 +00:00
parent 923ce6f922
commit 8f5fd23f60
4 changed files with 45 additions and 9 deletions

View File

@ -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 void
ShowImageView::AddToRecentDocuments() ShowImageView::AddToRecentDocuments()
{ {
@ -1480,7 +1499,8 @@ ShowImageView::UpdateSelectionRect(BPoint point, bool final)
// selection must be at least 2 pixels wide or 2 pixels tall // selection must be at least 2 pixels wide or 2 pixels tall
if (fCopyFromRect.Width() < 1.0 && fCopyFromRect.Height() < 1.0) if (fCopyFromRect.Width() < 1.0 && fCopyFromRect.Height() < 1.0)
SetHasSelection(false); SetHasSelection(false);
} } else
UpdateStatusText();
if (oldSelection != fCopyFromRect || !HasSelection()) { if (oldSelection != fCopyFromRect || !HasSelection()) {
BRect updateRect; BRect updateRect;
@ -1866,9 +1886,9 @@ ShowImageView::Undo()
if (!undoSelection) if (!undoSelection)
SetHasSelection(false); SetHasSelection(false);
else { else {
SetHasSelection(true);
fCopyFromRect = BRect(); fCopyFromRect = BRect();
fSelectionRect = fUndo.GetRect(); fSelectionRect = fUndo.GetRect();
SetHasSelection(true);
fSelBitmap = undoSelection; fSelBitmap = undoSelection;
} }
@ -1952,10 +1972,10 @@ ShowImageView::PasteBitmap(BBitmap *bitmap, BPoint point)
if (bitmap && bitmap->IsValid()) { if (bitmap && bitmap->IsValid()) {
MergeSelection(); MergeSelection();
SetHasSelection(true);
fSelBitmap = bitmap;
fCopyFromRect = BRect(); fCopyFromRect = BRect();
fSelectionRect = bitmap->Bounds(); fSelectionRect = bitmap->Bounds();
SetHasSelection(true);
fSelBitmap = bitmap;
BRect offsetRect = fSelectionRect; BRect offsetRect = fSelectionRect;
offsetRect.OffsetBy(point); offsetRect.OffsetBy(point);
@ -2017,6 +2037,8 @@ ShowImageView::SetHasSelection(bool bHasSelection)
DeleteSelBitmap(); DeleteSelBitmap();
fHasSelection = bHasSelection; fHasSelection = bHasSelection;
UpdateStatusText();
BMessage msg(MSG_SELECTION); BMessage msg(MSG_SELECTION);
msg.AddBool("has_selection", fHasSelection); msg.AddBool("has_selection", fHasSelection);
SendMessageToWindow(&msg); SendMessageToWindow(&msg);

View File

@ -136,6 +136,7 @@ class ShowImageView : public BView {
void SendMessageToWindow(BMessage *message); void SendMessageToWindow(BMessage *message);
void SendMessageToWindow(uint32 code); void SendMessageToWindow(uint32 code);
void Notify(); void Notify();
void UpdateStatusText();
void AddToRecentDocuments(); void AddToRecentDocuments();
void AddWhiteRect(BRect &rect); void AddWhiteRect(BRect &rect);
void GetMergeRects(BBitmap *merge, BRect selection, BRect &srcBits, BRect &destRect); void GetMergeRects(BBitmap *merge, BRect selection, BRect &srcBits, BRect &destRect);

View File

@ -97,6 +97,7 @@ ShowImageWindow::ShowImageWindow(const entry_ref *ref,
fImageView = NULL; fImageView = NULL;
fSlideShowDelay = NULL; fSlideShowDelay = NULL;
fResizerWindowMessenger = NULL; fResizerWindowMessenger = NULL;
fHeight = fWidth = 0;
LoadSettings(); LoadSettings();
@ -591,10 +592,9 @@ ShowImageWindow::MessageReceived(BMessage *message)
BString status; BString status;
bool messageProvidesSize = false; bool messageProvidesSize = false;
int32 width, height; if (message->FindInt32("width", &fWidth) >= B_OK
if (message->FindInt32("width", &width) >= B_OK && message->FindInt32("height", &fHeight) >= B_OK) {
&& message->FindInt32("height", &height) >= B_OK) { status << fWidth << "x" << fHeight;
status << width << "x" << height;
messageProvidesSize = true; messageProvidesSize = true;
} }
@ -606,7 +606,7 @@ ShowImageWindow::MessageReceived(BMessage *message)
} }
if (messageProvidesSize) { if (messageProvidesSize) {
UpdateResizerWindow(width, height); UpdateResizerWindow(fWidth, fHeight);
} }
fStatusView->SetText(status); fStatusView->SetText(status);
@ -615,6 +615,18 @@ ShowImageWindow::MessageReceived(BMessage *message)
break; 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: case MSG_SELECTION:
{ {
// The view sends this message when a selection is // The view sends this message when a selection is

View File

@ -98,6 +98,7 @@ class ShowImageWindow : public BWindow {
BMessage *fPrintSettings; BMessage *fPrintSettings;
PrintOptions fPrintOptions; PrintOptions fPrintOptions;
BMessenger* fResizerWindowMessenger; BMessenger* fResizerWindowMessenger;
int32 fHeight, fWidth;
}; };
#endif // SHOW_IMAGE_WINDOW_H #endif // SHOW_IMAGE_WINDOW_H