wxPictureWindow.cpp
changeset 2 b2772bffb62f
parent 1 506e0fc65ba3
child 3 b29987bfe7ed
--- 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);
     }