Mercurial > mercurial > hgweb_rsearcher.cgi
changeset 6:9a8b581c1993
improve performance.
author | pyon@macmini |
---|---|
date | Tue, 23 Oct 2018 19:15:22 +0900 |
parents | e3b10fb860b3 |
children | 29829e98d510 |
files | doc/Todo include/auth.h include/id.h include/main.h include/rsearcher.h src/auth.cpp src/main.cpp src/rsearcher.cpp |
diffstat | 8 files changed, 177 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/Todo Mon Oct 22 22:17:02 2018 +0900 +++ b/doc/Todo Tue Oct 23 19:15:22 2018 +0900 @@ -58,7 +58,7 @@ * バージョンアップ + client に pw + 10分間 Idle なら password - + dark-mode の搭載 + + green-mode の搭載 ( green, green/b, beige, gray ) + プライベートフォルダに写真 userid/startup.jpg, default.jpg, avatar.jpg ** その他 ***********************************************************************
--- a/include/auth.h Mon Oct 22 22:17:02 2018 +0900 +++ b/include/auth.h Tue Oct 23 19:15:22 2018 +0900 @@ -1,5 +1,5 @@ // Filename : auth.h -// Last Change: 2018-10-22 月 08:41:38. +// Last Change: 2018-10-23 火 09:02:05. // #ifndef __AUTH_H__ @@ -47,6 +47,7 @@ void SetServer( wxString server ) { m_server = server; }; void CreateControls( void ); + bool GetDB( void ); bool LoadDB( void ); bool IsValidUser( void ); wxString GetUser( void ) { return m_user; };
--- a/include/id.h Mon Oct 22 22:17:02 2018 +0900 +++ b/include/id.h Tue Oct 23 19:15:22 2018 +0900 @@ -1,5 +1,5 @@ // Filename : id.h -// Last Change: 2018-10-22 月 12:43:44. +// Last Change: 2018-10-23 火 12:36:12. // #ifndef __ID_H__ @@ -17,6 +17,9 @@ ID_LIST, ID_NBOOK, ID_SLDR, + ID_PZOOM, + ID_MZOOM, + ID_DARK, ID_TIMER, ID_LOGOUT, };
--- a/include/main.h Mon Oct 22 22:17:02 2018 +0900 +++ b/include/main.h Tue Oct 23 19:15:22 2018 +0900 @@ -1,5 +1,5 @@ // Filename : main.h -// Last Change: 2018-10-19 金 16:02:35. +// Last Change: 2018-10-23 火 10:09:58. // #include <wx/wx.h> #include <wx/config.h> @@ -31,6 +31,7 @@ void InitSetting(); void SaveSetting(); + void RemoveFile( wxString pattern ); }; DECLARE_APP( MyApp )
--- a/include/rsearcher.h Mon Oct 22 22:17:02 2018 +0900 +++ b/include/rsearcher.h Tue Oct 23 19:15:22 2018 +0900 @@ -1,5 +1,5 @@ // Filename : rsearcher.h -// Last Change: 2018-10-22 月 13:08:14. +// Last Change: 2018-10-23 火 14:26:02. // #ifndef __RSEARCH_H__ @@ -62,10 +62,11 @@ private: int m_dragx, m_dragy; // for image drag int cx, cy; // for mouse-gesture - int m_zoom = 0; - wxBitmap m_bmp[5]; + wxBitmap m_bmp0; wxScrolledWindow* m_parent; - int select_tab = 0; + + public: + int zoom = 0; public: MyStaticBitmap( wxScrolledWindow *parent, wxWindowID id, const wxBitmap &label, const wxPoint &pos, const wxSize &size, long style, const wxString &name ); @@ -77,8 +78,8 @@ void OnEndRGesture( wxMouseEvent& event ); void OnMotion( wxMouseEvent& event ); void OnWheel( wxMouseEvent& event ); - void SetImage( int i, wxBitmap bmp ) { m_bmp[i] = bmp; }; - void SetZoom( int m_zoom ); + void SetOrigImage( wxBitmap bmp ) { m_bmp0 = bmp; }; + wxBitmap GetOrigImage( void ) { return m_bmp0; }; void ChangeBook( int i ); }; @@ -93,6 +94,7 @@ wxArrayString m_index; wxTimer m_timer; HhsHash hhash; + bool m_dark = false; protected: MySearchCtrl* m_searchCtrl; @@ -117,9 +119,14 @@ wxDataViewColumn* m_dataViewListColumnNo; wxDataViewColumn* m_dataViewListColumnDate; wxTextCtrl* m_textCtrlLog; - wxSlider* m_slider; wxButton* m_buttonPsearch; wxButton* m_buttonPrint; + + // invisible button for shortcut-key + wxSlider* m_slider; + wxButton* m_buttonPzoom; + wxButton* m_buttonMzoom; + wxButton* m_buttonDark; wxButton* m_buttonHelp; wxButton* m_buttonLogout; @@ -135,12 +142,14 @@ void Search( void ); void PasteSeaarch( void ); void LoadDB( void ); - bool LoadBitmap( wxScrolledWindow* sc, wxStaticBitmap* sb, wxString file ); + bool LoadBitmap( wxScrolledWindow* sc, MyStaticBitmap* sb, wxString file ); bool LoadBitmaps( wxString date, bool reload ); + void ChangeCZoom( int z ); + void ChangeZoom( wxScrolledWindow* sc, MyStaticBitmap* sb, int z ); + void ChangeColor( MyStaticBitmap* sb ); void GetImages( wxString hhs, wxString date ); void PrintImages( void ); void WriteLog( wxString msg ); - void RemoveFile( wxString pattern ); void InDevelop( bool ); void OnItemSelected( wxDataViewEvent& event ); @@ -151,6 +160,9 @@ void OnClose( wxCloseEvent& event ); // save config void OnIdle( wxIdleEvent& event ); void OnTimer( wxTimerEvent& event ); + void OnPlusZoom( wxCommandEvent& event ); + void OnMinusZoom( wxCommandEvent& event ); + void OnDark( wxCommandEvent& event ); void OnHelp( wxCommandEvent& event ); void OnLogout( wxCommandEvent& event ); };
--- a/src/auth.cpp Mon Oct 22 22:17:02 2018 +0900 +++ b/src/auth.cpp Tue Oct 23 19:15:22 2018 +0900 @@ -1,5 +1,5 @@ // Filename : auth.cpp -// Last Change: 2018-10-22 譛 16:11:52. +// Last Change: 2018-10-23 轣ォ 09:05:53. // #include "id.h" @@ -110,7 +110,6 @@ m_buttonCancel = new wxButton( this, wxID_CANCEL, wxT( "Cancel" ), wxDefaultPosition, wxDefaultSize, 0 ); gSizer->Add( m_buttonCancel, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); - this->SetSizer( gSizer ); this->Layout(); gSizer->Fit( this ); @@ -119,17 +118,17 @@ m_textCtrlId->SetFocus(); } -bool AuthDialog::LoadDB( void ) -{ - // http get ( auth.db, hhs.db, index.db ) +bool AuthDialog::GetDB( void ) +{ // http get ( auth.db, hhs.db, index.db ) wxArrayString args; args.Add( wxT( "client.exe" ) ); args.Add( wxT( "-u" ) ); args.Add( m_server ); + wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE ); +} - wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE ); - - // load db +bool AuthDialog::LoadDB( void ) +{ wxTextFile file; if ( !file.Open( wxT( "auth.db" ) ) ) return false; for ( int i = 0; i < file.GetLineCount(); i++ ) {
--- a/src/main.cpp Mon Oct 22 22:17:02 2018 +0900 +++ b/src/main.cpp Tue Oct 23 19:15:22 2018 +0900 @@ -1,5 +1,5 @@ // Filename : main.cpp -// Last Change: 2018-10-22 譛 16:14:28. +// Last Change: 2018-10-23 轣ォ 10:09:42. // #include "id.h" #include "main.h" @@ -26,6 +26,11 @@ wxImage::AddHandler( new wxPNGHandler ); InitSetting(); + // Login Dialog + AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION ); + authdlg->SetServer( m_server ); + authdlg->GetDB(); + // Splash Screen wxFileSystem::AddHandler( new wxZipFSHandler ); wxFileSystem* fs = new wxFileSystem(); @@ -36,27 +41,13 @@ wxInputStream* s = file->GetStream(); wxImage image( *s, wxBITMAP_TYPE_PNG ); wxBitmap bmp = wxBitmap( image ); - wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 3000, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP ); + wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 2500, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP ); delete file; } - wxMilliSleep( 250 ); - } - - unsigned int seed = (unsigned int)time( 0 ); - srand( seed ); - int n = rand() % 13; - wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:%02d.jpg" ), n ) ); - if ( file ) { - wxInputStream* s = file->GetStream(); - wxFileOutputStream of( wxT( "./image/hello.jpg" ) ); - s->Read( of ); - delete file; + wxMilliSleep( 200 ); } delete fs; - // Login Dialog - AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION ); - authdlg->SetServer( m_server ); if ( !authdlg->LoadDB() ) { authdlg->Destroy(); return false; @@ -64,7 +55,22 @@ if ( authdlg->ShowModal() == wxID_OK ) { wxString ui = wxString::Format( wxT( "./image/" ) + authdlg->GetUser() + wxT( ".jpg" ) ); - if ( wxFileExists( ui ) ) wxCopyFile( ui, wxT( "./image/hello.jpg" ), true ); + if ( wxFileExists( ui ) ) { + wxCopyFile( ui, wxT( "./image/hello.jpg" ), true ); + } else { + unsigned int seed = (unsigned int)time( 0 ); + srand( seed ); + int n = rand() % 13; + wxFileSystem* fs = new wxFileSystem(); + wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:%02d.jpg" ), n ) ); + if ( file ) { + wxInputStream* s = file->GetStream(); + wxFileOutputStream of( wxT( "./image/hello.jpg" ) ); + s->Read( of ); + delete file; + } + delete fs; + } // Main Window MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE ); @@ -83,6 +89,9 @@ int MyApp::OnExit() { + RemoveFile( wxT( "auth.db" ) ); + RemoveFile( wxT( "hhs.db" ) ); + RemoveFile( wxT( ".cache/*" ) ); SaveSetting(); return 0; } @@ -122,3 +131,12 @@ delete config; } +void MyApp::RemoveFile( wxString pattern ) +{ + wxString file = wxFindFirstFile( pattern ); + while ( !file.empty() ) { + wxRemoveFile( file ); + file = wxFindNextFile(); + } +} +
--- 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 );