- Fixed bug in conversion from image coordinates to view coordinates are vice versa.

- Change the size of the image being dragged to size of the selection in the view coordinate system.
- Experimental: delay start of filtering thread(s) for some tenth of a second. This allows faster update during resizing.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5491 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer
2003-11-27 18:35:54 +00:00
parent c8ec7d9a9b
commit a55095419c
3 changed files with 64 additions and 23 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ ShowImageApp::Pulse()
// all windows are closed except for the file open panel, // all windows are closed except for the file open panel,
// quit the application // quit the application
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
} }
void void
ShowImageApp::ArgvReceived(int32 argc, char **argv) ShowImageApp::ArgvReceived(int32 argc, char **argv)
+56 -20
View File
@@ -27,6 +27,7 @@
/*****************************************************************************/ /*****************************************************************************/
#include <stdio.h> #include <stdio.h>
#include <math.h>
#include <Debug.h> #include <Debug.h>
#include <Message.h> #include <Message.h>
#include <ScrollBar.h> #include <ScrollBar.h>
@@ -152,7 +153,7 @@ ShowImageView::Pulse()
// animate marching ants // animate marching ants
if (HasSelection() && fAnimateSelection && Window()->IsActive()) { if (HasSelection() && fAnimateSelection && Window()->IsActive()) {
RotatePatterns(); RotatePatterns();
DrawSelectionBox(fSelectionRect); DrawSelectionBox();
} }
if (fSlideShow) { if (fSlideShow) {
fSlideShowCountDown --; fSlideShowCountDown --;
@@ -163,6 +164,14 @@ ShowImageView::Pulse()
} }
} }
} }
#if DELAYED_SCALING
if (fBitmap && (fScaleBilinear || fDither) && fScalingCountDown > 0) {
fScalingCountDown --;
if (fScalingCountDown == 0) {
GetScaler(AlignBitmap());
}
}
#endif
} }
ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode, ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
@@ -192,6 +201,9 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
fMovesImage = false; fMovesImage = false;
fScaleBilinear = false; fScaleBilinear = false;
fScaler = NULL; fScaler = NULL;
#if DELAYED_SCALING
fScalingCountDown = 10;
#endif
if (settings->Lock()) { if (settings->Lock()) {
fDither = settings->GetBool("Dither", fDither); fDither = settings->GetBool("Dither", fDither);
@@ -264,6 +276,9 @@ ShowImageView::DeleteScaler()
delete fScaler; delete fScaler;
fScaler = NULL; fScaler = NULL;
} }
#if DELAYED_SCALING
fScalingCountDown = 3; // delay for 3/10 seconds
#endif
} }
void void
@@ -564,25 +579,25 @@ ShowImageView::AlignBitmap()
void void
ShowImageView::Setup(BRect rect) ShowImageView::Setup(BRect rect)
{ {
fLeft = rect.left; fLeft = floorf(rect.left);
fTop = rect.top; fTop = floorf(rect.top);
fScaleX = rect.Width() / fBitmap->Bounds().Width(); fScaleX = (rect.Width()+1.0) / (fBitmap->Bounds().Width()+1.0);
fScaleY = rect.Height() / fBitmap->Bounds().Height(); fScaleY = (rect.Height()+1.0) / (fBitmap->Bounds().Height()+1.0);
} }
BPoint BPoint
ShowImageView::ImageToView(BPoint p) const ShowImageView::ImageToView(BPoint p) const
{ {
p.x = fScaleX * p.x + fLeft; p.x = floorf(fScaleX * p.x + fLeft);
p.y = fScaleY * p.y + fTop; p.y = floorf(fScaleY * p.y + fTop);
return p; return p;
} }
BPoint BPoint
ShowImageView::ViewToImage(BPoint p) const ShowImageView::ViewToImage(BPoint p) const
{ {
p.x = (p.x - fLeft) / fScaleX; p.x = floorf((p.x - fLeft) / fScaleX);
p.y = (p.y - fTop) / fScaleY; p.y = floorf((p.y - fTop) / fScaleY);
return p; return p;
} }
@@ -590,7 +605,10 @@ BRect
ShowImageView::ImageToView(BRect r) const ShowImageView::ImageToView(BRect r) const
{ {
BPoint leftTop(ImageToView(BPoint(r.left, r.top))); BPoint leftTop(ImageToView(BPoint(r.left, r.top)));
BPoint rightBottom(ImageToView(BPoint(r.right, r.bottom))); BPoint rightBottom(r.right, r.bottom);
rightBottom += BPoint(1, 1);
rightBottom = ImageToView(rightBottom);
rightBottom -= BPoint(1, 1);
return BRect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y); return BRect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y);
} }
@@ -690,7 +708,14 @@ void
ShowImageView::DrawImage(BRect rect) ShowImageView::DrawImage(BRect rect)
{ {
if (fScaleBilinear || fDither) { if (fScaleBilinear || fDither) {
#if DELAYED_SCALING
Scaler* scaler = fScaler;
if (scaler != NULL && !scaler->Matches(rect, fDither)) {
DeleteScaler(); scaler = NULL;
}
#else
Scaler* scaler = GetScaler(rect); Scaler* scaler = GetScaler(rect);
#endif
if (scaler != NULL && !scaler->IsRunning()) { if (scaler != NULL && !scaler->IsRunning()) {
BBitmap* bitmap = scaler->GetBitmap(); BBitmap* bitmap = scaler->GetBitmap();
if (bitmap) { if (bitmap) {
@@ -735,7 +760,7 @@ ShowImageView::Draw(BRect updateRect)
destRect = ImageToView(destRect); destRect = ImageToView(destRect);
DrawBitmap(fSelBitmap, srcBits, destRect); DrawBitmap(fSelBitmap, srcBits, destRect);
} }
DrawSelectionBox(fSelectionRect); DrawSelectionBox();
} }
} else { } else {
DrawBitmap(fBitmap); DrawBitmap(fBitmap);
@@ -744,15 +769,16 @@ ShowImageView::Draw(BRect updateRect)
} }
void void
ShowImageView::DrawSelectionBox(BRect &rect) ShowImageView::DrawSelectionBox()
{ {
BRect r = rect; BRect r(fSelectionRect);
ConstrainToImage(r); ConstrainToImage(r);
r = ImageToView(r);
// draw selection box *around* selection
r.InsetBy(-1, -1);
PushState(); PushState();
rgb_color white = {255, 255, 255}; rgb_color white = {255, 255, 255};
SetLowColor(white); SetLowColor(white);
r = ImageToView(r);
StrokeLine(BPoint(r.left, r.top), BPoint(r.right, r.top), fPatternLeft); StrokeLine(BPoint(r.left, r.top), BPoint(r.right, r.top), fPatternLeft);
StrokeLine(BPoint(r.right, r.top+1), BPoint(r.right, r.bottom-1), fPatternUp); StrokeLine(BPoint(r.right, r.top+1), BPoint(r.right, r.bottom-1), fPatternUp);
StrokeLine(BPoint(r.left, r.bottom), BPoint(r.right, r.bottom), fPatternRight); StrokeLine(BPoint(r.left, r.bottom), BPoint(r.right, r.bottom), fPatternRight);
@@ -789,13 +815,18 @@ ShowImageView::ConstrainToImage(BRect &rect)
} }
BBitmap* BBitmap*
ShowImageView::CopySelection(uchar alpha) ShowImageView::CopySelection(uchar alpha, bool imageSize)
{ {
bool hasAlpha = alpha != 255; bool hasAlpha = alpha != 255;
if (!HasSelection()) return NULL; if (!HasSelection()) return NULL;
BRect rect(0, 0, fSelectionRect.Width(), fSelectionRect.Height()); 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);
}
BView view(rect, NULL, B_FOLLOW_NONE, B_WILL_DRAW); BView view(rect, NULL, B_FOLLOW_NONE, B_WILL_DRAW);
BBitmap *bitmap = new BBitmap(rect, hasAlpha ? B_RGBA32 : fBitmap->ColorSpace(), true); BBitmap *bitmap = new BBitmap(rect, hasAlpha ? B_RGBA32 : fBitmap->ColorSpace(), true);
if (bitmap == NULL) return NULL; if (bitmap == NULL) return NULL;
@@ -854,7 +885,7 @@ ShowImageView::AddSupportedTypes(BMessage* msg, BBitmap* bitmap)
void void
ShowImageView::BeginDrag(BPoint sourcePoint) ShowImageView::BeginDrag(BPoint sourcePoint)
{ {
BBitmap* bitmap = CopySelection(128); BBitmap* bitmap = CopySelection(128, false);
if (bitmap == NULL) return; if (bitmap == NULL) return;
SetMouseEventMask(B_POINTER_EVENTS); SetMouseEventMask(B_POINTER_EVENTS);
@@ -875,9 +906,12 @@ ShowImageView::BeginDrag(BPoint sourcePoint)
// we also support "Passing Data via File" protocol // we also support "Passing Data via File" protocol
drag.AddString("be:types", B_FILE_MIME_TYPE); drag.AddString("be:types", B_FILE_MIME_TYPE);
// 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);
sourcePoint -= leftTop;
sourcePoint.x *= fScaleX;
sourcePoint.y *= fScaleY;
// DragMessage takes ownership of bitmap // DragMessage takes ownership of bitmap
DragMessage(&drag, bitmap, B_OP_ALPHA, sourcePoint - leftTop); DragMessage(&drag, bitmap, B_OP_ALPHA, sourcePoint);
} }
} }
@@ -1146,7 +1180,7 @@ ShowImageView::UpdateSelectionRect(BPoint point, bool final) {
fSelectionRect = fCopyFromRect; fSelectionRect = fCopyFromRect;
if (final) { if (final) {
// selection must contain a few pixels // selection must contain a few pixels
if (fCopyFromRect.Width() * fCopyFromRect.Height() <= 1) { if ((fCopyFromRect.Width()+1.0) * (fCopyFromRect.Height()+1.0) < 1) {
SetHasSelection(false); SetHasSelection(false);
} }
} }
@@ -1283,6 +1317,8 @@ ShowImageView::KeyDown (const char * bytes, int32 numBytes)
BMessenger msgr(Window()); BMessenger msgr(Window());
msgr.SendMessage(MSG_SLIDE_SHOW); msgr.SendMessage(MSG_SLIDE_SHOW);
} }
ClearSelection();
break;
case 'T': case 'T':
case 't': case 't':
SetIcon(*bytes == 't'); SetIcon(*bytes == 't');
+7 -2
View File
@@ -38,6 +38,8 @@
#include "Filter.h" #include "Filter.h"
#define DELAYED_SCALING 1
class ShowImageView : public BView { class ShowImageView : public BView {
public: public:
ShowImageView(BRect rect, const char *name, uint32 resizingMode, ShowImageView(BRect rect, const char *name, uint32 resizingMode,
@@ -152,7 +154,7 @@ private:
bool FirstFile(); bool FirstFile();
void ConstrainToImage(BPoint &point); void ConstrainToImage(BPoint &point);
void ConstrainToImage(BRect &rect); void ConstrainToImage(BRect &rect);
BBitmap* CopySelection(uchar alpha = 255); BBitmap* CopySelection(uchar alpha = 255, bool imageSize = true);
bool AddSupportedTypes(BMessage* msg, BBitmap* bitmap); bool AddSupportedTypes(BMessage* msg, BBitmap* bitmap);
void BeginDrag(BPoint sourcePoint); void BeginDrag(BPoint sourcePoint);
void SaveToFile(BDirectory* dir, const char* name, BBitmap* bitmap, translation_format* format); void SaveToFile(BDirectory* dir, const char* name, BBitmap* bitmap, translation_format* format);
@@ -166,7 +168,7 @@ private:
void LayoutCaption(BFont &font, BPoint &textPos, BRect &background); void LayoutCaption(BFont &font, BPoint &textPos, BRect &background);
void DrawCaption(); void DrawCaption();
void UpdateCaption(); void UpdateCaption();
void DrawSelectionBox(BRect &rect); void DrawSelectionBox();
Scaler* GetScaler(BRect rect); Scaler* GetScaler(BRect rect);
void DrawImage(BRect rect); void DrawImage(BRect rect);
float LimitToRange(float v, orientation o, bool absolute); float LimitToRange(float v, orientation o, bool absolute);
@@ -210,6 +212,9 @@ private:
bool fSlideShow; // is slide show enabled? bool fSlideShow; // is slide show enabled?
int fSlideShowDelay; // in pulse rate units int fSlideShowDelay; // in pulse rate units
int fSlideShowCountDown; // shows next image if it reaches zero int fSlideShowCountDown; // shows next image if it reaches zero
#if DELAYED_SCALING
int fScalingCountDown;
#endif
bool fShowCaption; // display caption? bool fShowCaption; // display caption?
BString fCaption; // caption text BString fCaption; // caption text