equal
deleted
inserted
replaced
1 #include <wx/scrolwin.h> |
1 #include <wx/scrolwin.h> |
2 #include <wx/image.h> |
2 #include <wx/image.h> |
3 #include <wx/bitmap.h> |
3 #include <wx/bitmap.h> |
4 #include <wx/dc.h> |
4 #include <wx/dc.h> |
5 #include <iostream> |
5 #include <iostream> |
|
6 #include <fstream> |
6 #include "wxPictureWindow.hpp" |
7 #include "wxPictureWindow.hpp" |
7 #include "MainWindow.hpp" |
8 #include "MainWindow.hpp" |
8 |
9 |
9 const int factor = 3; |
10 const int factor = 3; |
10 |
11 |
11 BEGIN_EVENT_TABLE(wxPictureWindow, wxScrolledWindow) |
12 BEGIN_EVENT_TABLE(wxPictureWindow, wxScrolledWindow) |
12 EVT_MOUSE_EVENTS (wxPictureWindow::OnMouse) |
13 EVT_MOUSE_EVENTS (wxPictureWindow::OnMouse) |
13 EVT_KEY_UP (wxPictureWindow::OnKey) |
14 EVT_KEY_UP (wxPictureWindow::OnKey) |
14 END_EVENT_TABLE() |
15 END_EVENT_TABLE() |
15 |
16 |
16 wxPictureWindow::wxPictureWindow(const wxImage &img, const CropArea area, wxWindow *parent) |
17 wxPictureWindow::wxPictureWindow(const wxString &img, const CropArea area, wxWindow *parent) |
17 :wxScrolledWindow(parent, wxID_ANY), |
18 :wxScrolledWindow(parent, wxID_ANY), |
18 _area(area) |
19 _area(area) |
19 { |
20 { |
20 SetImg(img); |
21 SetImg(img); |
21 _area.x /= factor; |
22 _area.x /= factor; |
25 SetScrollRate(10, 10); |
26 SetScrollRate(10, 10); |
26 SetFocus(); |
27 SetFocus(); |
27 } |
28 } |
28 |
29 |
29 void |
30 void |
30 wxPictureWindow::SetImg(const wxImage &img) |
31 wxPictureWindow::SetImg(const wxString &img) |
31 { |
32 { |
|
33 _filename = img; |
|
34 wxLogVerbose(_T("Opening file %s."), img.c_str()); |
|
35 wxImage i(img); |
|
36 if (!i.IsOk()) |
|
37 { |
|
38 wxLogFatalError(_T("Error opening file %s."), img.c_str()); |
|
39 } |
|
40 |
|
41 i.Rescale(i.GetWidth()/3, i.GetHeight()/3); |
|
42 |
|
43 _bmp = wxBitmap(i); |
32 SetVirtualSize(_bmp.GetWidth(), _bmp.GetHeight()); |
44 SetVirtualSize(_bmp.GetWidth(), _bmp.GetHeight()); |
33 _bmp = wxBitmap(img); |
|
34 } |
45 } |
35 |
46 |
36 void wxPictureWindow::OnDraw(wxDC &dc) |
47 void wxPictureWindow::OnDraw(wxDC &dc) |
37 { |
48 { |
38 dc.DrawBitmap(_bmp, 0, 0, false); |
49 dc.DrawBitmap(_bmp, 0, 0, false); |
64 Refresh(); |
75 Refresh(); |
65 } |
76 } |
66 |
77 |
67 wxPictureWindow::~wxPictureWindow() |
78 wxPictureWindow::~wxPictureWindow() |
68 { |
79 { |
69 std::cout << _area.x * factor << " "; |
|
70 std::cout << _area.y * factor << " "; |
|
71 std::cout << _area.width * factor << " "; |
|
72 std::cout << _area.height * factor << std::endl; |
|
73 } |
80 } |
74 |
81 |
75 void |
82 void |
76 wxPictureWindow::OnKey(wxKeyEvent &e) |
83 wxPictureWindow::OnKey(wxKeyEvent &e) |
77 { |
84 { |
78 using namespace std; |
85 using namespace std; |
79 if (e.GetKeyCode() == WXK_ESCAPE) |
86 if (e.GetKeyCode() == WXK_ESCAPE) |
80 { |
87 { |
81 cout << "escape" << endl;; |
88 std::ofstream of("crop.txt", std::fstream::app); |
|
89 of << (const char *) _filename.mb_str() << " "; |
|
90 of << _area.x * factor << " "; |
|
91 of << _area.y * factor << " "; |
|
92 of << _area.width * factor << " "; |
|
93 of << _area.height * factor << std::endl; |
|
94 |
82 wxCommandEvent e(EVT_NEXTPICTURE); |
95 wxCommandEvent e(EVT_NEXTPICTURE); |
83 GetParent()->AddPendingEvent(e); |
96 GetParent()->AddPendingEvent(e); |
84 } |
97 } |
85 else |
98 else |
86 e.Skip(); |
99 e.Skip(); |