Drag selection code can now move the selection inside the view, fixed selection drag code so that unwanted MouseUps don't affect the selection box movement. Though, drag selection code is not done yet, it is not yet copying the bitmap from where the selection was dragged from, it is just moving the selection rectangle. Dragging a selection to outside of the window still works the same.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5391 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber
2003-11-16 20:39:27 +00:00
parent f30761e5ee
commit 0e93ae51e9
2 changed files with 56 additions and 20 deletions
+54 -18
View File
@@ -163,7 +163,6 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
fVAlignment = B_ALIGN_TOP; fVAlignment = B_ALIGN_TOP;
fSlideShow = false; fSlideShow = false;
SetSlideShowDelay(3); // 3 seconds SetSlideShowDelay(3); // 3 seconds
fBeginDrag = false;
fShowCaption = false; fShowCaption = false;
fZoom = 1.0; fZoom = 1.0;
fMovesImage = false; fMovesImage = false;
@@ -628,10 +627,13 @@ ShowImageView::Draw(BRect updateRect)
void void
ShowImageView::DrawSelectionBox(BRect &rect) ShowImageView::DrawSelectionBox(BRect &rect)
{ {
BRect r = rect;
ConstrainToImage(r);
PushState(); PushState();
rgb_color white = {255, 255, 255}; rgb_color white = {255, 255, 255};
SetLowColor(white); SetLowColor(white);
BRect r(ImageToView(rect)); 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);
@@ -651,6 +653,22 @@ ShowImageView::ConstrainToImage(BPoint &point)
point.ConstrainTo(fpBitmap->Bounds()); point.ConstrainTo(fpBitmap->Bounds());
} }
void
ShowImageView::ConstrainToImage(BRect &rect)
{
BRect bounds = fpBitmap->Bounds();
BPoint leftTop, rightBottom;
leftTop = rect.LeftTop();
leftTop.ConstrainTo(bounds);
rightBottom = rect.RightBottom();
rightBottom.ConstrainTo(bounds);
rect.SetLeftTop(leftTop);
rect.SetRightBottom(rightBottom);
}
BBitmap* BBitmap*
ShowImageView::CopySelection(uchar alpha) ShowImageView::CopySelection(uchar alpha)
{ {
@@ -712,14 +730,8 @@ ShowImageView::AddSupportedTypes(BMessage* msg, BBitmap* bitmap)
} }
void void
ShowImageView::BeginDrag(BPoint point) ShowImageView::BeginDrag(BPoint sourcePoint)
{ {
// mouse moved?
if (!fBeginDrag) return;
point = ViewToImage(point);
if (point == fFirstPoint) return;
fBeginDrag = false;
BBitmap* bitmap = CopySelection(128); BBitmap* bitmap = CopySelection(128);
if (bitmap == NULL) return; if (bitmap == NULL) return;
@@ -731,7 +743,7 @@ ShowImageView::BeginDrag(BPoint point)
drag.AddInt32("be:actions", B_COPY_TARGET); drag.AddInt32("be:actions", B_COPY_TARGET);
drag.AddString("be:clip_name", "Bitmap Clip"); drag.AddString("be:clip_name", "Bitmap Clip");
// XXX undocumented fields // XXX undocumented fields
drag.AddPoint("be:_source_point", fFirstPoint); drag.AddPoint("be:_source_point", sourcePoint);
drag.AddRect("be:_frame", fSelectionRect); drag.AddRect("be:_frame", fSelectionRect);
// XXX meaning unknown??? // XXX meaning unknown???
// drag.AddInt32("be:_format", e.g.: B_TGA_FORMAT); // drag.AddInt32("be:_format", e.g.: B_TGA_FORMAT);
@@ -743,7 +755,7 @@ ShowImageView::BeginDrag(BPoint point)
// 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);
// DragMessage takes ownership of bitmap // DragMessage takes ownership of bitmap
DragMessage(&drag, bitmap, B_OP_ALPHA, fFirstPoint - leftTop); DragMessage(&drag, bitmap, B_OP_ALPHA, sourcePoint - leftTop);
} }
} }
@@ -890,8 +902,37 @@ ShowImageView::MouseDown(BPoint position)
if (fbHasSelection && fSelectionRect.Contains(point) && if (fbHasSelection && fSelectionRect.Contains(point) &&
(buttons & (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON))) { (buttons & (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON))) {
// delay drag until mouse is moved BPoint sourcePoint = point;
fBeginDrag = true; fFirstPoint = point; BeginDrag(sourcePoint);
while (buttons) {
// Keep reading mouse movement until
// the user lets up on all mouse buttons
GetMouse(&point, &buttons);
snooze(50000);
// sleep for 50 milliseconds to minimize CPU usage during loop
}
if (Bounds().Contains(point)) {
// If selection stayed inside this view
// (Some of the selection may be in the border area, which can be OK)
BPoint last, diff;
last = ViewToImage(point);
diff = last - sourcePoint;
BRect newSelection = fSelectionRect;
newSelection.OffsetBy(diff);
if (fpBitmap->Bounds().Intersects(newSelection)) {
// Do not accept the new selection box location
// if it does not intersect with the bitmap rectangle
fSelectionRect = newSelection;
Invalidate();
}
}
AnimateSelection(true);
} else if (buttons == B_PRIMARY_MOUSE_BUTTON) { } else if (buttons == B_PRIMARY_MOUSE_BUTTON) {
// begin new selection // begin new selection
fMakesSelection = true; fMakesSelection = true;
@@ -943,8 +984,6 @@ ShowImageView::MouseMoved(BPoint point, uint32 state, const BMessage *pmsg)
UpdateSelectionRect(point, false); UpdateSelectionRect(point, false);
} else if (fMovesImage) { } else if (fMovesImage) {
MoveImage(); MoveImage();
} else {
BeginDrag(point);
} }
} }
@@ -960,9 +999,6 @@ ShowImageView::MouseUp(BPoint point)
fMovesImage = false; fMovesImage = false;
Invalidate(); Invalidate();
} }
} else {
BeginDrag(point);
fBeginDrag = false;
} }
AnimateSelection(true); AnimateSelection(true);
} }
+2 -2
View File
@@ -128,9 +128,10 @@ private:
bool ShowNextImage(bool next, bool rewind); bool ShowNextImage(bool next, bool rewind);
bool FirstFile(); bool FirstFile();
void ConstrainToImage(BPoint &point); void ConstrainToImage(BPoint &point);
void ConstrainToImage(BRect &rect);
BBitmap* CopySelection(uchar alpha = 255); BBitmap* CopySelection(uchar alpha = 255);
bool AddSupportedTypes(BMessage* msg, BBitmap* bitmap); bool AddSupportedTypes(BMessage* msg, BBitmap* bitmap);
void BeginDrag(BPoint point); 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);
void SendInMessage(BMessage* msg, BBitmap* bitmap, translation_format* format); void SendInMessage(BMessage* msg, BBitmap* bitmap, translation_format* format);
bool OutputFormatForType(BBitmap* bitmap, const char* type, translation_format* format); bool OutputFormatForType(BBitmap* bitmap, const char* type, translation_format* format);
@@ -166,7 +167,6 @@ private:
float fScaleX; float fScaleX;
float fScaleY; float fScaleY;
bool fMovesImage; bool fMovesImage;
bool fBeginDrag;
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
bool fAnimateSelection; // marching ants bool fAnimateSelection; // marching ants