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

DialogSkyTweaker.cpp

Go to the documentation of this file.
00001 /*
00002  * DialogSkyTweaker.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 the Sky Tweaker interface, allowing users to customize
00024  *   the sky dome shading parameters, then load/save these parameter sets into
00025  *   the Skies.ini file.
00026  *
00027  */
00028 
00029 
00030 #include "../Include/FlyLegacy.h"
00031 #include "../Include/Ui.h"
00032 #include "../Include/Terrain.h"
00033 #include "../Include/Globals.h"
00034 
00035 /*
00036 typedef struct {
00037   float A[2], B[2], C[2], D[2], E[2];
00038 } SLuminanceCurve;
00039 
00040 typedef struct {
00041   float A[2], B[2], C[2], D[2], E[2];
00042 } SChromaCurve;
00043 
00044 typedef struct {
00045   float   A, B, C, D;
00046 } SLuminanceZenith;
00047 
00048 typedef struct {
00049   float   theta3[3];
00050   float   theta2[3];
00051   float   theta1[3];
00052   float   theta0[3];
00053 } SChromaZenith;
00054 
00055 typedef struct {
00056   char        name[64];
00057   SLuminanceCurve   Y_curve;
00058   SChromaCurve    x_curve;
00059   SChromaCurve    y_curve;
00060   SLuminanceZenith  Y_zenith;
00061   SChromaZenith   x_zenith;
00062   SChromaZenith   y_zenith;
00063 } SPerezParameters;
00064 */
00065 
00066 
00067 
00068 typedef struct {
00069   puDialogBox*  dialog;
00070   puFrame*    frame;
00071   puText*     title;
00072 
00073   puInput     *YCurve_A_0, *YCurve_A_1;
00074   puInput     *YCurve_B_0, *YCurve_B_1;
00075   puInput     *YCurve_C_0, *YCurve_C_1;
00076   puInput     *YCurve_D_0, *YCurve_D_1;
00077   puInput     *YCurve_E_0, *YCurve_E_1;
00078 
00079   puInput     *xCurve_A_0, *xCurve_A_1;
00080   puInput     *xCurve_B_0, *xCurve_B_1;
00081   puInput     *xCurve_C_0, *xCurve_C_1;
00082   puInput     *xCurve_D_0, *xCurve_D_1;
00083   puInput     *xCurve_E_0, *xCurve_E_1;
00084 
00085   puInput     *yCurve_A_0, *yCurve_A_1;
00086   puInput     *yCurve_B_0, *yCurve_B_1;
00087   puInput     *yCurve_C_0, *yCurve_C_1;
00088   puInput     *yCurve_D_0, *yCurve_D_1;
00089   puInput     *yCurve_E_0, *yCurve_E_1;
00090 
00091   puInput     *YZenith_A;
00092   puInput     *YZenith_B;
00093   puInput     *YZenith_C;
00094   puInput     *YZenith_D;
00095 
00096   puInput     *xZenith_theta3_T2, *xZenith_theta3_T1, *xZenith_theta3_T0;
00097   puInput     *xZenith_theta2_T2, *xZenith_theta2_T1, *xZenith_theta2_T0;
00098   puInput     *xZenith_theta1_T2, *xZenith_theta1_T1, *xZenith_theta1_T0;
00099   puInput     *xZenith_theta0;
00100 
00101   puInput     *yZenith_theta3_T2, *yZenith_theta3_T1, *yZenith_theta3_T0;
00102   puInput     *yZenith_theta2_T2, *yZenith_theta2_T1, *yZenith_theta2_T0;
00103   puInput     *yZenith_theta1_T2, *yZenith_theta1_T1, *yZenith_theta1_T0;
00104   puInput     *yZenith_theta0;
00105 
00106   puFrame*    frame_Profiles;
00107   puFrame*    frame_YCurve;
00108   puFrame*    frame_xCurve;
00109   puFrame*    frame_yCurve;
00110   puFrame*    frame_YZenith;
00111   puFrame*    frame_xZenith;
00112   puFrame*    frame_yZenith;
00113   puFrame*    frame_Turbidity;
00114 
00115   puOneShot*    defaults;
00116   puOneShot*    apply;
00117   puOneShot*    close;
00118 } SSkyTweakerDialogData;
00119 
00120 
00121 static SSkyTweakerDialogData *dt = NULL;
00122 
00123 
00124 static void apply_cb (puObject* obj)
00125 {
00126   if (dt == NULL) return;
00127 
00128   // Update sky with current settings
00129   // globals->terrainmgr->SetPerezParameters (dt->perez);
00130 }
00131 
00132 static void close_cb (puObject* obj)
00133 {
00134   if (dt == NULL) return;
00135 
00136   // Deleting the PUI dialog will delete all child widgets as well
00137   delete dt->dialog;
00138 
00139   // Delete dialog data structure
00140   delete dt;
00141   dt = NULL;
00142 }
00143 
00144 
00145 
00146 //
00147 // Helper function to instantiate puInput objects with common settings
00148 //
00149 static puInput*  makeInput (int x1, int y1, int x2, int y2, const char* label, int* v)
00150 {
00151   puInput *pi = new puInput (x1, y1, x2, y2);
00152   pi->setLabel (label);
00153   pi->setLabelPlace (PUPLACE_CENTERED_LEFT);
00154   pi->setStyle (PUSTYLE_BOXED);
00155   if (v != NULL) {
00156     pi->setValuator (v);
00157   }
00158   return pi;
00159 }
00160 
00161 
00162 void sky_tweaker_dlg_create (void)
00163 {
00164   if (dt != NULL) return;
00165 
00166   // Instantiate data structure for dialog contents
00167   dt = new SSkyTweakerDialogData;
00168 
00169   // Create dialog box
00170   int frame_w = 600;
00171   int frame_h = 600;
00172   dt->dialog = new puDialogBox (20, globals->screenHeight - 30 - frame_h);
00173   {
00174     // Frame
00175     dt->frame = new puFrame (0, 0, frame_w, frame_h);
00176     dt->frame->setStyle (PUSTYLE_SMALL_SHADED);
00177 
00178     dt->title = new puText (10, frame_h - 30);
00179     dt->title->setLabel ("Sky Tweaker");
00180 
00181     int x1 = 0;
00182 
00183     // Each of the sections of the dialog is contained within it its own
00184     //   puGroup; these variables are used for each group's location and size
00185     int gx, gy, gw, gh;
00186     puGroup *pg;
00187 
00188     // Profile load/save section
00189 
00190     //
00191     // Y Curve parameters
00192     //
00193     gx = 10;
00194     gy = 400;
00195     gw = 250;
00196     gh = 150;
00197     pg = new puGroup (gx, gy);
00198       dt->frame_YCurve = new puFrame (0, 0, gw, gh);
00199       dt->frame_YCurve->setStyle (PUSTYLE_BOXED);
00200       dt->frame_YCurve->setLegend ("Luminance Y Curve");
00201       dt->frame_YCurve->setLegendPlace (PUPLACE_TOP_LEFT);
00202 
00203       dt->YCurve_A_1 = makeInput (50, 90, 120, 105, "A: ", NULL);
00204       dt->YCurve_B_1 = makeInput (50, 70, 120, 85,  "B: ", NULL);
00205       dt->YCurve_C_1 = makeInput (50, 50, 120, 65,  "C: ", NULL);
00206       dt->YCurve_D_1 = makeInput (50, 30, 120, 45,  "D: ", NULL);
00207       dt->YCurve_E_1 = makeInput (50, 10, 120, 25,  "E: ", NULL);
00208 
00209       dt->YCurve_A_0 = makeInput (160, 90, 230, 105, "T + ", NULL);
00210       dt->YCurve_B_0 = makeInput (160, 70, 230, 85,  "T + ", NULL);
00211       dt->YCurve_C_0 = makeInput (160, 50, 230, 65,  "T + ", NULL);
00212       dt->YCurve_D_0 = makeInput (160, 30, 230, 45,  "T + ", NULL);
00213       dt->YCurve_E_0 = makeInput (160, 10, 230, 25,  "T + ", NULL);
00214     pg->close ();
00215 
00216     // x Curve parameters
00217     gx = 10;
00218     gy = 250;
00219     gw = 250;
00220     gh = 150;
00221     pg = new puGroup (gx, gy);
00222       dt->frame_xCurve = new puFrame (0, 0, gw, gh);
00223       dt->frame_xCurve->setStyle (PUSTYLE_BOXED);
00224       dt->frame_xCurve->setLegend ("Chrominance x Curve");
00225       dt->frame_xCurve->setLegendPlace (PUPLACE_TOP_LEFT);
00226 
00227       dt->xCurve_A_1 = makeInput (50, 90, 120, 105, "A: ", NULL);
00228       dt->xCurve_B_1 = makeInput (50, 70, 120, 85,  "B: ", NULL);
00229       dt->xCurve_C_1 = makeInput (50, 50, 120, 65,  "C: ", NULL);
00230       dt->xCurve_D_1 = makeInput (50, 30, 120, 45,  "D: ", NULL);
00231       dt->xCurve_E_1 = makeInput (50, 10, 120, 25,  "E: ", NULL);
00232 
00233       dt->xCurve_A_0 = makeInput (160, 90, 230, 105, "T + ", NULL);
00234       dt->xCurve_B_0 = makeInput (160, 70, 230, 85,  "T + ", NULL);
00235       dt->xCurve_C_0 = makeInput (160, 50, 230, 65,  "T + ", NULL);
00236       dt->xCurve_D_0 = makeInput (160, 30, 230, 45,  "T + ", NULL);
00237       dt->xCurve_E_0 = makeInput (160, 10, 230, 25,  "T + ", NULL);
00238     pg->close ();
00239 
00240     // y Curve parameters
00241     gx = 10;
00242     gy = 100;
00243     gw = 250;
00244     gh = 150;
00245     pg = new puGroup (gx, gy);
00246       dt->frame_yCurve = new puFrame (0, 0, gw, gh);
00247       dt->frame_yCurve->setStyle (PUSTYLE_BOXED);
00248       dt->frame_yCurve->setLegend ("Chrominance y Curve");
00249       dt->frame_yCurve->setLegendPlace (PUPLACE_TOP_LEFT);
00250 
00251       dt->yCurve_A_1 = makeInput (50, 90, 120, 105, "A: ", NULL);
00252       dt->yCurve_B_1 = makeInput (50, 70, 120, 85,  "B: ", NULL);
00253       dt->yCurve_C_1 = makeInput (50, 50, 120, 65,  "C: ", NULL);
00254       dt->yCurve_D_1 = makeInput (50, 30, 120, 45,  "D: ", NULL);
00255       dt->yCurve_E_1 = makeInput (50, 10, 120, 25,  "E: ", NULL);
00256 
00257       dt->yCurve_A_0 = makeInput (160, 90, 230, 105, "T + ", NULL);
00258       dt->yCurve_B_0 = makeInput (160, 70, 230, 85,  "T + ", NULL);
00259       dt->yCurve_C_0 = makeInput (160, 50, 230, 65,  "T + ", NULL);
00260       dt->yCurve_D_0 = makeInput (160, 30, 230, 45,  "T + ", NULL);
00261       dt->yCurve_E_0 = makeInput (160, 10, 230, 25,  "T + ", NULL);
00262     pg->close ();
00263 
00264     // Y Zenith parameters
00265     gx = 260;
00266     gy = 400;
00267     gw = 160;
00268     gh = 150;
00269     pg = new puGroup (gx, gy);
00270       dt->frame_YZenith = new puFrame (0, 0, gw, gh);
00271       dt->frame_YZenith->setStyle (PUSTYLE_BOXED);
00272       dt->frame_YZenith->setLegend ("Luminance Y Zenith");
00273       dt->frame_YZenith->setLegendPlace (PUPLACE_TOP_LEFT);
00274     pg->close ();
00275 
00276     // Profile load/save
00277     gx = 420;
00278     gy = 400;
00279     gw = 170;
00280     gh = 150;
00281     pg = new puGroup (gx, gy);
00282       dt->frame_Profiles = new puFrame (0, 0, gw, gh);
00283       dt->frame_Profiles->setStyle (PUSTYLE_BOXED);
00284       dt->frame_Profiles->setLegend ("Profiles (SKIES.INI)");
00285       dt->frame_Profiles->setLegendPlace (PUPLACE_TOP_CENTER);
00286     pg->close ();
00287 
00288     // x Zenith parameters
00289     gx = 260;
00290     gy = 100;
00291     gw = 330;
00292     gh = 150;
00293     pg = new puGroup (gx, gy);
00294       dt->frame_xZenith = new puFrame (0, 0, gw, gh);
00295       dt->frame_xZenith->setStyle (PUSTYLE_BOXED);
00296       dt->frame_xZenith->setLegend ("Chrominance x Zenith");
00297       dt->frame_xZenith->setLegendPlace (PUPLACE_TOP_LEFT);
00298     pg->close ();
00299 
00300     // y Zenith Curve parameters
00301     gx = 260;
00302     gy = 250;
00303     gw = 330;
00304     gh = 150;
00305     pg = new puGroup (gx, gy);
00306       dt->frame_yZenith = new puFrame (0, 0, gw, gh);
00307       dt->frame_yZenith->setStyle (PUSTYLE_BOXED);
00308       dt->frame_yZenith->setLegend ("Chrominance y Zenith");
00309       dt->frame_yZenith->setLegendPlace (PUPLACE_TOP_LEFT);
00310     pg->close ();
00311 
00312     // Turbidity slider
00313     gx = 10;
00314     gy = 60;
00315     gw = frame_w - 20;
00316     gh = 40;
00317     pg = new puGroup (gx, gy);
00318       dt->frame_Turbidity = new puFrame (0, 0, gw, gh);
00319       dt->frame_Turbidity->setStyle (PUSTYLE_BOXED);
00320     pg->close ();
00321 
00322     // Defaults button
00323     x1 = 20;
00324     dt->defaults = new puOneShot (x1, 20, x1+80, 40);
00325     dt->defaults->setLegend ("Defaults");
00326     dt->defaults->makeReturnDefault (false);
00327     dt->defaults->setStyle (PUSTYLE_SMALL_SHADED);
00328     dt->defaults->setCallback (apply_cb);
00329 
00330     // Apply button
00331     x1 = frame_w - 180;
00332     dt->apply = new puOneShot (x1, 20, x1+60, 40);
00333     dt->apply->setLegend ("Apply");
00334     dt->apply->makeReturnDefault (false);
00335     dt->apply->setStyle (PUSTYLE_SMALL_SHADED);
00336     dt->apply->setCallback (apply_cb);
00337 
00338     // Close dialog button
00339     x1 = frame_w - 80;
00340     dt->close = new puOneShot (x1, 20, x1+60, 40);
00341     dt->close->setLegend ("Close");
00342     dt->close->makeReturnDefault (false);
00343     dt->close->setStyle (PUSTYLE_SMALL_SHADED);
00344     dt->close->setCallback (close_cb);
00345   }
00346   dt->dialog->close ();
00347   dt->dialog->reveal ();
00348   dt->dialog->setFloating (true);
00349 }
00350 
SourceForge.net Logo Documentation generated by doxygen