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

DialogMsgDebug.cpp

Go to the documentation of this file.
00001 /*
00002  * DialogMsgDebug.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  * This dialog implements a messaging debug interface.  It allows the user
00024  *   to construct a message and send it through the normal messaging API.
00025  *   The dialog is then updated with the return message contents.
00026  *
00027  */
00028 
00029 
00030 #include "../Include/FlyLegacy.h"
00031 #include "../Include/Ui.h"
00032 #include "../Include/Utility.h"
00033 #include "../Include/Globals.h"
00034 
00035 char *idlist[] =
00036   {
00037     "SETDATA",
00038     "GETDATA",
00039     NULL
00040   };
00041 
00042 char *typelist[] =
00043   {
00044     "REAL",
00045     "INT",
00046     NULL
00047   };
00048 
00049 
00050 typedef struct {
00051   puDialogBox*  dialog;
00052   puFrame*    frame;
00053   puText*     title;
00054   puComboBox*   id;
00055   puInput*    group;
00056   puInput*    datatag;
00057   puComboBox*   datatype;
00058   puInput*    intData;
00059   puInput*    realData;
00060   puInput*    result;
00061   puOneShot*    send;
00062   puOneShot*    close;
00063 
00064   char      strGroup[80];
00065   char      strDatatag[80];
00066   int       valInt;
00067   float     valFloat;
00068 } SMsgDebugDialogData;
00069 
00070 SMessage    msg;
00071 
00072 static SMsgDebugDialogData *dt = NULL;
00073 
00074 
00075 static void msg_debug_sync (void)
00076 {
00077   // Sync data type
00078   switch (msg.dataType) {
00079   case TYPE_REAL:
00080     dt->datatype->setCurrentItem (0);
00081     break;
00082 
00083   case TYPE_INT:
00084     dt->datatype->setCurrentItem (1);
00085     break;
00086 
00087   default:
00088     // Do nothing
00089     ;
00090   }
00091 
00092   // Sync data
00093   dt->intData->setValue (msg.intData);
00094   dt->realData->setValue ((float)msg.realData);
00095 
00096   // Sync result
00097   switch (msg.result) {
00098   case MSG_IGNORED:
00099     dt->result->setValue ("IGNORED");
00100     break;
00101 
00102   case MSG_PROCESSED:
00103     dt->result->setValue ("PROCESSED");
00104     break;
00105 
00106   case MSG_USED:
00107     dt->result->setValue ("USED");
00108     break;
00109   }
00110 
00111   puDisplay ();
00112 }
00113 
00114 static void msg_debug_id_cb (puObject* obj)
00115 {
00116   int i = ((puComboBox*)obj)->getCurrentItem ();
00117   switch (i) {
00118   case 0:
00119     msg.id = MSG_SETDATA;
00120     break;
00121 
00122   case 1:
00123     msg.id = MSG_GETDATA;
00124     break;
00125   }
00126 }
00127 
00128 static void msg_debug_datatype_cb (puObject* obj)
00129 {
00130   int i = ((puComboBox*)obj)->getCurrentItem ();
00131   switch (i) {
00132   case 0:
00133     msg.dataType = TYPE_REAL;
00134     break;
00135 
00136   case 1:
00137     msg.dataType = TYPE_INT;
00138     break;
00139   }
00140 }
00141 
00142 static void msg_debug_send_cb (puObject* obj)
00143 {
00144   if (dt == NULL) return;
00145 
00146   // Send message.  'receiver' field is cleared to prevent the message from being
00147   //   sent to the previous message's receiver
00148   msg.group = StringToTag (dt->strGroup);
00149   msg.user.u.datatag = StringToTag (dt->strDatatag);
00150   switch (msg.dataType) {
00151   case TYPE_INT:
00152     msg.intData = dt->valInt;
00153     break;
00154 
00155   case TYPE_REAL:
00156     msg.realData = dt->valFloat;
00157     break;
00158 
00159   default:
00160     // Do nothing
00161     ;
00162   }
00163   msg.receiver = 0;
00164   SendMessage (&msg);
00165 
00166   // Synchronize fields with updated message contents
00167   msg_debug_sync ();
00168 }
00169 
00170 static void msg_debug_close_cb (puObject* obj)
00171 {
00172   if (dt == NULL) return;
00173 
00174   // Deleting the PUI dialog will delete all child widgets as well
00175   delete dt->dialog;
00176 
00177   // Delete dialog data structure
00178   delete dt;
00179   dt = NULL;
00180 }
00181 
00182 void msg_debug_dlg_create (void)
00183 {
00184   if (dt != NULL) return;
00185 
00186   // Initialize message
00187   memset (&msg, 0, sizeof(SMessage));
00188 
00189   // Instantiate data structure for dialog contents
00190   dt = new SMsgDebugDialogData;
00191   strcpy (dt->strGroup, "");
00192   strcpy (dt->strDatatag, "");
00193   dt->valInt = 0;
00194   dt->valFloat = 0.0f;
00195 
00196   int frame_w = 250;
00197   int frame_h = 300;
00198 
00199   // Create dialog box
00200   dt->dialog = new puDialogBox (20, globals->screenHeight - 25 - frame_h);
00201   {
00202     // Frame
00203     dt->frame = new puFrame (0, 0, frame_w, frame_h);
00204 
00205     dt->title = new puText (10, 270);
00206     dt->title->setLabel ("Messaging Debug:");
00207 
00208     // id select box
00209     dt->id = new puComboBox (100, 230, 240, 250, idlist);
00210     dt->id->setLabel ("id     :");
00211     dt->id->setLabelPlace (PUPLACE_CENTERED_LEFT);
00212     dt->id->setStyle (PUSTYLE_BOXED);
00213     dt->id->setCallback (msg_debug_id_cb);
00214     dt->id->setCurrentItem (0);
00215 
00216     // group input field
00217     dt->group = new puInput (100, 200, 240, 220);
00218     dt->group->setLabel ("group    :");
00219     dt->group->setLabelPlace (PUPLACE_CENTERED_LEFT);
00220     dt->group->setStyle (PUSTYLE_BOXED);
00221     dt->group->setValuator (dt->strGroup);
00222 
00223     // datatag input field
00224     dt->datatag = new puInput (100, 170, 240, 190);
00225     dt->datatag->setLabel ("datatag  :");
00226     dt->datatag->setLabelPlace (PUPLACE_CENTERED_LEFT);
00227     dt->datatag->setStyle (PUSTYLE_BOXED);
00228     dt->datatag->setValuator (dt->strDatatag);
00229 
00230     // datatype select box
00231     dt->datatype = new puComboBox (100, 140, 240, 160, typelist);
00232     dt->datatype->setLabel ("datatype:");
00233     dt->datatype->setLabelPlace (PUPLACE_CENTERED_LEFT);
00234     dt->datatype->setStyle (PUSTYLE_BOXED);
00235     dt->datatype->setCallback (msg_debug_datatype_cb);
00236     dt->datatype->setCurrentItem (0);
00237 
00238     // intData input field
00239     dt->intData = new puInput (100, 110, 240, 130);
00240     dt->intData->setLabel ("intData  :");
00241     dt->intData->setLabelPlace (PUPLACE_CENTERED_LEFT);
00242     dt->intData->setStyle (PUSTYLE_BOXED);
00243     dt->intData->setValuator (&dt->valInt);
00244 
00245     // realData input field
00246     dt->realData = new puInput (100, 80, 240, 100);
00247     dt->realData->setLabel ("realData :");
00248     dt->realData->setLabelPlace (PUPLACE_CENTERED_LEFT);
00249     dt->realData->setStyle (PUSTYLE_BOXED);
00250     dt->realData->setValuator (&dt->valFloat);
00251 
00252     // result text field
00253     dt->result = new puInput (100, 50, 240, 70);
00254     dt->result->setLabel ("result  :");
00255     dt->result->setLabelPlace (PUPLACE_CENTERED_LEFT);
00256     dt->result->setStyle (PUSTYLE_BOXED);
00257     dt->result->rejectInput ();
00258 
00259     // Send button
00260     dt->send = new puOneShot (120, 20, 170, 40);
00261     dt->send->setLegend ("Send");
00262     dt->send->makeReturnDefault (false);
00263     dt->send->setStyle (PUSTYLE_SMALL_SHADED);
00264     dt->send->setCallback (msg_debug_send_cb);
00265 
00266     // Close dialog button
00267     dt->close = new puOneShot (190, 20, 240, 40);
00268     dt->close->setLegend ("Close");
00269     dt->close->makeReturnDefault (false);
00270     dt->close->setStyle (PUSTYLE_SMALL_SHADED);
00271     dt->close->setCallback (msg_debug_close_cb);
00272 
00273     // Synchronize dialog fields with message contents
00274     msg_debug_sync ();
00275   }
00276   dt->dialog->close ();
00277   dt->dialog->reveal ();
00278 }
00279 
SourceForge.net Logo Documentation generated by doxygen