author | viric <viriketo@gmail.com> |
Sun, 24 Apr 2011 17:24:28 +0200 | |
changeset 3 | b29987bfe7ed |
parent 2 | b2772bffb62f |
permissions | -rw-r--r-- |
0 | 1 |
#include <wx/scrolwin.h> |
2 |
#include <wx/image.h> |
|
3 |
#include <wx/bitmap.h> |
|
4 |
#include <wx/dc.h> |
|
5 |
#include <iostream> |
|
2 | 6 |
#include <fstream> |
0 | 7 |
#include "wxPictureWindow.hpp" |
1
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
8 |
#include "MainWindow.hpp" |
0 | 9 |
|
10 |
const int factor = 3; |
|
11 |
||
12 |
BEGIN_EVENT_TABLE(wxPictureWindow, wxScrolledWindow) |
|
13 |
EVT_MOUSE_EVENTS (wxPictureWindow::OnMouse) |
|
1
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
14 |
EVT_KEY_UP (wxPictureWindow::OnKey) |
0 | 15 |
END_EVENT_TABLE() |
16 |
||
2 | 17 |
wxPictureWindow::wxPictureWindow(const wxString &img, const CropArea area, wxWindow *parent) |
0 | 18 |
:wxScrolledWindow(parent, wxID_ANY), |
19 |
_area(area) |
|
20 |
{ |
|
1
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
21 |
SetImg(img); |
0 | 22 |
_area.x /= factor; |
23 |
_area.y /= factor; |
|
24 |
_area.width /= factor; |
|
25 |
_area.height /= factor; |
|
1
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
26 |
SetScrollRate(10, 10); |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
27 |
SetFocus(); |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
28 |
} |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
29 |
|
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
30 |
void |
2 | 31 |
wxPictureWindow::SetImg(const wxString &img) |
1
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
32 |
{ |
2 | 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); |
|
1
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
44 |
SetVirtualSize(_bmp.GetWidth(), _bmp.GetHeight()); |
3
b29987bfe7ed
Falta un Refresh, que sino no repinta.
viric <viriketo@gmail.com>
parents:
2
diff
changeset
|
45 |
|
b29987bfe7ed
Falta un Refresh, que sino no repinta.
viric <viriketo@gmail.com>
parents:
2
diff
changeset
|
46 |
Refresh(); |
0 | 47 |
} |
48 |
||
49 |
void wxPictureWindow::OnDraw(wxDC &dc) |
|
50 |
{ |
|
51 |
dc.DrawBitmap(_bmp, 0, 0, false); |
|
52 |
||
53 |
wxRect rect(_area.x, _area.y, _area.width, _area.height); |
|
54 |
dc.SetPen(*wxGREEN_PEN); |
|
55 |
dc.SetBrush(*wxTRANSPARENT_BRUSH); |
|
56 |
dc.DrawRectangle(rect); |
|
57 |
} |
|
58 |
||
59 |
void wxPictureWindow::OnMouse(wxMouseEvent &ev) |
|
60 |
{ |
|
61 |
wxClientDC dc(this); |
|
62 |
DoPrepareDC(dc); |
|
63 |
||
64 |
if (ev.LeftDown()) |
|
65 |
{ |
|
66 |
_area.x = ev.GetLogicalPosition(dc).x; |
|
67 |
_area.y = ev.GetLogicalPosition(dc).y; |
|
68 |
_area.width = 0; |
|
69 |
_area.height = 0; |
|
70 |
} |
|
71 |
else if (ev.LeftIsDown()) |
|
72 |
{ |
|
73 |
_area.width = ev.GetLogicalPosition(dc).x - _area.x; |
|
74 |
_area.height = ev.GetLogicalPosition(dc).y - _area.y; |
|
75 |
} |
|
76 |
||
77 |
Refresh(); |
|
78 |
} |
|
79 |
||
80 |
wxPictureWindow::~wxPictureWindow() |
|
81 |
{ |
|
82 |
} |
|
1
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
83 |
|
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
84 |
void |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
85 |
wxPictureWindow::OnKey(wxKeyEvent &e) |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
86 |
{ |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
87 |
using namespace std; |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
88 |
if (e.GetKeyCode() == WXK_ESCAPE) |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
89 |
{ |
2 | 90 |
std::ofstream of("crop.txt", std::fstream::app); |
91 |
of << (const char *) _filename.mb_str() << " "; |
|
92 |
of << _area.x * factor << " "; |
|
93 |
of << _area.y * factor << " "; |
|
94 |
of << _area.width * factor << " "; |
|
95 |
of << _area.height * factor << std::endl; |
|
96 |
||
1
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
97 |
wxCommandEvent e(EVT_NEXTPICTURE); |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
98 |
GetParent()->AddPendingEvent(e); |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
99 |
} |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
100 |
else |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
101 |
e.Skip(); |
506e0fc65ba3
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
102 |
} |