Initial Checkin. Coded by Fernando Francisco de Oliveira.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@388 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,159 @@
|
|||||||
|
/*
|
||||||
|
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <Alert.h>
|
||||||
|
#include <FilePanel.h>
|
||||||
|
|
||||||
|
#include "ShowImageConstants.h"
|
||||||
|
#include "ShowImageApp.h"
|
||||||
|
#include "ShowImageWindow.h"
|
||||||
|
|
||||||
|
int main(int, char**)
|
||||||
|
{
|
||||||
|
ShowImageApp theApp;
|
||||||
|
theApp.Run();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowImageApp::ShowImageApp()
|
||||||
|
: BApplication(APP_SIG), m_pOpenPanel(0)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void ShowImageApp::AboutRequested()
|
||||||
|
{
|
||||||
|
BAlert* pAlert = new BAlert( "About ShowImage",
|
||||||
|
"OBOS ShowImage\n\nRecreated by Fernando F.Oliveira", "OK");
|
||||||
|
pAlert->Go();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageApp::ReadyToRun()
|
||||||
|
{
|
||||||
|
int32 count = ShowImageWindow::CountWindows();
|
||||||
|
if (count < 1)
|
||||||
|
OnOpen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageApp::ArgvReceived(int32 argc, char** argv)
|
||||||
|
{
|
||||||
|
BMessage* message = 0;
|
||||||
|
for (int32 i=1; i<argc; i++) {
|
||||||
|
entry_ref ref;
|
||||||
|
status_t err = get_ref_for_path(argv[i], &ref);
|
||||||
|
if (err == B_OK) {
|
||||||
|
if (! message) {
|
||||||
|
message = new BMessage;
|
||||||
|
message->what = B_REFS_RECEIVED;
|
||||||
|
}
|
||||||
|
message->AddRef("refs", &ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (message) {
|
||||||
|
RefsReceived(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageApp::MessageReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
switch (message->what) {
|
||||||
|
case MSG_FILE_OPEN:
|
||||||
|
OnOpen();
|
||||||
|
break;
|
||||||
|
case B_CANCEL:
|
||||||
|
if (ShowImageWindow::CountWindows() < 1)
|
||||||
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
BApplication::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShowImageApp::QuitRequested()
|
||||||
|
{
|
||||||
|
// Attempt to close all the document windows.
|
||||||
|
bool ok = QuitDudeWinLoop();
|
||||||
|
if (ok)
|
||||||
|
// Everything's been saved, and only unimportant windows should remain.
|
||||||
|
// Now we can forcibly blow those away.
|
||||||
|
CloseAllWindows();
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageApp::RefsReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
uint32 type;
|
||||||
|
int32 count;
|
||||||
|
entry_ref ref;
|
||||||
|
|
||||||
|
message->GetInfo("refs", &type, &count);
|
||||||
|
if (type != B_REF_TYPE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int32 i = --count; i >= 0; --i) {
|
||||||
|
if (message->FindRef("refs", i, &ref) == B_OK) {
|
||||||
|
Open(&ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageApp::OnOpen()
|
||||||
|
{
|
||||||
|
if (! m_pOpenPanel) {
|
||||||
|
m_pOpenPanel = new BFilePanel;
|
||||||
|
m_pOpenPanel->Window()->SetTitle("Open Image File");
|
||||||
|
}
|
||||||
|
m_pOpenPanel->Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShowImageApp::QuitDudeWinLoop()
|
||||||
|
{
|
||||||
|
bool ok = true;
|
||||||
|
status_t err;
|
||||||
|
int32 i=0;
|
||||||
|
while (ok) {
|
||||||
|
BWindow* pWin = WindowAt(i++);
|
||||||
|
if (! pWin)
|
||||||
|
break;
|
||||||
|
|
||||||
|
ShowImageWindow* pShowImageWindow = dynamic_cast<ShowImageWindow*>(pWin);
|
||||||
|
if (pShowImageWindow && pShowImageWindow->Lock()) {
|
||||||
|
BMessage quitMsg(B_QUIT_REQUESTED);
|
||||||
|
BMessage reply;
|
||||||
|
BMessenger winMsgr(pShowImageWindow);
|
||||||
|
pShowImageWindow->Unlock();
|
||||||
|
err = winMsgr.SendMessage(&quitMsg, &reply);
|
||||||
|
if (err == B_OK) {
|
||||||
|
bool result;
|
||||||
|
err = reply.FindBool("result", &result);
|
||||||
|
if (err == B_OK) {
|
||||||
|
ok = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageApp::CloseAllWindows()
|
||||||
|
{
|
||||||
|
int32 i = 0;
|
||||||
|
BWindow* pWin;
|
||||||
|
for (pWin = WindowAt(i++); pWin && pWin->Lock(); pWin = WindowAt(i++)) {
|
||||||
|
// don't take no for an answer
|
||||||
|
pWin->Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageApp::Open(const entry_ref* ref)
|
||||||
|
{
|
||||||
|
if (ShowImageWindow::NewWindow(ref) != B_OK) {
|
||||||
|
char errStr[B_FILE_NAME_LENGTH + 50];
|
||||||
|
sprintf(errStr, "Couldn't open file: %s",
|
||||||
|
(ref && ref->name) ? ref->name : "???");
|
||||||
|
BAlert* pAlert = new BAlert("file i/o error", errStr, "OK");
|
||||||
|
pAlert->Go();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ShowImageApp_h
|
||||||
|
#define _ShowImageApp_h
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
|
||||||
|
class ShowImageApp : public BApplication
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ShowImageApp();
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual void AboutRequested();
|
||||||
|
virtual void ArgvReceived(int32 argc, char** argv);
|
||||||
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
virtual bool QuitRequested();
|
||||||
|
virtual void ReadyToRun();
|
||||||
|
virtual void RefsReceived(BMessage* message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void OnOpen();
|
||||||
|
bool QuitDudeWinLoop();
|
||||||
|
void CloseAllWindows();
|
||||||
|
void Open(const entry_ref* ref);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BFilePanel* m_pOpenPanel;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _ShowImageApp_h */
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
/*
|
||||||
|
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ShowImageConstants.h"
|
||||||
|
|
||||||
|
extern const char* APP_SIG = "application/x-vnd.FFO-ShowImage";
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ShowImageConstants_
|
||||||
|
#define _ShowImageConstants_
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
const uint32 MSG_CAPTURE_MOUSE = 'mCPM';
|
||||||
|
const uint32 MSG_CHANGE_FOCUS = 'mCFS';
|
||||||
|
const uint32 MSG_FILE_OPEN = 'mFOP';
|
||||||
|
const uint32 MSG_FILE_SAVE = 'mFSA';
|
||||||
|
const uint32 MSG_CLEAR_SELECT = 'mCSL';
|
||||||
|
const uint32 MSG_SELECT_ALL = 'mSAL';
|
||||||
|
const uint32 MSG_DITHER_IMAGE = 'mDIM';
|
||||||
|
|
||||||
|
extern const char* APP_SIG;
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _ShowImageConstants_ */
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ShowImageStatusView.h"
|
||||||
|
|
||||||
|
ShowImageStatusView::ShowImageStatusView(BRect r, const char* name, uint32 resizingMode, uint32 flags)
|
||||||
|
: BView(r, name, resizingMode, flags)
|
||||||
|
{
|
||||||
|
m_caption = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageStatusView::Draw(BRect updateRect)
|
||||||
|
{
|
||||||
|
DrawString( m_caption, BPoint( 3, 11) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageStatusView::SetCaption( char * Caption )
|
||||||
|
{
|
||||||
|
m_caption = Caption;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ShowImageStatusView_h
|
||||||
|
#define _ShowImageStatusView_h
|
||||||
|
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
class ShowImageStatusView : public BView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ShowImageStatusView(BRect r, const char* name, uint32 resizingMode, uint32 flags);
|
||||||
|
|
||||||
|
virtual void Draw(BRect updateRect);
|
||||||
|
|
||||||
|
void SetCaption( char * Caption );
|
||||||
|
|
||||||
|
private:
|
||||||
|
char * m_caption;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _ShowImageStatusView_h */
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
/*
|
||||||
|
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <Bitmap.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <ScrollBar.h>
|
||||||
|
#include <StopWatch.h>
|
||||||
|
#include <Alert.h>
|
||||||
|
#include <MenuBar.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
|
|
||||||
|
#include "ShowImageConstants.h"
|
||||||
|
#include "ShowImageView.h"
|
||||||
|
|
||||||
|
ShowImageView::ShowImageView(BRect r, const char* name, uint32 resizingMode, uint32 flags)
|
||||||
|
: BView(r, name, resizingMode, flags), m_pBitmap(NULL)
|
||||||
|
{
|
||||||
|
Selecting = false;
|
||||||
|
Selected = false;
|
||||||
|
PointOn = false;
|
||||||
|
|
||||||
|
SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowImageView::~ShowImageView()
|
||||||
|
{
|
||||||
|
delete m_pBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageView::SetBitmap(BBitmap* pBitmap)
|
||||||
|
{
|
||||||
|
m_pBitmap = pBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
FixupScrollBars();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageView::Draw(BRect updateRect)
|
||||||
|
{
|
||||||
|
if ( m_pBitmap )
|
||||||
|
{
|
||||||
|
DrawBitmap( m_pBitmap, updateRect, updateRect );
|
||||||
|
|
||||||
|
if ( Selected && PointOn ) {
|
||||||
|
SetDrawingMode( B_OP_INVERT /*B_OP_ALPHA */);
|
||||||
|
|
||||||
|
StrokeRect( BRect( IniPoint, EndPoint ), B_MIXED_COLORS );
|
||||||
|
|
||||||
|
SetDrawingMode(B_OP_COPY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageView::FrameResized(float /* width */, float /* height */)
|
||||||
|
{
|
||||||
|
FixupScrollBars();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageView::MessageReceived(BMessage* msg)
|
||||||
|
{
|
||||||
|
switch (msg->what) {
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageView::FixupScrollBars()
|
||||||
|
{
|
||||||
|
if (! m_pBitmap)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BRect vBds = Bounds(), bBds = m_pBitmap->Bounds();
|
||||||
|
float prop;
|
||||||
|
float range;
|
||||||
|
|
||||||
|
BScrollBar* sb = ScrollBar(B_HORIZONTAL);
|
||||||
|
if (sb) {
|
||||||
|
range = bBds.Width() - vBds.Width();
|
||||||
|
if (range < 0) range = 0;
|
||||||
|
prop = vBds.Width() / bBds.Width();
|
||||||
|
if (prop > 1.0f) prop = 1.0f;
|
||||||
|
sb->SetRange(0, range);
|
||||||
|
sb->SetProportion(prop);
|
||||||
|
sb->SetSteps(10, 100);
|
||||||
|
}
|
||||||
|
sb = ScrollBar(B_VERTICAL);
|
||||||
|
if (sb) {
|
||||||
|
range = bBds.Height() - vBds.Height();
|
||||||
|
if (range < 0) range = 0;
|
||||||
|
prop = vBds.Height() / bBds.Height();
|
||||||
|
if (prop > 1.0f) prop = 1.0f;
|
||||||
|
sb->SetRange(0, range);
|
||||||
|
sb->SetProportion(prop);
|
||||||
|
sb->SetSteps(10, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageView::MouseDown( BPoint point )
|
||||||
|
{
|
||||||
|
if ( Selected && SelectedRect.Contains( point ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 buttons;
|
||||||
|
|
||||||
|
GetMouse(&point, &buttons);
|
||||||
|
|
||||||
|
if ( buttons == B_PRIMARY_MOUSE_BUTTON ) {
|
||||||
|
|
||||||
|
if ( Selected ) {
|
||||||
|
Selected = false;
|
||||||
|
Invalidate( BRect( IniPoint, EndPoint ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
BRect rect(point, point);
|
||||||
|
BeginRectTracking(rect, B_TRACK_RECT_CORNER);
|
||||||
|
|
||||||
|
IniPoint = point;
|
||||||
|
do {
|
||||||
|
snooze(30 * 1000);
|
||||||
|
GetMouse(&point, &buttons);
|
||||||
|
} while ( buttons );
|
||||||
|
|
||||||
|
EndRectTracking();
|
||||||
|
|
||||||
|
Selected = true;
|
||||||
|
|
||||||
|
rect.SetRightBottom(point);
|
||||||
|
|
||||||
|
EndPoint = point;
|
||||||
|
|
||||||
|
SelectedRect = BRect( IniPoint, EndPoint );
|
||||||
|
|
||||||
|
Invalidate( SelectedRect );
|
||||||
|
|
||||||
|
PointOn = true;
|
||||||
|
|
||||||
|
BMenuItem * pMenuCopy;
|
||||||
|
pMenuCopy = pBar->FindItem( B_COPY );
|
||||||
|
pMenuCopy->SetEnabled( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageView::MouseUp( BPoint point )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageView::MouseMoved( BPoint point, uint32 transit, const BMessage *message )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageView::Pulse(void)
|
||||||
|
{
|
||||||
|
if ( Selected ) {
|
||||||
|
PushState();
|
||||||
|
|
||||||
|
PointOn = ! PointOn;
|
||||||
|
|
||||||
|
SetDrawingMode( B_OP_INVERT );
|
||||||
|
|
||||||
|
StrokeRect( SelectedRect, B_MIXED_COLORS );
|
||||||
|
|
||||||
|
//SetDrawingMode(B_OP_COPY);
|
||||||
|
PopState();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ShowImageView_h
|
||||||
|
#define _ShowImageView_h
|
||||||
|
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
class OffscreenView;
|
||||||
|
|
||||||
|
class ShowImageView : public BView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ShowImageView(BRect r, const char* name, uint32 resizingMode, uint32 flags);
|
||||||
|
~ShowImageView();
|
||||||
|
|
||||||
|
void SetBitmap(BBitmap* pBitmap);
|
||||||
|
|
||||||
|
virtual void AttachedToWindow();
|
||||||
|
virtual void Draw(BRect updateRect);
|
||||||
|
virtual void FrameResized(float width, float height);
|
||||||
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
virtual void MouseDown( BPoint point );
|
||||||
|
virtual void MouseUp( BPoint point );
|
||||||
|
virtual void MouseMoved( BPoint point, uint32 transit, const BMessage *message );
|
||||||
|
virtual void Pulse(void);
|
||||||
|
|
||||||
|
void FixupScrollBars();
|
||||||
|
|
||||||
|
BMenuBar* pBar;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool Selecting, Selected, PointOn;
|
||||||
|
|
||||||
|
BRect SelectedRect, LastPoint, PointRecOn;
|
||||||
|
BPoint IniPoint, EndPoint;
|
||||||
|
|
||||||
|
BBitmap* m_pBitmap;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _ShowImageView_h */
|
||||||
@@ -0,0 +1,348 @@
|
|||||||
|
/*
|
||||||
|
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <algobase.h>
|
||||||
|
#include <Application.h>
|
||||||
|
#include <Bitmap.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <Menu.h>
|
||||||
|
#include <MenuBar.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <ScrollView.h>
|
||||||
|
#include <TranslationUtils.h>
|
||||||
|
#include <TranslatorRoster.h>
|
||||||
|
#include <Locker.h>
|
||||||
|
#include <Alert.h>
|
||||||
|
|
||||||
|
#include "ShowImageConstants.h"
|
||||||
|
#include "ShowImageWindow.h"
|
||||||
|
#include "ShowImageView.h"
|
||||||
|
#include "ShowImageStatusView.h"
|
||||||
|
|
||||||
|
BLocker ShowImageWindow::s_winListLocker("ShowImageWindow list lock");
|
||||||
|
BList ShowImageWindow::s_winList;
|
||||||
|
|
||||||
|
status_t ShowImageWindow::NewWindow(const entry_ref* ref)
|
||||||
|
{
|
||||||
|
BEntry entry(ref);
|
||||||
|
if (entry.InitCheck() == B_OK) {
|
||||||
|
BPath path;
|
||||||
|
entry.GetPath(&path);
|
||||||
|
if (path.InitCheck() == B_OK) {
|
||||||
|
BBitmap* pBitmap = BTranslationUtils::GetBitmap(path.Path());
|
||||||
|
if (pBitmap) {
|
||||||
|
ShowImageWindow* pWin = new ShowImageWindow(ref, pBitmap);
|
||||||
|
return pWin->InitCheck();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 ShowImageWindow::CountWindows()
|
||||||
|
{
|
||||||
|
int32 count = -1;
|
||||||
|
if (s_winListLocker.Lock()) {
|
||||||
|
count = s_winList.CountItems();
|
||||||
|
s_winListLocker.Unlock();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowImageWindow::ShowImageWindow(const entry_ref* ref, BBitmap* pBitmap)
|
||||||
|
: BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0),
|
||||||
|
m_pReferences(0)
|
||||||
|
{
|
||||||
|
SetPulseRate( 200000.0 );
|
||||||
|
|
||||||
|
// create menu bar
|
||||||
|
pBar = new BMenuBar( BRect(0,0, Bounds().right, 20), "menu_bar");
|
||||||
|
LoadMenus(pBar);
|
||||||
|
AddChild(pBar);
|
||||||
|
|
||||||
|
BRect viewFrame = Bounds();
|
||||||
|
// viewFrame.left += 20;
|
||||||
|
viewFrame.top = pBar->Bounds().bottom+1;
|
||||||
|
viewFrame.right -= B_V_SCROLL_BAR_WIDTH;
|
||||||
|
viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT;
|
||||||
|
|
||||||
|
// create the image view
|
||||||
|
m_PrivateView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
|
||||||
|
B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED);
|
||||||
|
m_PrivateView->SetBitmap(pBitmap);
|
||||||
|
|
||||||
|
// wrap a scroll view around the view
|
||||||
|
BScrollView* pScrollView = new BScrollView("image_scroller", m_PrivateView, B_FOLLOW_ALL,
|
||||||
|
0, false, false, B_PLAIN_BORDER);
|
||||||
|
|
||||||
|
AddChild(pScrollView);
|
||||||
|
|
||||||
|
BScrollBar *hor_scroll;
|
||||||
|
|
||||||
|
BRect rect;
|
||||||
|
|
||||||
|
rect = Bounds();
|
||||||
|
rect.top = viewFrame.bottom + 1;
|
||||||
|
rect.left = viewFrame.left + 160;
|
||||||
|
rect.right = viewFrame.right;
|
||||||
|
|
||||||
|
hor_scroll = new BScrollBar( rect, "hor_scroll", m_PrivateView, 0,150, B_HORIZONTAL );
|
||||||
|
AddChild( hor_scroll );
|
||||||
|
|
||||||
|
ShowImageStatusView * status_bar;
|
||||||
|
|
||||||
|
rect.left = 0;
|
||||||
|
rect.right = 159;
|
||||||
|
|
||||||
|
status_bar = new ShowImageStatusView( rect, "status_bar", B_FOLLOW_BOTTOM, B_WILL_DRAW );
|
||||||
|
status_bar->SetViewColor( ui_color( B_MENU_BACKGROUND_COLOR ) );
|
||||||
|
status_bar->SetCaption( "ImageShow" );
|
||||||
|
|
||||||
|
AddChild( status_bar );
|
||||||
|
|
||||||
|
BScrollBar *vert_scroll;
|
||||||
|
|
||||||
|
rect = Bounds();
|
||||||
|
rect.top = viewFrame.top;
|
||||||
|
rect.left = viewFrame.right + 1;
|
||||||
|
rect.bottom = viewFrame.bottom;
|
||||||
|
|
||||||
|
vert_scroll = new BScrollBar( rect, "vert_scroll", m_PrivateView, 0,150, B_VERTICAL );
|
||||||
|
AddChild( vert_scroll );
|
||||||
|
|
||||||
|
WindowRedimension( pBitmap );
|
||||||
|
|
||||||
|
// finish creating window
|
||||||
|
SetRef(ref);
|
||||||
|
UpdateTitle();
|
||||||
|
if (s_winListLocker.Lock()) {
|
||||||
|
s_winList.AddItem(this);
|
||||||
|
s_winListLocker.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_PrivateView->pBar = pBar;
|
||||||
|
|
||||||
|
Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowImageWindow::~ShowImageWindow()
|
||||||
|
{
|
||||||
|
if (m_pReferences) {
|
||||||
|
delete m_pReferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s_winListLocker.Lock()) {
|
||||||
|
s_winList.RemoveItem(this);
|
||||||
|
s_winListLocker.Unlock();
|
||||||
|
}
|
||||||
|
if (CountWindows() < 1) {
|
||||||
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageWindow::WindowActivated(bool active)
|
||||||
|
{
|
||||||
|
// WindowRedimension( pBitmap );
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t ShowImageWindow::InitCheck()
|
||||||
|
{
|
||||||
|
if (! m_pReferences) {
|
||||||
|
return B_ERROR;
|
||||||
|
} else {
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageWindow::SetRef(const entry_ref* ref)
|
||||||
|
{
|
||||||
|
if (! m_pReferences) {
|
||||||
|
m_pReferences = new entry_ref(*ref);
|
||||||
|
} else {
|
||||||
|
*m_pReferences = *ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageWindow::UpdateTitle()
|
||||||
|
{
|
||||||
|
BEntry entry(m_pReferences);
|
||||||
|
if (entry.InitCheck() == B_OK) {
|
||||||
|
BPath path;
|
||||||
|
entry.GetPath(&path);
|
||||||
|
if (path.InitCheck() == B_OK) {
|
||||||
|
SetTitle(path.Path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageWindow::LoadMenus(BMenuBar* pBar)
|
||||||
|
{
|
||||||
|
long unsigned int MSG_QUIT = B_QUIT_REQUESTED;
|
||||||
|
long unsigned int MSG_ABOUT = B_ABOUT_REQUESTED;
|
||||||
|
|
||||||
|
BMenu* pMenu = new BMenu("File");
|
||||||
|
|
||||||
|
AddItemMenu( pMenu, "Open", MSG_FILE_OPEN, 'O', 0, 'A', true );
|
||||||
|
pMenu->AddSeparatorItem();
|
||||||
|
|
||||||
|
// BMenuItem * pMenuSaveAs = AddItemMenu( pMenu, "Save As...", MSG_FILE_SAVE, 'S', 0, 'W', true);
|
||||||
|
|
||||||
|
BMenu* pMenuSaveAs = new BMenu( "Save As...", B_ITEMS_IN_COLUMN );
|
||||||
|
|
||||||
|
pMenu->AddItem( pMenuSaveAs );
|
||||||
|
|
||||||
|
|
||||||
|
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
||||||
|
|
||||||
|
int32 num_translators, i;
|
||||||
|
translator_id *translators;
|
||||||
|
const char *translator_name, *translator_info;
|
||||||
|
int32 translator_version;
|
||||||
|
|
||||||
|
roster->GetAllTranslators(&translators, &num_translators);
|
||||||
|
|
||||||
|
for (i=0;i<num_translators;i++) {
|
||||||
|
|
||||||
|
roster->GetTranslatorInfo(translators[i], &translator_name,
|
||||||
|
&translator_info, &translator_version);
|
||||||
|
|
||||||
|
BMenuItem * pSubMenu = new BMenuItem( translator_name , NULL );
|
||||||
|
|
||||||
|
pMenuSaveAs->AddItem( pSubMenu );
|
||||||
|
//printf("%s: %s (%.2f)n", translator_name, translator_info, translator_version/100.);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete [] translators; // clean up our droppings
|
||||||
|
|
||||||
|
AddItemMenu( pMenu, "Close", MSG_QUIT, 'W', 0, 'A', true);
|
||||||
|
pMenu->AddSeparatorItem();
|
||||||
|
AddItemMenu( pMenu, "About ShowImage...", MSG_ABOUT, 0, 0, 'A', true);
|
||||||
|
pMenu->AddSeparatorItem();
|
||||||
|
AddItemMenu( pMenu, "Quit", MSG_QUIT, 'Q', 0, 'A', true);
|
||||||
|
|
||||||
|
pBar->AddItem(pMenu);
|
||||||
|
|
||||||
|
pMenu = new BMenu("Edit");
|
||||||
|
|
||||||
|
AddItemMenu( pMenu, "Undo", B_UNDO, 'Z', 0, 'W', false);
|
||||||
|
pMenu->AddSeparatorItem();
|
||||||
|
AddItemMenu( pMenu, "Cut", B_CUT, 'X', 0, 'W', false);
|
||||||
|
AddItemMenu( pMenu, "Copy", B_COPY, 'C', 0, 'W', false);
|
||||||
|
AddItemMenu( pMenu, "Paste", B_PASTE, 'V', 0, 'W', false);
|
||||||
|
AddItemMenu( pMenu, "Clear", MSG_CLEAR_SELECT, 0, 0, 'W', false);
|
||||||
|
pMenu->AddSeparatorItem();
|
||||||
|
AddItemMenu( pMenu, "Select All", MSG_SELECT_ALL, 'A', 0, 'W', true);
|
||||||
|
|
||||||
|
pBar->AddItem(pMenu);
|
||||||
|
|
||||||
|
pMenu = new BMenu("Image");
|
||||||
|
AddItemMenu( pMenu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true);
|
||||||
|
pBar->AddItem(pMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
BMenuItem * ShowImageWindow::AddItemMenu( BMenu *pMenu, char *Caption, long unsigned int msg,
|
||||||
|
char shortcut, uint32 modifier, char target, bool enabled ) {
|
||||||
|
|
||||||
|
BMenuItem* pItem;
|
||||||
|
|
||||||
|
pItem = new BMenuItem( Caption, new BMessage(msg), shortcut );
|
||||||
|
|
||||||
|
if ( target == 'A' )
|
||||||
|
pItem->SetTarget(be_app);
|
||||||
|
|
||||||
|
pItem->SetEnabled( enabled );
|
||||||
|
pMenu->AddItem(pItem);
|
||||||
|
|
||||||
|
return( pItem );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageWindow::WindowRedimension( BBitmap *pBitmap )
|
||||||
|
{
|
||||||
|
// set the window's min & max size limits
|
||||||
|
// based on document's data bounds
|
||||||
|
float maxWidth = pBitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH;
|
||||||
|
float maxHeight = pBitmap->Bounds().Height()
|
||||||
|
+ pBar->Frame().Height()
|
||||||
|
+ B_H_SCROLL_BAR_HEIGHT + 1;
|
||||||
|
float minWidth = min(maxWidth, 100.0f);
|
||||||
|
float minHeight = min(maxHeight, 100.0f);
|
||||||
|
|
||||||
|
// adjust the window's current size based on new min/max values
|
||||||
|
float curWidth = Bounds().Width();
|
||||||
|
float curHeight = Bounds().Height();
|
||||||
|
if (curWidth < minWidth) {
|
||||||
|
curWidth = minWidth;
|
||||||
|
} else if (curWidth > maxWidth) {
|
||||||
|
curWidth = maxWidth;
|
||||||
|
}
|
||||||
|
if (curHeight < minHeight) {
|
||||||
|
curHeight = minHeight;
|
||||||
|
} else if (curHeight > maxHeight) {
|
||||||
|
curHeight = maxHeight;
|
||||||
|
}
|
||||||
|
if ( minWidth < 250 ) {
|
||||||
|
minWidth = 250;
|
||||||
|
}
|
||||||
|
SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
|
||||||
|
ResizeTo(curWidth, curHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageWindow::FrameResized( float new_width, float new_height )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowImageWindow::MessageReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
BAlert* pAlert;
|
||||||
|
|
||||||
|
switch (message->what) {
|
||||||
|
case MSG_FILE_SAVE :
|
||||||
|
pAlert = new BAlert( "File/Save",
|
||||||
|
"File/Save not implemented yet", "OK");
|
||||||
|
pAlert->Go();
|
||||||
|
break;
|
||||||
|
case B_UNDO :
|
||||||
|
pAlert = new BAlert( "Edit/Undo",
|
||||||
|
"Edit/Undo not implemented yet", "OK");
|
||||||
|
pAlert->Go();
|
||||||
|
break;
|
||||||
|
case B_CUT :
|
||||||
|
pAlert = new BAlert( "Edit/Cut",
|
||||||
|
"Edit/Cut not implemented yet", "OK");
|
||||||
|
pAlert->Go();
|
||||||
|
break;
|
||||||
|
case B_COPY :
|
||||||
|
pAlert = new BAlert( "Edit/Copy",
|
||||||
|
"Edit/Copy not implemented yet", "OK");
|
||||||
|
pAlert->Go();
|
||||||
|
break;
|
||||||
|
case B_PASTE :
|
||||||
|
pAlert = new BAlert( "Edit/Paste",
|
||||||
|
"Edit/Paste not implemented yet", "OK");
|
||||||
|
pAlert->Go();
|
||||||
|
break;
|
||||||
|
case MSG_CLEAR_SELECT :
|
||||||
|
pAlert = new BAlert( "Edit/Clear Select",
|
||||||
|
"Edit/Clear Select not implemented yet", "OK");
|
||||||
|
pAlert->Go();
|
||||||
|
break;
|
||||||
|
case MSG_SELECT_ALL :
|
||||||
|
pAlert = new BAlert( "Edit/Select All",
|
||||||
|
"Edit/Select All not implemented yet", "OK");
|
||||||
|
pAlert->Go();
|
||||||
|
break;
|
||||||
|
case MSG_DITHER_IMAGE :
|
||||||
|
BMenuItem * pMenuDither;
|
||||||
|
pMenuDither = pBar->FindItem( message->what );
|
||||||
|
pMenuDither->SetMarked( ! pMenuDither->IsMarked() );
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BWindow::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// BMenu* pMenuDither = ;
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ShowImageWindow_h
|
||||||
|
#define _ShowImageWindow_h
|
||||||
|
|
||||||
|
#include <Window.h>
|
||||||
|
class ShowImageView;
|
||||||
|
|
||||||
|
class ShowImageWindow : public BWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static status_t NewWindow(const entry_ref* ref);
|
||||||
|
static int32 CountWindows();
|
||||||
|
|
||||||
|
ShowImageWindow(const entry_ref* ref, BBitmap* pBitmap);
|
||||||
|
virtual ~ShowImageWindow();
|
||||||
|
|
||||||
|
virtual void WindowActivated(bool active);
|
||||||
|
virtual void FrameResized( float new_width, float new_height );
|
||||||
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
status_t InitCheck();
|
||||||
|
ShowImageView* GetShowImageView() const { return m_PrivateView; }
|
||||||
|
|
||||||
|
void SetRef(const entry_ref* ref);
|
||||||
|
void UpdateTitle();
|
||||||
|
void LoadMenus(BMenuBar* pBar);
|
||||||
|
void WindowRedimension( BBitmap *pBitmap );
|
||||||
|
|
||||||
|
BMenuBar* pBar;
|
||||||
|
private:
|
||||||
|
BMenuItem * AddItemMenu( BMenu *pMenu, char *Caption, long unsigned int msg,
|
||||||
|
char shortcut, uint32 modifier, char target, bool enabled );
|
||||||
|
|
||||||
|
entry_ref* m_pReferences;
|
||||||
|
ShowImageView* m_PrivateView;
|
||||||
|
|
||||||
|
static BLocker s_winListLocker;
|
||||||
|
static BList s_winList;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _ShowImageWindow_h */
|
||||||
Executable
BIN
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,107 @@
|
|||||||
|
## BeOS Generic Makefile v2.0 ##
|
||||||
|
|
||||||
|
## Fill in this file to specify the project being created, and the referenced
|
||||||
|
## makefile-engine will do all of the hard work for you. This handles both
|
||||||
|
## Intel and PowerPC builds of the BeOS.
|
||||||
|
|
||||||
|
## Application Specific Settings ---------------------------------------------
|
||||||
|
|
||||||
|
# specify the name of the binary
|
||||||
|
NAME= PotApp
|
||||||
|
|
||||||
|
# specify the type of binary
|
||||||
|
# APP: Application
|
||||||
|
# SHARED: Shared library or add-on
|
||||||
|
# STATIC: Static library archive
|
||||||
|
# DRIVER: Kernel Driver
|
||||||
|
TYPE= APP
|
||||||
|
|
||||||
|
# specify the source files to use
|
||||||
|
# full paths or paths relative to the makefile can be included
|
||||||
|
# all files, regardless of directory, will have their object
|
||||||
|
# files created in the common object directory.
|
||||||
|
# Note that this means this makefile will not work correctly
|
||||||
|
# if two source files with the same name (source.c or source.cpp)
|
||||||
|
# are included from different directories. Also note that spaces
|
||||||
|
# in folder names do not work well with this makefile.
|
||||||
|
SRCS= colorutils.cpp \
|
||||||
|
constants.cpp \
|
||||||
|
drawutils.cpp \
|
||||||
|
offscreenview.cpp \
|
||||||
|
pot.cpp \
|
||||||
|
potapp.cpp \
|
||||||
|
potview.cpp \
|
||||||
|
potwin.cpp \
|
||||||
|
testview.cpp \
|
||||||
|
testwin.cpp \
|
||||||
|
# end of srcs
|
||||||
|
|
||||||
|
# specify the resource files to use
|
||||||
|
# full path or a relative path to the resource file can be used.
|
||||||
|
RSRCS= pot.rsrc
|
||||||
|
|
||||||
|
# specify additional libraries to link against
|
||||||
|
# there are two acceptable forms of library specifications
|
||||||
|
# - if your library follows the naming pattern of:
|
||||||
|
# libXXX.so or libXXX.a you can simply specify XXX
|
||||||
|
# library: libbe.so entry: be
|
||||||
|
#
|
||||||
|
# - if your library does not follow the standard library
|
||||||
|
# naming scheme you need to specify the path to the library
|
||||||
|
# and it's name
|
||||||
|
# library: my_lib.a entry: my_lib.a or path/my_lib.a
|
||||||
|
LIBS= be translation tracker
|
||||||
|
|
||||||
|
# specify additional paths to directories following the standard
|
||||||
|
# libXXX.so or libXXX.a naming scheme. You can specify full paths
|
||||||
|
# or paths relative to the makefile. The paths included may not
|
||||||
|
# be recursive, so include all of the paths where libraries can
|
||||||
|
# be found. Directories where source files are found are
|
||||||
|
# automatically included.
|
||||||
|
LIBPATHS=
|
||||||
|
|
||||||
|
# additional paths to look for system headers
|
||||||
|
# thes use the form: #include <header>
|
||||||
|
# source file directories are NOT auto-included here
|
||||||
|
SYSTEM_INCLUDE_PATHS =
|
||||||
|
|
||||||
|
# additional paths to look for local headers
|
||||||
|
# thes use the form: #include "header"
|
||||||
|
# source file directories are automatically included
|
||||||
|
LOCAL_INCLUDE_PATHS =
|
||||||
|
|
||||||
|
# specify the level of optimization that you desire
|
||||||
|
# NONE, SOME, FULL
|
||||||
|
OPTIMIZE=
|
||||||
|
|
||||||
|
# specify any preprocessor symbols to be defined. The symbols
|
||||||
|
# will be set to a value of 1. For example specify DEBUG if you want
|
||||||
|
# DEBUG=1 to be set when compiling.
|
||||||
|
DEFINES=
|
||||||
|
|
||||||
|
# specify special warning levels
|
||||||
|
# if unspecified default warnings will be used
|
||||||
|
# NONE = supress all warnings
|
||||||
|
# ALL = enable all warnings
|
||||||
|
WARNINGS = ALL
|
||||||
|
|
||||||
|
# specify whether image symbols will be created
|
||||||
|
# so that stack crawls in the debugger are meaningful
|
||||||
|
# if TRUE symbols will be created
|
||||||
|
SYMBOLS = TRUE
|
||||||
|
|
||||||
|
# specify debug settings
|
||||||
|
# if TRUE will allow application to be run from
|
||||||
|
# a source-level debugger
|
||||||
|
DEBUGGER =
|
||||||
|
|
||||||
|
# specify additional compiler flags for all files
|
||||||
|
COMPILER_FLAGS =
|
||||||
|
|
||||||
|
# specify additional linker flags
|
||||||
|
LINKER_FLAGS =
|
||||||
|
|
||||||
|
|
||||||
|
## include the makefile-engine
|
||||||
|
include /boot/develop/etc/makefile-engine
|
||||||
|
|
||||||
Reference in New Issue
Block a user