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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <Application.h>
|
||||
#include <Bitmap.h>
|
||||
#include <BitmapStream.h>
|
||||
#include <Button.h>
|
||||
#include <Catalog.h>
|
||||
#include <Clipboard.h>
|
||||
#include <Entry.h>
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -10,6 +10,34 @@
|
||||
#include <SeparatorView.h>
|
||||
#include <SpaceLayoutItem.h>
|
||||
|
||||
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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user