Outputting crop.txt now.
--- a/CropArea.hpp Sun Apr 24 14:03:52 2011 +0200
+++ b/CropArea.hpp Sun Apr 24 14:26:29 2011 +0200
@@ -3,6 +3,13 @@
struct CropArea
{
+ CropArea()
+ :width(0),
+ height(0),
+ x(0),
+ y(0)
+ {
+ }
long int width;
long int height;
long int x;
--- a/MainWindow.cpp Sun Apr 24 14:03:52 2011 +0200
+++ b/MainWindow.cpp Sun Apr 24 14:26:29 2011 +0200
@@ -10,16 +10,28 @@
EVT_COMMAND (wxID_ANY, EVT_NEXTPICTURE, MainWindow::OnNextPicture)
END_EVENT_TABLE ()
-MainWindow::MainWindow(const wxImage &img, const CropArea area, const wxSize size)
- :wxFrame(0, wxID_ANY, _("wxDjvuMaker"), wxDefaultPosition, size)
+MainWindow::MainWindow(const std::vector<wxString> &imgs, const wxSize size)
+ :wxFrame(0, wxID_ANY, _("wxDjvuMaker"), wxDefaultPosition, size),
+ _imgs(imgs),
+ _counter(0)
{
wxBoxSizer *s = new wxBoxSizer(wxVERTICAL);
- wxPictureWindow *picture = new wxPictureWindow(img, area, this);
- s->Add(picture);
+
+ CropArea area;
+
+ _picture = new wxPictureWindow(imgs[0], area, this);
+ s->Add(_picture);
}
void MainWindow::OnNextPicture(wxCommandEvent &e)
{
- using namespace std;
- cout << "next picture" << endl;;
+ ++_counter;
+
+ if (_counter >= _imgs.size())
+ {
+ Close();
+ return;
+ }
+
+ _picture->SetImg(_imgs[_counter]);
}
--- a/MainWindow.hpp Sun Apr 24 14:03:52 2011 +0200
+++ b/MainWindow.hpp Sun Apr 24 14:26:29 2011 +0200
@@ -2,17 +2,25 @@
#define _HEADER_MAINWINDOW_HPP_
#include <wx/wx.h>
+#include <vector>
#include "CropArea.hpp"
+class wxPictureWindow;
+
DECLARE_EVENT_TYPE(EVT_NEXTPICTURE, -1)
class MainWindow : public wxFrame
{
public:
- MainWindow(const wxImage &img, CropArea area, wxSize size);
+ MainWindow(const std::vector<wxString> &imgs, const wxSize size);
void OnNextPicture(wxCommandEvent &e);
+private:
+ const std::vector<wxString> _imgs;
+ wxPictureWindow *_picture;
+ int _counter;
+
DECLARE_EVENT_TABLE ();
};
--- a/main.cpp Sun Apr 24 14:03:52 2011 +0200
+++ b/main.cpp Sun Apr 24 14:26:29 2011 +0200
@@ -4,6 +4,8 @@
#include <wx/string.h>
#include <wx/init.h>
+#include <vector>
+
#include "MainWindow.hpp"
class MyApp : public wxApp
@@ -21,33 +23,14 @@
::wxInitAllImageHandlers();
- wxString filename(argv[1]);
-
- wxLogVerbose(_T("Opening file %s."), filename.c_str());
- wxImage img(filename);
- if (!img.IsOk())
- return false;
-
- CropArea area;
- if (argc < 6)
+ std::vector<wxString> imgs;
+ for(int i=1; i < argc; ++i)
{
- area.x = 0;
- area.y = 0;
- area.width = 0;
- area.height = 0;
- }
- else
- {
- wxString(argv[2]).ToLong(&area.x);
- wxString(argv[3]).ToLong(&area.y);
- wxString(argv[4]).ToLong(&area.width);
- wxString(argv[5]).ToLong(&area.height);
+ wxString filename(argv[i]);
+ imgs.push_back(filename);
}
- img.Rescale(img.GetWidth()/3, img.GetHeight()/3);
-
- wxSize size(img.GetWidth(), img.GetHeight());
- MainWindow *mw = new MainWindow(img, area, size);
+ MainWindow *mw = new MainWindow(imgs, wxDefaultSize);
mw->Show();
return true;
--- a/wxPictureWindow.cpp Sun Apr 24 14:03:52 2011 +0200
+++ b/wxPictureWindow.cpp Sun Apr 24 14:26:29 2011 +0200
@@ -3,6 +3,7 @@
#include <wx/bitmap.h>
#include <wx/dc.h>
#include <iostream>
+#include <fstream>
#include "wxPictureWindow.hpp"
#include "MainWindow.hpp"
@@ -13,7 +14,7 @@
EVT_KEY_UP (wxPictureWindow::OnKey)
END_EVENT_TABLE()
-wxPictureWindow::wxPictureWindow(const wxImage &img, const CropArea area, wxWindow *parent)
+wxPictureWindow::wxPictureWindow(const wxString &img, const CropArea area, wxWindow *parent)
:wxScrolledWindow(parent, wxID_ANY),
_area(area)
{
@@ -27,10 +28,20 @@
}
void
-wxPictureWindow::SetImg(const wxImage &img)
+wxPictureWindow::SetImg(const wxString &img)
{
+ _filename = img;
+ wxLogVerbose(_T("Opening file %s."), img.c_str());
+ wxImage i(img);
+ if (!i.IsOk())
+ {
+ wxLogFatalError(_T("Error opening file %s."), img.c_str());
+ }
+
+ i.Rescale(i.GetWidth()/3, i.GetHeight()/3);
+
+ _bmp = wxBitmap(i);
SetVirtualSize(_bmp.GetWidth(), _bmp.GetHeight());
- _bmp = wxBitmap(img);
}
void wxPictureWindow::OnDraw(wxDC &dc)
@@ -66,10 +77,6 @@
wxPictureWindow::~wxPictureWindow()
{
- std::cout << _area.x * factor << " ";
- std::cout << _area.y * factor << " ";
- std::cout << _area.width * factor << " ";
- std::cout << _area.height * factor << std::endl;
}
void
@@ -78,7 +85,13 @@
using namespace std;
if (e.GetKeyCode() == WXK_ESCAPE)
{
- cout << "escape" << endl;;
+ std::ofstream of("crop.txt", std::fstream::app);
+ of << (const char *) _filename.mb_str() << " ";
+ of << _area.x * factor << " ";
+ of << _area.y * factor << " ";
+ of << _area.width * factor << " ";
+ of << _area.height * factor << std::endl;
+
wxCommandEvent e(EVT_NEXTPICTURE);
GetParent()->AddPendingEvent(e);
}
--- a/wxPictureWindow.hpp Sun Apr 24 14:03:52 2011 +0200
+++ b/wxPictureWindow.hpp Sun Apr 24 14:26:29 2011 +0200
@@ -5,9 +5,9 @@
class wxPictureWindow : public wxScrolledWindow
{
public:
- wxPictureWindow(const wxImage &img, CropArea area, wxWindow *parent);
+ wxPictureWindow(const wxString &img, CropArea area, wxWindow *parent);
~wxPictureWindow();
- void SetImg(const wxImage &img);
+ void SetImg(const wxString &img);
protected:
virtual void OnDraw(wxDC &dc);
void OnMouse(wxMouseEvent &ev);