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

Panels.cpp

Go to the documentation of this file.
00001 /*
00002  * Panels.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 
00034 #include "../Include/Globals.h"
00035 #include "../Include/FlyLegacy.h"
00036 #include "../Include/Panels.h"
00037 #include "../Include/Gauges.h"
00038 #include "../Include/Utility.h"
00039 #include "../Include/Ui.h"
00040 
00041 using namespace std;
00042 
00043 
00044 /*
00045  * CPanel
00046  */
00047 
00048 CPanel::CPanel (Tag id, const char* filename)
00049 {
00050   this->id = id;
00051   strcpy (this->filename, filename);
00052   surface = NULL;
00053   memset (&bmPanl, 0, sizeof(SBitmap));
00054 
00055   // Initialize to window dimensions
00056   xScreen = globals->screenWidth;
00057   yScreen = globals->screenHeight;
00058 
00059   // Initialize panel viewing parameters
00060   x_3Dxy = y_3Dxy = 0;
00061   x_3Dsz = y_3Dsz = 0;
00062   x_isiz = y_isiz = 0;
00063 
00064   // Initialize keep flag to false
00065 //  keep = false;
00066 
00067   // TEMP : Initialize keep flag to true, there appears to be a memory leak
00068   //   when creating/deleting non-permanent views
00069   keep = true;
00070 
00071   // Initialize panel scrolling offsets
00072   xOffset = yOffset = 0;
00073 
00074   // Initialize creeping flags
00075   creep_up = creep_down = creep_left = creep_right = false;
00076 
00077   // Initialize mouse handling data members
00078   track = MOUSE_TRACKING_OFF;
00079   buttonsDown = 0;
00080 
00081   // If the filename has a .PNL extension, then this is a dynamic panel,
00082   //   otherwise it is static
00083 
00084   SStream s;
00085   strcpy (s.filename, "Data\\");
00086   strcat (s.filename, filename);
00087   strcpy (s.mode, "r");
00088 
00089   char *p = strrchr (filename, '.');
00090   if (p && (stricmp (p, ".PNL") == 0)) {
00091     type = PANEL_INTERACTIVE;
00092   } else {
00093     type = PANEL_STATIC;
00094 
00095     // Filename suffix is the screen height in pixels
00096     char ext[16];
00097     sprintf (ext, ".%d", yScreen);
00098     strcat (s.filename, ext);
00099   }
00100 
00101   if (OpenStream (&s)) {
00102     ReadFrom (this, &s);
00103     CloseStream (&s);
00104   }
00105 }
00106 
00107 
00108 CPanel::~CPanel (void)
00109 {
00110   // Delete gauges
00111   vector<CGauge*>::iterator iter;
00112   for (iter=gage.begin(); iter!=gage.end(); iter++) {
00113     delete *iter;
00114   }
00115 
00117 
00118   // Delete panel backdrop
00119   FreeBitmap (&bmPanl);
00120 
00121   // Free surface created for panel backdrop
00122   FreeSurface (surface);
00123 }
00124 
00125 
00126 int CPanel::Read (SStream *stream, Tag tag)
00127 {
00128   int rc = TAG_IGNORED;
00129 
00130   switch (tag) {
00131   case 'panl':
00132     // Panel base bitmap
00133     ReadString (panl, 64, stream);
00134     rc = TAG_READ;
00135     break;
00136 
00137   case '3Dxy':
00138     // XY offset of panel in 3D space
00139     ReadInt (&x_3Dxy, stream);
00140     ReadInt (&y_3Dxy, stream);
00141     rc = TAG_READ;
00142     break;
00143 
00144   case '3Dsz':
00145     // Size of panel in 3D space
00146     ReadInt (&x_3Dsz, stream);
00147     ReadInt (&y_3Dsz, stream);
00148     rc = TAG_READ;
00149     break;
00150 
00151   case 'isiz':
00152     // Base bitmap image size
00153     ReadInt (&x_isiz, stream);
00154     ReadInt (&y_isiz, stream);
00155     rc = TAG_READ;
00156     break;
00157 
00158   case 'hoff':
00159     // Horizontal offset for various screen resolutions
00160     {
00161       int width, x;
00162       ReadInt (&width, stream);
00163       ReadInt (&x, stream);
00164       hoff[width] = x;
00165     }
00166     rc = TAG_READ;
00167     break;
00168 
00169   case 'home':
00170     // Home (x,y) offset for various screen resolutions
00171     {
00172       int width;
00173       SPanelOffset offset;
00174       ReadInt (&width, stream);
00175       ReadInt (&offset.x, stream);
00176       ReadInt (&offset.y, stream);
00177       home[width] = offset;
00178     }
00179     rc = TAG_READ;
00180     break;
00181 
00182   case 'keep':
00183     // Keep panel resident in memory when not visible
00184     keep = true;
00185     rc = TAG_READ;
00186     break;
00187 
00188   case 'scrl':
00189     // This is a scrolling panel
00190     scrl = true;
00191     rc = TAG_READ;
00192     break;
00193 
00194   case 'lite':
00195     // Panel light
00196     {
00197       SkipObject (stream);
00198 //      CPanelLight *light = new CPanelLight;
00199 //      ReadFrom (light, stream);
00200 //      lite.addEntity (light);
00201     }
00202     rc = TAG_READ;
00203     break;
00204 
00205   case 'mlsw':
00206     // Master light switch message
00207     SkipObject (stream);
00208     rc = TAG_READ;
00209     break;
00210 
00211   case 'clao':
00212     // Cockpit lights are always on
00213     clao = true;
00214     rc = TAG_READ;
00215     break;
00216 
00217   case 'dlid':
00218     // Default light ID
00219     ReadTag (&dlid, stream);
00220     rc = TAG_READ;
00221     break;
00222 
00223   case 'gage':
00224     // Read gauge type
00225     {
00226       Tag type;
00227       ReadTag (&type, stream);
00228 
00229       switch (type) {
00230       case GAUGE_BASE:
00231         // This is the unique tag of the abstract gauge base.  There should
00232         //   be no instances of this in any panel
00233         globals->logWarning->Write ("CPanel : Read gauge type 'gage'");
00234         break;
00235 
00236       case GAUGE_BITMAP:
00237         {
00238           CBitmapGauge *g = new CBitmapGauge;
00239           ReadFrom (g, stream);
00240           this->gage.push_back (g);
00241         }
00242         break;
00243 
00244       case GAUGE_NEEDLE:
00245         {
00246           CNeedleGauge *g = new CNeedleGauge;
00247           ReadFrom (g, stream);
00248           this->gage.push_back (g);
00249         }
00250         break;
00251 
00252       case GAUGE_NEEDLE_DUAL:
00253         {
00254           CTwoNeedleGauge *g = new CTwoNeedleGauge;
00255           ReadFrom (g, stream);
00256           this->gage.push_back (g);
00257         }
00258         break;
00259 
00260       case GAUGE_NEEDLE_TRIPLE:
00261         {
00262           CThreeNeedleGauge *g = new CThreeNeedleGauge;
00263           ReadFrom (g, stream);
00264           this->gage.push_back (g);
00265         }
00266         break;
00267 
00268       case GAUGE_DIGITAL_NEEDLE:
00269         {
00270           CDigitalNeedleGauge *g = new CDigitalNeedleGauge;
00271           ReadFrom (g, stream);
00272           this->gage.push_back (g);
00273         }
00274         break;
00275 
00276       case GAUGE_ALTIMETER:
00277         {
00278           CAltimeterGauge *g = new CAltimeterGauge;
00279       char *mark1 = new char[32];
00280       strcpy (mark1, "gauge start");
00281           ReadFrom (g, stream);
00282       char *mark2 = new char[32];
00283       strcpy (mark2, "gauge end");
00284           this->gage.push_back (g);
00285         }
00286         break;
00287 
00288       case GAUGE_ALTIMETER_ROLLING:
00289         {
00290           CRollingAltimeterGauge *g = new CRollingAltimeterGauge;
00291           ReadFrom (g, stream);
00292           this->gage.push_back (g);
00293         }
00294         break;
00295 
00296       case GAUGE_HORIZON:
00297         {
00298           CHorizonGauge *g = new CHorizonGauge;
00299           ReadFrom (g, stream);
00300           this->gage.push_back (g);
00301         }
00302         break;
00303 
00304       case GAUGE_HORIZON_FD:
00305         {
00306           CFDHorizonGauge *g = new CFDHorizonGauge;
00307           ReadFrom (g, stream);
00308           this->gage.push_back (g);
00309         }
00310         break;
00311 
00312       case GAUGE_HORIZONTAL_BALL:
00313         {
00314           CHorizontalBallGauge *g = new CHorizontalBallGauge;
00315           ReadFrom (g, stream);
00316           this->gage.push_back (g);
00317         }
00318         break;
00319 
00320       case GAUGE_AIRSPEED:
00321         {
00322           CAirspeedGauge *g = new CAirspeedGauge;
00323           ReadFrom (g, stream);
00324           this->gage.push_back (g);
00325         }
00326         break;
00327 
00328       case GAUGE_VERTICAL_SPEED:
00329         {
00330           CVerticalSpeedGauge *g = new CVerticalSpeedGauge;
00331           ReadFrom (g, stream);
00332           this->gage.push_back (g);
00333         }
00334         break;
00335 
00336       case GAUGE_DIRECTIONAL_GYRO:
00337         {
00338           CDirectionalGyroGauge *g = new CDirectionalGyroGauge;
00339           ReadFrom (g, stream);
00340           this->gage.push_back (g);
00341         }
00342         break;
00343 
00344       case GAUGE_VACUUM:
00345         {
00346           CVacuumGauge *g = new CVacuumGauge;
00347           ReadFrom (g, stream);
00348           this->gage.push_back (g);
00349         }
00350         break;
00351 
00352       case GAUGE_SUCTION:
00353         {
00354           CSuctionGauge *g = new CSuctionGauge;
00355           ReadFrom (g, stream);
00356           this->gage.push_back (g);
00357         }
00358         break;
00359 
00360       case GAUGE_FUEL:
00361         {
00362           CFuelGauge *g = new CFuelGauge;
00363           ReadFrom (g, stream);
00364           this->gage.push_back (g);
00365         }
00366         break;
00367 
00368       case GAUGE_FUEL_FLOW:
00369         {
00370           CFuelFlowGauge *g = new CFuelFlowGauge;
00371           ReadFrom (g, stream);
00372           this->gage.push_back (g);
00373         }
00374         break;
00375 
00376       case GAUGE_OIL_PRESSURE:
00377         {
00378           COilPressureGauge *g = new COilPressureGauge;
00379           ReadFrom (g, stream);
00380           this->gage.push_back (g);
00381         }
00382         break;
00383 
00384       case GAUGE_OIL_TEMPERATURE:
00385         {
00386           COilTemperatureGauge *g = new COilTemperatureGauge;
00387           ReadFrom (g, stream);
00388           this->gage.push_back (g);
00389         }
00390         break;
00391 
00392       case GAUGE_TACHOMETER:
00393         {
00394           CTachometerGauge *g = new CTachometerGauge;
00395           ReadFrom (g, stream);
00396           this->gage.push_back (g);
00397         }
00398         break;
00399 
00400       case GAUGE_TACHOMETER_DUAL:
00401         {
00402           CDualTachometerGauge *g = new CDualTachometerGauge;
00403           ReadFrom (g, stream);
00404           this->gage.push_back (g);
00405         }
00406         break;
00407 
00408       case GAUGE_N1_TACHOMETER:
00409         {
00410           CN1TachometerGauge *g = new CN1TachometerGauge;
00411           ReadFrom (g, stream);
00412           this->gage.push_back (g);
00413         }
00414         break;
00415 
00416       case GAUGE_EXHAUST_GAS_TEMP:
00417         {
00418           CExhaustGasTemperatureGauge *g = new CExhaustGasTemperatureGauge;
00419           ReadFrom (g, stream);
00420           this->gage.push_back (g);
00421         }
00422         break;
00423 
00424       case GAUGE_BASIC_COMPASS:
00425         {
00426           CBasicCompassGauge *g = new CBasicCompassGauge;
00427           ReadFrom (g, stream);
00428           this->gage.push_back (g);
00429         }
00430         break;
00431 
00432       case GAUGE_AMMETER:
00433         {
00434           CAmmeterGauge *g = new CAmmeterGauge;
00435           ReadFrom (g, stream);
00436           this->gage.push_back (g);
00437         }
00438         break;
00439 
00440       case GAUGE_ANALOG_CLOCK:
00441         {
00442           CAnalogClockGauge *g = new CAnalogClockGauge;
00443           ReadFrom (g, stream);
00444           this->gage.push_back (g);
00445         }
00446         break;
00447 
00448       case GAUGE_DIGITAL_CLOCK_FLYHAWK:
00449         {
00450           CFlyhawkDigitalClockGauge *g = new CFlyhawkDigitalClockGauge;
00451           ReadFrom (g, stream);
00452           this->gage.push_back (g);
00453         }
00454         break;
00455 
00456       case GAUGE_DIGITAL_CLOCK_BASIC:
00457         {
00458           CBasicDigitalClockGauge *g = new CBasicDigitalClockGauge;
00459           ReadFrom (g, stream);
00460           this->gage.push_back (g);
00461         }
00462         break;
00463 
00464       case GAUGE_ADF_BASIC:
00465         {
00466           CBasicADFGauge *g = new CBasicADFGauge;
00467           ReadFrom (g, stream);
00468           this->gage.push_back (g);
00469         }
00470         break;
00471 
00472       case GAUGE_DIGITAL_READOUT:
00473         {
00474           CDigitalReadoutGauge *g = new CDigitalReadoutGauge;
00475           ReadFrom (g, stream);
00476           this->gage.push_back (g);
00477         }
00478         break;
00479 
00480       case GAUGE_DIGITS_READOUT:
00481         {
00482           CDigitsReadoutGauge *g = new CDigitsReadoutGauge;
00483           ReadFrom (g, stream);
00484           this->gage.push_back (g);
00485         }
00486         break;
00487 
00488       case GAUGE_CABIN_PRESSURE_RATE:
00489         {
00490           CCabinPressureRateKnobGauge *g = new CCabinPressureRateKnobGauge;
00491           ReadFrom (g, stream);
00492           this->gage.push_back (g);
00493         }
00494         break;
00495 
00496       case GAUGE_CABIN_PRESSURE:
00497         {
00498           CCabinPressureGauge *g = new CCabinPressureGauge;
00499           ReadFrom (g, stream);
00500           this->gage.push_back (g);
00501         }
00502         break;
00503 
00504       case GAUGE_BRAKE_PRESSURE:
00505         {
00506           CBrakePressureGauge *g = new CBrakePressureGauge;
00507           ReadFrom (g, stream);
00508           this->gage.push_back (g);
00509         }
00510         break;
00511 
00512       case GAUGE_AOA:
00513         {
00514           CAOANeedleGauge *g = new CAOANeedleGauge;
00515           ReadFrom (g, stream);
00516           this->gage.push_back (g);
00517         }
00518         break;
00519 
00520       case GAUGE_TURN_COORDINATOR:
00521         {
00522           CTurnCoordinatorGauge *g = new CTurnCoordinatorGauge;
00523           ReadFrom (g, stream);
00524           this->gage.push_back (g);
00525         }
00526         break;
00527 
00528       case GAUGE_SLIP_INDICATOR:
00529         {
00530           CSlipIndicatorGauge *g = new CSlipIndicatorGauge;
00531           ReadFrom (g, stream);
00532           this->gage.push_back (g);
00533         }
00534         break;
00535 
00536       case GAUGE_HOBBS_METER:
00537         {
00538           CHobbsMeterGauge *g = new CHobbsMeterGauge;
00539           ReadFrom (g, stream);
00540           this->gage.push_back (g);
00541         }
00542         break;
00543 
00544       case GAUGE_NAVIGATION:
00545         {
00546           CNavigationGauge *g = new CNavigationGauge;
00547           ReadFrom (g, stream);
00548           this->gage.push_back (g);
00549         }
00550         break;
00551 
00552       case GAUGE_NAV_COMM_KX155:
00553         {
00554           CBKNavComKX155Gauge *g = new CBKNavComKX155Gauge;
00555           ReadFrom (g, stream);
00556           this->gage.push_back (g);
00557         }
00558         break;
00559 
00560       case GAUGE_GPS_KLN89:
00561         {
00562 //          CBKGPSKLN89Gauge *g = new CBKGPSKLN89Gauge;
00563           SkipObject (stream);
00564 //          ReadFrom (g, stream);
00565 //          this->gage.push_back (g);
00566         }
00567         break;
00568 
00569       case GAUGE_XPDR_KT76:
00570         {
00571           CBKXPDRKT76Gauge *g = new CBKXPDRKT76Gauge;
00572           ReadFrom (g, stream);
00573           this->gage.push_back (g);
00574         }
00575         break;
00576 
00577       case GAUGE_ADF_KR87:
00578         {
00579           CBKADFKR87Gauge *g = new CBKADFKR87Gauge;
00580           ReadFrom (g, stream);
00581           this->gage.push_back (g);
00582         }
00583         break;
00584 
00585       case GAUGE_AUTOPILOT_KAP140:
00586         {
00587           CBKAP140Gauge *g = new CBKAP140Gauge;
00588           ReadFrom (g, stream);
00589           this->gage.push_back (g);
00590         }
00591         break;
00592 
00593       case GAUGE_AUTOPILOT_KFC200:
00594         {
00595           CBKKFC200Gauge *g = new CBKKFC200Gauge;
00596           ReadFrom (g, stream);
00597           this->gage.push_back (g);
00598         }
00599         break;
00600 
00601       case GAUGE_AUTOPILOT_KFC150:
00602         {
00603           CBKKFC150Gauge *g = new CBKKFC150Gauge;
00604           ReadFrom (g, stream);
00605           this->gage.push_back (g);
00606         }
00607         break;
00608 
00609       case GAUGE_AUDIO_KMA26:
00610         {
00611           CBKAudioKMA26Gauge *g = new CBKAudioKMA26Gauge;
00612           ReadFrom (g, stream);
00613           this->gage.push_back (g);
00614         }
00615         break;
00616 
00617       case GAUGE_HSI:
00618         {
00619           CHSIGauge *g = new CHSIGauge;
00620           ReadFrom (g, stream);
00621           this->gage.push_back (g);
00622         }
00623         break;
00624 
00625       case GAUGE_FLYHAWK_ELT:
00626         {
00627           CFlyhawkELTGauge *g = new CFlyhawkELTGauge;
00628           ReadFrom (g, stream);
00629           this->gage.push_back (g);
00630         }
00631         break;
00632 
00633       case GAUGE_NAV_RADIO_GENERIC:
00634         {
00635           CGenericNavRadioGauge *g = new CGenericNavRadioGauge;
00636           ReadFrom (g, stream);
00637           this->gage.push_back (g);
00638         }
00639         break;
00640 
00641       case GAUGE_COMM_RADIO_GENERIC:
00642         {
00643           CGenericCommRadioGauge *g = new CGenericCommRadioGauge;
00644           ReadFrom (g, stream);
00645           this->gage.push_back (g);
00646         }
00647         break;
00648 
00649       case GAUGE_TRANSPONDER_GENERIC:
00650         {
00651           CGenericTransponderGauge *g = new CGenericTransponderGauge;
00652           ReadFrom (g, stream);
00653           this->gage.push_back (g);
00654         }
00655         break;
00656 
00657       case GAUGE_ADF_GENERIC:
00658         {
00659           CGenericADFRadioGauge *g = new CGenericADFRadioGauge;
00660           ReadFrom (g, stream);
00661           this->gage.push_back (g);
00662         }
00663         break;
00664 
00665       case GAUGE_RMI_NEEDLE:
00666         {
00667           CRMINeedleGauge *g = new CRMINeedleGauge;
00668           ReadFrom (g, stream);
00669           this->gage.push_back (g);
00670         }
00671         break;
00672 
00673       case GAUGE_RADIO_GAUGE_GROUP:
00674         {
00675           CRadioGaugeGroup *g = new CRadioGaugeGroup;
00676           ReadFrom (g, stream);
00677           this->gage.push_back (g);
00678         }
00679         break;
00680 
00681       case GAUGE_NAV_GAUGE_GROUP:
00682         {
00683           CNavGaugeGroup *g = new CNavGaugeGroup;
00684           ReadFrom (g, stream);
00685           this->gage.push_back (g);
00686         }
00687         break;
00688 
00689       case GAUGE_ANNUNCIATOR:
00690         {
00691           CAnnunciator *g = new CAnnunciator;
00692           ReadFrom (g, stream);
00693           this->gage.push_back (g);
00694         }
00695         break;
00696 
00697       case GAUGE_FLYHAWK_ANNUNCIATOR:
00698         {
00699           CFlyhawkAnnunciator *g = new CFlyhawkAnnunciator;
00700           ReadFrom (g, stream);
00701           this->gage.push_back (g);
00702         }
00703         break;
00704 
00705       case GAUGE_FLYHAWK_ANNUNCIATOR_TEST:
00706         {
00707           CFlyhawkAnnunciatorTest *g = new CFlyhawkAnnunciatorTest;
00708           ReadFrom (g, stream);
00709           this->gage.push_back (g);
00710         }
00711         break;
00712 
00713       case GAUGE_FLYHAWK_NAV_GPS_PANEL:
00714         {
00715           CFlyhawkNavGpsPanelGauge *g = new CFlyhawkNavGpsPanelGauge;
00716           ReadFrom (g, stream);
00717           this->gage.push_back (g);
00718         }
00719         break;
00720 
00721       case GAUGE_FLYHAWK_FUEL_SELECTOR:
00722         {
00723           CFlyhawkFuelSelectorGauge *g = new CFlyhawkFuelSelectorGauge;
00724           ReadFrom (g, stream);
00725           this->gage.push_back (g);
00726         }
00727         break;
00728 
00729       case GAUGE_FLYHAWK_ELEVATOR_TRIM:
00730         {
00731           CFlyhawkElevatorTrimGauge *g = new CFlyhawkElevatorTrimGauge;
00732           ReadFrom (g, stream);
00733           this->gage.push_back (g);
00734         }
00735         break;
00736 
00737       case GAUGE_MALIBU_CHT_INDICATOR:
00738         {
00739           CMalybooCHTIndicatorGauge *g = new CMalybooCHTIndicatorGauge;
00740           ReadFrom (g, stream);
00741           this->gage.push_back (g);
00742         }
00743         break;
00744 
00745       case GAUGE_MALIBU_CHT_BUTTON:
00746         {
00747           CMalybooCHTButtonGauge *g = new CMalybooCHTButtonGauge;
00748           ReadFrom (g, stream);
00749           this->gage.push_back (g);
00750         }
00751         break;
00752 
00753       case GAUGE_MALIBU_NAV_GPS_PANEL:
00754         {
00755           CMalybooNavGpsPanelGauge *g = new CMalybooNavGpsPanelGauge;
00756           ReadFrom (g, stream);
00757           this->gage.push_back (g);
00758         }
00759         break;
00760 
00761       case GAUGE_MALIBU_DIGITAL_CLOCK:
00762         {
00763           CMalybooDigitalClockGauge *g = new CMalybooDigitalClockGauge;
00764           ReadFrom (g, stream);
00765           this->gage.push_back (g);
00766         }
00767         break;
00768 
00769 //      case GAUGE_MALIBU_FUEL_SELECT:
00770 //        {
00771 //          CMalybooFuelSelectGauge *g = new CMalybooFuelSelectGauge;
00772 //          ReadFrom (g, stream);
00773 //          this->gage.push_back (g);
00774 //        }
00775 //        break;
00776 
00777       case GAUGE_MALIBU_ENGINE_MONITOR:
00778         {
00779           CMalybooEngineMonitorGauge *g = new CMalybooEngineMonitorGauge;
00780           ReadFrom (g, stream);
00781           this->gage.push_back (g);
00782         }
00783         break;
00784 
00785       case GAUGE_NAVAJO_FUEL_SELECTOR:
00786         {
00787           CNavajoFuelSelectorGauge *g = new CNavajoFuelSelectorGauge;
00788           ReadFrom (g, stream);
00789           this->gage.push_back (g);
00790         }
00791         break;
00792 
00793       case GAUGE_NAVAJO_AMMETER:
00794         {
00795           CNavajoAmmeterGauge *g = new CNavajoAmmeterGauge;
00796           ReadFrom (g, stream);
00797           this->gage.push_back (g);
00798         }
00799         break;
00800 
00801       case GAUGE_NAVAJO_RADAR_ALTIMETER:
00802         {
00803           CNavajoRadarAltimeterGauge *g = new CNavajoRadarAltimeterGauge;
00804           ReadFrom (g, stream);
00805           this->gage.push_back (g);
00806         }
00807         break;
00808 
00809       case GAUGE_COLLINS_EFIS_SELECTION:
00810         {
00811           CCollinsEFISSelectionGauge *g = new CCollinsEFISSelectionGauge;
00812           ReadFrom (g, stream);
00813           this->gage.push_back (g);
00814         }
00815         break;
00816 
00817       case GAUGE_COLLINS_VSPEED_PANEL:
00818         {
00819           CCollinsVspeedPanel *g = new CCollinsVspeedPanel;
00820           ReadFrom (g, stream);
00821           this->gage.push_back (g);
00822         }
00823         break;
00824 
00825 
00826       case GAUGE_COLLINS_HF_RADIO:
00827         {
00828           CCollinsHFRadioGauge *g = new CCollinsHFRadioGauge;
00829           ReadFrom (g, stream);
00830           this->gage.push_back (g);
00831         }
00832         break;
00833 
00834 
00835       case GAUGE_COLLINS_PFD:
00836         {
00837           CCollinsPFDGauge *g = new CCollinsPFDGauge;
00838           ReadFrom (g, stream);
00839           this->gage.push_back (g);
00840         }
00841         break;
00842 
00843 
00844       case GAUGE_COLLINS_ND:
00845         {
00846           CCollinsNDGauge *g = new CCollinsNDGauge;
00847           ReadFrom (g, stream);
00848           this->gage.push_back (g);
00849         }
00850         break;
00851 
00852       case GAUGE_COLLINS_RTU:
00853         {
00854           CCollinsRTUGauge *g = new CCollinsRTUGauge;
00855           ReadFrom (g, stream);
00856           this->gage.push_back (g);
00857         }
00858         break;
00859 
00860 
00861       case GAUGE_COLLINS_AD:
00862         {
00863           CCollinsAirDataGauge *g = new CCollinsAirDataGauge;
00864           ReadFrom (g, stream);
00865           this->gage.push_back (g);
00866         }
00867         break;
00868 
00869       case GAUGE_COLLINS_MND:
00870         {
00871           CCollinsMNDGauge *g = new CCollinsMNDGauge;
00872           ReadFrom (g, stream);
00873           this->gage.push_back (g);
00874         }
00875         break;
00876 
00877       case GAUGE_UNIVERSAL_FMS:
00878         {
00879           CUniversalFMSGauge *g = new CUniversalFMSGauge;
00880           ReadFrom (g, stream);
00881           this->gage.push_back (g);
00882         }
00883         break;
00884 
00885       case GAUGE_PILATUS_EFIS_PANEL:
00886         {
00887           CPilatusEFISPanel *g = new CPilatusEFISPanel;
00888           ReadFrom (g, stream);
00889           this->gage.push_back (g);
00890         }
00891         break;
00892 
00893       case GAUGE_WALKER_TEMP_AIRSPEED:
00894         {
00895           CWalkerTempAirspeedGauge *g = new CWalkerTempAirspeedGauge;
00896           ReadFrom (g, stream);
00897           this->gage.push_back (g);
00898         }
00899         break;
00900 
00901       case GAUGE_GYRO_SLAVING:
00902         {
00903           CGyroSlavingGauge *g = new CGyroSlavingGauge;
00904           ReadFrom (g, stream);
00905           this->gage.push_back (g);
00906         }
00907         break;
00908 
00909       case GAUGE_VERTICAL_RATE:
00910         {
00911           CVerticalRateGauge *g = new CVerticalRateGauge;
00912           ReadFrom (g, stream);
00913           this->gage.push_back (g);
00914         }
00915         break;
00916 
00917       case GAUGE_PROP_SYNC:
00918         {
00919           CPropSyncGauge *g = new CPropSyncGauge;
00920           ReadFrom (g, stream);
00921           this->gage.push_back (g);
00922         }
00923         break;
00924 
00925       case GAUGE_DME:
00926         {
00927           CDMEGauge *g = new CDMEGauge;
00928           ReadFrom (g, stream);
00929           this->gage.push_back (g);
00930         }
00931         break;
00932 
00933       case GAUGE_DME_2:
00934         {
00935           CDME2Gauge *g = new CDME2Gauge;
00936           ReadFrom (g, stream);
00937           this->gage.push_back (g);
00938         }
00939         break;
00940 
00941       case GAUGE_WEATHER_RADAR:
00942         {
00943           CWeatherRadarGauge *g = new CWeatherRadarGauge;
00944           ReadFrom (g, stream);
00945           this->gage.push_back (g);
00946         }
00947         break;
00948 
00949       case GAUGE_ANALOG_ALT_PRESELECT:
00950         {
00951           CAnalogAltPreselectGauge *g = new CAnalogAltPreselectGauge;
00952           ReadFrom (g, stream);
00953           this->gage.push_back (g);
00954         }
00955         break;
00956 
00957 //      case GAUGE_TCAS:
00958 //        {
00959 //          CTCASGauge *g = new CTCASGauge;
00960 //          ReadFrom (g, stream);
00961 //          this->gage.push_back (g);
00962 //        }
00963 //        break;
00964 
00965       case GAUGE_HOTSPOT:
00966         {
00967           CMomentaryHotSpotGauge *g = new CMomentaryHotSpotGauge;
00968           ReadFrom (g, stream);
00969           this->gage.push_back (g);
00970         }
00971         break;
00972       
00973       case GAUGE_SIMPLE_IN_OUT:
00974         {
00975           CSimpleInOutStateSwitch *g = new CSimpleInOutStateSwitch;
00976           ReadFrom (g, stream);
00977           this->gage.push_back (g);
00978         }
00979         break;
00980       
00981       case GAUGE_LIT_IN_OUT:
00982         {
00983           CLitInOutSwitch *g = new CLitInOutSwitch;
00984           ReadFrom (g, stream);
00985           this->gage.push_back (g);
00986         }
00987         break;
00988       
00989       case GAUGE_SIMPLE_SWITCH:
00990         {
00991           CSimpleSwitch *g = new CSimpleSwitch;
00992           ReadFrom (g, stream);
00993           this->gage.push_back (g);
00994         }
00995         break;
00996       
00997       case GAUGE_BATTERY_SWITCH:
00998         {
00999           CBasicBatterySwitch *g = new CBasicBatterySwitch;
01000           ReadFrom (g, stream);
01001           this->gage.push_back (g);
01002         }
01003         break;
01004       
01005       case GAUGE_TWO_STATE_ELT:
01006         {
01007           CTwoStateELTGauge *g = new CTwoStateELTGauge;
01008           ReadFrom (g, stream);
01009           this->gage.push_back (g);
01010         }
01011         break;
01012       
01013       case GAUGE_SWITCH_PAIR:
01014         {
01015           CSwitchPairGauge *g = new CSwitchPairGauge;
01016           ReadFrom (g, stream);
01017           this->gage.push_back (g);
01018         }
01019         break;
01020       
01021       case GAUGE_SIMPLE_FLOAT_SWITCH:
01022         {
01023           CSimpleFloatSwitch *g = new CSimpleFloatSwitch;
01024           ReadFrom (g, stream);
01025           this->gage.push_back (g);
01026         }
01027         break;
01028       
01029       case GAUGE_DUAL_SWITCH:
01030         {
01031           CDualSwitch *g = new CDualSwitch;
01032           ReadFrom (g, stream);
01033           this->gage.push_back (g);
01034         }
01035         break;
01036       
01037       case GAUGE_PUSH_PULL_KNOB:
01038         {
01039           CPushPullKnobGauge *g = new CPushPullKnobGauge;
01040           ReadFrom (g, stream);
01041           this->gage.push_back (g);
01042         }
01043         break;
01044       
01045       case GAUGE_PRIMER_KNOB:
01046         {
01047           CPrimerKnobGauge *g = new CPrimerKnobGauge;
01048           ReadFrom (g, stream);
01049           this->gage.push_back (g);
01050         }
01051         break;
01052       
01053       case GAUGE_FLAP:
01054         {
01055           CFlapsSwitchGauge *g = new CFlapsSwitchGauge;
01056           ReadFrom (g, stream);
01057           this->gage.push_back (g);
01058         }
01059         break;
01060       
01061       case GAUGE_LIT_LANDING_GEAR_KNOB:
01062         {
01063           CLitLandingGearKnobGauge *g = new CLitLandingGearKnobGauge;
01064           ReadFrom (g, stream);
01065           this->gage.push_back (g);
01066         }
01067         break;
01068       
01069       case GAUGE_MIXTURE_KNOB:
01070         {
01071           CMixtureKnobGauge *g = new CMixtureKnobGauge;
01072           ReadFrom (g, stream);
01073           this->gage.push_back (g);
01074         }
01075         break;
01076       
01077       case GAUGE_REVERSIBLE_THROTTLE_KNOB:
01078         {
01079           CReversibleThrottleKnobGauge *g = new CReversibleThrottleKnobGauge;
01080           ReadFrom (g, stream);
01081           this->gage.push_back (g);
01082         }
01083         break;
01084       
01085       case GAUGE_DUAL_KNOB:
01086         {
01087           CDualKnobGauge *g = new CDualKnobGauge;
01088           ReadFrom (g, stream);
01089           this->gage.push_back (g);
01090         }
01091         break;
01092       
01093       case GAUGE_FLYHAWK_LIGHT_KNOB:
01094         {
01095           CFlyhawkLightKnobGauge *g = new CFlyhawkLightKnobGauge;
01096           ReadFrom (g, stream);
01097           this->gage.push_back (g);
01098         }
01099         break;
01100       
01101       case GAUGE_TURN_KNOB:
01102         {
01103           CTurnKnobGauge *g = new CTurnKnobGauge;
01104           ReadFrom (g, stream);
01105           this->gage.push_back (g);
01106         }
01107         break;
01108       
01109       case GAUGE_MAGNETO_SWITCH:
01110         {
01111           CBasicMagnetoSwitch *g = new CBasicMagnetoSwitch;
01112           ReadFrom (g, stream);
01113           this->gage.push_back (g);
01114         }
01115         break;
01116       
01117       case GAUGE_COVERED_SWITCH:
01118         {
01119           CCoveredSwitch *g = new CCoveredSwitch;
01120           ReadFrom (g, stream);
01121           this->gage.push_back (g);
01122         }
01123         break;
01124       
01125       case GAUGE_COVERED_LIGHT_BUTTON:
01126         {
01127           CCoveredLightButtonGauge *g = new CCoveredLightButtonGauge;
01128           ReadFrom (g, stream);
01129           this->gage.push_back (g);
01130         }
01131         break;
01132       
01133       case GAUGE_VERTICAL_SLIDER:
01134         {
01135           CVerticalSliderGauge *g = new CVerticalSliderGauge;
01136           ReadFrom (g, stream);
01137           this->gage.push_back (g);
01138         }
01139         break;
01140       
01141       case GAUGE_TRIM_WHEEL:
01142         {
01143           CTrimWheelGauge *g = new CTrimWheelGauge;
01144           ReadFrom (g, stream);
01145           this->gage.push_back (g);
01146         }
01147         break;
01148       
01149       case GAUGE_TRIM_WHEEL_INDICATOR:
01150         {
01151           CTrimWheelIndicatorGauge *g = new CTrimWheelIndicatorGauge;
01152           ReadFrom (g, stream);
01153           this->gage.push_back (g);
01154         }
01155         break;
01156       
01157       case GAUGE_INDICATOR:
01158         {
01159           CIndicatorGauge *g = new CIndicatorGauge;
01160           ReadFrom (g, stream);
01161           this->gage.push_back (g);
01162         }
01163         break;
01164       
01165       case GAUGE_FLAPS_INDICATOR:
01166         {
01167           CFlapsIndicatorGauge *g = new CFlapsIndicatorGauge;
01168           ReadFrom (g, stream);
01169           this->gage.push_back (g);
01170         }
01171         break;
01172       
01173       case GAUGE_PUSHBUTTON:
01174         {
01175           CPushButtonGauge *g = new CPushButtonGauge;
01176           ReadFrom (g, stream);
01177           this->gage.push_back (g);
01178         }
01179         break;
01180       
01181       case GAUGE_LIGHT_BUTTON:
01182         {
01183           CLightButtonGauge *g = new CLightButtonGauge;
01184           ReadFrom (g, stream);
01185           this->gage.push_back (g);
01186         }
01187         break;
01188       
01189       case GAUGE_TURN_SWITCH:
01190         {
01191           CTurnSwitchGauge *g = new CTurnSwitchGauge;
01192           ReadFrom (g, stream);
01193           this->gage.push_back (g);
01194         }
01195         break;
01196       
01197       case GAUGE_MASTER_CAUTION_BUTTON:
01198         {
01199           CMasterCautionWarningButtonGauge *g = new CMasterCautionWarningButtonGauge;
01200           ReadFrom (g, stream);
01201           this->gage.push_back (g);
01202         }
01203         break;
01204       
01205       case GAUGE_KINGAIR_FIRE_EXT:
01206         {
01207           CKAFireExtinguisherButton *g = new CKAFireExtinguisherButton;
01208           ReadFrom (g, stream);
01209           this->gage.push_back (g);
01210         }
01211         break;
01212       
01213       case GAUGE_WALKER_AP_PANEL:
01214         {
01215           CWalkerAPPanel *g = new CWalkerAPPanel;
01216           ReadFrom (g, stream);
01217           this->gage.push_back (g);
01218         }
01219         break;
01220       
01221       case GAUGE_WALKER_FIRE_PANEL:
01222         {
01223           CWalkerFirePanel *g = new CWalkerFirePanel;
01224           ReadFrom (g, stream);
01225           this->gage.push_back (g);
01226         }
01227         break;
01228       
01229       case GAUGE_LIGHT_SWITCH_SET:
01230         {
01231           CLightSwitchSetGauge *g = new CLightSwitchSetGauge;
01232           ReadFrom (g, stream);
01233           this->gage.push_back (g);
01234         }
01235         break;
01236       
01237       case GAUGE_ROCKER_SWITCH:
01238         {
01239           CRockerSwitch *g = new CRockerSwitch;
01240           ReadFrom (g, stream);
01241           this->gage.push_back (g);
01242         }
01243         break;
01244       
01245       default:
01246         char s[16];
01247         TagToString (s, type);
01248         globals->logWarning->Write ("CPanel : Skipping gauge type <%s>", s);
01249         SkipObject (stream);
01250         rc = TAG_READ;
01251       }
01252     }
01253     rc = TAG_READ;
01254     break;
01255   }
01256 
01257 /*
01258 //
01259 // Unknown syntax (no known examples)
01260 //
01261 #define GAUGE_ATTITUDE_INDICATOR    'atti'
01262 #define GAUGE_GHOST           'ghst'
01263 #define GAUGE_NAV_RADIO         'nrdg'
01264 #define GAUGE_NAV_RADIO_KN53      'kn53'
01265 #define GAUGE_NAV_RADIO_KN80      'kn80'
01266 #define GAUGE_COMM_RADIO        'comm'
01267 #define GAUGE_COMM_RADIO_KY96     'ky96'
01268 #define GAUGE_TRANSPONDER_KT79      'kt79'
01269 #define GAUGE_AUTOPILOT         'atop'
01270 
01271 //
01272 // Unknown semantics
01273 //
01274 #define GAUGE_NAV_RADIO_GROUP     'ngrp'
01275 #define GAUGE_COM_RADIO_GROUP     'cgrp'
01276 #define GAUGE_NAV_GAUGE_GROUP     'ogrp'
01277 #define GAUGE_TRANSPONDER_RADIO_GROUP 'tgrp'
01278 #define GAUGE_ADF_RADIO_GROUP     'agrp'
01279 #define GAUGE_RADIO_GAUGE_GROUP     'radg'
01280 */
01281 
01282   if (rc != TAG_READ) {
01283     // Tag was not processed by this object, it is unrecognized
01284     char s[16];
01285     TagToString (s, tag);
01286     globals->logWarning->Write ("CPanel::Read : Unrecognized tag <%s>", s);
01287   }
01288 
01289   return rc;
01290 }
01291 
01292 
01293 void CPanel::ReadFinished (void)
01294 {
01295   // Set panel offsets to home position
01296   Home ();
01297 
01298   // Check the 'keep' flag which indicates that this panel should remain
01299   //   resident in memory even when it is not displayed.  If it is set,
01300   //   then pre-create the backdrop surface, load the backdrop bitmap
01301   //   and draw the bitmap into the surface
01302   if (keep) {
01303     Activate ();
01304   }
01305 
01306   // Set scrolling limits
01307   int temp;
01308   xMinLimit = 0;
01309   xMaxLimit = x_3Dsz - globals->screenWidth;
01310   if (xMinLimit > xMaxLimit) {
01311     temp = xMinLimit;
01312     xMinLimit = xMaxLimit;
01313     xMaxLimit = temp;
01314   }
01315 
01316   if (y_3Dxy <= 0) {
01317     yMinLimit = 0;
01318     yMaxLimit = -(y_3Dsz - globals->screenHeight - y_3Dxy);
01319   } else {
01320     yMinLimit = y_3Dxy;
01321     yMaxLimit = globals->screenHeight - y_isiz;
01322   }
01323 
01324   if (yMinLimit > yMaxLimit) {
01325     temp = yMinLimit;
01326     yMinLimit = yMaxLimit;
01327     yMaxLimit = temp;
01328   }
01329 
01330   // Validate offsets against limits
01331   if (yOffset < yMinLimit) yOffset = yMinLimit;
01332   if (yOffset > yMaxLimit) yOffset = yMaxLimit;
01333   if (xOffset < xMinLimit) xOffset = xMinLimit;
01334   if (xOffset > xMaxLimit) xOffset = xMaxLimit;
01335 }
01336 
01337 
01338 void CPanel::Activate (void)
01339 {
01340   // Create the backdrop drawing surface if needed
01341   if (surface == NULL) {
01342     if ((x_isiz > 0) && (x_isiz <= 2048) &&
01343         (y_isiz > 0) && (y_isiz <= 2048))
01344     {
01345       surface = CreateSurface (x_isiz, y_isiz);
01346       EraseSurface (surface);
01347     }
01348   }
01349 
01350   // Load backdrop bitmap
01351   if (bmPanl.bitmap == NULL) {
01352     strcpy (bmPanl.bitmapName, "ART\\");
01353     strcat (bmPanl.bitmapName, panl);
01354     LoadBitmap (&bmPanl);
01355 
01356     // Draw backdrop bitmap to surface
01357     DrawBitmap (surface, &bmPanl, 0, 0, 1);
01358   }
01359 }
01360 
01361 
01362 void CPanel::Deactivate (void)
01363 {
01364   if (!keep) {
01365     // Panel should not be kept in memory; deallocate all bitmaps and surface
01366     FreeSurface (surface);
01367     FreeBitmap (&bmPanl);
01368   }
01369 }
01370 
01371 
01372 void CPanel::CreepUp (void)
01373 {
01374   if (scrl) {
01375     yOffset -= globals->panelCreepStep;
01376     if (yOffset < yMinLimit) yOffset = yMinLimit;
01377   }
01378 }
01379 
01380 
01381 void CPanel::CreepDown (void)
01382 {
01383   if (scrl) {
01384     yOffset += globals->panelCreepStep;
01385     if (yOffset > yMaxLimit) yOffset = yMaxLimit;
01386   }
01387 }
01388 
01389 
01390 void CPanel::CreepLeft (void)
01391 {
01392   if (scrl) {
01393     xOffset -= globals->panelCreepStep;
01394     if (xOffset < xMinLimit) xOffset = xMinLimit;
01395   }
01396 }
01397 
01398 
01399 void CPanel::CreepRight (void)
01400 {
01401   if (scrl) {
01402     xOffset += globals->panelCreepStep;
01403     if (xOffset > xMaxLimit) xOffset = xMaxLimit;
01404   }
01405 }
01406 
01407 
01408 bool CPanel::GaugeHit (int mouseX, int mouseY, int& i, CGauge **gptr, int &x, int &y)
01409 {
01410   // Sanity check
01411   if (!gptr) return false;
01412 
01413   bool hit = false;
01414 
01415   // Check for intersection with a gauge
01416   vector<CGauge*>::iterator iter;
01417   for (iter=gage.begin(); iter!=gage.end() && !hit; iter++) {
01418     CGauge *g = *iter;
01419     if (g) {
01420       // Determine the screen position of the gauge
01421       int w, h;
01422       g->GetSize (&x, &y, &w, &h);
01423       x -= xOffset;
01424       y -= yOffset - (globals->screenHeight - y_isiz);
01425 
01426       // Check for a hit between the mouse position and the gauge bounds
01427       hit = (mouseX > x) && (mouseX < (x + w)) && (mouseY > y) && (mouseY < (y + h));
01428       if (hit) *gptr = g;
01429     } else {
01430       GTFO ("CPanel::GaugeHit : Panel gauge list contains NULL pointer.");
01431     }
01432   }
01433 
01434   return hit;
01435 }
01436 
01437 void CPanel::GaugeMouseClick (int mouseX, int mouseY)
01438 {
01439   int i, x, y;
01440   CGauge *g = NULL;
01441   if (GaugeHit (mouseX, mouseY, i, &g, x, y)) {
01442     // Send mouse click to the gauge
01443     track = g->MouseClick ((mouseX - x), (mouseY - y), buttonsDown);
01444   }
01445 }
01446 
01447 void CPanel::GaugeTrackClick (int mouseX, int mouseY)
01448 {
01449   int i, x, y;
01450   CGauge *g = NULL;
01451   if (GaugeHit (mouseX, mouseY, i, &g, x, y)) {
01452     // Send mouse click to the gauge
01453     track = g->TrackClick ((mouseX - x), (mouseY - y), buttonsDown);
01454   }
01455 }
01456 
01457 void CPanel::GaugeStopClick (int mouseX, int mouseY)
01458 {
01459   int i, x, y;
01460   CGauge *g = NULL;
01461   if (GaugeHit (mouseX, mouseY, i, &g, x, y)) {
01462     // Send mouse click to the gauge
01463     track = g->StopClick ((mouseX - x), (mouseY - y), buttonsDown);
01464   }
01465 }
01466 
01467 void CPanel::MouseMotion (int mouseX, int mouseY)
01468 {
01469   if (globals->mouseScrollingEnabled) {
01470     // Update creep settings.  Panel will actually be scrolled in Draw() method
01471     creep_up = (mouseY <= 0);
01472     creep_down = (mouseY >= globals->screenHeight-1);
01473     creep_left = (mouseX <= 0);
01474     creep_right = (mouseX >= globals->screenWidth-1);
01475   }
01476 
01477   // DEBUG
01478 //  char debug[80];
01479 //  sprintf (debug, "Mouse moved to %d, %d (offset %d, %d)",
01480 //    mouseX, mouseY, xOffset, yOffset);
01481 //  DrawNoticeToUser (debug, 2);
01482 
01483   int i, x, y;
01484   CGauge *g = NULL;
01485   if (GaugeHit (mouseX, mouseY, i, &g, x, y)) {
01486     if (buttonsDown != 0) {
01487       // At least one button is pressed; call gauge's TrackClick method
01488       //   only if the tracking flag is set
01489       if (track) {
01490         track = g->TrackClick ((mouseX - x), (mouseY - y), buttonsDown);
01491       }
01492     } else {
01493       // No buttons are pressed; always call gauge's MouseMoved method
01494       ECursorResult cursor = g->MouseMoved ((mouseX - x), (mouseY - y));
01495 
01496       // Update cursor if gauge has not set it
01497       if (cursor == CURSOR_NOT_CHANGED) {
01498         globals->cursormgr->SetCursor (globals->crsrArrow);
01499       }
01500     }
01501   } else {
01502     // No gauge area hit...set default cursor
01503     globals->cursormgr->SetCursor (globals->crsrArrow);
01504   }
01505 }
01506 
01507 
01508 //
01509 // Process mouse click event
01510 //
01511 void CPanel::MouseClick (int button, int updown, int mouseX, int mouseY)
01512 {
01513   // DEBUG
01514 //  char debug[80];
01515 //  sprintf (debug, "Mouse button %d state %d at %d, %d", button, updown, x, y);
01516 //  DrawNoticeToUser (debug, 2);
01517 
01518   // Update current set of pressed buttons
01520   switch (updown) {
01521   case GLUT_DOWN:
01522     switch (button) {
01523     case GLUT_LEFT_BUTTON:
01524       buttonsDown |= MOUSE_BUTTON_LEFT;
01525       break;
01526 
01527     case GLUT_MIDDLE_BUTTON:
01528       buttonsDown |= MOUSE_BUTTON_MIDDLE;
01529       break;
01530 
01531     case GLUT_RIGHT_BUTTON:
01532       buttonsDown |= MOUSE_BUTTON_RIGHT;
01533       break;
01534     }
01535 
01536     // Button down events are always sent to the underlying gauge
01537     GaugeMouseClick (mouseX, mouseY);
01538     break;
01539 
01540   case GLUT_UP:
01541     switch (button) {
01542     case GLUT_LEFT_BUTTON:
01543       buttonsDown &= ~MOUSE_BUTTON_LEFT;
01544       break;
01545 
01546     case GLUT_MIDDLE_BUTTON:
01547       buttonsDown &= ~MOUSE_BUTTON_MIDDLE;
01548       break;
01549 
01550     case GLUT_RIGHT_BUTTON:
01551       buttonsDown &= ~MOUSE_BUTTON_RIGHT;
01552       break;
01553     }
01554 
01555     // Button up events are only sent to the underlying gauge if tracking is ON
01556     if (track == MOUSE_TRACKING_ON) {
01557       GaugeStopClick (mouseX, mouseY);
01558     }
01559     break;
01560   }
01561 
01562   // All mouse down events are sent to the gauge over which the mouse is sitting.
01563   //   Mouse button up events are only sent to the gauge if mouse tracking is on.
01564   if ((updown == GLUT_DOWN) || (track == MOUSE_TRACKING_ON))
01565   {
01566   }
01567 }
01568 
01569 
01570 void CPanel::ScrollUp (void)
01571 {
01572   if (scrl) {
01573     yOffset -= globals->panelScrollStep;
01574     if (yOffset < yMinLimit) yOffset = yMinLimit;
01575   }
01576 }
01577 
01578 
01579 void CPanel::ScrollDown (void)
01580 {
01581   if (scrl) {
01582     yOffset += globals->panelScrollStep;
01583     if (yOffset > yMaxLimit) yOffset = yMaxLimit;
01584   }
01585 }
01586 
01587 
01588 void CPanel::ScrollLeft (void)
01589 {
01590   if (scrl) {
01591     xOffset -= globals->panelScrollStep;
01592     if (xOffset < xMinLimit) xOffset = xMinLimit;
01593   }
01594 }
01595 
01596 
01597 void CPanel::ScrollRight (void)
01598 {
01599   if (scrl) {
01600     xOffset += globals->panelScrollStep;
01601     if (xOffset > xMaxLimit) xOffset = xMaxLimit;
01602   }
01603 }
01604 
01605 
01606 //
01607 // Reset the xOffset and yOffset values to the "home" position for the panel
01608 //
01609 void CPanel::Home (void)
01610 {
01611   // See if there is a horizontal offset defined for this panel
01612   //   at the current screen resolution
01613   {
01614     map<int,int>::iterator i = hoff.find(xScreen);
01615     if (i != hoff.end()) {
01616       xOffset = i->second + x_3Dxy;
01617       yOffset = 0;
01618     }
01619   }
01620 
01621   // See if there is an offset (both horizontal and vertical) defined for
01622   //   this panel at the current screen resolution.  This overrides
01623   //   a horizontal offset if one was defined
01624   {
01625     map<int,SPanelOffset>::iterator i = home.find(xScreen);
01626     if (i != home.end()) {
01627       xOffset = i->second.x + x_3Dxy;
01628       yOffset = i->second.y + y_3Dxy;
01629     }
01630   }
01631 }
01632 
01633 
01634 //
01635 // Set the panel y-offset to the maximum "up" scrolled position
01636 //
01637 void CPanel::PageUp (void) {}
01638 
01639 
01640 //
01641 // Set the panel y-offset to the maximum "down" scrolled position
01642 //
01643 void CPanel::PageDown (void) {}
01644 
01645 
01646 //
01647 // Return the unique ID tag value for this panel instance
01648 //
01649 Tag CPanel::GetId (void)
01650 {
01651   return id;
01652 }
01653 
01654 
01655 //
01656 // Draw the panel, including all contained gauges
01657 //
01658 void CPanel::Draw (void)
01659 {
01660   // Creep the panel if any flags are set
01661   if (creep_up) CreepUp ();
01662   if (creep_down) CreepDown ();
01663   if (creep_left) CreepLeft ();
01664   if (creep_right) CreepRight ();
01665 
01666   // DEBUG
01667 //  char debug[80];
01668 //  sprintf (debug, "xOffset=%d yOffset = %d", xOffset, yOffset);
01669 //  DrawNoticeToUser (debug, 1);
01670 
01671   // Set projection matrix to 2D screen size
01672   glMatrixMode(GL_PROJECTION);
01673   glPushMatrix();
01674   glLoadIdentity();
01675   gluOrtho2D (xOffset, (xOffset + globals->screenWidth),
01676              -yOffset, (-yOffset + globals->screenHeight));
01677 
01678   // Set up OpenGL drawing state
01679   glPushAttrib (GL_ENABLE_BIT);
01680   glEnable (GL_ALPHA_TEST);
01681   glDisable (GL_DEPTH_TEST);
01682   glDisable (GL_LIGHTING);
01683   glDisable (GL_COLOR_MATERIAL);
01684   glDisable (GL_TEXTURE_2D);
01685 
01686   // Draw the panel backdrop.  The backdrop origin is always 0,0 which may
01687   //   be outside the clipping planes of the view.  A trick is used to position
01688   //   the raster point inside the viewing frustrum, drawing a NULL bitmap,
01689   //   then moving the raster position via the glBitmap function.
01690   if (surface != NULL) {
01691     glRasterPos2i (xOffset, -yOffset);
01692     glBitmap (0, 0, 0, 0, -xOffset, yOffset, NULL);
01693     BlitTransparent (surface, 0);
01694   }
01695 
01696   //
01697   // Not sure how to handle this...should all of the gauge surfaces be copied
01698   //   onto the backdrop, which is then blitted to the screen?  Or should
01699   //   the backdrop be blitted followed by individual gauges?  Probably the
01700   //   latter...eventually, different lighting attributes will be applied
01701   //   to the individual gauges, and this will allow GL to handle the different
01702   //   conditions in glDrawPixels (called in Blit())
01703   //
01704   // In part it depends which is faster, DrawBitmap() or Blit()
01705   //
01706 
01707   // Draw gauges which are even partially visible on screen
01708   vector<CGauge*>::iterator iter;
01709   for (iter=gage.begin(); iter!=gage.end(); iter++) {
01710     CGauge* g = *iter;
01711 
01712     if (g) {
01713       // Determine the screen position of the gauge
01714       int x, y, w, h;
01715       g->GetSize (&x, &y, &w, &h);
01716       x -= xOffset;
01717       y = y_isiz - y;   // Invert to GL coordinates
01718       y -= yOffset + (globals->screenHeight - y_isiz);
01719 
01720       bool onScreen = (x+w > 0) &&
01721                       (y+h > 0) &&
01722                       (x < globals->screenWidth) &&
01723                       (y < globals->screenHeight);
01724       if (onScreen) {
01725         // Tell the gauge to draw itself
01726         g->Draw ();
01727 
01728         // Blit gauge surface to the screen
01729         g->Blit (xOffset, yOffset, y_isiz);
01730       }
01731     } else {
01732       GTFO ("CPanel::Draw : Panel gauge list contains NULL pointer.");
01733     }
01734   }
01735 
01736   // Restore original OpenGL state
01737   glPopAttrib();
01738 
01739   // Restore original projection matrix
01740   glMatrixMode(GL_PROJECTION);
01741   glPopMatrix();
01742 
01743   // Check for an OpenGL error
01744   GLenum e = glGetError ();
01745   if (e != GL_NO_ERROR) {
01746     gtfo ("CPanel::Draw:Return : GL Error 0x%04X", e);
01747   }
01748 }
SourceForge.net Logo Documentation generated by doxygen