diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index 736e040116..75658a887d 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -56,8 +56,6 @@ class PopUpMenu : public BPopUpMenu { #define SHOW_IMAGE_ORIENTATION_ATTRIBUTE "ShowImage:orientation" -#define BORDER_WIDTH 16 -#define BORDER_HEIGHT 16 const rgb_color kBorderColor = { 0, 0, 0, 255 }; enum ShowImageView::image_orientation @@ -181,9 +179,7 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode, fHasSelection = false; fShrinkToBounds = false; fZoomToBounds = false; - fHasBorder = true; - fHAlignment = B_ALIGN_CENTER; - fVAlignment = B_ALIGN_MIDDLE; + fFullScreen = false; fSlideShow = false; fSlideShowDelay = 3 * 10; // 3 seconds fShowCaption = false; @@ -302,7 +298,7 @@ ShowImageView::Pulse() } // Hide cursor in full screen mode - if (!fHasBorder && !fShowingPopUpMenu) + if (fFullScreen && !fShowingPopUpMenu) be_app->ObscureCursor(); #if DELAYED_SCALING @@ -608,30 +604,15 @@ ShowImageView::SetZoomToBounds(bool enable) void -ShowImageView::SetBorder(bool hasBorder) +ShowImageView::SetFullScreen(bool fullScreen) { - if (fHasBorder != hasBorder) { - fHasBorder = hasBorder; - if (fHasBorder) - SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - else { + if (fFullScreen != fullScreen) { + fFullScreen = fullScreen; + if (fFullScreen) { SetLowColor(0, 0, 0, 255); be_app->ObscureCursor(); - } - FixupScrollBars(); - Invalidate(); - } -} - - -void -ShowImageView::SetAlignment(alignment horizontal, vertical_alignment vertical) -{ - if (fHAlignment != horizontal || fVAlignment != vertical) { - fHAlignment = horizontal; - fVAlignment = vertical; - FixupScrollBars(); - Invalidate(); + } else + SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); } } @@ -667,14 +648,6 @@ ShowImageView::GetPath(BString *outPath) } -void -ShowImageView::FlushToLeftTop() -{ - BRect rect = AlignBitmap(); - ScrollTo(rect.LeftTop()); -} - - void ShowImageView::SetScaleBilinear(bool enabled) { @@ -729,57 +702,20 @@ ShowImageView::AlignBitmap() rect.OffsetBy(static_cast((width - rect.Width()) / 2), 0); } } else { - float zoom; - if (fShrinkToBounds || fZoomToBounds) { - // ignore user zoom setting in automatic zoom modes - zoom = 1.0; - } else { - zoom = fZoom; - } - // zoom image - rect.right = floorf(bitmapWidth * zoom) - 1; - rect.bottom = floorf(bitmapHeight * zoom) - 1; + rect.right = floorf(bitmapWidth * fZoom) - 1; + rect.bottom = floorf(bitmapHeight * fZoom) - 1; // update the bitmap size after the zoom bitmapWidth = rect.Width() + 1.0; bitmapHeight = rect.Height() + 1.0; - // align - switch (fHAlignment) { - case B_ALIGN_CENTER: - if (width > bitmapWidth) { - rect.OffsetBy((width - bitmapWidth) / 2.0, 0); - break; - } - // fall through - default: - case B_ALIGN_LEFT: - if (fHasBorder) { - float border = min_c(BORDER_WIDTH, width - bitmapWidth); - if (border < 0) - border = 0; - rect.OffsetBy(border, 0); - } - break; - } - switch (fVAlignment) { - case B_ALIGN_MIDDLE: - if (height > bitmapHeight) { - rect.OffsetBy(0, (height - bitmapHeight) / 2.0); - break; - } - // fall through - default: - case B_ALIGN_TOP: - if (fHasBorder) { - float border = min_c(BORDER_WIDTH, height - bitmapHeight); - if (border < 0) - border = 0; - rect.OffsetBy(0, border); - } - break; - } + // always align in the center + if (width > bitmapWidth) + rect.OffsetBy((width - bitmapWidth) / 2.0, 0); + + if (height > bitmapHeight) + rect.OffsetBy(0, (height - bitmapHeight) / 2.0); } rect.OffsetBy(PEN_SIZE, PEN_SIZE); return rect; @@ -791,16 +727,14 @@ ShowImageView::Setup(BRect rect) { fLeft = floorf(rect.left); fTop = floorf(rect.top); - fScaleX = (rect.Width()+1.0) / (fBitmap->Bounds().Width()+1.0); - fScaleY = (rect.Height()+1.0) / (fBitmap->Bounds().Height()+1.0); } BPoint ShowImageView::ImageToView(BPoint p) const { - p.x = floorf(fScaleX * p.x + fLeft); - p.y = floorf(fScaleY * p.y + fTop); + p.x = floorf(fZoom * p.x + fLeft); + p.y = floorf(fZoom * p.y + fTop); return p; } @@ -808,8 +742,8 @@ ShowImageView::ImageToView(BPoint p) const BPoint ShowImageView::ViewToImage(BPoint p) const { - p.x = floorf((p.x - fLeft) / fScaleX); - p.y = floorf((p.y - fTop) / fScaleY); + p.x = floorf((p.x - fLeft) / fZoom); + p.y = floorf((p.y - fTop) / fZoom); return p; } @@ -1063,8 +997,8 @@ ShowImageView::CopySelection(uchar alpha, bool imageSize) BRect rect(0, 0, fSelectionRect.Width(), fSelectionRect.Height()); if (!imageSize) { // scale image to view size - rect.right = floorf((rect.right + 1.0) * fScaleX - 1.0); - rect.bottom = floorf((rect.bottom + 1.0) * fScaleY - 1.0); + rect.right = floorf((rect.right + 1.0) * fZoom - 1.0); + rect.bottom = floorf((rect.bottom + 1.0) * fZoom - 1.0); } BView view(rect, NULL, B_FOLLOW_NONE, B_WILL_DRAW); BBitmap *bitmap = new(nothrow) BBitmap(rect, hasAlpha ? B_RGBA32 : fBitmap->ColorSpace(), true); @@ -1150,11 +1084,11 @@ ShowImageView::BeginDrag(BPoint sourcePoint) // avoid flickering of dragged bitmap caused by drawing into the window AnimateSelection(false); // only use a transparent bitmap on selections less than 400x400 (taking into account scaling) - if ((fSelectionRect.Width() * fScaleX) < 400.0 && (fSelectionRect.Height() * fScaleY) < 400.0) + if ((fSelectionRect.Width() * fZoom) < 400.0 && (fSelectionRect.Height() * fZoom) < 400.0) { sourcePoint -= fSelectionRect.LeftTop(); - sourcePoint.x *= fScaleX; - sourcePoint.y *= fScaleY; + sourcePoint.x *= fZoom; + sourcePoint.y *= fZoom; // DragMessage takes ownership of bitmap DragMessage(&drag, bitmap, B_OP_ALPHA, sourcePoint); bitmap = NULL; @@ -1804,9 +1738,6 @@ ShowImageView::FixupScrollBar(orientation o, float bitmapLength, float viewLengt psb = ScrollBar(o); if (psb) { - if (fHasBorder && !fShrinkOrZoomToBounds && (fHAlignment == B_ALIGN_LEFT || fVAlignment == B_ALIGN_TOP)) { - bitmapLength += BORDER_WIDTH * 2; - } range = bitmapLength - viewLength; if (range < 0.0) { range = 0.0; @@ -2430,7 +2361,19 @@ ShowImageView::DoImageOperation(ImageProcessor::operation op, bool quiet) if (!quiet) { // remove selection SetHasSelection(false); - Notify(NULL); + // Pull the image type name from fCaption (hackish?) + int32 last_comma_index = fCaption.FindLast(','); + if (last_comma_index != B_ERROR) { + // The -1 at the end is -2 to get rid of the comma and space, +1 for the \0 + int32 name_size = fCaption.CountChars() - last_comma_index - 1; + char *name = new char[name_size]; + fCaption.CopyInto(name, last_comma_index + 2, name_size - 1); + name[name_size - 1] = '\0'; + Notify(name); + delete name; + } + else + Notify(NULL); } } diff --git a/src/apps/showimage/ShowImageView.h b/src/apps/showimage/ShowImageView.h index 8bec416624..8f3a20c9a8 100644 --- a/src/apps/showimage/ShowImageView.h +++ b/src/apps/showimage/ShowImageView.h @@ -57,13 +57,10 @@ class ShowImageView : public BView { bool GetShrinkToBounds() const { return fShrinkToBounds; } void SetZoomToBounds(bool enable); bool GetZoomToBounds() const { return fZoomToBounds; } - void SetBorder(bool hasBorder); - bool HasBorder() const { return fHasBorder; } - void SetAlignment(alignment horizontal, vertical_alignment vertical); + void SetFullScreen(bool fullScreen); BBitmap *GetBitmap(); void GetName(BString *name); void GetPath(BString *name); - void FlushToLeftTop(); void SetScaleBilinear(bool b); bool GetScaleBilinear() { return fScaleBilinear; } @@ -206,13 +203,9 @@ class ShowImageView : public BView { bool fShrinkToBounds; bool fZoomToBounds; bool fShrinkOrZoomToBounds; - bool fHasBorder; // should the image have a border? - alignment fHAlignment; // horizontal alignment (left and centered only) - vertical_alignment fVAlignment; // vertical alignment (left and centered only) + bool fFullScreen; // is the image displayed fullscreen? float fLeft; // the origin of the image in the view float fTop; - float fScaleX; // to convert image from/to view coordinates - float fScaleY; bool fMovesImage; // is the image being moved with the mouse bool fMakesSelection; // is a selection being made BPoint fFirstPoint; // first point in image space of selection diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index fbbc8f4adf..0887c7329a 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -156,7 +156,6 @@ ShowImageWindow::ShowImageWindow(const entry_ref *ref, SetPulseRate(100000); // every 1/10 second; ShowImageView needs it for marching ants - fImageView->FlushToLeftTop(); WindowRedimension(fImageView->GetBitmap()); fImageView->MakeFocus(true); // to receive KeyDown messages Show(); @@ -230,7 +229,7 @@ ShowImageWindow::BuildViewMenu(BMenu *menu) menu->AddSeparatorItem(); AddItemMenu(menu, "Original Size", MSG_ORIGINAL_SIZE, 0, 0, 'W', true); - AddItemMenu(menu, "Zoom In", MSG_ZOOM_IN, '+', 0, 'W', true); + AddItemMenu(menu, "Zoom In", MSG_ZOOM_IN, '=', 0, 'W', true); AddItemMenu(menu, "Zoom Out", MSG_ZOOM_OUT, '-', 0, 'W', true); menu->AddSeparatorItem(); @@ -934,7 +933,6 @@ ShowImageWindow::ToggleFullScreen() frame.InsetBy(-1, -1); // PEN_SIZE in ShowImageView SetFlags(Flags() | B_NOT_RESIZABLE | B_NOT_MOVABLE); - fImageView->SetAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE); Activate(); // make the window frontmost @@ -942,14 +940,9 @@ ShowImageWindow::ToggleFullScreen() frame = fWindowFrame; SetFlags(Flags() & ~(B_NOT_RESIZABLE | B_NOT_MOVABLE)); -// NOTE: I changed this to not use left/top alignment at all, because -// I have no idea why it would be useful. The layouting is much more -// predictable now. -Stephan -// fImageView->SetAlignment(B_ALIGN_LEFT, B_ALIGN_TOP); - fImageView->SetAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE); } - fImageView->SetBorder(!fFullScreen); + fImageView->SetFullScreen(fFullScreen); fImageView->SetShowCaption(fFullScreen && fShowCaption); MoveTo(frame.left, frame.top); ResizeTo(frame.Width(), frame.Height());