#include <Base/Common/W32Compat.hh>
#include <wx/wx.h>
#include <Gui/ScaledImageCanvas.hh>
#include <Gui/StringConv.hh>
#include <Base/Image/ImageIO.hh>
using namespace BIAS;
using namespace std;
class MyApp: public wxApp
{
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
class MyFrame: public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnLoad(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( wxT("ImageCanvas"), wxPoint(50,50),
wxSize(450,340) );
if (argc>1) {
BIASASSERT(frame!=NULL);
string filename(WxToAscii(argv[1]));
BIASERR("error loading "<<filename<<endl);
} else {
BIASASSERT(frame->_ic != NULL);
frame->_ic->Show(img, filename.c_str() );
cout<<"loaded image file "<<filename<<" successfully."<<endl;
}
};
frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Load, MyFrame::OnLoad)
END_EVENT_TABLE()
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
wxMenu *menuFile = new wxMenu;
menuFile->Append( ID_About, wxT("&About...") );
menuFile->Append( ID_Load, wxT("&Load...") );
menuFile->AppendSeparator();
menuFile->Append( ID_Quit, wxT("E&xit") );
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, wxT("&File"));
SetMenuBar(menuBar);
CreateStatusBar(2);
SetStatusText(wxT("ImageName"), 0);
wxBoxSizer *box=new wxBoxSizer(wxVERTICAL);
box->Add(_ic, 1, wxALL| wxGROW, 5);
box->SetSizeHints(this);
SetSizer(box);
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{ Close(TRUE); }
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox(wxT("This is a wxWidgets Hello world sample"),
wxT("About Hello World"), wxOK | wxICON_INFORMATION, this);
}
void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event))
{
wxFileDialog fileDialog(this, wxT("Choose a file"), wxT("."), wxT(""));
if (fileDialog.ShowModal() == wxID_OK){
string fname=WxToAscii(fileDialog.GetPath());
BIASERR("error loading "<<fname<<"\nshould a be float image");
} else {
SetStatusText(fileDialog.GetFilename().c_str(), 0);
_ic->Show(im, WxToAscii(fileDialog.GetFilename()));
}
} else {
cerr << "canceled loading image" << endl;
}
}