filename | src/gui/gtkui.c |
changeset | 447:3e095bfcb476 |
prev | 437:2c259474b474 |
next | 450:207461e79f21 |
author | nkeynes |
date | Tue Oct 16 12:36:29 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Add gui error reporting Add initial controller settings dialog |
view | annotate | diff | log | raw |
1 /**
2 * $Id: gtkui.c,v 1.3 2007-10-16 12:36:29 nkeynes Exp $
3 *
4 * Core GTK-based user interface
5 *
6 * Copyright (c) 2005 Nathan Keynes.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
19 #include <sys/time.h>
20 #include <time.h>
21 #include "dream.h"
22 #include "dreamcast.h"
23 #include "gui/gtkui.h"
26 void gtk_gui_update( void );
27 void gtk_gui_start( void );
28 void gtk_gui_stop( void );
29 void gtk_gui_alloc_resources ( void );
30 uint32_t gtk_gui_run_slice( uint32_t nanosecs );
32 struct dreamcast_module gtk_gui_module = { "gui", NULL,
33 gtk_gui_update,
34 gtk_gui_start,
35 gtk_gui_run_slice,
36 gtk_gui_stop,
37 NULL, NULL };
39 /**
40 * Single-instance windows (at most one)
41 */
42 static main_window_t main_win = NULL;
43 static debug_window_t debug_win = NULL;
44 static mmio_window_t mmio_win = NULL;
46 /**
47 * Count of running nanoseconds - used to cut back on the GUI runtime
48 */
49 static uint32_t gtk_gui_nanos = 0;
50 static struct timeval gtk_gui_lasttv;
52 gboolean gui_parse_cmdline( int *argc, char **argv[] )
53 {
54 return gtk_init_check( argc, argv );
55 }
57 gboolean gui_init( gboolean withDebug )
58 {
59 dreamcast_register_module( >k_gui_module );
60 gtk_gui_alloc_resources();
61 if( withDebug ) {
62 debug_win = debug_window_new();
63 }
64 main_win = main_window_new( APP_NAME " " APP_VERSION );
65 return TRUE;
66 }
68 void gui_main_loop(void)
69 {
70 gtk_main();
71 }
73 gboolean gui_error_dialog( const char *msg, ... )
74 {
75 if( main_win != NULL ) {
76 va_list args;
77 GtkWidget *dialog =
78 gtk_message_dialog_new( main_window_get_frame(main_win), GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
79 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, NULL );
80 va_start(args, msg);
81 gchar *markup = g_markup_vprintf_escaped( msg, args );
82 va_end( args );
83 gtk_message_dialog_set_markup( GTK_MESSAGE_DIALOG(dialog), markup );
84 g_free(markup);
85 gtk_dialog_run(GTK_DIALOG(dialog));
86 gtk_widget_destroy(dialog);
87 return TRUE;
88 }
89 return FALSE;
90 }
92 void gui_update_io_activity( io_activity_type io, gboolean active )
93 {
95 }
97 void gtk_gui_show_debugger()
98 {
99 if( debug_win ) {
100 debug_window_show(debug_win, TRUE);
101 } else {
102 debug_win = debug_window_new();
103 }
104 }
106 GtkWidget *gtk_gui_get_renderarea()
107 {
108 return main_window_get_renderarea(main_win);
109 }
111 /**
112 * Hook called when DC starts running. Just disables the run/step buttons
113 * and enables the stop button.
114 */
115 void gtk_gui_start( void )
116 {
117 main_window_set_running( main_win, TRUE );
118 if( debug_win != NULL ) {
119 debug_window_set_running( debug_win, TRUE );
120 }
121 gtk_gui_nanos = 0;
122 gettimeofday(>k_gui_lasttv,NULL);
123 }
125 /**
126 * Hook called when DC stops running. Enables the run/step buttons
127 * and disables the stop button.
128 */
129 void gtk_gui_stop( void )
130 {
131 main_window_set_running( main_win, FALSE );
132 gtk_gui_update();
133 }
135 void gtk_gui_update( void )
136 {
137 if( debug_win ) {
138 debug_window_set_running( debug_win, FALSE );
139 debug_window_update(debug_win);
140 }
141 if( mmio_win ) {
142 mmio_win_update(mmio_win);
143 }
144 dump_win_update_all();
145 }
147 /**
148 * Module run-slice. Because UI processing is fairly expensive, only
149 * run the processing about 10 times a second while we're emulating.
150 */
151 uint32_t gtk_gui_run_slice( uint32_t nanosecs )
152 {
153 gtk_gui_nanos += nanosecs;
154 if( gtk_gui_nanos > 100000000 ) {
155 struct timeval tv;
156 while( gtk_events_pending() )
157 gtk_main_iteration();
159 gettimeofday(&tv,NULL);
160 double ns = ((tv.tv_sec - gtk_gui_lasttv.tv_sec) * 1000000000.0) +
161 ((tv.tv_usec - gtk_gui_lasttv.tv_usec)*1000.0);
162 double speed = (float)( (double)gtk_gui_nanos * 100.0 / ns );
163 gtk_gui_lasttv.tv_sec = tv.tv_sec;
164 gtk_gui_lasttv.tv_usec = tv.tv_usec;
165 main_window_set_speed( main_win, speed );
166 gtk_gui_nanos = 0;
167 }
168 return nanosecs;
169 }
172 PangoFontDescription *gui_fixed_font;
173 GdkColor gui_colour_normal, gui_colour_changed, gui_colour_error;
174 GdkColor gui_colour_warn, gui_colour_pc, gui_colour_debug;
175 GdkColor gui_colour_trace, gui_colour_break, gui_colour_temp_break;
176 GdkColor gui_colour_white;
178 void gtk_gui_alloc_resources() {
179 GdkColormap *map;
181 gui_colour_normal.red = gui_colour_normal.green = gui_colour_normal.blue = 0;
182 gui_colour_changed.red = gui_colour_changed.green = 64*256;
183 gui_colour_changed.blue = 154*256;
184 gui_colour_error.red = 65535;
185 gui_colour_error.green = gui_colour_error.blue = 64*256;
186 gui_colour_pc.red = 32*256;
187 gui_colour_pc.green = 170*256;
188 gui_colour_pc.blue = 52*256;
189 gui_colour_warn = gui_colour_changed;
190 gui_colour_trace.red = 156*256;
191 gui_colour_trace.green = 78*256;
192 gui_colour_trace.blue = 201*256;
193 gui_colour_debug = gui_colour_pc;
194 gui_colour_break.red = 65535;
195 gui_colour_break.green = gui_colour_break.blue = 192*256;
196 gui_colour_temp_break.red = gui_colour_temp_break.green = 128*256;
197 gui_colour_temp_break.blue = 32*256;
198 gui_colour_white.red = gui_colour_white.green = gui_colour_white.blue = 65535;
200 map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
201 gdk_colormap_alloc_color(map, &gui_colour_normal, TRUE, TRUE);
202 gdk_colormap_alloc_color(map, &gui_colour_changed, TRUE, TRUE);
203 gdk_colormap_alloc_color(map, &gui_colour_error, TRUE, TRUE);
204 gdk_colormap_alloc_color(map, &gui_colour_warn, TRUE, TRUE);
205 gdk_colormap_alloc_color(map, &gui_colour_pc, TRUE, TRUE);
206 gdk_colormap_alloc_color(map, &gui_colour_debug, TRUE, TRUE);
207 gdk_colormap_alloc_color(map, &gui_colour_trace, TRUE, TRUE);
208 gdk_colormap_alloc_color(map, &gui_colour_break, TRUE, TRUE);
209 gdk_colormap_alloc_color(map, &gui_colour_temp_break, TRUE, TRUE);
210 gdk_colormap_alloc_color(map, &gui_colour_white, TRUE, TRUE);
211 gui_fixed_font = pango_font_description_from_string("Courier 10");
212 }
.