- added option resize image to window size
- added show next/previous file using Command + Cursor Up/Down key - rewrote selection code - added marching ants - renamed member variables to start with capital letter after field prefix git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5255 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -46,8 +46,8 @@ int main(int, char **)
|
|||||||
ShowImageApp::ShowImageApp()
|
ShowImageApp::ShowImageApp()
|
||||||
: BApplication(APP_SIG)
|
: BApplication(APP_SIG)
|
||||||
{
|
{
|
||||||
fbpulseStarted = false;
|
fbPulseStarted = false;
|
||||||
fpopenPanel = new BFilePanel(B_OPEN_PANEL);
|
fpOpenPanel = new BFilePanel(B_OPEN_PANEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -62,7 +62,7 @@ void
|
|||||||
ShowImageApp::ReadyToRun()
|
ShowImageApp::ReadyToRun()
|
||||||
{
|
{
|
||||||
if (CountWindows() == WINDOWS_TO_IGNORE)
|
if (CountWindows() == WINDOWS_TO_IGNORE)
|
||||||
fpopenPanel->Show();
|
fpOpenPanel->Show();
|
||||||
else
|
else
|
||||||
// If image windows are already open
|
// If image windows are already open
|
||||||
// (paths supplied on the command line)
|
// (paths supplied on the command line)
|
||||||
@@ -73,10 +73,10 @@ ShowImageApp::ReadyToRun()
|
|||||||
void
|
void
|
||||||
ShowImageApp::StartPulse()
|
ShowImageApp::StartPulse()
|
||||||
{
|
{
|
||||||
if (!fbpulseStarted) {
|
if (!fbPulseStarted) {
|
||||||
// Tell the app to begin checking
|
// Tell the app to begin checking
|
||||||
// for the number of open windows
|
// for the number of open windows
|
||||||
fbpulseStarted = true;
|
fbPulseStarted = true;
|
||||||
SetPulseRate(250000);
|
SetPulseRate(250000);
|
||||||
// Set pulse to every 1/4 second
|
// Set pulse to every 1/4 second
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ ShowImageApp::MessageReceived(BMessage *pmsg)
|
|||||||
{
|
{
|
||||||
switch (pmsg->what) {
|
switch (pmsg->what) {
|
||||||
case MSG_FILE_OPEN:
|
case MSG_FILE_OPEN:
|
||||||
fpopenPanel->Show();
|
fpOpenPanel->Show();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_WINDOW_QUIT:
|
case MSG_WINDOW_QUIT:
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ private:
|
|||||||
void StartPulse();
|
void StartPulse();
|
||||||
void Open(const entry_ref *pref);
|
void Open(const entry_ref *pref);
|
||||||
|
|
||||||
BFilePanel *fpopenPanel;
|
BFilePanel *fpOpenPanel;
|
||||||
bool fbpulseStarted;
|
bool fbPulseStarted;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _ShowImageApp_h */
|
#endif /* _ShowImageApp_h */
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ const uint32 MSG_PAGE_FIRST = 'mPGF';
|
|||||||
const uint32 MSG_PAGE_LAST = 'mPGL';
|
const uint32 MSG_PAGE_LAST = 'mPGL';
|
||||||
const uint32 MSG_PAGE_NEXT = 'mPGN';
|
const uint32 MSG_PAGE_NEXT = 'mPGN';
|
||||||
const uint32 MSG_PAGE_PREV = 'mPGP';
|
const uint32 MSG_PAGE_PREV = 'mPGP';
|
||||||
|
const uint32 MSG_FILE_NEXT = 'mFLN';
|
||||||
|
const uint32 MSG_FILE_PREV = 'mFLP';
|
||||||
|
const uint32 MSG_FIT_TO_WINDOW_SIZE = 'mFWS';
|
||||||
|
|
||||||
extern const char *APP_SIG;
|
extern const char *APP_SIG;
|
||||||
|
|
||||||
|
|||||||
@@ -37,12 +37,12 @@ ShowImageStatusView::ShowImageStatusView(BRect rect, const char* name,
|
|||||||
void
|
void
|
||||||
ShowImageStatusView::Draw(BRect updateRect)
|
ShowImageStatusView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
DrawString(fstrText.String(), BPoint(3, 11));
|
DrawString(fText.String(), BPoint(3, 11));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageStatusView::SetText(BString &strText)
|
ShowImageStatusView::SetText(BString &text)
|
||||||
{
|
{
|
||||||
fstrText = strText;
|
fText = text;
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,10 +39,10 @@ public:
|
|||||||
|
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
|
|
||||||
void SetText(BString &strText);
|
void SetText(BString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BString fstrText;
|
BString fText;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _ShowImageStatusView_h */
|
#endif /* _ShowImageStatusView_h */
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
#include <BitmapStream.h>
|
#include <BitmapStream.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
#include <Directory.h>
|
||||||
|
|
||||||
#include "ShowImageConstants.h"
|
#include "ShowImageConstants.h"
|
||||||
#include "ShowImageView.h"
|
#include "ShowImageView.h"
|
||||||
@@ -55,36 +56,129 @@
|
|||||||
#define PEN_SIZE 1.0f
|
#define PEN_SIZE 1.0f
|
||||||
const rgb_color kborderColor = { 0, 0, 0, 255 };
|
const rgb_color kborderColor = { 0, 0, 0, 255 };
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
uchar p;
|
||||||
|
bool set;
|
||||||
|
|
||||||
|
// rotate up
|
||||||
|
p = fPatternUp.data[0];
|
||||||
|
for (i = 0; i <= 6; i ++) {
|
||||||
|
fPatternUp.data[i] = fPatternUp.data[i+1];
|
||||||
|
}
|
||||||
|
fPatternUp.data[7] = p;
|
||||||
|
|
||||||
|
// rotate down
|
||||||
|
p = fPatternDown.data[7];
|
||||||
|
for (i = 7; i >= 1; i --) {
|
||||||
|
fPatternDown.data[i] = fPatternDown.data[i-1];
|
||||||
|
}
|
||||||
|
fPatternDown.data[0] = p;
|
||||||
|
|
||||||
|
// rotate to left
|
||||||
|
p = fPatternLeft.data[0];
|
||||||
|
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
|
||||||
|
ShowImageView::Pulse()
|
||||||
|
{
|
||||||
|
RotatePatterns();
|
||||||
|
if (fbHasSelection) {
|
||||||
|
DrawSelectionBox(fSelectionRect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
|
ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
|
||||||
uint32 flags)
|
uint32 flags)
|
||||||
: BView(rect, name, resizingMode, flags)
|
: BView(rect, name, resizingMode, flags)
|
||||||
{
|
{
|
||||||
fpbitmap = NULL;
|
InitPatterns();
|
||||||
fdocumentIndex = 1;
|
|
||||||
fdocumentCount = 1;
|
|
||||||
fbhasSelection = false;
|
|
||||||
|
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
fpBitmap = NULL;
|
||||||
|
fDocumentIndex = 1;
|
||||||
|
fDocumentCount = 1;
|
||||||
|
fbHasSelection = false;
|
||||||
|
fResizeToViewBounds = false;
|
||||||
|
|
||||||
|
SetViewColor(B_TRANSPARENT_COLOR);
|
||||||
SetHighColor(kborderColor);
|
SetHighColor(kborderColor);
|
||||||
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
SetPenSize(PEN_SIZE);
|
SetPenSize(PEN_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowImageView::~ShowImageView()
|
ShowImageView::~ShowImageView()
|
||||||
{
|
{
|
||||||
delete fpbitmap;
|
delete fpBitmap;
|
||||||
fpbitmap = NULL;
|
fpBitmap = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ShowImageView::IsImage(const entry_ref *pref)
|
||||||
|
{
|
||||||
|
BFile file(pref, B_READ_ONLY);
|
||||||
|
translator_info info;
|
||||||
|
memset(&info, 0, sizeof(translator_info));
|
||||||
|
BMessage ioExtension;
|
||||||
|
|
||||||
|
BTranslatorRoster *proster = BTranslatorRoster::Default();
|
||||||
|
if (!proster)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (ioExtension.AddInt32("/documentIndex", fDocumentIndex) != B_OK)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (proster->Identify(&file, &ioExtension, &info, 0, NULL,
|
||||||
|
B_TRANSLATOR_BITMAP) != B_OK)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::SetImage(const entry_ref *pref)
|
ShowImageView::SetImage(const entry_ref *pref)
|
||||||
{
|
{
|
||||||
ClearViewBitmap();
|
delete fpBitmap;
|
||||||
delete fpbitmap;
|
fpBitmap = NULL;
|
||||||
fpbitmap = NULL;
|
fbHasSelection = false;
|
||||||
|
fMakesSelection = false;
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
if (!pref)
|
if (!pref)
|
||||||
ref = fcurrentRef;
|
ref = fCurrentRef;
|
||||||
else
|
else
|
||||||
ref = *pref;
|
ref = *pref;
|
||||||
|
|
||||||
@@ -95,10 +189,10 @@ ShowImageView::SetImage(const entry_ref *pref)
|
|||||||
translator_info info;
|
translator_info info;
|
||||||
memset(&info, 0, sizeof(translator_info));
|
memset(&info, 0, sizeof(translator_info));
|
||||||
BMessage ioExtension;
|
BMessage ioExtension;
|
||||||
if (ref != fcurrentRef)
|
if (ref != fCurrentRef)
|
||||||
// if new image, reset to first document
|
// if new image, reset to first document
|
||||||
fdocumentIndex = 1;
|
fDocumentIndex = 1;
|
||||||
if (ioExtension.AddInt32("/documentIndex", fdocumentIndex) != B_OK)
|
if (ioExtension.AddInt32("/documentIndex", fDocumentIndex) != B_OK)
|
||||||
return;
|
return;
|
||||||
if (proster->Identify(&file, &ioExtension, &info, 0, NULL,
|
if (proster->Identify(&file, &ioExtension, &info, 0, NULL,
|
||||||
B_TRANSLATOR_BITMAP) != B_OK)
|
B_TRANSLATOR_BITMAP) != B_OK)
|
||||||
@@ -109,39 +203,43 @@ ShowImageView::SetImage(const entry_ref *pref)
|
|||||||
if (proster->Translate(&file, &info, &ioExtension, &outstream,
|
if (proster->Translate(&file, &info, &ioExtension, &outstream,
|
||||||
B_TRANSLATOR_BITMAP) != B_OK)
|
B_TRANSLATOR_BITMAP) != B_OK)
|
||||||
return;
|
return;
|
||||||
if (outstream.DetachBitmap(&fpbitmap) != B_OK)
|
if (outstream.DetachBitmap(&fpBitmap) != B_OK)
|
||||||
return;
|
return;
|
||||||
fcurrentRef = ref;
|
fCurrentRef = ref;
|
||||||
|
|
||||||
// get the number of documents (pages) if it has been supplied
|
// get the number of documents (pages) if it has been supplied
|
||||||
int32 documentCount = 0;
|
int32 documentCount = 0;
|
||||||
if (ioExtension.FindInt32("/documentCount", &documentCount) == B_OK &&
|
if (ioExtension.FindInt32("/documentCount", &documentCount) == B_OK &&
|
||||||
documentCount > 0)
|
documentCount > 0)
|
||||||
fdocumentCount = documentCount;
|
fDocumentCount = documentCount;
|
||||||
else
|
else
|
||||||
fdocumentCount = 1;
|
fDocumentCount = 1;
|
||||||
|
|
||||||
// send message to parent about new image
|
// send message to parent about new image
|
||||||
BMessage msg(MSG_UPDATE_STATUS);
|
BMessage msg(MSG_UPDATE_STATUS);
|
||||||
msg.AddString("status", info.name);
|
msg.AddString("status", info.name);
|
||||||
|
msg.AddRef("ref", &fCurrentRef);
|
||||||
BMessenger msgr(Window());
|
BMessenger msgr(Window());
|
||||||
msgr.SendMessage(&msg);
|
msgr.SendMessage(&msg);
|
||||||
|
|
||||||
SetViewBitmap(fpbitmap, fpbitmap->Bounds(),
|
|
||||||
BRect(BORDER_WIDTH, BORDER_HEIGHT,
|
|
||||||
fpbitmap->Bounds().Width() + BORDER_WIDTH,
|
|
||||||
fpbitmap->Bounds().Height() + BORDER_HEIGHT),
|
|
||||||
B_FOLLOW_TOP | B_FOLLOW_LEFT, 0
|
|
||||||
);
|
|
||||||
|
|
||||||
FixupScrollBars();
|
FixupScrollBars();
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::ResizeToViewBounds(bool resize)
|
||||||
|
{
|
||||||
|
if (fResizeToViewBounds != resize) {
|
||||||
|
fResizeToViewBounds = resize;
|
||||||
|
FixupScrollBars();
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BBitmap *
|
BBitmap *
|
||||||
ShowImageView::GetBitmap()
|
ShowImageView::GetBitmap()
|
||||||
{
|
{
|
||||||
return fpbitmap;
|
return fpBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -150,43 +248,122 @@ ShowImageView::AttachedToWindow()
|
|||||||
FixupScrollBars();
|
FixupScrollBars();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BRect
|
||||||
|
ShowImageView::AlignBitmap() const
|
||||||
|
{
|
||||||
|
BRect rect(fpBitmap->Bounds());
|
||||||
|
if (fResizeToViewBounds) {
|
||||||
|
float width, height;
|
||||||
|
width = Bounds().Width()-2*PEN_SIZE;
|
||||||
|
height = Bounds().Height()-2*PEN_SIZE;
|
||||||
|
if (width > 0 && height > 0) {
|
||||||
|
float s;
|
||||||
|
s = width / rect.Width();
|
||||||
|
|
||||||
|
if (s * rect.Height() <= height) {
|
||||||
|
rect.right = width;
|
||||||
|
rect.bottom = s * rect.Height();
|
||||||
|
// center horizontally
|
||||||
|
rect.OffsetBy(0, (height - rect.Height()) / 2);
|
||||||
|
} else {
|
||||||
|
rect.right = height / rect.Height() * rect.Width();
|
||||||
|
rect.bottom = height;
|
||||||
|
// center vertically
|
||||||
|
rect.OffsetBy((width - rect.Width()) / 2, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rect.OffsetBy(BORDER_WIDTH, BORDER_WIDTH);
|
||||||
|
}
|
||||||
|
rect.OffsetBy(PEN_SIZE, PEN_SIZE);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::Setup(BRect rect)
|
||||||
|
{
|
||||||
|
fLeft = rect.left;
|
||||||
|
fTop = rect.top;
|
||||||
|
fScaleX = rect.Width() / fpBitmap->Bounds().Width();
|
||||||
|
fScaleY = rect.Height() / fpBitmap->Bounds().Height();
|
||||||
|
// XXX Is Width/Height off by one?
|
||||||
|
// fScaleX = (rect.Width()+1) / (fpBitmap->Bounds().Width()+1);
|
||||||
|
// fScaleY = (rect.Width()+1) / (fpBitmap->Bounds().Height()+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
BPoint
|
||||||
|
ShowImageView::ImageToView(BPoint p) const
|
||||||
|
{
|
||||||
|
p.x = fScaleX * p.x + fLeft;
|
||||||
|
p.y = fScaleY * p.y + fTop;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
BPoint
|
||||||
|
ShowImageView::ViewToImage(BPoint p) const
|
||||||
|
{
|
||||||
|
p.x = (p.x - fLeft) / fScaleX;
|
||||||
|
p.y = (p.y - fTop) / fScaleY;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
BRect
|
||||||
|
ShowImageView::ImageToView(BRect r) const
|
||||||
|
{
|
||||||
|
BPoint leftTop(ImageToView(BPoint(r.left, r.top)));
|
||||||
|
BPoint rightBottom(ImageToView(BPoint(r.right, r.bottom)));
|
||||||
|
return BRect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::DrawBorder(BRect border)
|
||||||
|
{
|
||||||
|
BRect bounds(Bounds());
|
||||||
|
// top
|
||||||
|
FillRect(BRect(0, 0, bounds.right, border.top-1), B_SOLID_LOW);
|
||||||
|
// left
|
||||||
|
FillRect(BRect(0, border.top, border.left-1, border.bottom), B_SOLID_LOW);
|
||||||
|
// right
|
||||||
|
FillRect(BRect(border.right+1, border.top, bounds.right, border.bottom), B_SOLID_LOW);
|
||||||
|
// bottom
|
||||||
|
FillRect(BRect(0, border.bottom+1, bounds.right, bounds.bottom), B_SOLID_LOW);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::Draw(BRect updateRect)
|
ShowImageView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
if (fpbitmap) {
|
if (fpBitmap) {
|
||||||
|
BRect rect = AlignBitmap();
|
||||||
|
Setup(rect);
|
||||||
|
|
||||||
|
BRect border(rect);
|
||||||
|
border.InsetBy(-PEN_SIZE, -PEN_SIZE);
|
||||||
|
|
||||||
|
DrawBorder(border);
|
||||||
|
|
||||||
// Draw black rectangle around image
|
// Draw black rectangle around image
|
||||||
StrokeRect(
|
StrokeRect(border);
|
||||||
BRect(BORDER_WIDTH - PEN_SIZE,
|
|
||||||
BORDER_HEIGHT - PEN_SIZE,
|
// Draw image
|
||||||
fpbitmap->Bounds().Width() + BORDER_WIDTH + PEN_SIZE,
|
DrawBitmap(fpBitmap, fpBitmap->Bounds(), rect);
|
||||||
fpbitmap->Bounds().Height() + BORDER_HEIGHT + PEN_SIZE));
|
|
||||||
|
if (fbHasSelection)
|
||||||
if (fbhasSelection)
|
DrawSelectionBox(fSelectionRect);
|
||||||
DrawSelectionBox(fselectionRect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::DrawSelectionBox(BRect &rect)
|
ShowImageView::DrawSelectionBox(BRect &rect)
|
||||||
{
|
{
|
||||||
// TODO: Make my own pattern to mimic the
|
PushState();
|
||||||
// marching ants in Be's ShowImage?
|
rgb_color white = {255, 255, 255};
|
||||||
|
SetLowColor(white);
|
||||||
StrokeRect(rect, B_MIXED_COLORS);
|
BRect r(ImageToView(rect));
|
||||||
Sync();
|
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);
|
||||||
void
|
StrokeLine(BPoint(r.left, r.top+1), BPoint(r.left, r.bottom-1), fPatternDown);
|
||||||
ShowImageView::ClearSelectionBox(BRect &rect)
|
PopState();
|
||||||
{
|
|
||||||
BRect bitmapRect = rect;
|
|
||||||
if (!bitmapRect.IsValid())
|
|
||||||
printf("Invalid Rect\n");
|
|
||||||
|
|
||||||
bitmapRect.OffsetBy(-(BORDER_WIDTH), -(BORDER_HEIGHT));
|
|
||||||
DrawBitmapAsync(fpbitmap, bitmapRect, rect);
|
|
||||||
// don't draw the bitmap immediately, more drawing
|
|
||||||
// almost always comes after this function is used
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -199,83 +376,64 @@ void
|
|||||||
ShowImageView::ConstrainToImage(BPoint &point)
|
ShowImageView::ConstrainToImage(BPoint &point)
|
||||||
{
|
{
|
||||||
point.ConstrainTo(
|
point.ConstrainTo(
|
||||||
BRect(
|
fpBitmap->Bounds()
|
||||||
BORDER_WIDTH, BORDER_HEIGHT,
|
|
||||||
fpbitmap->Bounds().Width() + BORDER_WIDTH,
|
|
||||||
fpbitmap->Bounds().Height() + BORDER_HEIGHT
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::MouseDown(BPoint point)
|
ShowImageView::MouseDown(BPoint point)
|
||||||
{
|
{
|
||||||
// TODO: Need to handle the case where user clicks
|
point = ViewToImage(point);
|
||||||
// inside an existing selection and starts a drag operation
|
|
||||||
|
|
||||||
if (fbhasSelection)
|
if (fbHasSelection && fSelectionRect.Contains(point)) {
|
||||||
ClearSelectionBox(fselectionRect);
|
// TODO: start drag and drop
|
||||||
|
|
||||||
fbhasSelection = false;
|
|
||||||
|
|
||||||
if (!fpbitmap) {
|
|
||||||
// Can't select anything if there is no image
|
|
||||||
Invalidate();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BPoint firstPoint, secondPoint;
|
|
||||||
firstPoint = point;
|
|
||||||
ConstrainToImage(firstPoint);
|
|
||||||
secondPoint = firstPoint;
|
|
||||||
|
|
||||||
BRect curSel, lastSel;
|
|
||||||
|
|
||||||
BMessage *pmsg = Window()->CurrentMessage();
|
|
||||||
uint32 buttons = static_cast<uint32>(pmsg->FindInt32("buttons"));
|
|
||||||
bool bfirst = true;
|
|
||||||
// While any combination of mouse buttons is down,
|
|
||||||
// allow the user to size their selection. When all
|
|
||||||
// mouse buttons are up, the loop ends, and the selection
|
|
||||||
// has been made.
|
|
||||||
while (buttons) {
|
|
||||||
ConstrainToImage(secondPoint);
|
|
||||||
|
|
||||||
// make a BRect that passes IsValid()
|
|
||||||
curSel.left = min(firstPoint.x, secondPoint.x);
|
|
||||||
curSel.top = min(firstPoint.y, secondPoint.y);
|
|
||||||
curSel.right = max(firstPoint.x, secondPoint.x);
|
|
||||||
curSel.bottom = max(firstPoint.y, secondPoint.y);
|
|
||||||
|
|
||||||
if (!bfirst && curSel != lastSel)
|
|
||||||
ClearSelectionBox(lastSel);
|
|
||||||
if (curSel != lastSel)
|
|
||||||
DrawSelectionBox(curSel);
|
|
||||||
|
|
||||||
snooze(25 * 1000);
|
|
||||||
lastSel = curSel;
|
|
||||||
GetMouse(&secondPoint, &buttons);
|
|
||||||
bfirst = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (curSel.IntegerWidth() < 2 && curSel.IntegerHeight() < 2) {
|
|
||||||
// The user must select at least 2 pixels
|
|
||||||
fbhasSelection = false;
|
|
||||||
Invalidate();
|
|
||||||
} else {
|
} else {
|
||||||
fselectionRect = curSel;
|
// begin new selection
|
||||||
fbhasSelection = true;
|
fMakesSelection = true;
|
||||||
|
fbHasSelection = true;
|
||||||
|
SetMouseEventMask(B_POINTER_EVENTS);
|
||||||
|
ConstrainToImage(point);
|
||||||
|
fFirstPoint = point;
|
||||||
|
fSelectionRect.Set(point.x, point.y, point.x, point.y);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::UpdateSelectionRect(BPoint point, bool final) {
|
||||||
|
BRect oldSelection = fSelectionRect;
|
||||||
|
point = ViewToImage(point);
|
||||||
|
ConstrainToImage(point);
|
||||||
|
fSelectionRect.left = min(fFirstPoint.x, point.x);
|
||||||
|
fSelectionRect.right = max(fFirstPoint.x, point.x);
|
||||||
|
fSelectionRect.top = min(fFirstPoint.y, point.y);
|
||||||
|
fSelectionRect.bottom = max(fFirstPoint.y, point.y);
|
||||||
|
if (final) {
|
||||||
|
// selection must contain a few pixels
|
||||||
|
if (fSelectionRect.Width() * fSelectionRect.Height() <= 1) {
|
||||||
|
fbHasSelection = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (oldSelection != fSelectionRect || !fbHasSelection) {
|
||||||
|
Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::MouseMoved(BPoint point, uint32 state, const BMessage *pmsg)
|
ShowImageView::MouseMoved(BPoint point, uint32 state, const BMessage *pmsg)
|
||||||
{
|
{
|
||||||
|
if (fMakesSelection) {
|
||||||
|
UpdateSelectionRect(point, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::MouseUp(BPoint point)
|
ShowImageView::MouseUp(BPoint point)
|
||||||
{
|
{
|
||||||
|
if (fMakesSelection) {
|
||||||
|
UpdateSelectionRect(point, true);
|
||||||
|
fMakesSelection = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -291,12 +449,21 @@ ShowImageView::MessageReceived(BMessage *pmsg)
|
|||||||
void
|
void
|
||||||
ShowImageView::FixupScrollBars()
|
ShowImageView::FixupScrollBars()
|
||||||
{
|
{
|
||||||
|
BScrollBar *psb;
|
||||||
|
if (fResizeToViewBounds) {
|
||||||
|
psb = ScrollBar(B_HORIZONTAL);
|
||||||
|
if (psb) psb->SetRange(0, 0);
|
||||||
|
psb = ScrollBar(B_VERTICAL);
|
||||||
|
if (psb) psb->SetRange(0, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BRect rctview = Bounds(), rctbitmap(0, 0, 0, 0);
|
BRect rctview = Bounds(), rctbitmap(0, 0, 0, 0);
|
||||||
if (fpbitmap)
|
if (fpBitmap)
|
||||||
rctbitmap = fpbitmap->Bounds();
|
rctbitmap = fpBitmap->Bounds();
|
||||||
|
|
||||||
float prop, range;
|
float prop, range;
|
||||||
BScrollBar *psb = ScrollBar(B_HORIZONTAL);
|
psb = ScrollBar(B_HORIZONTAL);
|
||||||
if (psb) {
|
if (psb) {
|
||||||
range = rctbitmap.Width() + (BORDER_WIDTH * 2) - rctview.Width();
|
range = rctbitmap.Width() + (BORDER_WIDTH * 2) - rctview.Width();
|
||||||
if (range < 0) range = 0;
|
if (range < 0) range = 0;
|
||||||
@@ -322,20 +489,20 @@ ShowImageView::FixupScrollBars()
|
|||||||
int32
|
int32
|
||||||
ShowImageView::CurrentPage()
|
ShowImageView::CurrentPage()
|
||||||
{
|
{
|
||||||
return fdocumentIndex;
|
return fDocumentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32
|
int32
|
||||||
ShowImageView::PageCount()
|
ShowImageView::PageCount()
|
||||||
{
|
{
|
||||||
return fdocumentCount;
|
return fDocumentCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::FirstPage()
|
ShowImageView::FirstPage()
|
||||||
{
|
{
|
||||||
if (fdocumentIndex != 1) {
|
if (fDocumentIndex != 1) {
|
||||||
fdocumentIndex = 1;
|
fDocumentIndex = 1;
|
||||||
SetImage(NULL);
|
SetImage(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,8 +510,8 @@ ShowImageView::FirstPage()
|
|||||||
void
|
void
|
||||||
ShowImageView::LastPage()
|
ShowImageView::LastPage()
|
||||||
{
|
{
|
||||||
if (fdocumentIndex != fdocumentCount) {
|
if (fDocumentIndex != fDocumentCount) {
|
||||||
fdocumentIndex = fdocumentCount;
|
fDocumentIndex = fDocumentCount;
|
||||||
SetImage(NULL);
|
SetImage(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,8 +519,8 @@ ShowImageView::LastPage()
|
|||||||
void
|
void
|
||||||
ShowImageView::NextPage()
|
ShowImageView::NextPage()
|
||||||
{
|
{
|
||||||
if (fdocumentIndex < fdocumentCount) {
|
if (fDocumentIndex < fDocumentCount) {
|
||||||
fdocumentIndex++;
|
fDocumentIndex++;
|
||||||
SetImage(NULL);
|
SetImage(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -361,8 +528,88 @@ ShowImageView::NextPage()
|
|||||||
void
|
void
|
||||||
ShowImageView::PrevPage()
|
ShowImageView::PrevPage()
|
||||||
{
|
{
|
||||||
if (fdocumentIndex > 1) {
|
if (fDocumentIndex > 1) {
|
||||||
fdocumentIndex--;
|
fDocumentIndex--;
|
||||||
SetImage(NULL);
|
SetImage(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::FreeEntries(BList* entries)
|
||||||
|
{
|
||||||
|
const int32 n = entries->CountItems();
|
||||||
|
for (int32 i = 0; i < n; i ++) {
|
||||||
|
BEntry* entry = (BEntry*)entries->ItemAt(i);
|
||||||
|
delete entry;
|
||||||
|
}
|
||||||
|
entries->MakeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notes: BDirectory::GetNextEntry() must not necessary
|
||||||
|
// return entries sorted by name, thou BFS does.
|
||||||
|
bool
|
||||||
|
ShowImageView::FindNextImage(BEntry* image, bool next)
|
||||||
|
{
|
||||||
|
BEntry curImage(&fCurrentRef);
|
||||||
|
BEntry entry;
|
||||||
|
BDirectory parent;
|
||||||
|
BList entries;
|
||||||
|
|
||||||
|
if (curImage.GetParent(&parent) != B_OK)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
while (parent.GetNextEntry(&entry) == B_OK) {
|
||||||
|
if (entry == curImage) {
|
||||||
|
// found current image
|
||||||
|
if (next) {
|
||||||
|
// find next image in directory
|
||||||
|
while (parent.GetNextEntry(&entry) == B_OK) {
|
||||||
|
entry_ref ref;
|
||||||
|
if (entry.GetRef(&ref) == B_OK && IsImage(&ref)) {
|
||||||
|
*image = entry;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// find privous image in directory
|
||||||
|
for (int32 i = entries.CountItems() - 1; i >= 0; i --) {
|
||||||
|
BEntry* entry = (BEntry*)entries.ItemAt(i);
|
||||||
|
entry_ref ref;
|
||||||
|
if (entry->GetRef(&ref) == B_OK && IsImage(&ref)) {
|
||||||
|
*image = *entry;
|
||||||
|
FreeEntries(&entries);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!next) {
|
||||||
|
// record entries if we search for previous file
|
||||||
|
entries.AddItem(new BEntry(entry));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FreeEntries(&entries);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::NextFile()
|
||||||
|
{
|
||||||
|
BEntry image;
|
||||||
|
entry_ref ref;
|
||||||
|
|
||||||
|
if (FindNextImage(&image, true) && image.GetRef(&ref) == B_OK) {
|
||||||
|
SetImage(&ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageView::PrevFile()
|
||||||
|
{
|
||||||
|
BEntry image;
|
||||||
|
entry_ref ref;
|
||||||
|
|
||||||
|
if (FindNextImage(&image, false) && image.GetRef(&ref) == B_OK) {
|
||||||
|
SetImage(&ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,7 +40,10 @@ public:
|
|||||||
uint32 flags);
|
uint32 flags);
|
||||||
~ShowImageView();
|
~ShowImageView();
|
||||||
|
|
||||||
|
void Pulse();
|
||||||
|
|
||||||
void SetImage(const entry_ref *pref);
|
void SetImage(const entry_ref *pref);
|
||||||
|
void ResizeToViewBounds(bool resize);
|
||||||
BBitmap *GetBitmap();
|
BBitmap *GetBitmap();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
@@ -60,18 +63,39 @@ public:
|
|||||||
void LastPage();
|
void LastPage();
|
||||||
void NextPage();
|
void NextPage();
|
||||||
void PrevPage();
|
void PrevPage();
|
||||||
|
void NextFile();
|
||||||
|
void PrevFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void InitPatterns();
|
||||||
|
void RotatePatterns();
|
||||||
|
BRect AlignBitmap() const;
|
||||||
|
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);
|
||||||
|
void FreeEntries(BList* entries);
|
||||||
|
bool FindNextImage(BEntry* entry, bool next);
|
||||||
void ConstrainToImage(BPoint &point);
|
void ConstrainToImage(BPoint &point);
|
||||||
|
void UpdateSelectionRect(BPoint point, bool final);
|
||||||
|
void DrawBorder(BRect border);
|
||||||
void DrawSelectionBox(BRect &rect);
|
void DrawSelectionBox(BRect &rect);
|
||||||
void ClearSelectionBox(BRect &rect);
|
|
||||||
|
|
||||||
entry_ref fcurrentRef;
|
entry_ref fCurrentRef;
|
||||||
int32 fdocumentIndex;
|
int32 fDocumentIndex;
|
||||||
int32 fdocumentCount;
|
int32 fDocumentCount;
|
||||||
BBitmap *fpbitmap;
|
BBitmap *fpBitmap;
|
||||||
bool fbhasSelection;
|
bool fResizeToViewBounds;
|
||||||
BRect fselectionRect;
|
float fLeft; // the origin of the image in the view
|
||||||
|
float fTop;
|
||||||
|
float fScaleX;
|
||||||
|
float fScaleY;
|
||||||
|
bool fMakesSelection; // is a selection being made
|
||||||
|
BPoint fFirstPoint; // first point in image space of selection
|
||||||
|
bool fbHasSelection; // is fSelectionRect valid
|
||||||
|
BRect fSelectionRect; // the selection in image space
|
||||||
|
pattern fPatternUp, fPatternDown, fPatternLeft, fPatternRight;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _ShowImageView_h */
|
#endif /* _ShowImageView_h */
|
||||||
|
|||||||
@@ -51,24 +51,28 @@
|
|||||||
ShowImageWindow::ShowImageWindow(const entry_ref *pref)
|
ShowImageWindow::ShowImageWindow(const entry_ref *pref)
|
||||||
: BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0)
|
: BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0)
|
||||||
{
|
{
|
||||||
fpsavePanel = NULL;
|
fpSavePanel = NULL;
|
||||||
fpref = NULL;
|
fpRef = NULL;
|
||||||
|
|
||||||
|
// add shortcuts
|
||||||
|
AddShortcut(B_UP_ARROW, B_COMMAND_KEY, new BMessage(MSG_FILE_PREV));
|
||||||
|
AddShortcut(B_DOWN_ARROW, B_COMMAND_KEY, new BMessage(MSG_FILE_NEXT));
|
||||||
|
|
||||||
// create menu bar
|
// create menu bar
|
||||||
fpbar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar");
|
fpBar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar");
|
||||||
LoadMenus(fpbar);
|
LoadMenus(fpBar);
|
||||||
AddChild(fpbar);
|
AddChild(fpBar);
|
||||||
|
|
||||||
BRect viewFrame = Bounds();
|
BRect viewFrame = Bounds();
|
||||||
viewFrame.top = fpbar->Bounds().bottom + 1;
|
viewFrame.top = fpBar->Bounds().bottom + 1;
|
||||||
viewFrame.right -= B_V_SCROLL_BAR_WIDTH;
|
viewFrame.right -= B_V_SCROLL_BAR_WIDTH;
|
||||||
viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT;
|
viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT;
|
||||||
|
|
||||||
// create the image view
|
// create the image view
|
||||||
fpimageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
|
fpImageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS);
|
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED);
|
||||||
// wrap a scroll view around the view
|
// wrap a scroll view around the view
|
||||||
BScrollView *pscrollView = new BScrollView("image_scroller", fpimageView,
|
BScrollView *pscrollView = new BScrollView("image_scroller", fpImageView,
|
||||||
B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER);
|
B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER);
|
||||||
AddChild(pscrollView);
|
AddChild(pscrollView);
|
||||||
|
|
||||||
@@ -79,23 +83,23 @@ ShowImageWindow::ShowImageWindow(const entry_ref *pref)
|
|||||||
rect.left = viewFrame.left + kstatusWidth;
|
rect.left = viewFrame.left + kstatusWidth;
|
||||||
rect.right = viewFrame.right;
|
rect.right = viewFrame.right;
|
||||||
BScrollBar *phscroll;
|
BScrollBar *phscroll;
|
||||||
phscroll = new BScrollBar(rect, "hscroll", fpimageView, 0, 150,
|
phscroll = new BScrollBar(rect, "hscroll", fpImageView, 0, 150,
|
||||||
B_HORIZONTAL);
|
B_HORIZONTAL);
|
||||||
AddChild(phscroll);
|
AddChild(phscroll);
|
||||||
|
|
||||||
rect.left = 0;
|
rect.left = 0;
|
||||||
rect.right = kstatusWidth - 1;
|
rect.right = kstatusWidth - 1;
|
||||||
fpstatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM,
|
fpStatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM,
|
||||||
B_WILL_DRAW);
|
B_WILL_DRAW);
|
||||||
fpstatusView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
|
fpStatusView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
|
||||||
AddChild(fpstatusView);
|
AddChild(fpStatusView);
|
||||||
|
|
||||||
rect = Bounds();
|
rect = Bounds();
|
||||||
rect.top = viewFrame.top;
|
rect.top = viewFrame.top;
|
||||||
rect.left = viewFrame.right + 1;
|
rect.left = viewFrame.right + 1;
|
||||||
rect.bottom = viewFrame.bottom;
|
rect.bottom = viewFrame.bottom;
|
||||||
BScrollBar *pvscroll;
|
BScrollBar *pvscroll;
|
||||||
pvscroll = new BScrollBar(rect, "vscroll", fpimageView, 0, 150, B_VERTICAL);
|
pvscroll = new BScrollBar(rect, "vscroll", fpImageView, 0, 150, B_VERTICAL);
|
||||||
AddChild(pvscroll);
|
AddChild(pvscroll);
|
||||||
|
|
||||||
SetSizeLimits(250, 100000, 100, 100000);
|
SetSizeLimits(250, 100000, 100, 100000);
|
||||||
@@ -104,20 +108,22 @@ ShowImageWindow::ShowImageWindow(const entry_ref *pref)
|
|||||||
SetRef(pref);
|
SetRef(pref);
|
||||||
UpdateTitle();
|
UpdateTitle();
|
||||||
|
|
||||||
fpimageView->SetImage(pref);
|
fpImageView->SetImage(pref);
|
||||||
|
|
||||||
|
SetPulseRate(100000); // every 1/10 second; ShowImageView needs it for marching ants
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowImageWindow::~ShowImageWindow()
|
ShowImageWindow::~ShowImageWindow()
|
||||||
{
|
{
|
||||||
delete fpref;
|
delete fpRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ShowImageWindow::InitCheck()
|
ShowImageWindow::InitCheck()
|
||||||
{
|
{
|
||||||
if (!fpref || !fpimageView)
|
if (!fpRef || !fpImageView)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
else
|
else
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -126,16 +132,16 @@ ShowImageWindow::InitCheck()
|
|||||||
void
|
void
|
||||||
ShowImageWindow::SetRef(const entry_ref *pref)
|
ShowImageWindow::SetRef(const entry_ref *pref)
|
||||||
{
|
{
|
||||||
if (!fpref)
|
if (!fpRef)
|
||||||
fpref = new entry_ref(*pref);
|
fpRef = new entry_ref(*pref);
|
||||||
else
|
else
|
||||||
*fpref = *pref;
|
*fpRef = *pref;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageWindow::UpdateTitle()
|
ShowImageWindow::UpdateTitle()
|
||||||
{
|
{
|
||||||
BEntry entry(fpref);
|
BEntry entry(fpRef);
|
||||||
if (entry.InitCheck() == B_OK) {
|
if (entry.InitCheck() == B_OK) {
|
||||||
BPath path;
|
BPath path;
|
||||||
entry.GetPath(&path);
|
entry.GetPath(&path);
|
||||||
@@ -173,7 +179,7 @@ ShowImageWindow::LoadMenus(BMenuBar *pbar)
|
|||||||
AddItemMenu(pmenu, "Select All", MSG_SELECT_ALL, 'A', 0, 'W', false);
|
AddItemMenu(pmenu, "Select All", MSG_SELECT_ALL, 'A', 0, 'W', false);
|
||||||
pbar->AddItem(pmenu);
|
pbar->AddItem(pmenu);
|
||||||
|
|
||||||
pmenu = fppageMenu = new BMenu("Page");
|
pmenu = fpPageMenu = new BMenu("Page");
|
||||||
AddItemMenu(pmenu, "First", MSG_PAGE_FIRST, 'F', 0, 'W', true);
|
AddItemMenu(pmenu, "First", MSG_PAGE_FIRST, 'F', 0, 'W', true);
|
||||||
AddItemMenu(pmenu, "Last", MSG_PAGE_LAST, 'L', 0, 'W', true);
|
AddItemMenu(pmenu, "Last", MSG_PAGE_LAST, 'L', 0, 'W', true);
|
||||||
AddItemMenu(pmenu, "Next", MSG_PAGE_NEXT, 'N', 0, 'W', true);
|
AddItemMenu(pmenu, "Next", MSG_PAGE_NEXT, 'N', 0, 'W', true);
|
||||||
@@ -182,6 +188,7 @@ ShowImageWindow::LoadMenus(BMenuBar *pbar)
|
|||||||
|
|
||||||
pmenu = new BMenu("Image");
|
pmenu = new BMenu("Image");
|
||||||
AddItemMenu(pmenu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true);
|
AddItemMenu(pmenu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true);
|
||||||
|
AddItemMenu(pmenu, "Fit To Window Size", MSG_FIT_TO_WINDOW_SIZE, 0, 0, 'W', true);
|
||||||
pbar->AddItem(pmenu);
|
pbar->AddItem(pmenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +214,7 @@ ShowImageWindow::WindowRedimension(BBitmap *pbitmap)
|
|||||||
// set the window's min & max size limits
|
// set the window's min & max size limits
|
||||||
// based on document's data bounds
|
// based on document's data bounds
|
||||||
float maxWidth = pbitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH;
|
float maxWidth = pbitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH;
|
||||||
float maxHeight = pbitmap->Bounds().Height() + fpbar->Frame().Height() +
|
float maxHeight = pbitmap->Bounds().Height() + fpBar->Frame().Height() +
|
||||||
B_H_SCROLL_BAR_HEIGHT + 1;
|
B_H_SCROLL_BAR_HEIGHT + 1;
|
||||||
float minWidth = min(maxWidth, 100.0f);
|
float minWidth = min(maxWidth, 100.0f);
|
||||||
float minHeight = min(maxHeight, 100.0f);
|
float minHeight = min(maxHeight, 100.0f);
|
||||||
@@ -237,13 +244,26 @@ ShowImageWindow::FrameResized(float width, float height)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ShowImageWindow::ToggleMenuItem(uint32 what)
|
||||||
|
{
|
||||||
|
BMenuItem *item;
|
||||||
|
bool marked = false;
|
||||||
|
item = fpBar->FindItem(what);
|
||||||
|
if (item != NULL) {
|
||||||
|
marked = !item->IsMarked();
|
||||||
|
item->SetMarked(marked);
|
||||||
|
}
|
||||||
|
return marked;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageWindow::MessageReceived(BMessage *pmsg)
|
ShowImageWindow::MessageReceived(BMessage *pmsg)
|
||||||
{
|
{
|
||||||
switch (pmsg->what) {
|
switch (pmsg->what) {
|
||||||
case MSG_OUTPUT_TYPE:
|
case MSG_OUTPUT_TYPE:
|
||||||
// User clicked Save As then choose an output format
|
// User clicked Save As then choose an output format
|
||||||
if (!fpsavePanel)
|
if (!fpSavePanel)
|
||||||
// If user doesn't already have a save panel open
|
// If user doesn't already have a save panel open
|
||||||
SaveAs(pmsg);
|
SaveAs(pmsg);
|
||||||
break;
|
break;
|
||||||
@@ -259,21 +279,27 @@ ShowImageWindow::MessageReceived(BMessage *pmsg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case B_CANCEL:
|
case B_CANCEL:
|
||||||
delete fpsavePanel;
|
delete fpSavePanel;
|
||||||
fpsavePanel = NULL;
|
fpSavePanel = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_UPDATE_STATUS:
|
case MSG_UPDATE_STATUS:
|
||||||
{
|
{
|
||||||
bool benable = (fpimageView->PageCount() > 1) ? true : false;
|
bool benable = (fpImageView->PageCount() > 1) ? true : false;
|
||||||
if (fppageMenu->IsEnabled() != benable)
|
if (fpPageMenu->IsEnabled() != benable)
|
||||||
// Only call this function if the state is changing
|
// Only call this function if the state is changing
|
||||||
// to avoid flickering
|
// to avoid flickering
|
||||||
fppageMenu->SetEnabled(benable);
|
fpPageMenu->SetEnabled(benable);
|
||||||
|
|
||||||
BString str;
|
BString str;
|
||||||
if (pmsg->FindString("status", &str) == B_OK)
|
if (pmsg->FindString("status", &str) == B_OK)
|
||||||
fpstatusView->SetText(str);
|
fpStatusView->SetText(str);
|
||||||
|
|
||||||
|
entry_ref ref;
|
||||||
|
if (pmsg->FindRef("ref", &ref) == B_OK) {
|
||||||
|
SetRef(&ref);
|
||||||
|
UpdateTitle();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,27 +317,41 @@ ShowImageWindow::MessageReceived(BMessage *pmsg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_PAGE_FIRST:
|
case MSG_PAGE_FIRST:
|
||||||
fpimageView->FirstPage();
|
fpImageView->FirstPage();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_PAGE_LAST:
|
case MSG_PAGE_LAST:
|
||||||
fpimageView->LastPage();
|
fpImageView->LastPage();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_PAGE_NEXT:
|
case MSG_PAGE_NEXT:
|
||||||
fpimageView->NextPage();
|
fpImageView->NextPage();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_PAGE_PREV:
|
case MSG_PAGE_PREV:
|
||||||
fpimageView->PrevPage();
|
fpImageView->PrevPage();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_DITHER_IMAGE:
|
case MSG_DITHER_IMAGE:
|
||||||
BMenuItem *pmenuDither;
|
ToggleMenuItem(pmsg->what);
|
||||||
pmenuDither = fpbar->FindItem(pmsg->what);
|
break;
|
||||||
pmenuDither->SetMarked(!pmenuDither->IsMarked());
|
|
||||||
break;
|
case MSG_FIT_TO_WINDOW_SIZE:
|
||||||
|
{
|
||||||
|
bool resize;
|
||||||
|
resize = ToggleMenuItem(pmsg->what);
|
||||||
|
fpImageView->ResizeToViewBounds(resize);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MSG_FILE_PREV:
|
||||||
|
fpImageView->PrevFile();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MSG_FILE_NEXT:
|
||||||
|
fpImageView->NextFile();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(pmsg);
|
BWindow::MessageReceived(pmsg);
|
||||||
break;
|
break;
|
||||||
@@ -338,12 +378,12 @@ ShowImageWindow::SaveAs(BMessage *pmsg)
|
|||||||
ppanelMsg->AddInt32(TYPE_FLD, outType);
|
ppanelMsg->AddInt32(TYPE_FLD, outType);
|
||||||
|
|
||||||
// Create save panel and show it
|
// Create save panel and show it
|
||||||
fpsavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, 0,
|
fpSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, 0,
|
||||||
false, ppanelMsg);
|
false, ppanelMsg);
|
||||||
if (!fpsavePanel)
|
if (!fpSavePanel)
|
||||||
return;
|
return;
|
||||||
fpsavePanel->Window()->SetWorkspaces(B_CURRENT_WORKSPACE);
|
fpSavePanel->Window()->SetWorkspaces(B_CURRENT_WORKSPACE);
|
||||||
fpsavePanel->Show();
|
fpSavePanel->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -375,7 +415,7 @@ ShowImageWindow::SaveToFile(BMessage *pmsg)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Translate the image and write it out to the output file
|
// Translate the image and write it out to the output file
|
||||||
BBitmapStream stream(fpimageView->GetBitmap());
|
BBitmapStream stream(fpImageView->GetBitmap());
|
||||||
BTranslatorRoster *proster = BTranslatorRoster::Default();
|
BTranslatorRoster *proster = BTranslatorRoster::Default();
|
||||||
if (proster->Translate(outTranslator, &stream, NULL,
|
if (proster->Translate(outTranslator, &stream, NULL,
|
||||||
&file, outType) != B_OK) {
|
&file, outType) != B_OK) {
|
||||||
@@ -392,7 +432,7 @@ ShowImageWindow::SaveToFile(BMessage *pmsg)
|
|||||||
bool
|
bool
|
||||||
ShowImageWindow::CanQuit()
|
ShowImageWindow::CanQuit()
|
||||||
{
|
{
|
||||||
if (fpsavePanel)
|
if (fpSavePanel)
|
||||||
// Don't allow this window to be closed if a save panel is open
|
// Don't allow this window to be closed if a save panel is open
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
virtual void Quit();
|
virtual void Quit();
|
||||||
|
|
||||||
status_t InitCheck();
|
status_t InitCheck();
|
||||||
ShowImageView *GetShowImageView() const { return fpimageView; }
|
ShowImageView *GetShowImageView() const { return fpImageView; }
|
||||||
|
|
||||||
void SetRef(const entry_ref *pref);
|
void SetRef(const entry_ref *pref);
|
||||||
void UpdateTitle();
|
void UpdateTitle();
|
||||||
@@ -63,6 +63,8 @@ private:
|
|||||||
BMenuItem *AddItemMenu(BMenu *pmenu, char *caption,
|
BMenuItem *AddItemMenu(BMenu *pmenu, char *caption,
|
||||||
long unsigned int msg, char shortcut, uint32 modifier,
|
long unsigned int msg, char shortcut, uint32 modifier,
|
||||||
char target, bool enabled);
|
char target, bool enabled);
|
||||||
|
|
||||||
|
bool ToggleMenuItem(uint32 what);
|
||||||
|
|
||||||
void SaveAs(BMessage *pmsg);
|
void SaveAs(BMessage *pmsg);
|
||||||
// Handle Save As submenu choice
|
// Handle Save As submenu choice
|
||||||
@@ -71,12 +73,12 @@ private:
|
|||||||
bool CanQuit();
|
bool CanQuit();
|
||||||
// returns true if the window can be closed safely, false if not
|
// returns true if the window can be closed safely, false if not
|
||||||
|
|
||||||
BFilePanel *fpsavePanel;
|
BFilePanel *fpSavePanel;
|
||||||
BMenuBar *fpbar;
|
BMenuBar *fpBar;
|
||||||
BMenu *fppageMenu;
|
BMenu *fpPageMenu;
|
||||||
entry_ref *fpref;
|
entry_ref *fpRef;
|
||||||
ShowImageView *fpimageView;
|
ShowImageView *fpImageView;
|
||||||
ShowImageStatusView *fpstatusView;
|
ShowImageStatusView *fpStatusView;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _ShowImageWindow_h */
|
#endif /* _ShowImageWindow_h */
|
||||||
|
|||||||
Reference in New Issue
Block a user