Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

wingotodlg.cpp

Go to the documentation of this file.
00001 // wingotodlg.cpp
00002 // 
00003 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
00004 //
00005 // Goto object dialog for Windows.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 
00012 #include <windows.h>
00013 #include "wingotodlg.h"
00014 
00015 #include "res/resource.h"
00016 
00017 using namespace std;
00018 
00019 
00020 static bool GetDialogFloat(HWND hDlg, int id, float& f)
00021 {
00022     char buf[128];
00023     
00024     if (GetDlgItemText(hDlg, id, buf, sizeof buf) > 0 &&
00025         sscanf(buf, " %f", &f) == 1)
00026         return true;
00027     else
00028         return false;
00029 }
00030 
00031 static bool SetDialogFloat(HWND hDlg, int id, char* format, float f)
00032 {
00033     char buf[128];
00034 
00035     sprintf(buf, format, f);
00036 
00037     return (SetDlgItemText(hDlg, id, buf) == TRUE);
00038 }
00039 
00040 
00041 static BOOL APIENTRY GotoObjectProc(HWND hDlg,
00042                                     UINT message,
00043                                     UINT wParam,
00044                                     LONG lParam)
00045 {
00046     GotoObjectDialog* gotoDlg = reinterpret_cast<GotoObjectDialog*>(GetWindowLong(hDlg, DWL_USER));
00047 
00048     switch (message)
00049     {
00050     case WM_INITDIALOG:
00051         {
00052             GotoObjectDialog* gotoDlg = reinterpret_cast<GotoObjectDialog*>(lParam);
00053             if (gotoDlg == NULL)
00054                 return EndDialog(hDlg, 0);
00055             SetWindowLong(hDlg, DWL_USER, lParam);
00056             CheckRadioButton(hDlg,
00057                              IDC_RADIO_KM, IDC_RADIO_RADII,
00058                              IDC_RADIO_KM);
00059 
00060             //Initialize name, distance, latitude and longitude edit boxes with current values.
00061             Simulation* sim = gotoDlg->appCore->getSimulation();
00062             double distance, longitude, latitude;
00063             sim->getSelectionLongLat(distance, longitude, latitude);
00064 
00065             //Display information in format appropriate for object
00066             if (sim->getSelection().body() != NULL)
00067             {
00068                 distance = distance - (double) sim->getSelection().body()->getRadius();
00069                 SetDialogFloat(hDlg, IDC_EDIT_DISTANCE, "%.1f", (float)distance);
00070                 SetDialogFloat(hDlg, IDC_EDIT_LONGITUDE, "%.5f", (float)longitude);
00071                 SetDialogFloat(hDlg, IDC_EDIT_LATITUDE, "%.5f", (float)latitude);
00072                 SetDlgItemText(hDlg, IDC_EDIT_OBJECTNAME, (char*) sim->getSelection().body()->getName().c_str());
00073             }
00074 //            else if (sim->getSelection().star != NULL)
00075 //            {
00076 //                //Code to obtain searchable star name
00077 //               SetDlgItemText(hDlg, IDC_EDIT_OBJECTNAME, (char*)sim->getSelection().star->);
00078 //            }
00079 
00080             return(TRUE);
00081         }
00082         break;
00083 
00084     case WM_COMMAND:
00085         if (LOWORD(wParam) == IDC_BUTTON_GOTO)
00086         {
00087             char buf[1024];
00088             int len = GetDlgItemText(hDlg, IDC_EDIT_OBJECTNAME, buf, sizeof buf);
00089             Simulation* sim = gotoDlg->appCore->getSimulation();
00090             Selection sel;
00091             if (len > 0)
00092                 sel = sim->findObjectFromPath(buf);
00093             
00094             if (!sel.empty())
00095             {
00096                 sim->setSelection(sel);
00097                 sim->geosynchronousFollow();
00098 
00099                 float distance = (float) (sel.radius() * 5);
00100 
00101                 if (GetDialogFloat(hDlg, IDC_EDIT_DISTANCE, distance))
00102                 {
00103                     if (IsDlgButtonChecked(hDlg, IDC_RADIO_AU) == BST_CHECKED)
00104                         distance = astro::AUtoKilometers(distance);
00105                     else if (IsDlgButtonChecked(hDlg, IDC_RADIO_RADII) == BST_CHECKED)
00106                         distance = distance * (float) sel.radius();
00107                     
00108                     distance += (float) sel.radius();
00109                 }
00110                 distance = astro::kilometersToLightYears(distance);
00111 
00112                 float longitude, latitude;
00113                 if (GetDialogFloat(hDlg, IDC_EDIT_LONGITUDE, longitude) &&
00114                     GetDialogFloat(hDlg, IDC_EDIT_LATITUDE, latitude))
00115                 {
00116                     sim->gotoSelectionLongLat(5.0,
00117                                               distance,
00118                                               degToRad(longitude),
00119                                               degToRad(latitude),
00120                                               Vec3f(0, 1, 0));
00121                 }
00122                 else
00123                 {
00124                     sim->gotoSelection(5.0,
00125                                        distance,
00126                                        Vec3f(0, 1, 0),
00127                                        astro::ObserverLocal);
00128                 }
00129             }
00130             return TRUE;
00131         }
00132         else if (LOWORD(wParam) == IDCANCEL)
00133         {
00134             if (gotoDlg != NULL && gotoDlg->parent != NULL)
00135             {
00136                 SendMessage(gotoDlg->parent, WM_COMMAND, IDCLOSE,
00137                             reinterpret_cast<LPARAM>(gotoDlg));
00138             }
00139             EndDialog(hDlg, 0);
00140             return TRUE;
00141         }
00142         break;
00143 
00144     case WM_DESTROY:
00145         if (gotoDlg != NULL && gotoDlg->parent != NULL)
00146         {
00147             SendMessage(gotoDlg->parent, WM_COMMAND, IDCLOSE,
00148                         reinterpret_cast<LPARAM>(gotoDlg));
00149         }
00150         EndDialog(hDlg, 0);
00151         return TRUE;
00152     }
00153 
00154     return FALSE;
00155 }
00156 
00157 
00158 GotoObjectDialog::GotoObjectDialog(HINSTANCE appInstance,
00159                                    HWND _parent,
00160                                    CelestiaCore* _appCore) :
00161     appCore(_appCore),
00162     parent(_parent)
00163 {
00164     hwnd = CreateDialogParam(appInstance,
00165                              MAKEINTRESOURCE(IDD_GOTO_OBJECT),
00166                              parent,
00167                              GotoObjectProc,
00168                              reinterpret_cast<LONG>(this));
00169 }

Generated on Sat Jan 14 22:30:31 2006 for Celestia by  doxygen 1.4.1