Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
authorviric <viriketo@gmail.com>
Sun, 24 Apr 2011 14:03:52 +0200
changeset 1 506e0fc65ba3
parent 0 7e720dcafcaf
child 2 b2772bffb62f
Ara processo la tecla ESC, almenys, i ho preparo per un next_picture
MainWindow.cpp
MainWindow.hpp
wxPictureWindow.cpp
wxPictureWindow.hpp
--- a/MainWindow.cpp	Sat Nov 01 20:57:17 2008 +0100
+++ b/MainWindow.cpp	Sun Apr 24 14:03:52 2011 +0200
@@ -1,8 +1,15 @@
 #include <wx/wx.h>
 #include <wx/image.h>
+#include <iostream>
 #include "wxPictureWindow.hpp"
 #include "MainWindow.hpp"
 
+DEFINE_EVENT_TYPE(EVT_NEXTPICTURE)
+
+BEGIN_EVENT_TABLE (MainWindow, wxFrame)
+    EVT_COMMAND (wxID_ANY, EVT_NEXTPICTURE, MainWindow::OnNextPicture)
+END_EVENT_TABLE ()
+
 MainWindow::MainWindow(const wxImage &img, const CropArea area, const wxSize size)
     :wxFrame(0, wxID_ANY, _("wxDjvuMaker"), wxDefaultPosition, size)
 {
@@ -10,3 +17,9 @@
     wxPictureWindow *picture = new wxPictureWindow(img, area, this);
     s->Add(picture);
 }
+
+void MainWindow::OnNextPicture(wxCommandEvent &e)
+{
+    using namespace std;
+    cout << "next picture" << endl;;
+}
--- a/MainWindow.hpp	Sat Nov 01 20:57:17 2008 +0100
+++ b/MainWindow.hpp	Sun Apr 24 14:03:52 2011 +0200
@@ -4,10 +4,16 @@
 #include <wx/wx.h>
 #include "CropArea.hpp"
 
+DECLARE_EVENT_TYPE(EVT_NEXTPICTURE, -1)
+
 class MainWindow : public wxFrame
 {
 public:
     MainWindow(const wxImage &img, CropArea area, wxSize size);
+
+    void OnNextPicture(wxCommandEvent &e);
+
+    DECLARE_EVENT_TABLE ();
 };
 
 #endif /* _HEADER_MAINWINDOW_HPP_ */
--- a/wxPictureWindow.cpp	Sat Nov 01 20:57:17 2008 +0100
+++ b/wxPictureWindow.cpp	Sun Apr 24 14:03:52 2011 +0200
@@ -4,24 +4,33 @@
 #include <wx/dc.h>
 #include <iostream>
 #include "wxPictureWindow.hpp"
+#include "MainWindow.hpp"
 
 const int factor = 3;
 
 BEGIN_EVENT_TABLE(wxPictureWindow, wxScrolledWindow)
   EVT_MOUSE_EVENTS (wxPictureWindow::OnMouse)
+  EVT_KEY_UP (wxPictureWindow::OnKey)
 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);
+    SetImg(img);
     _area.x /= factor;
     _area.y /= factor;
     _area.width /= factor;
     _area.height /= factor;
+    SetScrollRate(10, 10);
+    SetFocus();
+}
+
+void
+wxPictureWindow::SetImg(const wxImage &img)
+{
+    SetVirtualSize(_bmp.GetWidth(), _bmp.GetHeight());
+    _bmp = wxBitmap(img);
 }
 
 void wxPictureWindow::OnDraw(wxDC &dc)
@@ -62,3 +71,17 @@
     std::cout << _area.width * factor << " ";
     std::cout << _area.height * factor << std::endl;
 }
+
+void
+wxPictureWindow::OnKey(wxKeyEvent &e)
+{
+    using namespace std;
+    if (e.GetKeyCode() == WXK_ESCAPE)
+    {
+        cout << "escape" << endl;;
+        wxCommandEvent e(EVT_NEXTPICTURE);
+        GetParent()->AddPendingEvent(e);
+    }
+    else
+        e.Skip();
+}
--- a/wxPictureWindow.hpp	Sat Nov 01 20:57:17 2008 +0100
+++ b/wxPictureWindow.hpp	Sun Apr 24 14:03:52 2011 +0200
@@ -7,9 +7,11 @@
     public:
         wxPictureWindow(const wxImage &img, CropArea area, wxWindow *parent);
         ~wxPictureWindow();
+        void SetImg(const wxImage &img);
     protected:
         virtual void OnDraw(wxDC &dc);
         void OnMouse(wxMouseEvent &ev);
+        void OnKey(wxKeyEvent &ev);
 
     private:
         wxString _filename;