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