Several ShowImage changes:
- Changed the hotkey for the zoom to be = instead of + so that no shifting is necessary. - Fixed the bitmap alignment code to solve some problems when zooming. - Removed all references to alignment in the view since the image was already always centered. This greatly simplified the bitmap alignment. - Removed the redundant fScaleX and fScaleY members of the view since they were always the same as fZoom. - Removed all code related to having a border in the view. - Fixed a bug where the type of file would disappear in the status area when zooming (this fix is a little hackish.) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19253 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -56,8 +56,6 @@ class PopUpMenu : public BPopUpMenu {
|
|||||||
|
|
||||||
|
|
||||||
#define SHOW_IMAGE_ORIENTATION_ATTRIBUTE "ShowImage:orientation"
|
#define SHOW_IMAGE_ORIENTATION_ATTRIBUTE "ShowImage:orientation"
|
||||||
#define BORDER_WIDTH 16
|
|
||||||
#define BORDER_HEIGHT 16
|
|
||||||
const rgb_color kBorderColor = { 0, 0, 0, 255 };
|
const rgb_color kBorderColor = { 0, 0, 0, 255 };
|
||||||
|
|
||||||
enum ShowImageView::image_orientation
|
enum ShowImageView::image_orientation
|
||||||
@@ -181,9 +179,7 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
|
|||||||
fHasSelection = false;
|
fHasSelection = false;
|
||||||
fShrinkToBounds = false;
|
fShrinkToBounds = false;
|
||||||
fZoomToBounds = false;
|
fZoomToBounds = false;
|
||||||
fHasBorder = true;
|
fFullScreen = false;
|
||||||
fHAlignment = B_ALIGN_CENTER;
|
|
||||||
fVAlignment = B_ALIGN_MIDDLE;
|
|
||||||
fSlideShow = false;
|
fSlideShow = false;
|
||||||
fSlideShowDelay = 3 * 10; // 3 seconds
|
fSlideShowDelay = 3 * 10; // 3 seconds
|
||||||
fShowCaption = false;
|
fShowCaption = false;
|
||||||
@@ -302,7 +298,7 @@ ShowImageView::Pulse()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hide cursor in full screen mode
|
// Hide cursor in full screen mode
|
||||||
if (!fHasBorder && !fShowingPopUpMenu)
|
if (fFullScreen && !fShowingPopUpMenu)
|
||||||
be_app->ObscureCursor();
|
be_app->ObscureCursor();
|
||||||
|
|
||||||
#if DELAYED_SCALING
|
#if DELAYED_SCALING
|
||||||
@@ -608,30 +604,15 @@ ShowImageView::SetZoomToBounds(bool enable)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::SetBorder(bool hasBorder)
|
ShowImageView::SetFullScreen(bool fullScreen)
|
||||||
{
|
{
|
||||||
if (fHasBorder != hasBorder) {
|
if (fFullScreen != fullScreen) {
|
||||||
fHasBorder = hasBorder;
|
fFullScreen = fullScreen;
|
||||||
if (fHasBorder)
|
if (fFullScreen) {
|
||||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
||||||
else {
|
|
||||||
SetLowColor(0, 0, 0, 255);
|
SetLowColor(0, 0, 0, 255);
|
||||||
be_app->ObscureCursor();
|
be_app->ObscureCursor();
|
||||||
}
|
} else
|
||||||
FixupScrollBars();
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::SetAlignment(alignment horizontal, vertical_alignment vertical)
|
|
||||||
{
|
|
||||||
if (fHAlignment != horizontal || fVAlignment != vertical) {
|
|
||||||
fHAlignment = horizontal;
|
|
||||||
fVAlignment = vertical;
|
|
||||||
FixupScrollBars();
|
|
||||||
Invalidate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -667,14 +648,6 @@ ShowImageView::GetPath(BString *outPath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::FlushToLeftTop()
|
|
||||||
{
|
|
||||||
BRect rect = AlignBitmap();
|
|
||||||
ScrollTo(rect.LeftTop());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::SetScaleBilinear(bool enabled)
|
ShowImageView::SetScaleBilinear(bool enabled)
|
||||||
{
|
{
|
||||||
@@ -729,57 +702,20 @@ ShowImageView::AlignBitmap()
|
|||||||
rect.OffsetBy(static_cast<int>((width - rect.Width()) / 2), 0);
|
rect.OffsetBy(static_cast<int>((width - rect.Width()) / 2), 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
float zoom;
|
|
||||||
if (fShrinkToBounds || fZoomToBounds) {
|
|
||||||
// ignore user zoom setting in automatic zoom modes
|
|
||||||
zoom = 1.0;
|
|
||||||
} else {
|
|
||||||
zoom = fZoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
// zoom image
|
// zoom image
|
||||||
rect.right = floorf(bitmapWidth * zoom) - 1;
|
rect.right = floorf(bitmapWidth * fZoom) - 1;
|
||||||
rect.bottom = floorf(bitmapHeight * zoom) - 1;
|
rect.bottom = floorf(bitmapHeight * fZoom) - 1;
|
||||||
|
|
||||||
// update the bitmap size after the zoom
|
// update the bitmap size after the zoom
|
||||||
bitmapWidth = rect.Width() + 1.0;
|
bitmapWidth = rect.Width() + 1.0;
|
||||||
bitmapHeight = rect.Height() + 1.0;
|
bitmapHeight = rect.Height() + 1.0;
|
||||||
|
|
||||||
// align
|
// always align in the center
|
||||||
switch (fHAlignment) {
|
if (width > bitmapWidth)
|
||||||
case B_ALIGN_CENTER:
|
rect.OffsetBy((width - bitmapWidth) / 2.0, 0);
|
||||||
if (width > bitmapWidth) {
|
|
||||||
rect.OffsetBy((width - bitmapWidth) / 2.0, 0);
|
if (height > bitmapHeight)
|
||||||
break;
|
rect.OffsetBy(0, (height - bitmapHeight) / 2.0);
|
||||||
}
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rect.OffsetBy(PEN_SIZE, PEN_SIZE);
|
rect.OffsetBy(PEN_SIZE, PEN_SIZE);
|
||||||
return rect;
|
return rect;
|
||||||
@@ -791,16 +727,14 @@ ShowImageView::Setup(BRect rect)
|
|||||||
{
|
{
|
||||||
fLeft = floorf(rect.left);
|
fLeft = floorf(rect.left);
|
||||||
fTop = floorf(rect.top);
|
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
|
BPoint
|
||||||
ShowImageView::ImageToView(BPoint p) const
|
ShowImageView::ImageToView(BPoint p) const
|
||||||
{
|
{
|
||||||
p.x = floorf(fScaleX * p.x + fLeft);
|
p.x = floorf(fZoom * p.x + fLeft);
|
||||||
p.y = floorf(fScaleY * p.y + fTop);
|
p.y = floorf(fZoom * p.y + fTop);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -808,8 +742,8 @@ ShowImageView::ImageToView(BPoint p) const
|
|||||||
BPoint
|
BPoint
|
||||||
ShowImageView::ViewToImage(BPoint p) const
|
ShowImageView::ViewToImage(BPoint p) const
|
||||||
{
|
{
|
||||||
p.x = floorf((p.x - fLeft) / fScaleX);
|
p.x = floorf((p.x - fLeft) / fZoom);
|
||||||
p.y = floorf((p.y - fTop) / fScaleY);
|
p.y = floorf((p.y - fTop) / fZoom);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1063,8 +997,8 @@ ShowImageView::CopySelection(uchar alpha, bool imageSize)
|
|||||||
BRect rect(0, 0, fSelectionRect.Width(), fSelectionRect.Height());
|
BRect rect(0, 0, fSelectionRect.Width(), fSelectionRect.Height());
|
||||||
if (!imageSize) {
|
if (!imageSize) {
|
||||||
// scale image to view size
|
// scale image to view size
|
||||||
rect.right = floorf((rect.right + 1.0) * fScaleX - 1.0);
|
rect.right = floorf((rect.right + 1.0) * fZoom - 1.0);
|
||||||
rect.bottom = floorf((rect.bottom + 1.0) * fScaleY - 1.0);
|
rect.bottom = floorf((rect.bottom + 1.0) * fZoom - 1.0);
|
||||||
}
|
}
|
||||||
BView view(rect, NULL, B_FOLLOW_NONE, B_WILL_DRAW);
|
BView view(rect, NULL, B_FOLLOW_NONE, B_WILL_DRAW);
|
||||||
BBitmap *bitmap = new(nothrow) BBitmap(rect, hasAlpha ? B_RGBA32 : fBitmap->ColorSpace(), true);
|
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
|
// avoid flickering of dragged bitmap caused by drawing into the window
|
||||||
AnimateSelection(false);
|
AnimateSelection(false);
|
||||||
// only use a transparent bitmap on selections less than 400x400 (taking into account scaling)
|
// 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 -= fSelectionRect.LeftTop();
|
||||||
sourcePoint.x *= fScaleX;
|
sourcePoint.x *= fZoom;
|
||||||
sourcePoint.y *= fScaleY;
|
sourcePoint.y *= fZoom;
|
||||||
// DragMessage takes ownership of bitmap
|
// DragMessage takes ownership of bitmap
|
||||||
DragMessage(&drag, bitmap, B_OP_ALPHA, sourcePoint);
|
DragMessage(&drag, bitmap, B_OP_ALPHA, sourcePoint);
|
||||||
bitmap = NULL;
|
bitmap = NULL;
|
||||||
@@ -1804,9 +1738,6 @@ ShowImageView::FixupScrollBar(orientation o, float bitmapLength, float viewLengt
|
|||||||
|
|
||||||
psb = ScrollBar(o);
|
psb = ScrollBar(o);
|
||||||
if (psb) {
|
if (psb) {
|
||||||
if (fHasBorder && !fShrinkOrZoomToBounds && (fHAlignment == B_ALIGN_LEFT || fVAlignment == B_ALIGN_TOP)) {
|
|
||||||
bitmapLength += BORDER_WIDTH * 2;
|
|
||||||
}
|
|
||||||
range = bitmapLength - viewLength;
|
range = bitmapLength - viewLength;
|
||||||
if (range < 0.0) {
|
if (range < 0.0) {
|
||||||
range = 0.0;
|
range = 0.0;
|
||||||
@@ -2430,7 +2361,19 @@ ShowImageView::DoImageOperation(ImageProcessor::operation op, bool quiet)
|
|||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
// remove selection
|
// remove selection
|
||||||
SetHasSelection(false);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,13 +57,10 @@ class ShowImageView : public BView {
|
|||||||
bool GetShrinkToBounds() const { return fShrinkToBounds; }
|
bool GetShrinkToBounds() const { return fShrinkToBounds; }
|
||||||
void SetZoomToBounds(bool enable);
|
void SetZoomToBounds(bool enable);
|
||||||
bool GetZoomToBounds() const { return fZoomToBounds; }
|
bool GetZoomToBounds() const { return fZoomToBounds; }
|
||||||
void SetBorder(bool hasBorder);
|
void SetFullScreen(bool fullScreen);
|
||||||
bool HasBorder() const { return fHasBorder; }
|
|
||||||
void SetAlignment(alignment horizontal, vertical_alignment vertical);
|
|
||||||
BBitmap *GetBitmap();
|
BBitmap *GetBitmap();
|
||||||
void GetName(BString *name);
|
void GetName(BString *name);
|
||||||
void GetPath(BString *name);
|
void GetPath(BString *name);
|
||||||
void FlushToLeftTop();
|
|
||||||
void SetScaleBilinear(bool b);
|
void SetScaleBilinear(bool b);
|
||||||
bool GetScaleBilinear() { return fScaleBilinear; }
|
bool GetScaleBilinear() { return fScaleBilinear; }
|
||||||
|
|
||||||
@@ -206,13 +203,9 @@ class ShowImageView : public BView {
|
|||||||
bool fShrinkToBounds;
|
bool fShrinkToBounds;
|
||||||
bool fZoomToBounds;
|
bool fZoomToBounds;
|
||||||
bool fShrinkOrZoomToBounds;
|
bool fShrinkOrZoomToBounds;
|
||||||
bool fHasBorder; // should the image have a border?
|
bool fFullScreen; // is the image displayed fullscreen?
|
||||||
alignment fHAlignment; // horizontal alignment (left and centered only)
|
|
||||||
vertical_alignment fVAlignment; // vertical alignment (left and centered only)
|
|
||||||
float fLeft; // the origin of the image in the view
|
float fLeft; // the origin of the image in the view
|
||||||
float fTop;
|
float fTop;
|
||||||
float fScaleX; // to convert image from/to view coordinates
|
|
||||||
float fScaleY;
|
|
||||||
bool fMovesImage; // is the image being moved with the mouse
|
bool fMovesImage; // is the image being moved with the mouse
|
||||||
bool fMakesSelection; // is a selection being made
|
bool fMakesSelection; // is a selection being made
|
||||||
BPoint fFirstPoint; // first point in image space of selection
|
BPoint fFirstPoint; // first point in image space of selection
|
||||||
|
|||||||
@@ -156,7 +156,6 @@ ShowImageWindow::ShowImageWindow(const entry_ref *ref,
|
|||||||
SetPulseRate(100000);
|
SetPulseRate(100000);
|
||||||
// every 1/10 second; ShowImageView needs it for marching ants
|
// every 1/10 second; ShowImageView needs it for marching ants
|
||||||
|
|
||||||
fImageView->FlushToLeftTop();
|
|
||||||
WindowRedimension(fImageView->GetBitmap());
|
WindowRedimension(fImageView->GetBitmap());
|
||||||
fImageView->MakeFocus(true); // to receive KeyDown messages
|
fImageView->MakeFocus(true); // to receive KeyDown messages
|
||||||
Show();
|
Show();
|
||||||
@@ -230,7 +229,7 @@ ShowImageWindow::BuildViewMenu(BMenu *menu)
|
|||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
|
|
||||||
AddItemMenu(menu, "Original Size", MSG_ORIGINAL_SIZE, 0, 0, 'W', true);
|
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);
|
AddItemMenu(menu, "Zoom Out", MSG_ZOOM_OUT, '-', 0, 'W', true);
|
||||||
|
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
@@ -934,7 +933,6 @@ ShowImageWindow::ToggleFullScreen()
|
|||||||
frame.InsetBy(-1, -1); // PEN_SIZE in ShowImageView
|
frame.InsetBy(-1, -1); // PEN_SIZE in ShowImageView
|
||||||
|
|
||||||
SetFlags(Flags() | B_NOT_RESIZABLE | B_NOT_MOVABLE);
|
SetFlags(Flags() | B_NOT_RESIZABLE | B_NOT_MOVABLE);
|
||||||
fImageView->SetAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE);
|
|
||||||
|
|
||||||
Activate();
|
Activate();
|
||||||
// make the window frontmost
|
// make the window frontmost
|
||||||
@@ -942,14 +940,9 @@ ShowImageWindow::ToggleFullScreen()
|
|||||||
frame = fWindowFrame;
|
frame = fWindowFrame;
|
||||||
|
|
||||||
SetFlags(Flags() & ~(B_NOT_RESIZABLE | B_NOT_MOVABLE));
|
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);
|
fImageView->SetShowCaption(fFullScreen && fShowCaption);
|
||||||
MoveTo(frame.left, frame.top);
|
MoveTo(frame.left, frame.top);
|
||||||
ResizeTo(frame.Width(), frame.Height());
|
ResizeTo(frame.Width(), frame.Height());
|
||||||
|
|||||||
Reference in New Issue
Block a user