Search
lxdream.org :: lxdream/src/gui/gtkui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gtkui.c
changeset 464:8e099fad42a6
prev457:af605fd32c0b
next470:e09a16196693
author nkeynes
date Sat Oct 27 05:44:54 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change Initial gdrom attachment menu
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@464
     2
 * $Id: gtkui.c,v 1.7 2007-10-27 05:44:54 nkeynes Exp $
nkeynes@435
     3
 *
nkeynes@435
     4
 * Core GTK-based user interface
nkeynes@435
     5
 *
nkeynes@435
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@435
     7
 *
nkeynes@435
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@435
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@435
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@435
    11
 * (at your option) any later version.
nkeynes@435
    12
 *
nkeynes@435
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@435
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@435
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@435
    16
 * GNU General Public License for more details.
nkeynes@435
    17
 */
nkeynes@435
    18
nkeynes@437
    19
#include <sys/time.h>
nkeynes@437
    20
#include <time.h>
nkeynes@435
    21
#include "dream.h"
nkeynes@435
    22
#include "dreamcast.h"
nkeynes@464
    23
#include "gdrom/gdrom.h"
nkeynes@435
    24
#include "gui/gtkui.h"
nkeynes@435
    25
nkeynes@435
    26
nkeynes@435
    27
void gtk_gui_update( void );
nkeynes@435
    28
void gtk_gui_start( void );
nkeynes@435
    29
void gtk_gui_stop( void );
nkeynes@435
    30
void gtk_gui_alloc_resources ( void );
nkeynes@435
    31
uint32_t gtk_gui_run_slice( uint32_t nanosecs );
nkeynes@435
    32
nkeynes@435
    33
struct dreamcast_module gtk_gui_module = { "gui", NULL,
nkeynes@435
    34
					   gtk_gui_update, 
nkeynes@435
    35
					   gtk_gui_start, 
nkeynes@435
    36
					   gtk_gui_run_slice, 
nkeynes@435
    37
					   gtk_gui_stop, 
nkeynes@435
    38
					   NULL, NULL };
nkeynes@435
    39
nkeynes@435
    40
/**
nkeynes@435
    41
 * Single-instance windows (at most one)
nkeynes@435
    42
 */
nkeynes@435
    43
static main_window_t main_win = NULL;
nkeynes@435
    44
static debug_window_t debug_win = NULL;
nkeynes@435
    45
static mmio_window_t mmio_win = NULL;
nkeynes@435
    46
nkeynes@435
    47
/**
nkeynes@455
    48
 * UIManager and action helpers
nkeynes@455
    49
 */
nkeynes@455
    50
static GtkUIManager *global_ui_manager;
nkeynes@455
    51
static GtkAccelGroup *global_accel_group;
nkeynes@455
    52
static GtkActionGroup *global_action_group;
nkeynes@455
    53
nkeynes@455
    54
/**
nkeynes@435
    55
 * Count of running nanoseconds - used to cut back on the GUI runtime
nkeynes@435
    56
 */
nkeynes@435
    57
static uint32_t gtk_gui_nanos = 0;
nkeynes@437
    58
static struct timeval gtk_gui_lasttv;
nkeynes@435
    59
nkeynes@455
    60
#define ENABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,TRUE)
nkeynes@455
    61
#define DISABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,FALSE)
nkeynes@455
    62
nkeynes@455
    63
// UI Actions
nkeynes@455
    64
static const GtkActionEntry ui_actions[] = {
nkeynes@455
    65
    { "FileMenu", NULL, "_File" },
nkeynes@455
    66
    { "SettingsMenu", NULL, "_Settings" },
nkeynes@455
    67
    { "HelpMenu", NULL, "_Help" },
nkeynes@455
    68
    { "Reset", GTK_STOCK_REFRESH, "_Reset", "<control>R", "Reset dreamcast", G_CALLBACK(reset_action_callback) },
nkeynes@455
    69
    { "Pause", GTK_STOCK_MEDIA_PAUSE, "_Pause", NULL, "Pause dreamcast", G_CALLBACK(pause_action_callback) },
nkeynes@455
    70
    { "Run", GTK_STOCK_MEDIA_PLAY, "Resume", NULL, "Resume", G_CALLBACK(resume_action_callback) },
nkeynes@455
    71
    { "LoadState", GTK_STOCK_REVERT_TO_SAVED, "_Load state...", "F4", "Load an lxdream save state", G_CALLBACK(load_state_action_callback) },
nkeynes@455
    72
    { "SaveState", GTK_STOCK_SAVE_AS, "_Save state...", "F3", "Create an lxdream save state", G_CALLBACK(save_state_action_callback) },
nkeynes@455
    73
    { "Exit", GTK_STOCK_QUIT, "E_xit", NULL, "Exit lxdream", G_CALLBACK(exit_action_callback) },
nkeynes@464
    74
    { "GdromSettings", NULL, "_GD-Rom..." },
nkeynes@464
    75
    { "GdromUnmount", NULL, "_Empty" },
nkeynes@464
    76
    { "GdromMount", GTK_STOCK_CDROM, "_Open Image...", "<control>O", "Mount a cdrom disc", G_CALLBACK(mount_action_callback) },
nkeynes@455
    77
    { "PathSettings", NULL, "_Paths...", NULL, "Configure files and paths", G_CALLBACK(path_settings_callback) }, 
nkeynes@455
    78
    { "AudioSettings", NULL, "_Audio...", NULL, "Configure audio output", G_CALLBACK(audio_settings_callback) },
nkeynes@455
    79
    { "ControllerSettings", NULL, "_Controllers...", NULL, "Configure controllers", G_CALLBACK(maple_settings_callback) },
nkeynes@455
    80
    { "NetworkSettings", NULL, "_Network...", NULL, "Configure network settings", G_CALLBACK(network_settings_callback) },
nkeynes@455
    81
    { "VideoSettings", NULL, "_Video...", NULL, "Configure video output", G_CALLBACK(video_settings_callback) },
nkeynes@455
    82
    { "About", GTK_STOCK_ABOUT, "_About...", NULL, "About lxdream", G_CALLBACK(about_action_callback) },
nkeynes@455
    83
    { "DebugMenu", NULL, "_Debug" },
nkeynes@455
    84
    { "Debugger", NULL, "_Debugger", NULL, "Open debugger window", G_CALLBACK(debugger_action_callback) },
nkeynes@455
    85
    { "DebugMem", NULL, "View _Memory", NULL, "View memory dump", G_CALLBACK(debug_memory_action_callback) },
nkeynes@455
    86
    { "DebugMmio", NULL, "View IO _Registers", NULL, "View MMIO Registers", G_CALLBACK(debug_mmio_action_callback) },
nkeynes@455
    87
    { "SaveScene", NULL, "_Save Scene", NULL, "Save next rendered scene", G_CALLBACK(save_scene_action_callback) },
nkeynes@455
    88
    { "SingleStep", GTK_STOCK_REDO, "_Single Step", NULL, "Single step", G_CALLBACK(debug_step_action_callback) },
nkeynes@455
    89
    { "RunTo", GTK_STOCK_GOTO_LAST, "Run _To", NULL, "Run to", G_CALLBACK( debug_runto_action_callback) },
nkeynes@455
    90
    { "SetBreakpoint", GTK_STOCK_CLOSE, "_Breakpoint", NULL, "Toggle breakpoint", G_CALLBACK( debug_breakpoint_action_callback) }
nkeynes@455
    91
};
nkeynes@455
    92
static const GtkToggleActionEntry ui_toggle_actions[] = {
nkeynes@455
    93
    { "FullScreen", NULL, "_Full Screen", "<alt>Return", "Toggle full screen video", G_CALLBACK(fullscreen_toggle_callback), 0 },
nkeynes@455
    94
};
nkeynes@455
    95
    
nkeynes@455
    96
// Menus and toolbars
nkeynes@455
    97
static const char *ui_description =
nkeynes@455
    98
    "<ui>"
nkeynes@455
    99
    " <menubar name='MainMenu'>"
nkeynes@455
   100
    "  <menu action='FileMenu'>"
nkeynes@464
   101
    "   <menuitem action='GdromSettings'/>"
nkeynes@455
   102
    "   <separator/>"
nkeynes@455
   103
    "   <menuitem action='Reset'/>"
nkeynes@455
   104
    "   <menuitem action='Pause'/>"
nkeynes@455
   105
    "   <menuitem action='Run'/>"
nkeynes@455
   106
    "   <menuitem action='Debugger'/>"
nkeynes@455
   107
    "   <separator/>"
nkeynes@455
   108
    "   <menuitem action='LoadState'/>"
nkeynes@455
   109
    "   <menuitem action='SaveState'/>"
nkeynes@455
   110
    "   <separator/>"
nkeynes@455
   111
    "   <menuitem action='Exit'/>"
nkeynes@455
   112
    "  </menu>"
nkeynes@455
   113
    "  <menu action='SettingsMenu'>"
nkeynes@455
   114
    "   <menuitem action='PathSettings'/>"
nkeynes@455
   115
    "   <menuitem action='AudioSettings'/>"
nkeynes@455
   116
    "   <menuitem action='ControllerSettings'/>"
nkeynes@455
   117
    "   <menuitem action='NetworkSettings'/>"
nkeynes@455
   118
    "   <menuitem action='VideoSettings'/>"
nkeynes@455
   119
    "   <separator/>"
nkeynes@455
   120
    "   <menuitem action='FullScreen'/>"
nkeynes@455
   121
    "  </menu>"
nkeynes@455
   122
    "  <menu action='HelpMenu'>"
nkeynes@455
   123
    "   <menuitem action='About'/>"
nkeynes@455
   124
    "  </menu>"
nkeynes@455
   125
    " </menubar>"
nkeynes@455
   126
    " <toolbar name='MainToolbar'>"
nkeynes@464
   127
    "  <toolitem action='GdromMount'/>"
nkeynes@455
   128
    "  <toolitem action='Reset'/>"
nkeynes@455
   129
    "  <toolitem action='Pause'/>"
nkeynes@455
   130
    "  <toolitem action='Run'/>"
nkeynes@455
   131
    "  <separator/>"
nkeynes@455
   132
    "  <toolitem action='LoadState'/>"
nkeynes@455
   133
    "  <toolitem action='SaveState'/>"
nkeynes@455
   134
    " </toolbar>"
nkeynes@455
   135
    " <menubar name='DebugMenu'>"
nkeynes@455
   136
    "  <menu action='FileMenu'>"
nkeynes@464
   137
    "   <menuitem action='GdromMount'/>"
nkeynes@455
   138
    "   <separator/>"
nkeynes@455
   139
    "   <menuitem action='Reset'/>"
nkeynes@455
   140
    "   <separator/>"
nkeynes@455
   141
    "   <menuitem action='LoadState'/>"
nkeynes@455
   142
    "   <menuitem action='SaveState'/>"
nkeynes@455
   143
    "   <separator/>"
nkeynes@455
   144
    "   <menuitem action='Exit'/>"
nkeynes@455
   145
    "  </menu>"
nkeynes@455
   146
    "  <menu action='DebugMenu'>"
nkeynes@455
   147
    "   <menuitem action='DebugMem'/>"
nkeynes@455
   148
    "   <menuitem action='DebugMmio'/>"
nkeynes@455
   149
    "   <menuitem action='SaveScene'/>"
nkeynes@455
   150
    "   <separator/>"
nkeynes@455
   151
    "   <menuitem action='SetBreakpoint'/>"
nkeynes@455
   152
    "   <menuitem action='Pause'/>"
nkeynes@455
   153
    "   <menuitem action='SingleStep'/>"
nkeynes@455
   154
    "   <menuitem action='RunTo'/>"
nkeynes@455
   155
    "   <menuitem action='Run'/>"
nkeynes@455
   156
    "  </menu>"
nkeynes@455
   157
    "  <menu action='SettingsMenu'>"
nkeynes@455
   158
    "   <menuitem action='PathSettings'/>"
nkeynes@455
   159
    "   <menuitem action='AudioSettings'/>"
nkeynes@455
   160
    "   <menuitem action='ControllerSettings'/>"
nkeynes@455
   161
    "   <menuitem action='NetworkSettings'/>"
nkeynes@455
   162
    "   <menuitem action='VideoSettings'/>"
nkeynes@455
   163
    "   <separator/>"
nkeynes@455
   164
    "   <menuitem action='FullScreen'/>"
nkeynes@455
   165
    "  </menu>"
nkeynes@455
   166
    "  <menu action='HelpMenu'>"
nkeynes@455
   167
    "   <menuitem action='About'/>"
nkeynes@455
   168
    "  </menu>"
nkeynes@455
   169
    " </menubar>"
nkeynes@455
   170
    " <toolbar name='DebugToolbar'>"
nkeynes@464
   171
    "  <toolitem action='GdromMount'/>"
nkeynes@455
   172
    "  <toolitem action='Reset'/>"
nkeynes@455
   173
    "  <toolitem action='Pause'/>"
nkeynes@455
   174
    "  <separator/>"
nkeynes@455
   175
    "  <toolitem action='SingleStep'/>"
nkeynes@455
   176
    "  <toolitem action='RunTo'/>"
nkeynes@455
   177
    "  <toolitem action='Run'/>"
nkeynes@455
   178
    "  <toolitem action='SetBreakpoint'/>"
nkeynes@455
   179
    "  <separator/>"
nkeynes@455
   180
    "  <toolitem action='LoadState'/>"
nkeynes@455
   181
    "  <toolitem action='SaveState'/>"
nkeynes@455
   182
    " </toolbar>"
nkeynes@455
   183
    "</ui>";
nkeynes@455
   184
nkeynes@435
   185
gboolean gui_parse_cmdline( int *argc, char **argv[] )
nkeynes@435
   186
{
nkeynes@435
   187
    return gtk_init_check( argc, argv );
nkeynes@435
   188
}
nkeynes@435
   189
nkeynes@435
   190
gboolean gui_init( gboolean withDebug )
nkeynes@435
   191
{
nkeynes@455
   192
    GError *error = NULL;
nkeynes@435
   193
    dreamcast_register_module( &gtk_gui_module );
nkeynes@435
   194
    gtk_gui_alloc_resources();
nkeynes@455
   195
    
nkeynes@455
   196
    global_action_group = gtk_action_group_new("MenuActions");
nkeynes@455
   197
    gtk_action_group_add_actions( global_action_group, ui_actions, G_N_ELEMENTS(ui_actions), NULL );
nkeynes@455
   198
    gtk_action_group_add_toggle_actions( global_action_group, ui_toggle_actions, G_N_ELEMENTS(ui_toggle_actions), NULL );
nkeynes@455
   199
    gtk_gui_enable_action("AudioSettings", FALSE);
nkeynes@455
   200
    gtk_gui_enable_action("NetworkSettings", FALSE);
nkeynes@455
   201
    gtk_gui_enable_action("VideoSettings", FALSE);
nkeynes@464
   202
    gtk_gui_enable_action("FullScreen", FALSE);
nkeynes@464
   203
nkeynes@455
   204
    global_ui_manager = gtk_ui_manager_new();
nkeynes@455
   205
    gtk_ui_manager_set_add_tearoffs(global_ui_manager, TRUE);
nkeynes@455
   206
    gtk_ui_manager_insert_action_group( global_ui_manager, global_action_group, 0 );
nkeynes@455
   207
nkeynes@455
   208
    if (!gtk_ui_manager_add_ui_from_string (global_ui_manager, ui_description, -1, &error)) {
nkeynes@455
   209
	g_message ("building menus failed: %s", error->message);
nkeynes@455
   210
	g_error_free (error);
nkeynes@455
   211
	exit(1);
nkeynes@455
   212
    }
nkeynes@455
   213
    GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group (global_ui_manager);
nkeynes@455
   214
    GtkWidget *menubar = gtk_ui_manager_get_widget(global_ui_manager, "/MainMenu");
nkeynes@455
   215
    GtkWidget *toolbar = gtk_ui_manager_get_widget(global_ui_manager, "/MainToolbar");
nkeynes@464
   216
nkeynes@464
   217
    GtkWidget *gdrommenuitem = gtk_ui_manager_get_widget(global_ui_manager, "/MainMenu/FileMenu/GdromSettings");
nkeynes@464
   218
    GtkWidget *gdrommenu = gdrom_menu_new();
nkeynes@464
   219
    gtk_menu_item_set_submenu( GTK_MENU_ITEM(gdrommenuitem), gdrommenu );
nkeynes@455
   220
    main_win = main_window_new( APP_NAME " " APP_VERSION, menubar, toolbar, accel_group  );
nkeynes@435
   221
    if( withDebug ) {
nkeynes@455
   222
	gtk_gui_show_debugger();
nkeynes@435
   223
    }
nkeynes@455
   224
nkeynes@435
   225
    return TRUE;
nkeynes@435
   226
}
nkeynes@435
   227
nkeynes@435
   228
void gui_main_loop(void)
nkeynes@435
   229
{
nkeynes@435
   230
    gtk_main();
nkeynes@435
   231
}
nkeynes@435
   232
nkeynes@447
   233
gboolean gui_error_dialog( const char *msg, ... )
nkeynes@447
   234
{
nkeynes@447
   235
    if( main_win != NULL ) {
nkeynes@447
   236
	va_list args;
nkeynes@447
   237
	GtkWidget *dialog = 
nkeynes@447
   238
	    gtk_message_dialog_new( main_window_get_frame(main_win), GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
nkeynes@447
   239
				    GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, NULL );
nkeynes@447
   240
	va_start(args, msg);
nkeynes@447
   241
	gchar *markup = g_markup_vprintf_escaped( msg, args );
nkeynes@447
   242
	va_end( args );
nkeynes@447
   243
	gtk_message_dialog_set_markup( GTK_MESSAGE_DIALOG(dialog), markup );
nkeynes@447
   244
	g_free(markup);
nkeynes@447
   245
	gtk_dialog_run(GTK_DIALOG(dialog));
nkeynes@447
   246
	gtk_widget_destroy(dialog);
nkeynes@447
   247
	return TRUE;
nkeynes@447
   248
    }
nkeynes@447
   249
    return FALSE;
nkeynes@447
   250
}
nkeynes@447
   251
nkeynes@435
   252
void gui_update_io_activity( io_activity_type io, gboolean active )
nkeynes@435
   253
{
nkeynes@435
   254
nkeynes@435
   255
}
nkeynes@435
   256
nkeynes@435
   257
void gtk_gui_show_debugger()
nkeynes@435
   258
{
nkeynes@435
   259
    if( debug_win ) {
nkeynes@435
   260
	debug_window_show(debug_win, TRUE);
nkeynes@435
   261
    } else {
nkeynes@455
   262
	GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group (global_ui_manager);
nkeynes@455
   263
	GtkWidget *menubar = gtk_ui_manager_get_widget(global_ui_manager, "/DebugMenu");
nkeynes@455
   264
	GtkWidget *toolbar = gtk_ui_manager_get_widget(global_ui_manager, "/DebugToolbar");
nkeynes@455
   265
	debug_win = debug_window_new( APP_NAME " " APP_VERSION " :: Debugger", menubar, toolbar, accel_group  );
nkeynes@435
   266
    }
nkeynes@455
   267
}
nkeynes@455
   268
nkeynes@455
   269
void gtk_gui_show_mmio()
nkeynes@455
   270
{
nkeynes@455
   271
    if( mmio_win ) {
nkeynes@455
   272
	mmio_window_show(mmio_win, TRUE);
nkeynes@455
   273
    } else {
nkeynes@455
   274
	mmio_win = mmio_window_new( APP_NAME " " APP_VERSION " :: MMIO Registers" );
nkeynes@455
   275
    }
nkeynes@455
   276
}
nkeynes@455
   277
nkeynes@455
   278
nkeynes@455
   279
main_window_t gtk_gui_get_main()
nkeynes@455
   280
{
nkeynes@455
   281
    return main_win;
nkeynes@455
   282
}
nkeynes@455
   283
nkeynes@455
   284
debug_window_t gtk_gui_get_debugger()
nkeynes@455
   285
{
nkeynes@455
   286
    return debug_win;
nkeynes@455
   287
}
nkeynes@455
   288
nkeynes@455
   289
mmio_window_t gtk_gui_get_mmio()
nkeynes@455
   290
{
nkeynes@455
   291
    return mmio_win;
nkeynes@455
   292
}
nkeynes@435
   293
nkeynes@435
   294
GtkWidget *gtk_gui_get_renderarea()
nkeynes@435
   295
{
nkeynes@435
   296
    return main_window_get_renderarea(main_win);
nkeynes@435
   297
}
nkeynes@435
   298
nkeynes@435
   299
/**
nkeynes@435
   300
 * Hook called when DC starts running. Just disables the run/step buttons
nkeynes@435
   301
 * and enables the stop button.
nkeynes@435
   302
 */
nkeynes@435
   303
void gtk_gui_start( void )
nkeynes@435
   304
{
nkeynes@435
   305
    main_window_set_running( main_win, TRUE );
nkeynes@435
   306
    if( debug_win != NULL ) {
nkeynes@435
   307
	debug_window_set_running( debug_win, TRUE );
nkeynes@435
   308
    }
nkeynes@437
   309
    gtk_gui_nanos = 0;
nkeynes@437
   310
    gettimeofday(&gtk_gui_lasttv,NULL);
nkeynes@435
   311
}
nkeynes@435
   312
nkeynes@435
   313
/**
nkeynes@435
   314
 * Hook called when DC stops running. Enables the run/step buttons
nkeynes@435
   315
 * and disables the stop button.
nkeynes@435
   316
 */
nkeynes@435
   317
void gtk_gui_stop( void )
nkeynes@435
   318
{
nkeynes@435
   319
    main_window_set_running( main_win, FALSE );
nkeynes@435
   320
    gtk_gui_update();
nkeynes@435
   321
}
nkeynes@435
   322
nkeynes@435
   323
void gtk_gui_update( void )
nkeynes@435
   324
{
nkeynes@435
   325
    if( debug_win ) {
nkeynes@435
   326
	debug_window_set_running( debug_win, FALSE );
nkeynes@435
   327
	debug_window_update(debug_win);
nkeynes@435
   328
    }
nkeynes@435
   329
    if( mmio_win ) {
nkeynes@457
   330
	mmio_window_update(mmio_win);
nkeynes@435
   331
    }
nkeynes@455
   332
    dump_window_update_all();
nkeynes@435
   333
}
nkeynes@435
   334
nkeynes@435
   335
/**
nkeynes@435
   336
 * Module run-slice. Because UI processing is fairly expensive, only 
nkeynes@435
   337
 * run the processing about 10 times a second while we're emulating.
nkeynes@435
   338
 */
nkeynes@435
   339
uint32_t gtk_gui_run_slice( uint32_t nanosecs ) 
nkeynes@435
   340
{
nkeynes@435
   341
    gtk_gui_nanos += nanosecs;
nkeynes@435
   342
    if( gtk_gui_nanos > 100000000 ) { 
nkeynes@437
   343
	struct timeval tv;
nkeynes@435
   344
	while( gtk_events_pending() )
nkeynes@435
   345
	    gtk_main_iteration();
nkeynes@437
   346
	
nkeynes@437
   347
	gettimeofday(&tv,NULL);
nkeynes@437
   348
	double ns = ((tv.tv_sec - gtk_gui_lasttv.tv_sec) * 1000000000.0) +
nkeynes@437
   349
	    ((tv.tv_usec - gtk_gui_lasttv.tv_usec)*1000.0);
nkeynes@437
   350
	double speed = (float)( (double)gtk_gui_nanos * 100.0 / ns );
nkeynes@437
   351
	gtk_gui_lasttv.tv_sec = tv.tv_sec;
nkeynes@437
   352
	gtk_gui_lasttv.tv_usec = tv.tv_usec;
nkeynes@437
   353
	main_window_set_speed( main_win, speed );
nkeynes@437
   354
	gtk_gui_nanos = 0;
nkeynes@435
   355
    }
nkeynes@435
   356
    return nanosecs;
nkeynes@435
   357
}
nkeynes@435
   358
nkeynes@435
   359
nkeynes@435
   360
PangoFontDescription *gui_fixed_font;
nkeynes@435
   361
GdkColor gui_colour_normal, gui_colour_changed, gui_colour_error;
nkeynes@435
   362
GdkColor gui_colour_warn, gui_colour_pc, gui_colour_debug;
nkeynes@435
   363
GdkColor gui_colour_trace, gui_colour_break, gui_colour_temp_break;
nkeynes@435
   364
GdkColor gui_colour_white;
nkeynes@435
   365
nkeynes@435
   366
void gtk_gui_alloc_resources() {
nkeynes@435
   367
    GdkColormap *map;
nkeynes@435
   368
nkeynes@435
   369
    gui_colour_normal.red = gui_colour_normal.green = gui_colour_normal.blue = 0;
nkeynes@435
   370
    gui_colour_changed.red = gui_colour_changed.green = 64*256;
nkeynes@435
   371
    gui_colour_changed.blue = 154*256;
nkeynes@435
   372
    gui_colour_error.red = 65535;
nkeynes@435
   373
    gui_colour_error.green = gui_colour_error.blue = 64*256;
nkeynes@435
   374
    gui_colour_pc.red = 32*256;
nkeynes@435
   375
    gui_colour_pc.green = 170*256;
nkeynes@435
   376
    gui_colour_pc.blue = 52*256;
nkeynes@435
   377
    gui_colour_warn = gui_colour_changed;
nkeynes@435
   378
    gui_colour_trace.red = 156*256;
nkeynes@435
   379
    gui_colour_trace.green = 78*256;
nkeynes@435
   380
    gui_colour_trace.blue = 201*256;
nkeynes@435
   381
    gui_colour_debug = gui_colour_pc;
nkeynes@435
   382
    gui_colour_break.red = 65535;
nkeynes@435
   383
    gui_colour_break.green = gui_colour_break.blue = 192*256;
nkeynes@435
   384
    gui_colour_temp_break.red = gui_colour_temp_break.green = 128*256;
nkeynes@435
   385
    gui_colour_temp_break.blue = 32*256;
nkeynes@435
   386
    gui_colour_white.red = gui_colour_white.green = gui_colour_white.blue = 65535;
nkeynes@435
   387
nkeynes@435
   388
    map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
nkeynes@435
   389
    gdk_colormap_alloc_color(map, &gui_colour_normal, TRUE, TRUE);
nkeynes@435
   390
    gdk_colormap_alloc_color(map, &gui_colour_changed, TRUE, TRUE);
nkeynes@435
   391
    gdk_colormap_alloc_color(map, &gui_colour_error, TRUE, TRUE);
nkeynes@435
   392
    gdk_colormap_alloc_color(map, &gui_colour_warn, TRUE, TRUE);
nkeynes@435
   393
    gdk_colormap_alloc_color(map, &gui_colour_pc, TRUE, TRUE);
nkeynes@435
   394
    gdk_colormap_alloc_color(map, &gui_colour_debug, TRUE, TRUE);
nkeynes@435
   395
    gdk_colormap_alloc_color(map, &gui_colour_trace, TRUE, TRUE);
nkeynes@435
   396
    gdk_colormap_alloc_color(map, &gui_colour_break, TRUE, TRUE);
nkeynes@435
   397
    gdk_colormap_alloc_color(map, &gui_colour_temp_break, TRUE, TRUE);
nkeynes@435
   398
    gdk_colormap_alloc_color(map, &gui_colour_white, TRUE, TRUE);
nkeynes@435
   399
    gui_fixed_font = pango_font_description_from_string("Courier 10");
nkeynes@435
   400
}
nkeynes@450
   401
nkeynes@455
   402
gint gtk_gui_run_property_dialog( const gchar *title, GtkWidget *panel, gtk_dialog_done_fn fn )
nkeynes@450
   403
{
nkeynes@450
   404
    GtkWidget *dialog =
nkeynes@450
   405
	gtk_dialog_new_with_buttons(title, main_window_get_frame(main_win), 
nkeynes@450
   406
				    GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
nkeynes@450
   407
				    GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
nkeynes@450
   408
				    GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
nkeynes@450
   409
				    NULL);
nkeynes@450
   410
    gint result;
nkeynes@450
   411
    gtk_widget_show_all(panel);
nkeynes@450
   412
    gtk_container_add( GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), panel );
nkeynes@450
   413
    result = gtk_dialog_run( GTK_DIALOG(dialog) );
nkeynes@455
   414
    if( fn != NULL ) {
nkeynes@455
   415
	fn(panel, result == GTK_RESPONSE_ACCEPT);
nkeynes@455
   416
    }
nkeynes@450
   417
    gtk_widget_destroy( dialog );
nkeynes@450
   418
    return result;
nkeynes@450
   419
}
nkeynes@455
   420
nkeynes@455
   421
void gtk_gui_enable_action( const gchar *action, gboolean enable )
nkeynes@455
   422
{
nkeynes@455
   423
    gtk_action_set_sensitive( gtk_action_group_get_action( global_action_group, action), enable);
nkeynes@455
   424
}
.