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