wxPictureWindow.cpp
changeset 0 7e720dcafcaf
child 1 506e0fc65ba3
equal deleted inserted replaced
-1:000000000000 0:7e720dcafcaf
       
     1 #include <wx/scrolwin.h>
       
     2 #include <wx/image.h>
       
     3 #include <wx/bitmap.h>
       
     4 #include <wx/dc.h>
       
     5 #include <iostream>
       
     6 #include "wxPictureWindow.hpp"
       
     7 
       
     8 const int factor = 3;
       
     9 
       
    10 BEGIN_EVENT_TABLE(wxPictureWindow, wxScrolledWindow)
       
    11   EVT_MOUSE_EVENTS (wxPictureWindow::OnMouse)
       
    12 END_EVENT_TABLE()
       
    13 
       
    14 wxPictureWindow::wxPictureWindow(const wxImage &img, const CropArea area, wxWindow *parent)
       
    15     :wxScrolledWindow(parent, wxID_ANY),
       
    16     _bmp(wxBitmap(img)),
       
    17     _area(area)
       
    18 {
       
    19     SetVirtualSize(_bmp.GetWidth(), _bmp.GetHeight());
       
    20     SetScrollRate(10, 10);
       
    21     _area.x /= factor;
       
    22     _area.y /= factor;
       
    23     _area.width /= factor;
       
    24     _area.height /= factor;
       
    25 }
       
    26 
       
    27 void wxPictureWindow::OnDraw(wxDC &dc)
       
    28 {
       
    29     dc.DrawBitmap(_bmp, 0, 0, false);
       
    30 
       
    31     wxRect rect(_area.x, _area.y, _area.width, _area.height);
       
    32     dc.SetPen(*wxGREEN_PEN);
       
    33     dc.SetBrush(*wxTRANSPARENT_BRUSH);
       
    34     dc.DrawRectangle(rect);
       
    35 }
       
    36 
       
    37 void wxPictureWindow::OnMouse(wxMouseEvent &ev)
       
    38 {
       
    39     wxClientDC dc(this);
       
    40     DoPrepareDC(dc);
       
    41 
       
    42     if (ev.LeftDown())
       
    43     {
       
    44         _area.x = ev.GetLogicalPosition(dc).x;
       
    45         _area.y = ev.GetLogicalPosition(dc).y;
       
    46         _area.width = 0;
       
    47         _area.height = 0;
       
    48     }
       
    49     else if (ev.LeftIsDown())
       
    50     {
       
    51         _area.width = ev.GetLogicalPosition(dc).x - _area.x;
       
    52         _area.height = ev.GetLogicalPosition(dc).y - _area.y;
       
    53     }
       
    54 
       
    55     Refresh();
       
    56 }
       
    57 
       
    58 wxPictureWindow::~wxPictureWindow()
       
    59 {
       
    60     std::cout << _area.x * factor << " ";
       
    61     std::cout << _area.y * factor << " ";
       
    62     std::cout << _area.width * factor << " ";
       
    63     std::cout << _area.height * factor << std::endl;
       
    64 }