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