]> git.mxchange.org Git - flightgear.git/blob - src/GUI/gui_funcs.cxx
Get rid of the double comma's for the file section of the generic protocol also.
[flightgear.git] / src / GUI / gui_funcs.cxx
1 /**************************************************************************
2  * gui_funcs.cxx
3  *
4  * Based on gui.cxx and renamed on 2002/08/13 by Erik Hofman.
5  *
6  * Written 1998 by Durk Talsma, started Juni, 1998.  For the flight gear
7  * project.
8  *
9  * Additional mouse supported added by David Megginson, 1999.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of the
14  * License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  * $Id$
26  **************************************************************************/
27
28
29 #ifdef HAVE_CONFIG_H
30 #  include <config.h>
31 #endif
32
33 #include <simgear/compiler.h>
34
35 #ifdef SG_MATH_EXCEPTION_CLASH
36 #  include <math.h>
37 #endif
38
39 #ifdef HAVE_WINDOWS_H
40 #  include <windows.h>
41 #endif
42
43 #include <GL/gl.h>
44
45 #if defined(FX) && defined(XMESA)
46 #  include <GL/xmesa.h>
47 #endif
48
49 #include STL_FSTREAM
50 #include STL_STRING
51
52 #include <stdlib.h>
53 #include <string.h>
54
55 // for help call back
56 #ifdef WIN32
57 # include <shellapi.h>
58 # ifdef __CYGWIN__
59 #  include <sys/cygwin.h>
60 # endif
61 #endif
62
63 #include <simgear/constants.h>
64 #include <simgear/debug/logstream.hxx>
65 #include <simgear/misc/sg_path.hxx>
66 #include <simgear/screen/screen-dump.hxx>
67
68 #include <Include/general.hxx>
69 #include <Aircraft/aircraft.hxx>
70 #include <Airports/simple.hxx>
71 #include <Autopilot/auto_gui.hxx>
72 #include <Cockpit/panel.hxx>
73 #include <Controls/controls.hxx>
74 #include <FDM/flight.hxx>
75 #include <Main/main.hxx>
76 #include <Main/fg_init.hxx>
77 #include <Main/fg_io.hxx>
78 #include <Main/globals.hxx>
79 #include <Main/fg_props.hxx>
80 #include <Main/viewmgr.hxx>
81
82 #if defined( WIN32 ) && !defined( __CYGWIN__ ) && !defined(__MINGW32__)
83 #  include <simgear/screen/win32-printer.h>
84 #  include <simgear/screen/GlBitmaps.h>
85 #endif
86
87 #include "gui.h"
88 #include "gui_local.hxx"
89 #include "preset_dlg.hxx"
90 #include "prop_picker.hxx"
91 #include "sgVec3Slider.hxx"
92
93 SG_USING_STD(string);
94 SG_USING_STD(cout);
95
96 extern void fgHUDalphaAdjust( puObject * );
97
98 // from cockpit.cxx
99 extern void fgLatLonFormatToggle( puObject *);
100
101 #if defined( TR_HIRES_SNAP)
102 #include <simgear/screen/tr.h>
103 extern void trRenderFrame( void );
104 extern void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
105                          GLfloat x_end, GLfloat y_end );
106 #endif
107
108 puDialogBox  *dialogBox = 0;
109 puFrame      *dialogFrame = 0;
110 puText       *dialogBoxMessage = 0;
111 puOneShot    *dialogBoxOkButton = 0;
112
113 puDialogBox  *YNdialogBox = 0;
114 puFrame      *YNdialogFrame = 0;
115 puText       *YNdialogBoxMessage = 0;
116 puOneShot    *YNdialogBoxOkButton = 0;
117 puOneShot    *YNdialogBoxNoButton = 0;
118
119 char *gui_msg_OK;     // "OK"
120 char *gui_msg_NO;     // "NO"
121 char *gui_msg_YES;    // "YES"
122 char *gui_msg_CANCEL; // "CANCEL"
123 char *gui_msg_RESET;  // "RESET"
124
125 char msg_OK[]     = "OK";
126 char msg_NO[]     = "NO";
127 char msg_YES[]    = "YES";
128 char msg_CANCEL[] = "Cancel";
129 char msg_RESET[]  = "Reset";
130
131 char global_dialog_string[256];
132
133 const __fg_gui_fn_t __fg_gui_fn[] = {
134
135         // File
136         {"saveFlight", saveFlight},
137         {"loadFlight", loadFlight},
138         {"reInit", reInit},
139 #ifdef TR_HIRES_SNAP
140         {"dumpHiResSnapShot", dumpHiResSnapShot},
141 #endif
142         {"dumpSnapShot", dumpSnapShot},
143 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
144         {"printScreen", printScreen},
145 #endif
146         {"MayBeGoodBye", MayBeGoodBye},
147
148         //View
149         {"guiTogglePanel", guiTogglePanel},
150         {"PilotOffsetAdjust", PilotOffsetAdjust},
151         {"fgHUDalphaAdjust", fgHUDalphaAdjust},
152         {"prop_pickerView", prop_pickerView},
153
154         // Environment
155         {"fgPresetAirport", fgPresetAirport},
156         {"fgPresetRunway", fgPresetRunway},
157         {"fgPresetOffsetDistance", fgPresetOffsetDistance},
158         {"fgPresetAltitude", fgPresetAltitude},
159         {"fgPresetGlideslope", fgPresetGlideslope},
160         {"fgPresetAirspeed", fgPresetAirspeed},
161         {"fgPresetCommit", fgPresetCommit},
162
163         // Autopilot
164         {"NewAltitude", NewAltitude},
165         {"NewHeading", NewHeading},
166         {"AddWayPoint", AddWayPoint},
167         {"PopWayPoint", PopWayPoint},
168         {"ClearRoute", ClearRoute},
169         {"fgLatLonFormatToggle", fgLatLonFormatToggle},
170
171         // Help
172         {"helpCb", helpCb},
173
174         // Structure termination
175         {"", NULL}
176 };
177
178
179 /* ================ General Purpose Functions ================ */
180
181 void initDialog(void) {
182     // Initialize our GLOBAL GUI STRINGS
183     gui_msg_OK     = msg_OK;     // "OK"
184     gui_msg_NO     = msg_NO;     // "NO"
185     gui_msg_YES    = msg_YES;    // "YES"
186     gui_msg_CANCEL = msg_CANCEL; // "CANCEL"
187     gui_msg_RESET  = msg_RESET;  // "RESET"
188 }
189
190 // General Purpose Message Box
191 void mkDialog (const char *txt)
192 {
193     strncpy(global_dialog_string, txt, 256);
194     dialogBoxMessage->setLabel(global_dialog_string);
195     FG_PUSH_PUI_DIALOG( dialogBox );
196 }
197
198 // Message Box to report an error.
199 void guiErrorMessage (const char *txt)
200 {
201     SG_LOG(SG_GENERAL, SG_ALERT, txt);
202     if (dialogBox != 0)
203       mkDialog(txt);
204 }
205
206 // Message Box to report a throwable (usually an exception).
207 void guiErrorMessage (const char *txt, const sg_throwable &throwable)
208 {
209     string msg = txt;
210     msg += '\n';
211     msg += throwable.getFormattedMessage();
212     if (!throwable.getOrigin().empty()) {
213       msg += "\n (reported by ";
214       msg += throwable.getOrigin();
215       msg += ')';
216     }
217     SG_LOG(SG_GENERAL, SG_ALERT, msg);
218     if (dialogBox != 0)
219       mkDialog(msg.c_str());
220 }
221
222 // Intercept the Escape Key
223 void ConfirmExitDialog(void)
224 {
225     FG_PUSH_PUI_DIALOG( YNdialogBox );
226 }
227
228
229
230 /* -----------------------------------------------------------------------
231 the Gui callback functions 
232 ____________________________________________________________________*/
233
234
235 // Hier Neu :-) This is my newly added code
236 // Added by David Findlay <nedz@bigpond.com>
237 // on Sunday 3rd of December
238
239 // Start new Save Dialog Box
240 puDialogBox     *SaveDialog = 0;
241 puFrame         *SaveDialogFrame = 0;
242 puText          *SaveDialogMessage = 0;
243 puInput         *SaveDialogInput = 0;
244
245 puOneShot       *SaveDialogOkButton = 0;
246 puOneShot       *SaveDialogCancelButton = 0;
247 // static puOneShot       *SaveDialogResetButton = 0;
248
249 // Default save filename
250 char saveFile[256] = "fgfs.sav";
251
252 // Cancel Button
253 void SaveDialogCancel(puObject *) {
254     FG_POP_PUI_DIALOG( SaveDialog );
255 }
256
257 // If press OK do this
258 void SaveDialogOk(puObject*) {
259
260     FG_POP_PUI_DIALOG( SaveDialog );
261
262     char *s;
263     SaveDialogInput->getValue(&s);
264
265     ofstream output(s);
266     // cout << saveFile << endl;
267     if (output.good() && fgSaveFlight(output)) {
268         output.close();
269         mkDialog("Saved flight");
270         SG_LOG(SG_INPUT, SG_INFO, "Saved flight");
271     } else {
272         mkDialog("Cannot save flight");
273         SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight");
274     }
275 }
276
277 // Create Dialog
278 void saveFlight(puObject *cv) {
279     SaveDialog = new puDialogBox (150, 50);
280     {
281         SaveDialogFrame   = new puFrame           (0,0,350, 150);
282         SaveDialogMessage
283             = new puText( (150 - puGetDefaultLabelFont().getStringWidth( "File Name:" ) / 2), 110 );
284         SaveDialogMessage ->    setLabel          ("File Name:");
285
286         SaveDialogInput   = new puInput           (50, 70, 300, 100);
287         SaveDialogInput   ->    setValue          (saveFile);
288         SaveDialogInput   ->    acceptInput();
289
290         SaveDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
291         SaveDialogOkButton     ->     setLegend   (gui_msg_OK);
292         SaveDialogOkButton     ->     setCallback ( SaveDialogOk );
293         SaveDialogOkButton     ->     makeReturnDefault(TRUE);
294
295         SaveDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
296         SaveDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
297         SaveDialogCancelButton ->     setCallback ( SaveDialogCancel );
298     }
299     FG_FINALIZE_PUI_DIALOG( SaveDialog );
300    
301     SaveDialog -> reveal();
302 }
303
304 // Load Dialog Start
305 puDialogBox     *LoadDialog = 0;
306 puFrame         *LoadDialogFrame = 0;
307 puText          *LoadDialogMessage = 0;
308 puInput         *LoadDialogInput = 0;
309
310 puOneShot       *LoadDialogOkButton = 0;
311 puOneShot       *LoadDialogCancelButton = 0;
312 // static puOneShot       *LoadDialogResetButton = 0;
313
314 // Default load filename
315 char loadFile[256] = "fgfs.sav";
316
317 // Do this if the person click okay
318 void LoadDialogOk(puObject *) {
319
320     FG_POP_PUI_DIALOG( LoadDialog );
321
322     char *l;
323     LoadDialogInput->getValue(&l);
324
325     ifstream input(l);
326     if (input.good() && fgLoadFlight(input)) {
327         input.close();
328         mkDialog("Loaded flight");
329         SG_LOG(SG_INPUT, SG_INFO, "Restored flight");
330     } else {
331         mkDialog("Failed to load flight");
332         SG_LOG(SG_INPUT, SG_ALERT, "Cannot load flight");
333     }
334 }
335
336 // Do this if the person presses cancel
337 void LoadDialogCancel(puObject *) {
338     FG_POP_PUI_DIALOG( LoadDialog );
339 }
340
341 // Create Load Dialog
342 void loadFlight(puObject *cb)
343 {
344     LoadDialog = new puDialogBox (150, 50);
345     {
346         LoadDialogFrame   = new puFrame           (0,0,350, 150);
347         LoadDialogMessage
348             = new puText( (150 - puGetDefaultLabelFont().getStringWidth( "File Name:" ) / 2), 110 );
349         LoadDialogMessage ->    setLabel          ("File Name:");
350
351         LoadDialogInput   = new puInput           (50, 70, 300, 100);
352         LoadDialogInput   ->    setValue          (loadFile);
353         LoadDialogInput   ->    acceptInput();
354
355         LoadDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
356         LoadDialogOkButton     ->     setLegend   (gui_msg_OK);
357         LoadDialogOkButton     ->     setCallback ( LoadDialogOk );
358         LoadDialogOkButton     ->     makeReturnDefault(TRUE);
359
360         LoadDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
361         LoadDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
362         LoadDialogCancelButton ->     setCallback ( LoadDialogCancel );
363     }
364     FG_FINALIZE_PUI_DIALOG( LoadDialog );
365    
366     LoadDialog -> reveal();
367 }
368
369 // This is the accessor function
370 void guiTogglePanel(puObject *cb)
371 {
372   if (fgGetBool("/sim/panel/visibility"))
373     fgSetBool("/sim/panel/visibility", false);
374   else
375     fgSetBool("/sim/panel/visibility", true);
376
377   fgReshape(fgGetInt("/sim/startup/xsize"),
378             fgGetInt("/sim/startup/ysize"));
379 }
380
381 void goodBye(puObject *)
382 {
383     // SG_LOG( SG_INPUT, SG_ALERT,
384     //      "Program exiting normally at user request." );
385     cout << "Program exiting normally at user request." << endl;
386
387     // close all external I/O connections
388     globals->get_io()->shutdown_all();
389
390     exit(0);
391 }
392
393
394 void goAwayCb (puObject *me)
395 {
396     FG_POP_PUI_DIALOG( dialogBox );
397 }
398
399 void mkDialogInit (void)
400 {
401     //  printf("mkDialogInit\n");
402     int x = (fgGetInt("/sim/startup/xsize")/2 - 400/2);
403     int y = (fgGetInt("/sim/startup/ysize")/2 - 100/2);
404     dialogBox = new puDialogBox (x, y); // 150, 50
405     {
406         dialogFrame = new puFrame (0,0,400,100);
407         dialogBoxMessage  =  new puText         (10, 70);
408         dialogBoxMessage  -> setLabel           ("");
409         dialogBoxOkButton =  new puOneShot      (180, 10, 240, 50);
410         dialogBoxOkButton -> setLegend          (gui_msg_OK);
411         dialogBoxOkButton -> makeReturnDefault  (TRUE );
412         dialogBoxOkButton -> setCallback        (goAwayCb);
413     }
414     FG_FINALIZE_PUI_DIALOG( dialogBox );
415 }
416
417 void MayBeGoodBye(puObject *)
418 {
419     ConfirmExitDialog(); 
420 }
421
422 void goAwayYesNoCb(puObject *me)
423 {
424     FG_POP_PUI_DIALOG( YNdialogBox);
425 }
426
427 void ConfirmExitDialogInit(void)
428 {
429     char msg[] = "Really Quit";
430     char *s;
431
432     //  printf("ConfirmExitDialogInit\n");
433     int len = 200 - puGetDefaultLabelFont().getStringWidth ( msg ) / 2;
434
435     int x = (fgGetInt("/sim/startup/xsize")/2 - 400/2);
436     int y = (fgGetInt("/sim/startup/ysize")/2 - 100/2);
437         
438     YNdialogBox = new puDialogBox (x, y); // 150, 50
439     {
440         YNdialogFrame = new puFrame (0,0,400, 100);
441         
442         YNdialogBoxMessage  =  new puText         (len, 70);
443         YNdialogBoxMessage  -> setDefaultValue    (msg);
444         YNdialogBoxMessage  -> getDefaultValue    (&s);
445         YNdialogBoxMessage  -> setLabel           (s);
446         
447         YNdialogBoxOkButton =  new puOneShot      (100, 10, 160, 50);
448         YNdialogBoxOkButton -> setLegend          (gui_msg_OK);
449         YNdialogBoxOkButton -> makeReturnDefault  (TRUE );
450         YNdialogBoxOkButton -> setCallback        (goodBye);
451         
452         YNdialogBoxNoButton =  new puOneShot      (240, 10, 300, 50);
453         YNdialogBoxNoButton -> setLegend          (gui_msg_NO);
454         YNdialogBoxNoButton -> setCallback        (goAwayYesNoCb);
455     }
456     FG_FINALIZE_PUI_DIALOG( YNdialogBox );
457 }
458
459 void notCb (puObject *)
460 {
461     mkDialog ("This function isn't implemented yet");
462 }
463
464 void helpCb (puObject *)
465 {
466     string command;
467         
468 #if defined(FX) && !defined(WIN32)
469 #  if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
470     if ( globals->get_fullscreen() ) {
471         globals->set_fullscreen(false);
472         XMesaSetFXmode( XMESA_FX_WINDOW );
473     }
474 #  endif
475 #endif
476         
477     SGPath path( globals->get_fg_root() );
478     path.append( "Docs/index.html" );
479         
480 #if !defined(WIN32)
481
482     string help_app = fgGetString("/sim/startup/browser-app");
483
484     if ( system("xwininfo -name Netscape > /dev/null 2>&1") == 0 ) {
485         command = help_app + " -remote \"openURL(" + path.str() + ")\"";
486     } else {
487         command = help_app + " " + path.str();
488     }
489     command += " &";
490     system( command.c_str() );
491
492 #else // WIN32
493
494     // Look for favorite browser
495     char Dummy[1024], ExecName[1024], browserParameter[1024];
496     char win32_name[1024];
497 # ifdef __CYGWIN__
498     cygwin32_conv_to_full_win32_path(path.c_str(),win32_name);
499 # else
500     strcpy(win32_name,path.c_str());
501 # endif
502     Dummy[0] = 0;
503     FindExecutable(win32_name, Dummy, ExecName);
504     sprintf(browserParameter, "file:///%s", win32_name);
505     ShellExecute ( NULL, "open", ExecName, browserParameter, Dummy,
506                    SW_SHOWNORMAL ) ;
507
508 #endif
509         
510     mkDialog ("Help started in your web browser window.");
511 }
512
513 #if defined( TR_HIRES_SNAP)
514 void fgHiResDump()
515 {
516     FILE *f;
517     string message;
518     bool show_pu_cursor = false;
519     char *filename = new char [24];
520     static int count = 1;
521
522     static const SGPropertyNode *master_freeze
523         = fgGetNode("/sim/freeze/master");
524
525     bool freeze = master_freeze->getBoolValue();
526     if ( !freeze ) {
527         fgSetBool("/sim/freeze/master", true);
528     }
529
530     if ( !puCursorIsHidden() ) {
531         show_pu_cursor = true;
532         puHideCursor();
533     }
534
535     fgInitVisuals();
536     fgReshape( fgGetInt("/sim/startup/xsize"),
537                fgGetInt("/sim/startup/ysize") );
538
539     // we need two render frames here to clear the menu and cursor
540     // ... not sure why but doing an extra fgRenderFrame() shouldn't
541     // hurt anything
542     fgRenderFrame();
543     fgRenderFrame();
544
545     // Make sure we have SSG projection primed for current view
546     glMatrixMode(GL_MODELVIEW);
547     glLoadIdentity();
548     ssgSetCamera( (sgVec4 *)globals->get_current_view()->get_VIEW() );
549     ssgSetFOV( globals->get_current_view()->get_h_fov(),
550                globals->get_current_view()->get_v_fov() );
551     // ssgSetNearFar( 10.0f, 120000.0f );
552     ssgSetNearFar( 0.5f, 1200000.0f );
553
554         
555     // This ImageSize stuff is a temporary hack
556     // should probably use 128x128 tile size and
557     // support any image size
558
559     // This should be a requester to get multiplier from user
560     int multiplier = 3;
561     int width = fgGetInt("/sim/startup/xsize");
562     int height = fgGetInt("/sim/startup/ysize");
563         
564     /* allocate buffer large enough to store one tile */
565     GLubyte *tile = (GLubyte *)malloc(width * height * 3 * sizeof(GLubyte));
566     if (!tile) {
567         printf("Malloc of tile buffer failed!\n");
568         return;
569     }
570
571     int imageWidth  = multiplier*width;
572     int imageHeight = multiplier*height;
573
574     /* allocate buffer to hold a row of tiles */
575     GLubyte *buffer
576         = (GLubyte *)malloc(imageWidth * height * 3 * sizeof(GLubyte));
577     if (!buffer) {
578         free(tile);
579         printf("Malloc of tile row buffer failed!\n");
580         return;
581     }
582     TRcontext *tr = trNew();
583     trTileSize(tr, width, height, 0);
584     trTileBuffer(tr, GL_RGB, GL_UNSIGNED_BYTE, tile);
585     trImageSize(tr, imageWidth, imageHeight);
586     trRowOrder(tr, TR_TOP_TO_BOTTOM);
587     sgFrustum *frustum = ssgGetFrustum();
588     trFrustum(tr,
589               frustum->getLeft(), frustum->getRight(),
590               frustum->getBot(),  frustum->getTop(), 
591               frustum->getNear(), frustum->getFar());
592         
593     /* Prepare ppm output file */
594     while (count < 1000) {
595         snprintf(filename, 24, "fgfs-screen-%03d.ppm", count++);
596         if ( (f = fopen(filename, "r")) == NULL )
597             break;
598         fclose(f);
599     }
600     f = fopen(filename, "wb");
601     if (!f) {
602         printf("Couldn't open image file: %s\n", filename);
603         free(buffer);
604         free(tile);
605         return;
606     }
607     fprintf(f,"P6\n");
608     fprintf(f,"# ppm-file created by %s\n", "trdemo2");
609     fprintf(f,"%i %i\n", imageWidth, imageHeight);
610     fprintf(f,"255\n");
611
612     /* just to be safe... */
613     glPixelStorei(GL_PACK_ALIGNMENT, 1);
614
615     /* Because the HUD and Panel change the ViewPort we will
616      * need to handle some lowlevel stuff ourselves */
617     int ncols = trGet(tr, TR_COLUMNS);
618     int nrows = trGet(tr, TR_ROWS);
619
620     bool do_hud = fgGetBool("/sim/hud/visibility");
621     GLfloat hud_col_step = 640.0 / ncols;
622     GLfloat hud_row_step = 480.0 / nrows;
623         
624     bool do_panel = fgPanelVisible();
625     GLfloat panel_col_step = globals->get_current_panel()->getWidth() / ncols;
626     GLfloat panel_row_step = globals->get_current_panel()->getHeight() / nrows;
627         
628     /* Draw tiles */
629     int more = 1;
630     while (more) {
631         trBeginTile(tr);
632         int curColumn = trGet(tr, TR_CURRENT_COLUMN);
633         int curRow =  trGet(tr, TR_CURRENT_ROW);
634         trRenderFrame();
635         if ( do_hud )
636             fgUpdateHUD( curColumn*hud_col_step,      curRow*hud_row_step,
637                          (curColumn+1)*hud_col_step, (curRow+1)*hud_row_step );
638         if (do_panel)
639             globals->get_current_panel()->update(
640                                    curColumn*panel_col_step, panel_col_step,
641                                    curRow*panel_row_step,    panel_row_step );
642         more = trEndTile(tr);
643
644         /* save tile into tile row buffer*/
645         int curTileWidth = trGet(tr, TR_CURRENT_TILE_WIDTH);
646         int bytesPerImageRow = imageWidth * 3*sizeof(GLubyte);
647         int bytesPerTileRow = (width) * 3*sizeof(GLubyte);
648         int xOffset = curColumn * bytesPerTileRow;
649         int bytesPerCurrentTileRow = (curTileWidth) * 3*sizeof(GLubyte);
650         int i;
651         for (i=0;i<height;i++) {
652             memcpy(buffer + i*bytesPerImageRow + xOffset, /* Dest */
653                    tile + i*bytesPerTileRow,              /* Src */
654                    bytesPerCurrentTileRow);               /* Byte count*/
655         }
656
657         if (curColumn == trGet(tr, TR_COLUMNS)-1) {
658             /* write this buffered row of tiles to the file */
659             int curTileHeight = trGet(tr, TR_CURRENT_TILE_HEIGHT);
660             int bytesPerImageRow = imageWidth * 3*sizeof(GLubyte);
661             int i;
662             for (i=0;i<curTileHeight;i++) {
663                 /* Remember, OpenGL images are bottom to top.  Have to reverse. */
664                 GLubyte *rowPtr = buffer + (curTileHeight-1-i) * bytesPerImageRow;
665                 fwrite(rowPtr, 1, imageWidth*3, f);
666             }
667         }
668
669     }
670
671     fgReshape( width, height );
672
673     trDelete(tr);
674
675     fclose(f);
676
677     message = "Snap shot saved to ";
678     message += filename;
679     mkDialog (message.c_str());
680
681     free(tile);
682     free(buffer);
683
684     //  message = "Snap shot saved to ";
685     //  message += filename;
686     //  mkDialog (message.c_str());
687
688     delete [] filename;
689
690     if ( show_pu_cursor ) {
691         puShowCursor();
692     }
693
694     if ( !freeze ) {
695         fgSetBool("/sim/freeze/master", false);
696     }
697 }
698 #endif // #if defined( TR_HIRES_SNAP)
699
700
701 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
702
703 void rotateView( double roll, double pitch, double yaw )
704 {
705         // rotate view
706 }
707
708 GlBitmap *b1 = NULL;
709 GLubyte *hiResScreenCapture( int multiplier )
710 {
711     float oldfov = fgGetDouble("/sim/current-view/field-of-view");
712     float fov = oldfov / multiplier;
713     FGViewer *v = globals->get_current_view();
714     fgSetDouble("/sim/current-view/field-of-view", fov);
715     fgInitVisuals();
716     int cur_width = fgGetInt("/sim/startup/xsize");
717     int cur_height = fgGetInt("/sim/startup/ysize");
718     if (b1) delete( b1 );
719     // New empty (mostly) bitmap
720     b1 = new GlBitmap( GL_RGB, 1, 1, (unsigned char *)"123" );
721     int x,y;
722     for ( y = 0; y < multiplier; y++ ) {
723         for ( x = 0; x < multiplier; x++ ) {
724             fgReshape( cur_width, cur_height );
725             // pan to tile
726             rotateView( 0, (y*fov)-((multiplier-1)*fov/2), (x*fov)-((multiplier-1)*fov/2) );
727             fgRenderFrame();
728             // restore view
729             GlBitmap b2;
730             b1->copyBitmap( &b2, cur_width*x, cur_height*y );
731         }
732     }
733     fgSetDouble("/sim/current-view/field-of-view", oldfov);
734     return b1->getBitmap();
735 }
736 #endif
737
738 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
739 // win32 print screen function
740 void printScreen ( puObject *obj ) {
741     bool show_pu_cursor = false;
742     TurnCursorOff();
743     if ( !puCursorIsHidden() ) {
744         show_pu_cursor = true;
745         puHideCursor();
746     }
747     // BusyCursor( 0 );
748
749     CGlPrinter p( CGlPrinter::PRINT_BITMAP );
750     int cur_width = fgGetInt("/sim/startup/xsize");
751     int cur_height = fgGetInt("/sim/startup/ysize");
752     p.Begin( "FlightGear", cur_width*3, cur_height*3 );
753         p.End( hiResScreenCapture(3) );
754
755     // BusyCursor(1);
756     if ( show_pu_cursor ) {
757         puShowCursor();
758     }
759     TurnCursorOn();
760 }
761 #endif // #ifdef WIN32
762
763
764 void dumpSnapShot ( puObject *obj ) {
765     fgDumpSnapShot();
766 }
767
768
769 void dumpHiResSnapShot ( puObject *obj ) {
770     fgHiResDump();
771 }
772
773
774 // do a screen snap shot
775 void fgDumpSnapShot () {
776     bool show_pu_cursor = false;
777     char *filename = new char [24];
778     string message;
779     static int count = 1;
780
781     static const SGPropertyNode *master_freeze
782         = fgGetNode("/sim/freeze/master");
783
784     bool freeze = master_freeze->getBoolValue();
785     if ( !freeze ) {
786         fgSetBool("/sim/freeze/master", true);
787     }
788
789     TurnCursorOff();
790     if ( !puCursorIsHidden() ) {
791         show_pu_cursor = true;
792         puHideCursor();
793     }
794
795     fgInitVisuals();
796     fgReshape( fgGetInt("/sim/startup/xsize"),
797                fgGetInt("/sim/startup/ysize") );
798
799     // we need two render frames here to clear the menu and cursor
800     // ... not sure why but doing an extra fgRenderFrame() shouldn't
801     // hurt anything
802     fgRenderFrame();
803     fgRenderFrame();
804
805     while (count < 1000) {
806         FILE *fp;
807         snprintf(filename, 24, "fgfs-screen-%03d.ppm", count++);
808         if ( (fp = fopen(filename, "r")) == NULL )
809             break;
810         fclose(fp);
811     }
812
813     if ( sg_glDumpWindow( filename,
814                           fgGetInt("/sim/startup/xsize"), 
815                           fgGetInt("/sim/startup/ysize")) ) {
816         message = "Snap shot saved to ";
817         message += filename;
818     } else {
819         message = "Failed to save to ";
820         message += filename;
821     }
822
823     mkDialog (message.c_str());
824
825     delete [] filename;
826
827     if ( show_pu_cursor ) {
828         puShowCursor();
829     }
830
831     TurnCursorOn();
832
833     if ( !freeze ) {
834         fgSetBool("/sim/freeze/master", false);
835     }
836 }
837