Search
lxdream.org :: lxdream/src/gui/gtkui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gtkui.c
changeset 450:207461e79f21
prev447:3e095bfcb476
next455:3080881d00d4
author nkeynes
date Wed Oct 17 11:26:45 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Split config management out to config.[ch]
Manage config filename
Check home dir + sysconfdir for conf file
Initial work on a path settings dialog
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@450
     2
 * $Id: gtkui.c,v 1.4 2007-10-17 11:26:45 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@435
    23
#include "gui/gtkui.h"
nkeynes@435
    24
nkeynes@435
    25
nkeynes@435
    26
void gtk_gui_update( void );
nkeynes@435
    27
void gtk_gui_start( void );
nkeynes@435
    28
void gtk_gui_stop( void );
nkeynes@435
    29
void gtk_gui_alloc_resources ( void );
nkeynes@435
    30
uint32_t gtk_gui_run_slice( uint32_t nanosecs );
nkeynes@435
    31
nkeynes@435
    32
struct dreamcast_module gtk_gui_module = { "gui", NULL,
nkeynes@435
    33
					   gtk_gui_update, 
nkeynes@435
    34
					   gtk_gui_start, 
nkeynes@435
    35
					   gtk_gui_run_slice, 
nkeynes@435
    36
					   gtk_gui_stop, 
nkeynes@435
    37
					   NULL, NULL };
nkeynes@435
    38
nkeynes@435
    39
/**
nkeynes@435
    40
 * Single-instance windows (at most one)
nkeynes@435
    41
 */
nkeynes@435
    42
static main_window_t main_win = NULL;
nkeynes@435
    43
static debug_window_t debug_win = NULL;
nkeynes@435
    44
static mmio_window_t mmio_win = NULL;
nkeynes@435
    45
nkeynes@435
    46
/**
nkeynes@435
    47
 * Count of running nanoseconds - used to cut back on the GUI runtime
nkeynes@435
    48
 */
nkeynes@435
    49
static uint32_t gtk_gui_nanos = 0;
nkeynes@437
    50
static struct timeval gtk_gui_lasttv;
nkeynes@435
    51
nkeynes@435
    52
gboolean gui_parse_cmdline( int *argc, char **argv[] )
nkeynes@435
    53
{
nkeynes@435
    54
    return gtk_init_check( argc, argv );
nkeynes@435
    55
}
nkeynes@435
    56
nkeynes@435
    57
gboolean gui_init( gboolean withDebug )
nkeynes@435
    58
{
nkeynes@435
    59
    dreamcast_register_module( &gtk_gui_module );
nkeynes@435
    60
    gtk_gui_alloc_resources();
nkeynes@435
    61
    if( withDebug ) {
nkeynes@435
    62
	debug_win = debug_window_new();
nkeynes@435
    63
    }
nkeynes@435
    64
    main_win = main_window_new( APP_NAME " " APP_VERSION );
nkeynes@435
    65
    return TRUE;
nkeynes@435
    66
}
nkeynes@435
    67
nkeynes@435
    68
void gui_main_loop(void)
nkeynes@435
    69
{
nkeynes@435
    70
    gtk_main();
nkeynes@435
    71
}
nkeynes@435
    72
nkeynes@447
    73
gboolean gui_error_dialog( const char *msg, ... )
nkeynes@447
    74
{
nkeynes@447
    75
    if( main_win != NULL ) {
nkeynes@447
    76
	va_list args;
nkeynes@447
    77
	GtkWidget *dialog = 
nkeynes@447
    78
	    gtk_message_dialog_new( main_window_get_frame(main_win), GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
nkeynes@447
    79
				    GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, NULL );
nkeynes@447
    80
	va_start(args, msg);
nkeynes@447
    81
	gchar *markup = g_markup_vprintf_escaped( msg, args );
nkeynes@447
    82
	va_end( args );
nkeynes@447
    83
	gtk_message_dialog_set_markup( GTK_MESSAGE_DIALOG(dialog), markup );
nkeynes@447
    84
	g_free(markup);
nkeynes@447
    85
	gtk_dialog_run(GTK_DIALOG(dialog));
nkeynes@447
    86
	gtk_widget_destroy(dialog);
nkeynes@447
    87
	return TRUE;
nkeynes@447
    88
    }
nkeynes@447
    89
    return FALSE;
nkeynes@447
    90
}
nkeynes@447
    91
nkeynes@435
    92
void gui_update_io_activity( io_activity_type io, gboolean active )
nkeynes@435
    93
{
nkeynes@435
    94
nkeynes@435
    95
}
nkeynes@435
    96
nkeynes@435
    97
void gtk_gui_show_debugger()
nkeynes@435
    98
{
nkeynes@435
    99
    if( debug_win ) {
nkeynes@435
   100
	debug_window_show(debug_win, TRUE);
nkeynes@435
   101
    } else {
nkeynes@435
   102
	debug_win = debug_window_new();
nkeynes@435
   103
    }
nkeynes@435
   104
}    
nkeynes@435
   105
nkeynes@435
   106
GtkWidget *gtk_gui_get_renderarea()
nkeynes@435
   107
{
nkeynes@435
   108
    return main_window_get_renderarea(main_win);
nkeynes@435
   109
}
nkeynes@435
   110
nkeynes@435
   111
/**
nkeynes@435
   112
 * Hook called when DC starts running. Just disables the run/step buttons
nkeynes@435
   113
 * and enables the stop button.
nkeynes@435
   114
 */
nkeynes@435
   115
void gtk_gui_start( void )
nkeynes@435
   116
{
nkeynes@435
   117
    main_window_set_running( main_win, TRUE );
nkeynes@435
   118
    if( debug_win != NULL ) {
nkeynes@435
   119
	debug_window_set_running( debug_win, TRUE );
nkeynes@435
   120
    }
nkeynes@437
   121
    gtk_gui_nanos = 0;
nkeynes@437
   122
    gettimeofday(&gtk_gui_lasttv,NULL);
nkeynes@435
   123
}
nkeynes@435
   124
nkeynes@435
   125
/**
nkeynes@435
   126
 * Hook called when DC stops running. Enables the run/step buttons
nkeynes@435
   127
 * and disables the stop button.
nkeynes@435
   128
 */
nkeynes@435
   129
void gtk_gui_stop( void )
nkeynes@435
   130
{
nkeynes@435
   131
    main_window_set_running( main_win, FALSE );
nkeynes@435
   132
    gtk_gui_update();
nkeynes@435
   133
}
nkeynes@435
   134
nkeynes@435
   135
void gtk_gui_update( void )
nkeynes@435
   136
{
nkeynes@435
   137
    if( debug_win ) {
nkeynes@435
   138
	debug_window_set_running( debug_win, FALSE );
nkeynes@435
   139
	debug_window_update(debug_win);
nkeynes@435
   140
    }
nkeynes@435
   141
    if( mmio_win ) {
nkeynes@435
   142
	mmio_win_update(mmio_win);
nkeynes@435
   143
    }
nkeynes@435
   144
    dump_win_update_all();
nkeynes@435
   145
}
nkeynes@435
   146
nkeynes@435
   147
/**
nkeynes@435
   148
 * Module run-slice. Because UI processing is fairly expensive, only 
nkeynes@435
   149
 * run the processing about 10 times a second while we're emulating.
nkeynes@435
   150
 */
nkeynes@435
   151
uint32_t gtk_gui_run_slice( uint32_t nanosecs ) 
nkeynes@435
   152
{
nkeynes@435
   153
    gtk_gui_nanos += nanosecs;
nkeynes@435
   154
    if( gtk_gui_nanos > 100000000 ) { 
nkeynes@437
   155
	struct timeval tv;
nkeynes@435
   156
	while( gtk_events_pending() )
nkeynes@435
   157
	    gtk_main_iteration();
nkeynes@437
   158
	
nkeynes@437
   159
	gettimeofday(&tv,NULL);
nkeynes@437
   160
	double ns = ((tv.tv_sec - gtk_gui_lasttv.tv_sec) * 1000000000.0) +
nkeynes@437
   161
	    ((tv.tv_usec - gtk_gui_lasttv.tv_usec)*1000.0);
nkeynes@437
   162
	double speed = (float)( (double)gtk_gui_nanos * 100.0 / ns );
nkeynes@437
   163
	gtk_gui_lasttv.tv_sec = tv.tv_sec;
nkeynes@437
   164
	gtk_gui_lasttv.tv_usec = tv.tv_usec;
nkeynes@437
   165
	main_window_set_speed( main_win, speed );
nkeynes@437
   166
	gtk_gui_nanos = 0;
nkeynes@435
   167
    }
nkeynes@435
   168
    return nanosecs;
nkeynes@435
   169
}
nkeynes@435
   170
nkeynes@435
   171
nkeynes@435
   172
PangoFontDescription *gui_fixed_font;
nkeynes@435
   173
GdkColor gui_colour_normal, gui_colour_changed, gui_colour_error;
nkeynes@435
   174
GdkColor gui_colour_warn, gui_colour_pc, gui_colour_debug;
nkeynes@435
   175
GdkColor gui_colour_trace, gui_colour_break, gui_colour_temp_break;
nkeynes@435
   176
GdkColor gui_colour_white;
nkeynes@435
   177
nkeynes@435
   178
void gtk_gui_alloc_resources() {
nkeynes@435
   179
    GdkColormap *map;
nkeynes@435
   180
nkeynes@435
   181
    gui_colour_normal.red = gui_colour_normal.green = gui_colour_normal.blue = 0;
nkeynes@435
   182
    gui_colour_changed.red = gui_colour_changed.green = 64*256;
nkeynes@435
   183
    gui_colour_changed.blue = 154*256;
nkeynes@435
   184
    gui_colour_error.red = 65535;
nkeynes@435
   185
    gui_colour_error.green = gui_colour_error.blue = 64*256;
nkeynes@435
   186
    gui_colour_pc.red = 32*256;
nkeynes@435
   187
    gui_colour_pc.green = 170*256;
nkeynes@435
   188
    gui_colour_pc.blue = 52*256;
nkeynes@435
   189
    gui_colour_warn = gui_colour_changed;
nkeynes@435
   190
    gui_colour_trace.red = 156*256;
nkeynes@435
   191
    gui_colour_trace.green = 78*256;
nkeynes@435
   192
    gui_colour_trace.blue = 201*256;
nkeynes@435
   193
    gui_colour_debug = gui_colour_pc;
nkeynes@435
   194
    gui_colour_break.red = 65535;
nkeynes@435
   195
    gui_colour_break.green = gui_colour_break.blue = 192*256;
nkeynes@435
   196
    gui_colour_temp_break.red = gui_colour_temp_break.green = 128*256;
nkeynes@435
   197
    gui_colour_temp_break.blue = 32*256;
nkeynes@435
   198
    gui_colour_white.red = gui_colour_white.green = gui_colour_white.blue = 65535;
nkeynes@435
   199
nkeynes@435
   200
    map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
nkeynes@435
   201
    gdk_colormap_alloc_color(map, &gui_colour_normal, TRUE, TRUE);
nkeynes@435
   202
    gdk_colormap_alloc_color(map, &gui_colour_changed, TRUE, TRUE);
nkeynes@435
   203
    gdk_colormap_alloc_color(map, &gui_colour_error, TRUE, TRUE);
nkeynes@435
   204
    gdk_colormap_alloc_color(map, &gui_colour_warn, TRUE, TRUE);
nkeynes@435
   205
    gdk_colormap_alloc_color(map, &gui_colour_pc, TRUE, TRUE);
nkeynes@435
   206
    gdk_colormap_alloc_color(map, &gui_colour_debug, TRUE, TRUE);
nkeynes@435
   207
    gdk_colormap_alloc_color(map, &gui_colour_trace, TRUE, TRUE);
nkeynes@435
   208
    gdk_colormap_alloc_color(map, &gui_colour_break, TRUE, TRUE);
nkeynes@435
   209
    gdk_colormap_alloc_color(map, &gui_colour_temp_break, TRUE, TRUE);
nkeynes@435
   210
    gdk_colormap_alloc_color(map, &gui_colour_white, TRUE, TRUE);
nkeynes@435
   211
    gui_fixed_font = pango_font_description_from_string("Courier 10");
nkeynes@435
   212
}
nkeynes@450
   213
nkeynes@450
   214
gint gtk_gui_run_property_dialog( const gchar *title, GtkWidget *panel )
nkeynes@450
   215
{
nkeynes@450
   216
    GtkWidget *dialog =
nkeynes@450
   217
	gtk_dialog_new_with_buttons(title, main_window_get_frame(main_win), 
nkeynes@450
   218
				    GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
nkeynes@450
   219
				    GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
nkeynes@450
   220
				    GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
nkeynes@450
   221
				    NULL);
nkeynes@450
   222
    gint result;
nkeynes@450
   223
    gtk_widget_show_all(panel);
nkeynes@450
   224
    gtk_container_add( GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), panel );
nkeynes@450
   225
    result = gtk_dialog_run( GTK_DIALOG(dialog) );
nkeynes@450
   226
    gtk_widget_destroy( dialog );
nkeynes@450
   227
    return result;
nkeynes@450
   228
}
.