Main Page | Class List | File List | Class Members | Related Pages

dlgpath.cpp

00001 /***************************************************************************
00002                            dlgpath.cpp
00003                            -------------------
00004     begin                : 2004-08-11
00005     copyright            : (C) 2004-2005 by Dominik Haumann
00006     email                : dhaumann@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  This program is free software; you can redistribute it and/or
00011  modify it under the terms of the GNU General Public License
00012  as published by the Free Software Foundation; either version 2
00013  of the License, or (at your option) any later version.
00014 
00015  This program is distributed in the hope that it will be useful,
00016  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  GNU General Public License for more details.
00019 
00020  You should have received a copy of the GNU General Public License
00021  along with this program; if not, write to the Free Software
00022  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023  ***************************************************************************/
00024 
00025 #include "dlgpath.h"
00026 
00027 #include <wx/clipbrd.h>
00028 
00029 namespace WDS
00030 {
00031 
00032 BEGIN_EVENT_TABLE(CDlgPath, wxDialog)
00033     EVT_BUTTON( wxID_OK, CDlgPath::OnOK)
00034     EVT_BUTTON( IDC_COPY, CDlgPath::OnCopy)
00035     EVT_TEXT  ( IDC_SPEED, CDlgPath::OnSpeedChanged)
00036 END_EVENT_TABLE()
00037 
00038 // constructor
00039 CDlgPath::CDlgPath( int sx, int sy, int ex, int ey, int nElapsedTime,
00040                     float fCost, const wxString& strPath, wxWindow *pParent )
00041     : wxDialog(pParent, -1, wxString("Weg - WDSMap"), wxDefaultPosition,
00042                wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
00043                pTxtCtrl(0L), pSpeedCtrl(0L), pTxtDuration(0L), pathlength(fCost)
00044 {
00045     wxBoxSizer *sVert  = new wxBoxSizer( wxVERTICAL );
00046     wxBoxSizer *sHorz1 = new wxBoxSizer( wxHORIZONTAL );
00047     wxBoxSizer *sHorz2 = new wxBoxSizer( wxHORIZONTAL );
00048 
00049     // Controls
00050     pTxtFound = new wxStaticText( this, -1,
00051         wxString::Format( "Weg von %d:%d nach %d:%d in %.2f Sekunden gefunden!", sx, sy, ex, ey, nElapsedTime/1000.0f ) );
00052     pTxtLength = new wxStaticText( this, -1,
00053         wxString::Format( "Länge: %.2f WP / ", pathlength) );
00054     pTxtDuration = new wxStaticText( this, -1, " = 88d 88h 88m." );
00055 
00056     pSpeedCtrl = new wxTextCtrl( this, IDC_SPEED, "6",
00057         wxDefaultPosition, wxSize(40, -1));
00058 
00059     pTxtCtrl = new wxTextCtrl( this, -1, strPath, wxDefaultPosition,
00060         wxSize(200, 50), wxTE_MULTILINE );
00061     pTxtCtrl->SetEditable(false);
00062     wxButton* pBtnOk   = new wxButton( this, wxID_OK, "OK" );
00063     wxButton* pBtnCopy = new wxButton( this, IDC_COPY, "In die Zwischenablage kopieren" );
00064     wxStaticLine* pLine= new wxStaticLine( this, -1 );
00065 
00066     sHorz1->Add( pBtnCopy, 0, wxRIGHT | wxALIGN_CENTER, 5 );
00067     sHorz1->Add( pBtnOk  , 0, wxALIGN_CENTER, 0 );
00068 
00069     sHorz2->Add( pTxtLength, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, 5 );
00070     sHorz2->Add( pSpeedCtrl, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, 5 );
00071     sHorz2->Add( pTxtDuration, 1, wxALIGN_CENTER | wxTOP | wxBOTTOM, 5 );
00072 
00073     sVert->Add( pTxtFound , 0, wxALIGN_LEFT | wxTOP | wxLEFT | wxRIGHT, 10 );
00074     sVert->Add( sHorz2, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT, 10 );
00075     sVert->Add( pTxtCtrl  , 1, wxEXPAND | wxLEFT | wxRIGHT, 10 );
00076     sVert->Add( pLine, 0, wxEXPAND | wxALL, 5 );
00077     sVert->Add( sHorz1, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxALIGN_RIGHT, 10 );
00078 
00079     SetAutoLayout( true );
00080     SetSizer( sVert );
00081 
00082     sVert->SetSizeHints( this );
00083     sVert->Fit( this );
00084 
00085     pBtnOk->SetFocus( );
00086     pBtnOk->SetDefault( );
00087 
00088     UpdateSpeed(6);
00089 
00090     // HACK: hide cancel button and make ESC-key work
00091     (new wxButton( this, wxID_CANCEL, "Cancel" ))->Show(false);
00092 }
00093 
00094 CDlgPath::~CDlgPath()
00095 {
00096     // all widgets are automatically deleted.
00097 }
00098 
00099 void CDlgPath::UpdateValues( int sx, int sy, int ex, int ey, int nElapsedTime,
00100                              float fCost, const wxString& strPath )
00101 {
00102     pathlength = fCost;
00103 
00104     pTxtFound->SetLabel(
00105         wxString::Format( "Weg von %d:%d nach %d:%d in %.2f Sekunden gefunden!",
00106                           sx, sy, ex, ey, nElapsedTime/1000.0f ) );
00107     pTxtLength->SetLabel( wxString::Format( "Länge: %.2f WP / ", pathlength ) );
00108     pTxtCtrl->SetValue( strPath );
00109 
00110     wxString strSpeed = pSpeedCtrl->GetValue();
00111     long nspeed = 6;
00112     if ( !strSpeed.ToLong(&nspeed) ) {
00113         nspeed = 6;
00114     }
00115     UpdateSpeed( int(nspeed) );
00116 }
00117 
00118 void CDlgPath::UpdateSpeed(int speed)
00119 {
00120     if (speed > 0) {
00121         // time in minutes
00122         int t = int(60 * pathlength / double(speed));
00123         int m = t % 60;
00124         t /= 60; // t in hours
00125         int h = t % 24;
00126         t /= 24; // t in days
00127         int d = t;
00128         pTxtDuration->SetLabel( wxString::Format( " = %dd %dh %dm.", d, h, m) );
00129     }
00130 }
00131 
00132 //BEGIN eventhandling
00133 void CDlgPath::OnOK( wxCommandEvent &event )
00134 {
00135     event.Skip( );
00136 }
00137 
00138 void CDlgPath::OnCopy( wxCommandEvent &event )
00139 {
00140 //  // copy to clipbord
00141     if (wxTheClipboard->Open()) {
00142         // NOTE: this may trigger a segmentation fault in for example SuSE Linux,
00143         // whereas for ex. in Gentoo Linux it works smooth! Maybe this only
00144         // appears in GTK 1.x. If the segfault appears we are innocent!!! ja genau! :)
00145         wxTheClipboard->SetData( new wxTextDataObject(pTxtCtrl->GetValue()) );
00146         wxTheClipboard->Close();
00147     }
00148 }
00149 
00150 void CDlgPath::OnSpeedChanged ( wxCommandEvent &event )
00151 {
00152     // only update if it is a valid number
00153     if (pSpeedCtrl && pSpeedCtrl->GetValue().IsNumber()) {
00154         UpdateSpeed(atoi(pSpeedCtrl->GetValue().c_str()));
00155     }
00156 }
00157 //END eventhandling
00158 
00159 }
00160 // kate: space-indent off; tab-width 4; replace-tabs off;

Generated on Sun Jan 16 18:20:26 2005 for WDSMap by  doxygen 1.3.9.1