diff src/rsearcher.cpp @ 6:9a8b581c1993

improve performance.
author pyon@macmini
date Tue, 23 Oct 2018 19:15:22 +0900
parents e3b10fb860b3
children 29829e98d510
line wrap: on
line diff
--- a/src/rsearcher.cpp	Mon Oct 22 22:17:02 2018 +0900
+++ b/src/rsearcher.cpp	Tue Oct 23 19:15:22 2018 +0900
@@ -1,5 +1,5 @@
 // Filename   : rsearcher.cpp
-// Last Change: 2018-10-22 ŒŽ 16:20:03.
+// Last Change: 2018-10-23 ‰Î 13:09:30.
 //
 
 #include <wx/arrstr.h> 
@@ -116,13 +116,11 @@
 {
     if ( event.ControlDown() ) {
         if ( event.GetWheelRotation() < 0 ) {
-            if ( m_zoom < 4 ) m_zoom++;
+            //if ( m_zoom < 4 ) m_zoom++;
         }
         else {
-            if ( m_zoom > 0 ) m_zoom--;
+            //if ( m_zoom > 0 ) m_zoom--;
         }
-        SetBitmap( m_bmp[ m_zoom ] );
-        m_parent->SetScrollbars( 10, 10, m_bmp[ m_zoom ].GetWidth() / 10, m_bmp[ m_zoom ].GetHeight() / 10 );
         return;
     }
     event.Skip();
@@ -228,9 +226,6 @@
 
 MainFrame::~MainFrame()
 {
-	RemoveFile( wxT( "auth.db" ) );
-	RemoveFile( wxT( "hhs.db" ) );
-	RemoveFile( wxT( ".cache/*" )  );
 }
 
 // Event Table
@@ -240,6 +235,9 @@
     EVT_NOTEBOOK_PAGE_CHANGED( ID_NBOOK, MainFrame::OnNBookChanged )
 	EVT_BUTTON( wxID_PRINT, MainFrame::OnPrint )
 	EVT_BUTTON( ID_PSEARCH, MainFrame::OnPasteSearch )
+	EVT_BUTTON( ID_PZOOM, MainFrame::OnPlusZoom )
+	EVT_BUTTON( ID_MZOOM, MainFrame::OnMinusZoom )
+	EVT_BUTTON( ID_DARK, MainFrame::OnDark )
 	EVT_BUTTON( wxID_HELP, MainFrame::OnHelp )
 	EVT_BUTTON( ID_LOGOUT, MainFrame::OnLogout )
 	EVT_CLOSE( MainFrame::OnClose )
@@ -302,6 +300,26 @@
 	PrintImages();
 }
 
+void MainFrame::OnPlusZoom( wxCommandEvent& WXUNUSED(event) )
+{
+	ChangeCZoom( 1 );
+}
+
+void MainFrame::OnMinusZoom( wxCommandEvent& WXUNUSED(event ) )
+{
+	ChangeCZoom( -1 );
+}
+
+void MainFrame::OnDark( wxCommandEvent& WXUNUSED(event ) )
+{
+	ChangeColor( m_staticBitmap1 );
+	ChangeColor( m_staticBitmap2 );
+	ChangeColor( m_staticBitmap3 );
+	ChangeColor( m_staticBitmap4 );
+	ChangeColor( m_staticBitmap5 );
+	m_dark = !m_dark;
+}
+
 void MainFrame::OnHelp( wxCommandEvent& WXUNUSED(event) )
 {
 	wxString version, build;
@@ -413,12 +431,19 @@
 	m_buttonPrint = new wxButton( this, wxID_PRINT, wxT( "Print" ), wxDefaultPosition, wxDefaultSize, 0 );
 	bSizerRight->Add( m_buttonPrint, 0, wxALL, 5 );
 	
-	m_buttonHelp = new wxButton( this, wxID_HELP, wxT( "Help" ), wxDefaultPosition, wxDefaultSize, 0 );
-	bSizerRight->Add( m_buttonHelp, 0, wxALL, 5 );
-	
 	m_buttonLogout = new wxButton( this, ID_LOGOUT, wxT( "Logout" ), wxDefaultPosition, wxDefaultSize, 0 );
 	bSizerRight->Add( m_buttonLogout, 0, wxALL, 5 );
 	
+	// invisible buttons for shortcut-key
+	m_buttonPzoom = new wxButton( this, ID_PZOOM, wxT( "ZOOM" ), wxDefaultPosition, wxDefaultSize, 0 );
+	m_buttonPzoom->Hide();
+	m_buttonMzoom = new wxButton( this, ID_MZOOM, wxT( "zoom" ), wxDefaultPosition, wxDefaultSize, 0 );
+	m_buttonMzoom->Hide();
+	m_buttonDark = new wxButton( this, ID_DARK, wxT( "Dark" ), wxDefaultPosition, wxDefaultSize, 0 );
+	m_buttonDark->Hide();
+	m_buttonHelp  = new wxButton( this, wxID_HELP, wxT( "Help" ), wxDefaultPosition, wxDefaultSize, 0 );
+	m_buttonHelp->Hide();
+	
 	bSizerTop->Add( bSizerRight, 0, wxEXPAND, 5 );
 	
 	this->SetSizer( bSizerTop );
@@ -435,22 +460,23 @@
 
 void MainFrame::SetAccelerator( void )
 {
-	wxAcceleratorEntry entries[2];
-	entries[0].Set( wxACCEL_CTRL,  (int) 'P', wxID_PRINT );
-	entries[1].Set( wxACCEL_NORMAL,  WXK_F1,  wxID_HELP );
-	/*
-	entries[1].Set( wxACCEL_CTRL,  (int) 'X', wxID_EXIT );
-	entries[2].Set( wxACCEL_SHIFT, (int) 'A', ID_ABOUT);
-	entries[3].Set( wxACCEL_NORMAL, WXK_DELETE, wxID_CUT);
-	*/
-	wxAcceleratorTable accel( 2, entries );
+	wxAcceleratorEntry entries[5];
+	entries[0].Set( wxACCEL_CTRL,   (int)'P', wxID_PRINT );
+	entries[1].Set( wxACCEL_NORMAL, WXK_F1,   wxID_HELP );
+	entries[2].Set( wxACCEL_NORMAL, (int)'Z', ID_PZOOM );
+	entries[3].Set( wxACCEL_NORMAL, (int)'X', ID_MZOOM );
+	entries[4].Set( wxACCEL_NORMAL, (int)'D', ID_DARK );
+	wxAcceleratorTable accel( 5, entries );
 	SetAcceleratorTable( accel );
 }
 
 void MainFrame::Cmd( wxString cmd )
 {
 	m_dataViewListCtrl->DeleteAllItems();
+	m_textCtrlName->SetValue( wxEmptyString );
+	m_textCtrlAddr->SetValue( wxEmptyString );
 	LoadBitmaps( wxEmptyString, false );
+
     wxRegEx reHhs( wxT( "^0[1238][0-9]{8}$" ) );
 
     if ( cmd.IsSameAs( wxT( "q" ), true ) || cmd.IsSameAs( wxT( "9" ), true ) ) {
@@ -480,7 +506,7 @@
 	}
 
     if ( cmd.IsSameAs( wxT( "+" ), false ) ) {
-		PrintImages();
+		//PrintImages();
         return;
 	}
 
@@ -493,9 +519,10 @@
 	wxMessageBox( wxT( "Bad Input !!" ) );
 }
 
-bool MainFrame::LoadBitmap( wxScrolledWindow* sc, wxStaticBitmap* sb, wxString file )
+bool MainFrame::LoadBitmap( wxScrolledWindow* sc, MyStaticBitmap* sb, wxString file )
 {
 	sb->SetBitmap( wxNullBitmap );
+	sb->zoom = 0;
 	sc->Scroll( 0, 0 );
 
 	bool ok = true;
@@ -508,6 +535,7 @@
 		ok = false;
 	}
     wxBitmap bmp( file, wxBITMAP_TYPE_JPEG );
+	sb->SetOrigImage( bmp );
     int width  = bmp.GetWidth();
     int height = bmp.GetHeight();
     wxImage img = bmp.ConvertToImage();
@@ -539,6 +567,60 @@
 	return ok;
 }
 
+void MainFrame::ChangeCZoom( int z )
+{
+	int n = m_notebook->GetSelection();
+	if ( n == 0 ) ChangeZoom( m_scrolledWindow1, m_staticBitmap1, z );
+	if ( n == 1 ) ChangeZoom( m_scrolledWindow2, m_staticBitmap2, z );
+	if ( n == 2 ) ChangeZoom( m_scrolledWindow3, m_staticBitmap3, z );
+	if ( n == 3 ) ChangeZoom( m_scrolledWindow4, m_staticBitmap4, z );
+	if ( n == 4 ) ChangeZoom( m_scrolledWindow5, m_staticBitmap5, z );
+}
+
+void MainFrame::ChangeZoom( wxScrolledWindow* sc, MyStaticBitmap* sb, int z )
+{
+	if ( z > 0 ) sb->zoom++;
+	else         sb->zoom--;
+
+	float zz = pow( 1.1, sb->zoom );
+
+	int x, y;
+	sc->GetViewStart( &x, &y );
+	sc->Scroll( 0, 0 );
+	wxBitmap bmp = sb->GetOrigImage();
+
+    int width  = bmp.GetWidth();
+    int height = bmp.GetHeight();
+    wxImage img = bmp.ConvertToImage();
+
+    int ww, wh;
+    sc->GetSize( &ww, &wh );
+
+    float w = ww * zz - 30;
+    float h = w * height / width;
+    sb->SetBitmap( wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
+    sc->SetScrollbars( 10, 10, (int)w / 10, (int)h / 10 );
+	sc->Scroll( x, y );
+
+	if ( m_dark ) ChangeColor( sb );
+}
+
+void MainFrame::ChangeColor( MyStaticBitmap* sb )
+{
+	wxBitmap bmp = sb->GetBitmap();
+    wxImage img = bmp.ConvertToImage();
+	unsigned char r, g, b;
+	for ( int x = 0; x < img.GetWidth(); x++ ) {
+		for ( int y = 0; y < img.GetHeight(); y++ ) {
+			r = 255 - img.GetRed( x, y );
+			g = 255 - img.GetGreen( x, y );
+			b = 255 - img.GetBlue( x, y );
+			img.SetRGB( x, y, r, g, b );
+		}
+	}
+    sb->SetBitmap( wxBitmap( img ) );
+}
+
 void MainFrame::GetImages( wxString hhs, wxString date )
 {
 	wxArrayString args;	// http get
@@ -700,15 +782,6 @@
 	WriteLog( wxT( "[print]" ) );
 }
 
-void MainFrame::RemoveFile( wxString pattern )
-{
-	wxString file = wxFindFirstFile( pattern );
-	while ( !file.empty() ) {
-		wxRemoveFile( file  );
-		file = wxFindNextFile();
-	}
-}
-
 void MainFrame::WriteLog( wxString msg )
 {
 	wxDateTime now = wxDateTime::Now();
@@ -727,10 +800,6 @@
 {
     if ( !flag ) return;
     
-	bool he = false;
-	m_buttonHelp->Enable( he );
-	m_buttonHelp->Show( he );
-
 	bool lo = false;
 	m_buttonLogout->Enable( lo );
 	m_buttonLogout->Show( lo );