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