* Moved selection box handling into a separate class SelectionBox. Mouse hooks
of that class are not yet used. Invalidation of the view could also work via listener mechanism. * Made image <-> view conversion and constraint methods public. * Sorted .cpp files in Jamfile alphabetically. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37164 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -5,17 +5,18 @@ UsePrivateHeaders tracker shared ;
|
|||||||
UsePublicHeaders [ FDirName be_apps Tracker ] ;
|
UsePublicHeaders [ FDirName be_apps Tracker ] ;
|
||||||
|
|
||||||
Application ShowImage :
|
Application ShowImage :
|
||||||
|
EntryMenuItem.cpp
|
||||||
|
Filter.cpp
|
||||||
|
PrintOptionsWindow.cpp
|
||||||
|
ProgressWindow.cpp
|
||||||
|
ResizerWindow.cpp
|
||||||
|
SelectionBox.cpp
|
||||||
ShowImageApp.cpp
|
ShowImageApp.cpp
|
||||||
ShowImageSettings.cpp
|
ShowImageSettings.cpp
|
||||||
ShowImageStatusView.cpp
|
ShowImageStatusView.cpp
|
||||||
ShowImageUndo.cpp
|
ShowImageUndo.cpp
|
||||||
ShowImageView.cpp
|
ShowImageView.cpp
|
||||||
ShowImageWindow.cpp
|
ShowImageWindow.cpp
|
||||||
PrintOptionsWindow.cpp
|
|
||||||
Filter.cpp
|
|
||||||
EntryMenuItem.cpp
|
|
||||||
ProgressWindow.cpp
|
|
||||||
ResizerWindow.cpp
|
|
||||||
: libshared.a
|
: libshared.a
|
||||||
be tracker translation liblocale.so $(TARGET_LIBSUPC++)
|
be tracker translation liblocale.so $(TARGET_LIBSUPC++)
|
||||||
: ShowImage.rdef
|
: ShowImage.rdef
|
||||||
|
|||||||
@@ -0,0 +1,201 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2010, Haiku, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2004-2005 yellowTAB GmbH. All Rights Reserverd.
|
||||||
|
* Copyright 2006 Bernd Korz. All Rights Reserved
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Fernando Francisco de Oliveira
|
||||||
|
* Michael Wilber
|
||||||
|
* Michael Pfeiffer
|
||||||
|
* Ryan Leavengood
|
||||||
|
* yellowTAB GmbH
|
||||||
|
* Bernd Korz
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "SelectionBox.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <new>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "ShowImageView.h"
|
||||||
|
|
||||||
|
|
||||||
|
SelectionBox::SelectionBox()
|
||||||
|
:
|
||||||
|
fBounds()
|
||||||
|
{
|
||||||
|
_InitPatterns();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SelectionBox::~SelectionBox()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SelectionBox::SetBounds(ShowImageView* view, BRect bounds)
|
||||||
|
{
|
||||||
|
view->ConstrainToImage(bounds);
|
||||||
|
|
||||||
|
if (fBounds == bounds)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BRect dirtyOld = _RectInView(view);
|
||||||
|
|
||||||
|
fBounds = bounds;
|
||||||
|
|
||||||
|
BRect dirtyNew = _RectInView(view);
|
||||||
|
|
||||||
|
if (dirtyOld.IsValid() && dirtyNew.IsValid())
|
||||||
|
view->Invalidate(dirtyOld | dirtyNew);
|
||||||
|
else if (dirtyOld.IsValid())
|
||||||
|
view->Invalidate(dirtyOld);
|
||||||
|
else if (dirtyNew.IsValid())
|
||||||
|
view->Invalidate(dirtyNew);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRect
|
||||||
|
SelectionBox::Bounds() const
|
||||||
|
{
|
||||||
|
return fBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SelectionBox::MouseDown(ShowImageView* view, BPoint where)
|
||||||
|
{
|
||||||
|
// TODO: Allow to re-adjust corners.
|
||||||
|
where = view->ViewToImage(where);
|
||||||
|
SetBounds(view, BRect(where, where));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SelectionBox::MouseMoved(ShowImageView* view, BPoint where)
|
||||||
|
{
|
||||||
|
// TODO: Allow to re-adjust corners.
|
||||||
|
where = view->ViewToImage(where);
|
||||||
|
|
||||||
|
BRect bounds(fBounds);
|
||||||
|
|
||||||
|
if (where.x >= bounds.left)
|
||||||
|
bounds.right = where.x;
|
||||||
|
else
|
||||||
|
bounds.left = where.x;
|
||||||
|
|
||||||
|
if (where.y >= bounds.top)
|
||||||
|
bounds.bottom = where.y;
|
||||||
|
else
|
||||||
|
bounds.top = where.y;
|
||||||
|
|
||||||
|
SetBounds(view, bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SelectionBox::MouseUp(ShowImageView* view, BPoint where)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SelectionBox::Animate()
|
||||||
|
{
|
||||||
|
// rotate up
|
||||||
|
uchar p = fPatternUp.data[0];
|
||||||
|
for (int i = 0; i <= 6; i ++)
|
||||||
|
fPatternUp.data[i] = fPatternUp.data[i + 1];
|
||||||
|
fPatternUp.data[7] = p;
|
||||||
|
|
||||||
|
// rotate down
|
||||||
|
p = fPatternDown.data[7];
|
||||||
|
for (int i = 7; i >= 1; i --)
|
||||||
|
fPatternDown.data[i] = fPatternDown.data[i - 1];
|
||||||
|
fPatternDown.data[0] = p;
|
||||||
|
|
||||||
|
// rotate to left
|
||||||
|
p = fPatternLeft.data[0];
|
||||||
|
bool set = (p & 0x80) != 0;
|
||||||
|
p <<= 1;
|
||||||
|
p &= 0xfe;
|
||||||
|
if (set)
|
||||||
|
p |= 1;
|
||||||
|
memset(fPatternLeft.data, p, 8);
|
||||||
|
|
||||||
|
// rotate to right
|
||||||
|
p = fPatternRight.data[0];
|
||||||
|
set = (p & 1) != 0;
|
||||||
|
p >>= 1;
|
||||||
|
if (set)
|
||||||
|
p |= 0x80;
|
||||||
|
memset(fPatternRight.data, p, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SelectionBox::Draw(ShowImageView* view, const BRect& updateRect) const
|
||||||
|
{
|
||||||
|
BRect r = _RectInView(view);
|
||||||
|
if (!r.IsValid() || !updateRect.Intersects(r))
|
||||||
|
return;
|
||||||
|
|
||||||
|
view->PushState();
|
||||||
|
|
||||||
|
view->SetLowColor(255, 255, 255);
|
||||||
|
view->StrokeLine(BPoint(r.left, r.top), BPoint(r.right, r.top),
|
||||||
|
fPatternLeft);
|
||||||
|
view->StrokeLine(BPoint(r.right, r.top + 1), BPoint(r.right, r.bottom - 1),
|
||||||
|
fPatternUp);
|
||||||
|
view->StrokeLine(BPoint(r.left, r.bottom), BPoint(r.right, r.bottom),
|
||||||
|
fPatternRight);
|
||||||
|
view->StrokeLine(BPoint(r.left, r.top + 1), BPoint(r.left, r.bottom - 1),
|
||||||
|
fPatternDown);
|
||||||
|
|
||||||
|
view->PopState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SelectionBox::_InitPatterns()
|
||||||
|
{
|
||||||
|
uchar p;
|
||||||
|
uchar p1 = 0x33;
|
||||||
|
uchar p2 = 0xCC;
|
||||||
|
for (int i = 0; i <= 7; i ++) {
|
||||||
|
fPatternLeft.data[i] = p1;
|
||||||
|
fPatternRight.data[i] = p2;
|
||||||
|
if ((i / 2) % 2 == 0)
|
||||||
|
p = 255;
|
||||||
|
else
|
||||||
|
p = 0;
|
||||||
|
fPatternUp.data[i] = p;
|
||||||
|
fPatternDown.data[i] = ~p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRect
|
||||||
|
SelectionBox::_RectInView(ShowImageView* view) const
|
||||||
|
{
|
||||||
|
BRect r;
|
||||||
|
if (fBounds.Height() <= 0.0 || fBounds.Width() <= 0.0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = fBounds;
|
||||||
|
// Layout selection rect in view coordinate space
|
||||||
|
view->ConstrainToImage(r);
|
||||||
|
r = view->ImageToView(r);
|
||||||
|
// draw selection box *around* selection
|
||||||
|
r.InsetBy(-1, -1);
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2010, Haiku, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2004-2005 yellowTAB GmbH. All Rights Reserverd.
|
||||||
|
* Copyright 2006 Bernd Korz. All Rights Reserved
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Fernando Francisco de Oliveira
|
||||||
|
* Michael Wilber
|
||||||
|
* Michael Pfeiffer
|
||||||
|
* yellowTAB GmbH
|
||||||
|
* Bernd Korz
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef SELECTION_BOX_H
|
||||||
|
#define SELECTION_BOX_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
class ShowImageView;
|
||||||
|
|
||||||
|
|
||||||
|
class SelectionBox {
|
||||||
|
public:
|
||||||
|
SelectionBox();
|
||||||
|
~SelectionBox();
|
||||||
|
|
||||||
|
void SetBounds(ShowImageView* view, BRect bounds);
|
||||||
|
BRect Bounds() const;
|
||||||
|
|
||||||
|
void MouseDown(ShowImageView* view, BPoint where);
|
||||||
|
void MouseMoved(ShowImageView* view, BPoint where);
|
||||||
|
void MouseUp(ShowImageView* view, BPoint where);
|
||||||
|
|
||||||
|
void Animate();
|
||||||
|
void Draw(ShowImageView* view,
|
||||||
|
const BRect& updateRect) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _InitPatterns();
|
||||||
|
|
||||||
|
BRect _RectInView(ShowImageView* view) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
BRect fBounds;
|
||||||
|
|
||||||
|
// Use patterns to simulate marching ants for selection.
|
||||||
|
pattern fPatternUp;
|
||||||
|
pattern fPatternDown;
|
||||||
|
pattern fPatternLeft;
|
||||||
|
pattern fPatternRight;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SELECTION_BOX_H
|
||||||
@@ -220,8 +220,6 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
|
|||||||
fIsActiveWin(true),
|
fIsActiveWin(true),
|
||||||
fProgressWindow(NULL)
|
fProgressWindow(NULL)
|
||||||
{
|
{
|
||||||
_InitPatterns();
|
|
||||||
|
|
||||||
ShowImageSettings* settings;
|
ShowImageSettings* settings;
|
||||||
settings = my_app->Settings();
|
settings = my_app->Settings();
|
||||||
if (settings->Lock()) {
|
if (settings->Lock()) {
|
||||||
@@ -246,60 +244,6 @@ ShowImageView::~ShowImageView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Use patterns to simulate marching ants for selection
|
|
||||||
void
|
|
||||||
ShowImageView::_InitPatterns()
|
|
||||||
{
|
|
||||||
uchar p;
|
|
||||||
uchar p1 = 0x33;
|
|
||||||
uchar p2 = 0xCC;
|
|
||||||
for (int i = 0; i <= 7; i ++) {
|
|
||||||
fPatternLeft.data[i] = p1;
|
|
||||||
fPatternRight.data[i] = p2;
|
|
||||||
if ((i / 2) % 2 == 0)
|
|
||||||
p = 255;
|
|
||||||
else
|
|
||||||
p = 0;
|
|
||||||
fPatternUp.data[i] = p;
|
|
||||||
fPatternDown.data[i] = ~p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::_RotatePatterns()
|
|
||||||
{
|
|
||||||
// rotate up
|
|
||||||
uchar p = fPatternUp.data[0];
|
|
||||||
for (int i = 0; i <= 6; i ++)
|
|
||||||
fPatternUp.data[i] = fPatternUp.data[i + 1];
|
|
||||||
fPatternUp.data[7] = p;
|
|
||||||
|
|
||||||
// rotate down
|
|
||||||
p = fPatternDown.data[7];
|
|
||||||
for (int i = 7; i >= 1; i --)
|
|
||||||
fPatternDown.data[i] = fPatternDown.data[i - 1];
|
|
||||||
fPatternDown.data[0] = p;
|
|
||||||
|
|
||||||
// rotate to left
|
|
||||||
p = fPatternLeft.data[0];
|
|
||||||
bool set = (p & 0x80) != 0;
|
|
||||||
p <<= 1;
|
|
||||||
p &= 0xfe;
|
|
||||||
if (set)
|
|
||||||
p |= 1;
|
|
||||||
memset(fPatternLeft.data, p, 8);
|
|
||||||
|
|
||||||
// rotate to right
|
|
||||||
p = fPatternRight.data[0];
|
|
||||||
set = (p & 1) != 0;
|
|
||||||
p >>= 1;
|
|
||||||
if (set)
|
|
||||||
p |= 0x80;
|
|
||||||
memset(fPatternRight.data, p, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::_AnimateSelection(bool enabled)
|
ShowImageView::_AnimateSelection(bool enabled)
|
||||||
{
|
{
|
||||||
@@ -312,8 +256,8 @@ ShowImageView::Pulse()
|
|||||||
{
|
{
|
||||||
// animate marching ants
|
// animate marching ants
|
||||||
if (fHasSelection && fAnimateSelection && fIsActiveWin) {
|
if (fHasSelection && fAnimateSelection && fIsActiveWin) {
|
||||||
_RotatePatterns();
|
fSelectionBox.Animate();
|
||||||
_DrawSelectionBox();
|
fSelectionBox.Draw(this, Bounds());
|
||||||
}
|
}
|
||||||
if (fSlideShow) {
|
if (fSlideShow) {
|
||||||
fSlideShowCountDown --;
|
fSlideShowCountDown --;
|
||||||
@@ -424,8 +368,8 @@ ShowImageView::_UpdateStatusText()
|
|||||||
if (fHasSelection) {
|
if (fHasSelection) {
|
||||||
char size[50];
|
char size[50];
|
||||||
sprintf(size, " (%.0fx%.0f)",
|
sprintf(size, " (%.0fx%.0f)",
|
||||||
fSelectionRect.Width()+1.0,
|
fSelectionBox.Bounds().Width() + 1.0,
|
||||||
fSelectionRect.Height()+1.0);
|
fSelectionBox.Bounds().Height() + 1.0);
|
||||||
status_to_send << size;
|
status_to_send << size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,6 +556,50 @@ ShowImageView::SetImage(const entry_ref *ref)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BPoint
|
||||||
|
ShowImageView::ImageToView(BPoint p) const
|
||||||
|
{
|
||||||
|
p.x = floorf(fZoom * p.x + fBitmapLocationInView.x);
|
||||||
|
p.y = floorf(fZoom * p.y + fBitmapLocationInView.y);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BPoint
|
||||||
|
ShowImageView::ViewToImage(BPoint p) const
|
||||||
|
{
|
||||||
|
p.x = floorf((p.x - fBitmapLocationInView.x) / fZoom);
|
||||||
|
p.y = floorf((p.y - fBitmapLocationInView.y) / fZoom);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRect
|
||||||
|
ShowImageView::ImageToView(BRect r) const
|
||||||
|
{
|
||||||
|
BPoint leftTop(ImageToView(BPoint(r.left, r.top)));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::ConstrainToImage(BPoint& point) const
|
||||||
|
{
|
||||||
|
point.ConstrainTo(fBitmap->Bounds());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::ConstrainToImage(BRect& rect) const
|
||||||
|
{
|
||||||
|
rect = rect & fBitmap->Bounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ShowImageView::_SetSelection(const entry_ref *ref, BPoint point)
|
ShowImageView::_SetSelection(const entry_ref *ref, BPoint point)
|
||||||
{
|
{
|
||||||
@@ -822,36 +810,6 @@ ShowImageView::_Setup(BRect rect)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BPoint
|
|
||||||
ShowImageView::_ImageToView(BPoint p) const
|
|
||||||
{
|
|
||||||
p.x = floorf(fZoom * p.x + fBitmapLocationInView.x);
|
|
||||||
p.y = floorf(fZoom * p.y + fBitmapLocationInView.y);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BPoint
|
|
||||||
ShowImageView::_ViewToImage(BPoint p) const
|
|
||||||
{
|
|
||||||
p.x = floorf((p.x - fBitmapLocationInView.x) / fZoom);
|
|
||||||
p.y = floorf((p.y - fBitmapLocationInView.y) / fZoom);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BRect
|
|
||||||
ShowImageView::_ImageToView(BRect r) const
|
|
||||||
{
|
|
||||||
BPoint leftTop(_ImageToView(BPoint(r.left, r.top)));
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::_DrawBorder(BRect border)
|
ShowImageView::_DrawBorder(BRect border)
|
||||||
{
|
{
|
||||||
@@ -1009,39 +967,14 @@ ShowImageView::Draw(BRect updateRect)
|
|||||||
BRect srcRect;
|
BRect srcRect;
|
||||||
BRect dstRect;
|
BRect dstRect;
|
||||||
_GetSelectionMergeRects(srcRect, dstRect);
|
_GetSelectionMergeRects(srcRect, dstRect);
|
||||||
dstRect = _ImageToView(dstRect);
|
dstRect = ImageToView(dstRect);
|
||||||
DrawBitmap(fSelectionBitmap, srcRect, dstRect);
|
DrawBitmap(fSelectionBitmap, srcRect, dstRect);
|
||||||
}
|
}
|
||||||
_DrawSelectionBox();
|
fSelectionBox.Draw(this, updateRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::_DrawSelectionBox()
|
|
||||||
{
|
|
||||||
if (fSelectionRect.Height() <= 0.0 || fSelectionRect.Width() <= 0.0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
BRect r(fSelectionRect);
|
|
||||||
_ConstrainToImage(r);
|
|
||||||
r = _ImageToView(r);
|
|
||||||
// draw selection box *around* selection
|
|
||||||
r.InsetBy(-1, -1);
|
|
||||||
PushState();
|
|
||||||
SetLowColor(255, 255, 255);
|
|
||||||
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.left, r.bottom), BPoint(r.right, r.bottom),
|
|
||||||
fPatternRight);
|
|
||||||
StrokeLine(BPoint(r.left, r.top + 1), BPoint(r.left, r.bottom - 1),
|
|
||||||
fPatternDown);
|
|
||||||
PopState();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::FrameResized(float /* width */, float /* height */)
|
ShowImageView::FrameResized(float /* width */, float /* height */)
|
||||||
{
|
{
|
||||||
@@ -1049,20 +982,6 @@ ShowImageView::FrameResized(float /* width */, float /* height */)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::_ConstrainToImage(BPoint &point)
|
|
||||||
{
|
|
||||||
point.ConstrainTo(fBitmap->Bounds());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::_ConstrainToImage(BRect &rect)
|
|
||||||
{
|
|
||||||
rect = rect & fBitmap->Bounds();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BBitmap*
|
BBitmap*
|
||||||
ShowImageView::_CopyFromRect(BRect srcRect)
|
ShowImageView::_CopyFromRect(BRect srcRect)
|
||||||
{
|
{
|
||||||
@@ -1094,7 +1013,7 @@ ShowImageView::_CopySelection(uchar alpha, bool imageSize)
|
|||||||
if (!fHasSelection)
|
if (!fHasSelection)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
BRect rect(0, 0, fSelectionRect.Width(), fSelectionRect.Height());
|
BRect rect = fSelectionBox.Bounds().OffsetToCopy(B_ORIGIN);
|
||||||
if (!imageSize) {
|
if (!imageSize) {
|
||||||
// scale image to view size
|
// scale image to view size
|
||||||
rect.right = floorf((rect.right + 1.0) * fZoom - 1.0);
|
rect.right = floorf((rect.right + 1.0) * fZoom - 1.0);
|
||||||
@@ -1211,7 +1130,7 @@ ShowImageView::_BeginDrag(BPoint sourcePoint)
|
|||||||
drag.AddString("be:clip_name", "Bitmap Clip");
|
drag.AddString("be:clip_name", "Bitmap Clip");
|
||||||
// ShowImage specific fields
|
// ShowImage specific fields
|
||||||
drag.AddPoint("be:_source_point", sourcePoint);
|
drag.AddPoint("be:_source_point", sourcePoint);
|
||||||
drag.AddRect("be:_frame", fSelectionRect);
|
drag.AddRect("be:_frame", fSelectionBox.Bounds());
|
||||||
if (_AddSupportedTypes(&drag, bitmap)) {
|
if (_AddSupportedTypes(&drag, bitmap)) {
|
||||||
// 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);
|
||||||
@@ -1219,9 +1138,10 @@ ShowImageView::_BeginDrag(BPoint sourcePoint)
|
|||||||
_AnimateSelection(false);
|
_AnimateSelection(false);
|
||||||
// only use a transparent bitmap on selections less than 400x400
|
// only use a transparent bitmap on selections less than 400x400
|
||||||
// (taking into account zooming)
|
// (taking into account zooming)
|
||||||
if ((fSelectionRect.Width() * fZoom) < 400.0
|
BRect selectionRect = fSelectionBox.Bounds();
|
||||||
&& (fSelectionRect.Height() * fZoom) < 400.0) {
|
if ((selectionRect.Width() * fZoom) < 400.0
|
||||||
sourcePoint -= fSelectionRect.LeftTop();
|
&& (selectionRect.Height() * fZoom) < 400.0) {
|
||||||
|
sourcePoint -= selectionRect.LeftTop();
|
||||||
sourcePoint.x *= fZoom;
|
sourcePoint.x *= fZoom;
|
||||||
sourcePoint.y *= fZoom;
|
sourcePoint.y *= fZoom;
|
||||||
// DragMessage takes ownership of bitmap
|
// DragMessage takes ownership of bitmap
|
||||||
@@ -1230,8 +1150,8 @@ ShowImageView::_BeginDrag(BPoint sourcePoint)
|
|||||||
} else {
|
} else {
|
||||||
delete bitmap;
|
delete bitmap;
|
||||||
// Offset and scale the rect
|
// Offset and scale the rect
|
||||||
BRect rect(fSelectionRect);
|
BRect rect(selectionRect);
|
||||||
rect = _ImageToView(rect);
|
rect = ImageToView(rect);
|
||||||
rect.InsetBy(-1, -1);
|
rect.InsetBy(-1, -1);
|
||||||
DragMessage(&drag, rect);
|
DragMessage(&drag, rect);
|
||||||
}
|
}
|
||||||
@@ -1414,7 +1334,7 @@ ShowImageView::_GetMergeRects(BBitmap* merge, BRect selection, BRect& srcRect,
|
|||||||
dstRect = selection;
|
dstRect = selection;
|
||||||
|
|
||||||
BRect clippedDstRect(dstRect);
|
BRect clippedDstRect(dstRect);
|
||||||
_ConstrainToImage(clippedDstRect);
|
ConstrainToImage(clippedDstRect);
|
||||||
|
|
||||||
srcRect = merge->Bounds().OffsetToCopy(B_ORIGIN);
|
srcRect = merge->Bounds().OffsetToCopy(B_ORIGIN);
|
||||||
|
|
||||||
@@ -1430,7 +1350,7 @@ ShowImageView::_GetMergeRects(BBitmap* merge, BRect selection, BRect& srcRect,
|
|||||||
void
|
void
|
||||||
ShowImageView::_GetSelectionMergeRects(BRect& srcRect, BRect& dstRect)
|
ShowImageView::_GetSelectionMergeRects(BRect& srcRect, BRect& dstRect)
|
||||||
{
|
{
|
||||||
_GetMergeRects(fSelectionBitmap, fSelectionRect, srcRect, dstRect);
|
_GetMergeRects(fSelectionBitmap, fSelectionBox.Bounds(), srcRect, dstRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1475,14 +1395,14 @@ ShowImageView::_MergeSelection()
|
|||||||
if (fSelectionBitmap == NULL) {
|
if (fSelectionBitmap == NULL) {
|
||||||
// Even though the merge will not change the background image,
|
// Even though the merge will not change the background image,
|
||||||
// undo information still needs to be saved here.
|
// undo information still needs to be saved here.
|
||||||
fUndo.SetTo(fSelectionRect, NULL, _CopySelection());
|
fUndo.SetTo(fSelectionBox.Bounds(), NULL, _CopySelection());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge selection with background
|
// Merge selection with background
|
||||||
fUndo.SetTo(fSelectionRect, _CopyFromRect(fSelectionRect),
|
fUndo.SetTo(fSelectionBox.Bounds(), _CopyFromRect(fSelectionBox.Bounds()),
|
||||||
_CopySelection());
|
_CopySelection());
|
||||||
_MergeWithBitmap(fSelectionBitmap, fSelectionRect);
|
_MergeWithBitmap(fSelectionBitmap, fSelectionBox.Bounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1493,10 +1413,10 @@ ShowImageView::MouseDown(BPoint position)
|
|||||||
uint32 buttons;
|
uint32 buttons;
|
||||||
MakeFocus(true);
|
MakeFocus(true);
|
||||||
|
|
||||||
point = _ViewToImage(position);
|
point = ViewToImage(position);
|
||||||
buttons = _GetMouseButtons();
|
buttons = _GetMouseButtons();
|
||||||
|
|
||||||
if (fHasSelection && fSelectionRect.Contains(point)
|
if (fHasSelection && fSelectionBox.Bounds().Contains(point)
|
||||||
&& (buttons & (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON))) {
|
&& (buttons & (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON))) {
|
||||||
if (!fSelectionBitmap)
|
if (!fSelectionBitmap)
|
||||||
fSelectionBitmap = _CopySelection();
|
fSelectionBitmap = _CopySelection();
|
||||||
@@ -1515,19 +1435,11 @@ ShowImageView::MouseDown(BPoint position)
|
|||||||
if (Bounds().Contains(point)) {
|
if (Bounds().Contains(point)) {
|
||||||
// If selection stayed inside this view
|
// If selection stayed inside this view
|
||||||
// (Some of the selection may be in the border area, which can be OK)
|
// (Some of the selection may be in the border area, which can be OK)
|
||||||
BPoint last, diff;
|
BPoint last = ViewToImage(point);
|
||||||
last = _ViewToImage(point);
|
BPoint diff = last - sourcePoint;
|
||||||
diff = last - sourcePoint;
|
|
||||||
|
|
||||||
BRect newSelection = fSelectionRect;
|
fSelectionBox.SetBounds(this,
|
||||||
newSelection.OffsetBy(diff);
|
fSelectionBox.Bounds().OffsetByCopy(diff));
|
||||||
|
|
||||||
if (fBitmap->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);
|
_AnimateSelection(true);
|
||||||
@@ -1540,10 +1452,10 @@ ShowImageView::MouseDown(BPoint position)
|
|||||||
_SetHasSelection(true);
|
_SetHasSelection(true);
|
||||||
fCreatingSelection = true;
|
fCreatingSelection = true;
|
||||||
SetMouseEventMask(B_POINTER_EVENTS);
|
SetMouseEventMask(B_POINTER_EVENTS);
|
||||||
_ConstrainToImage(point);
|
ConstrainToImage(point);
|
||||||
fFirstPoint = point;
|
fFirstPoint = point;
|
||||||
fCopyFromRect.Set(point.x, point.y, point.x, point.y);
|
fCopyFromRect.Set(point.x, point.y, point.x, point.y);
|
||||||
fSelectionRect = fCopyFromRect;
|
fSelectionBox.SetBounds(this, fCopyFromRect);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
} else if (buttons == B_SECONDARY_MOUSE_BUTTON) {
|
} else if (buttons == B_SECONDARY_MOUSE_BUTTON) {
|
||||||
_ShowPopUpMenu(ConvertToScreen(position));
|
_ShowPopUpMenu(ConvertToScreen(position));
|
||||||
@@ -1560,13 +1472,13 @@ void
|
|||||||
ShowImageView::_UpdateSelectionRect(BPoint point, bool final)
|
ShowImageView::_UpdateSelectionRect(BPoint point, bool final)
|
||||||
{
|
{
|
||||||
BRect oldSelection = fCopyFromRect;
|
BRect oldSelection = fCopyFromRect;
|
||||||
point = _ViewToImage(point);
|
point = ViewToImage(point);
|
||||||
_ConstrainToImage(point);
|
ConstrainToImage(point);
|
||||||
fCopyFromRect.left = min_c(fFirstPoint.x, point.x);
|
fCopyFromRect.left = min_c(fFirstPoint.x, point.x);
|
||||||
fCopyFromRect.right = max_c(fFirstPoint.x, point.x);
|
fCopyFromRect.right = max_c(fFirstPoint.x, point.x);
|
||||||
fCopyFromRect.top = min_c(fFirstPoint.y, point.y);
|
fCopyFromRect.top = min_c(fFirstPoint.y, point.y);
|
||||||
fCopyFromRect.bottom = max_c(fFirstPoint.y, point.y);
|
fCopyFromRect.bottom = max_c(fFirstPoint.y, point.y);
|
||||||
fSelectionRect = fCopyFromRect;
|
fSelectionBox.SetBounds(this, fCopyFromRect);
|
||||||
|
|
||||||
if (final) {
|
if (final) {
|
||||||
// selection must be at least 2 pixels wide or 2 pixels tall
|
// selection must be at least 2 pixels wide or 2 pixels tall
|
||||||
@@ -1578,7 +1490,7 @@ ShowImageView::_UpdateSelectionRect(BPoint point, bool final)
|
|||||||
if (oldSelection != fCopyFromRect || !fHasSelection) {
|
if (oldSelection != fCopyFromRect || !fHasSelection) {
|
||||||
BRect updateRect;
|
BRect updateRect;
|
||||||
updateRect = oldSelection | fCopyFromRect;
|
updateRect = oldSelection | fCopyFromRect;
|
||||||
updateRect = _ImageToView(updateRect);
|
updateRect = ImageToView(updateRect);
|
||||||
updateRect.InsetBy(-PEN_SIZE, -PEN_SIZE);
|
updateRect.InsetBy(-PEN_SIZE, -PEN_SIZE);
|
||||||
Invalidate(updateRect);
|
Invalidate(updateRect);
|
||||||
}
|
}
|
||||||
@@ -1853,7 +1765,7 @@ ShowImageView::MessageReceived(BMessage *message)
|
|||||||
if (message->FindRef("refs", 0, &ref) == B_OK) {
|
if (message->FindRef("refs", 0, &ref) == B_OK) {
|
||||||
BPoint point = message->DropPoint();
|
BPoint point = message->DropPoint();
|
||||||
point = ConvertFromScreen(point);
|
point = ConvertFromScreen(point);
|
||||||
point = _ViewToImage(point);
|
point = ViewToImage(point);
|
||||||
_SetSelection(&ref, point);
|
_SetSelection(&ref, point);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1878,7 +1790,7 @@ ShowImageView::MessageReceived(BMessage *message)
|
|||||||
point.y - (sourcePoint.y - sourceRect.top));
|
point.y - (sourcePoint.y - sourceRect.top));
|
||||||
// adjust drop point before scaling is factored in
|
// adjust drop point before scaling is factored in
|
||||||
point = ConvertFromScreen(point);
|
point = ConvertFromScreen(point);
|
||||||
point = _ViewToImage(point);
|
point = ViewToImage(point);
|
||||||
|
|
||||||
_PasteBitmap(bitmap, point);
|
_PasteBitmap(bitmap, point);
|
||||||
}
|
}
|
||||||
@@ -1969,7 +1881,7 @@ ShowImageView::Undo()
|
|||||||
// backup current selection
|
// backup current selection
|
||||||
BRect undoneSelRect;
|
BRect undoneSelRect;
|
||||||
BBitmap *undoneSelection;
|
BBitmap *undoneSelection;
|
||||||
undoneSelRect = fSelectionRect;
|
undoneSelRect = fSelectionBox.Bounds();
|
||||||
undoneSelection = _CopySelection();
|
undoneSelection = _CopySelection();
|
||||||
|
|
||||||
if (undoType == UNDO_UNDO) {
|
if (undoType == UNDO_UNDO) {
|
||||||
@@ -1988,7 +1900,7 @@ ShowImageView::Undo()
|
|||||||
_SetHasSelection(false);
|
_SetHasSelection(false);
|
||||||
else {
|
else {
|
||||||
fCopyFromRect = BRect();
|
fCopyFromRect = BRect();
|
||||||
fSelectionRect = fUndo.GetRect();
|
fSelectionBox.SetBounds(this, fUndo.GetRect());
|
||||||
_SetHasSelection(true);
|
_SetHasSelection(true);
|
||||||
fSelectionBitmap = undoSelection;
|
fSelectionBitmap = undoSelection;
|
||||||
}
|
}
|
||||||
@@ -2036,7 +1948,7 @@ ShowImageView::_RemoveSelection(bool toClipboard, bool neverCutBackground)
|
|||||||
if (!fHasSelection)
|
if (!fHasSelection)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BRect rect = fSelectionRect;
|
BRect rect = fSelectionBox.Bounds();
|
||||||
bool cutBackground = (fSelectionBitmap) ? false : true;
|
bool cutBackground = (fSelectionBitmap) ? false : true;
|
||||||
BBitmap* selection = _CopySelection();
|
BBitmap* selection = _CopySelection();
|
||||||
BBitmap* restore = NULL;
|
BBitmap* restore = NULL;
|
||||||
@@ -2076,21 +1988,19 @@ ShowImageView::_PasteBitmap(BBitmap* bitmap, BPoint point)
|
|||||||
_MergeSelection();
|
_MergeSelection();
|
||||||
|
|
||||||
fCopyFromRect = BRect();
|
fCopyFromRect = BRect();
|
||||||
fSelectionRect = bitmap->Bounds().OffsetToCopy(B_ORIGIN);
|
BRect selectionRect = bitmap->Bounds().OffsetToCopy(B_ORIGIN);
|
||||||
_SetHasSelection(true);
|
_SetHasSelection(true);
|
||||||
delete fSelectionBitmap;
|
delete fSelectionBitmap;
|
||||||
fSelectionBitmap = bitmap;
|
fSelectionBitmap = bitmap;
|
||||||
|
|
||||||
BRect offsetRect(fSelectionRect.OffsetToCopy(point));
|
BRect offsetRect(selectionRect.OffsetToCopy(point));
|
||||||
if (fBitmap->Bounds().Intersects(offsetRect)) {
|
if (fBitmap->Bounds().Intersects(offsetRect)) {
|
||||||
// Move the selection rectangle to desired origin,
|
// Move the selection rectangle to desired origin,
|
||||||
// but only if the resulting selection rectangle
|
// but only if the resulting selection rectangle
|
||||||
// intersects with the background bitmap rectangle
|
// intersects with the background bitmap rectangle
|
||||||
fSelectionRect = offsetRect;
|
selectionRect = offsetRect;
|
||||||
}
|
}
|
||||||
printf("bitmap: "); bitmap->Bounds().PrintToStream();
|
fSelectionBox.SetBounds(this, selectionRect);
|
||||||
printf("selection: "); fSelectionRect.PrintToStream();
|
|
||||||
printf("point: "); point.PrintToStream();
|
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
|
||||||
@@ -2131,7 +2041,7 @@ ShowImageView::SelectAll()
|
|||||||
_SetHasSelection(true);
|
_SetHasSelection(true);
|
||||||
fCopyFromRect.Set(0, 0, fBitmap->Bounds().Width(),
|
fCopyFromRect.Set(0, 0, fBitmap->Bounds().Width(),
|
||||||
fBitmap->Bounds().Height());
|
fBitmap->Bounds().Height());
|
||||||
fSelectionRect = fCopyFromRect;
|
fSelectionBox.SetBounds(this, fCopyFromRect);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2178,7 +2088,7 @@ ShowImageView::CopySelectionToClipboard()
|
|||||||
// This works with WonderBrush, though, which in turn had been
|
// This works with WonderBrush, though, which in turn had been
|
||||||
// tested with other apps.
|
// tested with other apps.
|
||||||
data->AddMessage("image/bitmap", &bitmapArchive);
|
data->AddMessage("image/bitmap", &bitmapArchive);
|
||||||
data->AddPoint("be:location", fSelectionRect.LeftTop());
|
data->AddPoint("be:location", fSelectionBox.Bounds().LeftTop());
|
||||||
|
|
||||||
delete bitmap;
|
delete bitmap;
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Filter.h"
|
#include "Filter.h"
|
||||||
|
#include "SelectionBox.h"
|
||||||
#include "ShowImageUndo.h"
|
#include "ShowImageUndo.h"
|
||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
@@ -64,6 +65,12 @@ public:
|
|||||||
status_t SetImage(const entry_ref* ref);
|
status_t SetImage(const entry_ref* ref);
|
||||||
const entry_ref* Image() const { return &fCurrentRef; }
|
const entry_ref* Image() const { return &fCurrentRef; }
|
||||||
|
|
||||||
|
BPoint ImageToView(BPoint p) const;
|
||||||
|
BPoint ViewToImage(BPoint p) const;
|
||||||
|
BRect ImageToView(BRect r) const;
|
||||||
|
void ConstrainToImage(BPoint& point) const;
|
||||||
|
void ConstrainToImage(BRect& rect) const;
|
||||||
|
|
||||||
void SaveToFile(BDirectory* dir, const char* name,
|
void SaveToFile(BDirectory* dir, const char* name,
|
||||||
BBitmap* bitmap,
|
BBitmap* bitmap,
|
||||||
const translation_format* format);
|
const translation_format* format);
|
||||||
@@ -141,8 +148,6 @@ private:
|
|||||||
kNumberOfOrientations,
|
kNumberOfOrientations,
|
||||||
};
|
};
|
||||||
|
|
||||||
void _InitPatterns();
|
|
||||||
void _RotatePatterns();
|
|
||||||
void _RemoveSelection(bool bToClipboard,
|
void _RemoveSelection(bool bToClipboard,
|
||||||
bool neverCutBackground = false);
|
bool neverCutBackground = false);
|
||||||
void _SetHasSelection(bool bHasSelection);
|
void _SetHasSelection(bool bHasSelection);
|
||||||
@@ -183,9 +188,6 @@ private:
|
|||||||
bool quiet = false);
|
bool quiet = false);
|
||||||
BRect _AlignBitmap();
|
BRect _AlignBitmap();
|
||||||
void _Setup(BRect r);
|
void _Setup(BRect r);
|
||||||
BPoint _ImageToView(BPoint p) const;
|
|
||||||
BPoint _ViewToImage(BPoint p) const;
|
|
||||||
BRect _ImageToView(BRect r) const;
|
|
||||||
bool _IsImage(const entry_ref* pref);
|
bool _IsImage(const entry_ref* pref);
|
||||||
static int _CompareEntries(const void* a, const void* b);
|
static int _CompareEntries(const void* a, const void* b);
|
||||||
void _FreeEntries(BList* entries);
|
void _FreeEntries(BList* entries);
|
||||||
@@ -195,8 +197,6 @@ private:
|
|||||||
bool rewind);
|
bool rewind);
|
||||||
bool _ShowNextImage(bool next, bool rewind);
|
bool _ShowNextImage(bool next, bool rewind);
|
||||||
bool _FirstFile();
|
bool _FirstFile();
|
||||||
void _ConstrainToImage(BPoint& point);
|
|
||||||
void _ConstrainToImage(BRect& rect);
|
|
||||||
BBitmap* _CopyFromRect(BRect srcRect);
|
BBitmap* _CopyFromRect(BRect srcRect);
|
||||||
BBitmap* _CopySelection(uchar alpha = 255,
|
BBitmap* _CopySelection(uchar alpha = 255,
|
||||||
bool imageSize = true);
|
bool imageSize = true);
|
||||||
@@ -218,7 +218,6 @@ private:
|
|||||||
BRect& background);
|
BRect& background);
|
||||||
void _DrawCaption();
|
void _DrawCaption();
|
||||||
void _UpdateCaption();
|
void _UpdateCaption();
|
||||||
void _DrawSelectionBox();
|
|
||||||
|
|
||||||
Scaler* _GetScaler(BRect rect);
|
Scaler* _GetScaler(BRect rect);
|
||||||
void _DrawImage(BRect rect);
|
void _DrawImage(BRect rect);
|
||||||
@@ -272,16 +271,11 @@ private:
|
|||||||
// first point in image space of selection
|
// first point in image space of selection
|
||||||
bool fAnimateSelection;
|
bool fAnimateSelection;
|
||||||
bool fHasSelection;
|
bool fHasSelection;
|
||||||
BRect fSelectionRect;
|
SelectionBox fSelectionBox;
|
||||||
BRect fCopyFromRect;
|
BRect fCopyFromRect;
|
||||||
// the portion of the background bitmap the selection is made
|
// the portion of the background bitmap the selection is made
|
||||||
// from
|
// from
|
||||||
|
|
||||||
pattern fPatternUp;
|
|
||||||
pattern fPatternDown;
|
|
||||||
pattern fPatternLeft;
|
|
||||||
pattern fPatternRight;
|
|
||||||
|
|
||||||
bool fSlideShow;
|
bool fSlideShow;
|
||||||
int fSlideShowDelay;
|
int fSlideShowDelay;
|
||||||
// in pulse rate units
|
// in pulse rate units
|
||||||
|
|||||||
Reference in New Issue
Block a user