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

DialogKeysButtons.cpp

Go to the documentation of this file.
00001 /*
00002  * DialogKeysButtons.cpp
00003  *
00004  * Part of Fly! Legacy project
00005  *
00006  * Copyright 2003 Chris Wallace
00007  *
00008  * Fly! Legacy is free software; you can redistribute it and/or modify
00009  *   it under the terms of the GNU General Public License as published by
00010  *   the Free Software Foundation; either version 2 of the License, or
00011  *   (at your option) any later version.
00012  *
00013  * Fly! Legacy is distributed in the hope that it will be useful,
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *   GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  *   along with Fly! Legacy; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 
00025 #include "../Include/FlyLegacy.h"
00026 #include "../Include/Ui.h"
00027 #include "../Include/TimeManager.h"
00028 #include "../Include/Situation.h"
00029 #include "../Include/Globals.h"
00030 
00031 
00032 typedef struct {
00033   puDialogBox*  dialog;
00034   puFrame*    frame;
00035   puText*     title;
00036   puComboBox*   keyset;
00037   puLargeInput* text;
00038   puOneShot*    ok;
00039 
00040   char      buffer[5000];   // Room for 100 key definitions per set
00041 } SKeysButtonsDialogData;
00042 
00043 static SKeysButtonsDialogData *data = NULL;
00044 
00045 
00046 void keys_buttons_dlg_kill (void)
00047 {
00048   if (data == NULL) return;
00049 
00050   // Deleting the PUI dialog will delete all child widgets as well
00051   delete data->dialog;
00052 
00053   // Delete dialog data structure
00054   delete data;
00055   data = NULL;
00056 }
00057 
00058 static void keys_buttons_ok_cb (puObject* obj)
00059 {
00060   // Close dialog box
00061   keys_buttons_dlg_kill ();
00062 }
00063 
00064 static void keys_buttons_keyset_cb (puObject* obj)
00065 {
00066   puComboBox *cb = (puComboBox*)obj;
00067 
00068   // Initialized buffer
00069   strcpy (data->buffer, "");
00070 
00071   // Get selected key set
00072   int iKset = cb->getCurrentItem();
00073   CKeySet* kset = globals->keymap->GetKeySet (iKset);
00074 
00075   // Copy key definitions into buffer
00076   int nDefs = kset->GetNumKeyDefinitions ();
00077   for (int i=0; i< nDefs; i++) {
00078     CKeyDefinition *kkey = kset->GetKeyDefinition (i);
00079 
00080     char code[64];
00081     formatKeyCode (code, kkey->GetCode ());
00082 
00083     char def[64];
00084     sprintf (def, "%-28s%22s\n", kkey->GetName(), code);
00085 
00086     strcat (data->buffer, def);
00087   }
00088 
00089   data->text->setText (data->buffer);
00090   data->text->setCursor (0);
00091 }
00092 
00093 void keys_buttons_dlg_create (void)
00094 {
00095   if (data != NULL) return;
00096 
00097   // Instantiate data structure for dialog contents
00098   data = new SKeysButtonsDialogData;
00099 
00100   // Create dialog box
00101   data->dialog = new puDialogBox (20, 100);
00102   {
00103     // Frame
00104     data->frame = new puFrame (0, 0, 500, 440);
00105 
00106     // Title
00107     data->title = new puText (10, 410);
00108     data->title->setLabel ("Keys and Buttons:");
00109 
00110     // Create key set list for select box
00111     int nSets = globals->keymap->GetNumKeySets();
00112     char **list = new char*[nSets+1];
00113     for (int i=0; i<nSets; i++) {
00114       CKeySet *kset = globals->keymap->GetKeySet (i);
00115       list[i] = new char[64];
00116       strcpy (list[i], kset->GetName ());
00117     }
00118     list[nSets] = NULL;
00119 
00120     // Key set selector
00121     data->keyset = new puComboBox (20, 380, 480, 400, list);
00122     data->keyset->setLabel ("Key Set : ");
00123     data->keyset->setLabelPlace (PUPLACE_CENTERED_LEFT);
00124     data->keyset->setStyle (PUSTYLE_BOXED);
00125     data->keyset->setCallback (keys_buttons_keyset_cb);
00126 
00127     // Key mappings
00128     data->text = new puLargeInput (20, 60, 460, 300, 2, 20);
00129     data->text->disableInput();
00130     data->text->setStyle (PUSTYLE_SMALL_SHADED);
00131     strcpy (data->buffer, "");
00132     data->text->setText (data->buffer);
00133 
00134     // OK button
00135     data->ok = new puOneShot (400, 20, 460, 40);
00136     data->ok->setLegend ("OK");
00137     data->ok->makeReturnDefault (true);
00138     data->ok->setStyle (PUSTYLE_SMALL_SHADED);
00139     data->ok->setCallback (keys_buttons_ok_cb);
00140   }
00141   data->dialog->close ();
00142   data->dialog->reveal ();
00143 
00144   // Initialize select box with first key set
00145   data->keyset->setCurrentItem (0);
00146 }
00147 
SourceForge.net Logo Documentation generated by doxygen