--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/wxPictureWindow.cpp Sat Nov 01 20:57:17 2008 +0100
@@ -0,0 +1,64 @@
+#include <wx/scrolwin.h>
+#include <wx/image.h>
+#include <wx/bitmap.h>
+#include <wx/dc.h>
+#include <iostream>
+#include "wxPictureWindow.hpp"
+
+const int factor = 3;
+
+BEGIN_EVENT_TABLE(wxPictureWindow, wxScrolledWindow)
+ EVT_MOUSE_EVENTS (wxPictureWindow::OnMouse)
+END_EVENT_TABLE()
+
+wxPictureWindow::wxPictureWindow(const wxImage &img, const CropArea area, wxWindow *parent)
+ :wxScrolledWindow(parent, wxID_ANY),
+ _bmp(wxBitmap(img)),
+ _area(area)
+{
+ SetVirtualSize(_bmp.GetWidth(), _bmp.GetHeight());
+ SetScrollRate(10, 10);
+ _area.x /= factor;
+ _area.y /= factor;
+ _area.width /= factor;
+ _area.height /= factor;
+}
+
+void wxPictureWindow::OnDraw(wxDC &dc)
+{
+ dc.DrawBitmap(_bmp, 0, 0, false);
+
+ wxRect rect(_area.x, _area.y, _area.width, _area.height);
+ dc.SetPen(*wxGREEN_PEN);
+ dc.SetBrush(*wxTRANSPARENT_BRUSH);
+ dc.DrawRectangle(rect);
+}
+
+void wxPictureWindow::OnMouse(wxMouseEvent &ev)
+{
+ wxClientDC dc(this);
+ DoPrepareDC(dc);
+
+ if (ev.LeftDown())
+ {
+ _area.x = ev.GetLogicalPosition(dc).x;
+ _area.y = ev.GetLogicalPosition(dc).y;
+ _area.width = 0;
+ _area.height = 0;
+ }
+ else if (ev.LeftIsDown())
+ {
+ _area.width = ev.GetLogicalPosition(dc).x - _area.x;
+ _area.height = ev.GetLogicalPosition(dc).y - _area.y;
+ }
+
+ Refresh();
+}
+
+wxPictureWindow::~wxPictureWindow()
+{
+ std::cout << _area.x * factor << " ";
+ std::cout << _area.y * factor << " ";
+ std::cout << _area.width * factor << " ";
+ std::cout << _area.height * factor << std::endl;
+}