diff src/preview.cpp @ 15:de222bc84e48

Implement Mouse Gesture in Preview Dialog.
author pyon@macmini
date Sun, 15 Jun 2014 16:45:52 +0900
parents ac17a73e39b3
children 92188f60323d
line wrap: on
line diff
--- a/src/preview.cpp	Thu Jun 05 04:19:03 2014 +0900
+++ b/src/preview.cpp	Sun Jun 15 16:45:52 2014 +0900
@@ -1,5 +1,5 @@
 // Filename   : preview.cpp
-// Last Change: 04-Jun-2014.
+// Last Change: 11-Jun-2014.
 //
 
 #include "marksheet.h"
@@ -58,7 +58,7 @@
 }
 
 // Functions
-/* サムネイル表示 */
+/* サムネイル画像作成 */
 void PThumbnailPanel::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select )
 {
     m_imagefiles = imagefiles;
@@ -135,9 +135,11 @@
 	wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
 
     m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL|wxALWAYS_SHOW_SB );
-    m_scrolledWindow->Connect( wxEVT_MOUSEWHEEL,  wxMouseEventHandler( PreviewDialog::OnWheel  ), NULL, this );
+    m_scrolledWindow->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PreviewDialog::OnWheel ), NULL, this );
 	m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
     m_bitmap->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this );
+    m_bitmap->Connect( wxEVT_RIGHT_DOWN,  wxMouseEventHandler( PreviewDialog::OnStartRGesture ), NULL, this );
+    m_bitmap->Connect( wxEVT_RIGHT_UP,    wxMouseEventHandler( PreviewDialog::OnEndRGesture   ), NULL, this );
 	bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 );
 	
 	wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL );
@@ -166,8 +168,10 @@
 
 PreviewDialog::~PreviewDialog()
 {
-    m_scrolledWindow->Disconnect( wxEVT_MOUSEWHEEL,  wxMouseEventHandler( PreviewDialog::OnWheel  ), NULL, this );
+    m_scrolledWindow->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PreviewDialog::OnWheel ), NULL, this );
     m_bitmap->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this );
+    m_bitmap->Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( PreviewDialog::OnStartRGesture ), NULL, this );
+    m_bitmap->Disconnect( wxEVT_RIGHT_UP,   wxMouseEventHandler( PreviewDialog::OnEndRGesture   ), NULL, this );
 }
 
 // Event Table
@@ -177,9 +181,10 @@
 
 #define WIDTH  2480
 #define HEIGHT 3509
+/* プレビューするファイルをセット */
 void PreviewDialog::SetPreviewImage( int n )
 {
-    m_preview = m_imagefiles[n];
+    m_preview = n;
     m_zoom = 1.0;
     SetZoom( m_zoom );
 
@@ -193,6 +198,7 @@
     m_textInfo->SetValue( info );
 }
 
+/* 倍率を指定しロード */
 void PreviewDialog::SetZoom( float zoom )
 {
     int w, h;
@@ -202,7 +208,7 @@
 
     m_bitmap->SetBitmap( wxNullBitmap );
     wxImage img;
-    img.LoadFile( m_preview, wxBITMAP_TYPE_JPEG );
+    img.LoadFile( m_imagefiles[m_preview], wxBITMAP_TYPE_JPEG );
     wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) );
     m_bitmap->SetBitmap( bmp );
     m_bitmap->Centre( wxHORIZONTAL );
@@ -211,6 +217,7 @@
     m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 );
 }
 
+/* ファイル名を保持 */
 void PreviewDialog::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select )
 { 
     m_imagefiles = imagefiles;
@@ -221,6 +228,7 @@
     this->SetTitle( title );
 }
 
+/* コントロールキー + マウスホイール で画像を拡大・縮小 */
 void PreviewDialog::OnWheel( wxMouseEvent& event )
 {
     if ( event.ControlDown() ) {
@@ -238,6 +246,7 @@
     event.Skip();
 }
 
+/* 画像のダブルクリックで倍率変更 */
 void PreviewDialog::OnDClick( wxMouseEvent& WXUNUSED(event) )
 {
     if ( m_zoom > 2.1 ) m_zoom  = 1.0;
@@ -246,6 +255,46 @@
     SetZoom( m_zoom );
 }
 
+/* 右ジェスチャー検知開始 */
+void PreviewDialog::OnStartRGesture( wxMouseEvent& event )
+{
+    event.GetPosition( &cx, &cy );
+}
+
+/* 右ジェスチャー判定 */
+void PreviewDialog::OnEndRGesture( wxMouseEvent& event )
+{
+    int x, y;
+    event.GetPosition( &x, &y );
+
+    int dx = x - cx;
+    int dy = y - cy;
+    float rad = fabs( atan2( dy, dx ) );
+    float pi = 3.14159;
+
+    // 右へジェスチャー
+    if ( rad < pi/8 && dx > 0 ) {
+        if ( m_preview < m_imagefiles.GetCount() - 1 ) 
+            m_preview++;
+        else 
+            return;
+        m_thumbPanel->Preview( m_preview );
+    }
+    // 左へジェスチャー
+    else if ( rad > pi/8*7 && rad < pi && dx < 0 ) { 
+        if ( m_preview > 0 ) 
+            m_preview--;
+        else 
+            return;
+        m_thumbPanel->Preview( m_preview );
+    }
+    // 右上ヘジェスチャー
+    else if ( rad > pi/8 && rad < pi/8*3 && dx > 0 ) {
+        Close();
+    }
+}
+
+/* 印刷 */
 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(event) )
 {
     wxString html;
@@ -253,7 +302,7 @@
 
     wxString tmpjpg = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("preview.jpg");
 
-    wxCopyFile( m_preview, tmpjpg, true );
+    wxCopyFile( m_imagefiles[m_preview], tmpjpg, true );
 
     html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>");
     html = html + wxT("</body></html>");