From 554e2073842e023e35e1523fba025f30574fe137 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Mon, 28 Apr 2014 22:00:45 +0200 Subject: [PATCH] ShowImage: add feature to force original size. * This is enabled by shift+click on the Original Size toolbar button. * The button stays pressed as long as the feature is enabled. Clicking it again disables it. * When this is enabled, all images will be shown at original size, instead of being scaled up or down to fit the window. * This is not persistent, and only affects the current session/window. --- src/apps/showimage/ShowImageView.cpp | 3 +- src/apps/showimage/ShowImageView.h | 3 ++ src/apps/showimage/ShowImageWindow.cpp | 28 ++++++++++++------ src/apps/showimage/ToolBarView.cpp | 41 +++++++++++++++++++++++--- src/apps/showimage/ToolBarView.h | 6 ++-- 5 files changed, 65 insertions(+), 16 deletions(-) diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index 1a0faa431f..efc58ef7d2 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -186,6 +186,7 @@ ShowImageView::ShowImageView(BRect rect, const char* name, uint32 resizingMode, fBitmapLocationInView(0.0, 0.0), fStretchToBounds(false), + fForceOriginalSize(false), fHideCursor(false), fScrollingBitmap(false), fCreatingSelection(false), @@ -1630,7 +1631,7 @@ ShowImageView::FitToBounds() return; float fitToBoundsZoom = _FitToBoundsZoom(); - if (!fStretchToBounds && fitToBoundsZoom > 1.0f) + if (!fStretchToBounds && fitToBoundsZoom > 1.0f || fForceOriginalSize) SetZoom(1.0f); else SetZoom(fitToBoundsZoom); diff --git a/src/apps/showimage/ShowImageView.h b/src/apps/showimage/ShowImageView.h index 33f312770e..a0d207e240 100644 --- a/src/apps/showimage/ShowImageView.h +++ b/src/apps/showimage/ShowImageView.h @@ -87,6 +87,8 @@ public: void CopySelectionToClipboard(); void FitToBounds(); + void ForceOriginalSize(bool force) + { fForceOriginalSize = force; } void SetZoom(float zoom, BPoint where = BPoint(-1, -1)); float Zoom() const @@ -194,6 +196,7 @@ private: BPoint fBitmapLocationInView; bool fStretchToBounds; + bool fForceOriginalSize; bool fHideCursor; bool fScrollingBitmap; bool fCreatingSelection; diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index ca7b5a30ff..46efa71ff6 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -176,29 +177,31 @@ ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref, // fToolBarView->AddAction(MSG_FILE_OPEN, be_app, // tool_bar_icon(kIconDocumentOpen), B_TRANSLATE("Open"B_UTF8_ELLIPSIS)); fToolBarView->AddAction(MSG_FILE_PREV, this, - tool_bar_icon(kIconGoPrevious), B_TRANSLATE("Previous file")); + tool_bar_icon(kIconGoPrevious), B_TRANSLATE("Previous file"), false); fToolBarView->AddAction(MSG_FILE_NEXT, this, tool_bar_icon(kIconGoNext), - B_TRANSLATE("Next file")); + B_TRANSLATE("Next file"), false); BMessage* fullScreenSlideShow = new BMessage(MSG_SLIDE_SHOW); fullScreenSlideShow->AddBool("full screen", true); fToolBarView->AddAction(fullScreenSlideShow, this, - tool_bar_icon(kIconMediaMovieLibrary), B_TRANSLATE("Slide show")); + tool_bar_icon(kIconMediaMovieLibrary), B_TRANSLATE("Slide show"), + false); fToolBarView->AddSeparator(); fToolBarView->AddAction(MSG_SELECTION_MODE, this, tool_bar_icon(kIconDrawRectangularSelection), - B_TRANSLATE("Selection mode")); + B_TRANSLATE("Selection mode"), false); fToolBarView->AddSeparator(); fToolBarView->AddAction(kMsgOriginalSize, this, - tool_bar_icon(kIconZoomOriginal), B_TRANSLATE("Original size")); + tool_bar_icon(kIconZoomOriginal), B_TRANSLATE("Original size"), true); fToolBarView->AddAction(kMsgFitToWindow, this, - tool_bar_icon(kIconZoomFitBest), B_TRANSLATE("Fit to window")); + tool_bar_icon(kIconZoomFitBest), B_TRANSLATE("Fit to window"), false); fToolBarView->AddAction(MSG_ZOOM_IN, this, tool_bar_icon(kIconZoomIn), - B_TRANSLATE("Zoom in")); + B_TRANSLATE("Zoom in"), false); fToolBarView->AddAction(MSG_ZOOM_OUT, this, tool_bar_icon(kIconZoomOut), - B_TRANSLATE("Zoom out")); + B_TRANSLATE("Zoom out"), false); fToolBarView->AddGlue(); fToolBarView->AddAction(MSG_FULL_SCREEN, this, - tool_bar_icon(kIconViewWindowed), B_TRANSLATE("Leave full screen")); + tool_bar_icon(kIconViewWindowed), B_TRANSLATE("Leave full screen"), + false); fToolBarView->SetActionVisible(MSG_FULL_SCREEN, false); fToolBarView->ResizeTo(viewFrame.Width(), fToolBarView->MinSize().height); @@ -966,6 +969,13 @@ ShowImageWindow::MessageReceived(BMessage* message) break; case kMsgOriginalSize: + if (message->FindInt32("behavior") == BButton::B_TOGGLE_BEHAVIOR) + { + bool force = message->FindInt32("be:value"); + fImageView->ForceOriginalSize(force); + if (!force) + break; + } fImageView->SetZoom(1.0); break; diff --git a/src/apps/showimage/ToolBarView.cpp b/src/apps/showimage/ToolBarView.cpp index 3c154080dc..58c37f270a 100644 --- a/src/apps/showimage/ToolBarView.cpp +++ b/src/apps/showimage/ToolBarView.cpp @@ -10,6 +10,34 @@ #include #include +class LockableButton: public BButton +{ +public: + LockableButton(const char* name, const char* label, BMessage* message); + + void MouseDown(BPoint point); +}; + + +LockableButton::LockableButton(const char* name, const char* label, + BMessage* message) + : BButton(name, label, message) +{ +} + + +void +LockableButton::MouseDown(BPoint point) +{ + if (modifiers() & B_SHIFT_KEY || Value() == B_CONTROL_ON) + SetBehavior(B_TOGGLE_BEHAVIOR); + else + SetBehavior(B_BUTTON_BEHAVIOR); + + Message()->SetInt32("behavior", Behavior()); + BButton::MouseDown(point); +} + ToolBarView::ToolBarView(BRect frame) : @@ -44,17 +72,22 @@ ToolBarView::Hide() void ToolBarView::AddAction(uint32 command, BHandler* target, const BBitmap* icon, - const char* toolTipText) + const char* toolTipText, bool lockable) { - AddAction(new BMessage(command), target, icon, toolTipText); + AddAction(new BMessage(command), target, icon, toolTipText, lockable); } void ToolBarView::AddAction(BMessage* message, BHandler* target, - const BBitmap* icon, const char* toolTipText) + const BBitmap* icon, const char* toolTipText, bool lockable) { - BButton* button = new BButton(NULL, NULL, message); + + BButton* button; + if (lockable) + button = new LockableButton(NULL, NULL, message); + else + button = new BButton(NULL, NULL, message); button->SetIcon(icon); button->SetFlat(true); if (toolTipText != NULL) diff --git a/src/apps/showimage/ToolBarView.h b/src/apps/showimage/ToolBarView.h index 63c6f0b202..6273d33713 100644 --- a/src/apps/showimage/ToolBarView.h +++ b/src/apps/showimage/ToolBarView.h @@ -20,10 +20,12 @@ public: void AddAction(uint32 command, BHandler* target, const BBitmap* icon, - const char* toolTipText = NULL); + const char* toolTipText = NULL, + bool lockable = false); void AddAction(BMessage* message, BHandler* target, const BBitmap* icon, - const char* toolTipText = NULL); + const char* toolTipText = NULL, + bool lockable = false); void AddSeparator(); void AddGlue();